Package org.jclouds.openstack.nova.v2_0.extensions

Examples of org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi


   }

   @Test
   public void testReturnsNullWhenNotFound() throws Exception {
      NovaApi api = createMock(NovaApi.class);
      FloatingIPApi ipApi = createMock(FloatingIPApi.class);

      expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();

      expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of()))
      .atLeastOnce();

      replay(api);
      replay(ipApi);
View Full Code Here


   }

   @Test
   public void testReturnsNullWhenNotAssigned() throws Exception {
      NovaApi api = createMock(NovaApi.class);
      FloatingIPApi ipApi = createMock(FloatingIPApi.class);

      expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();

      expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of(FloatingIP.builder().id("1").ip("1.1.1.1").build())))
      .atLeastOnce();

      replay(api);
      replay(ipApi);
View Full Code Here

   public AtomicReference<NodeMetadata> apply(AtomicReference<NodeAndNovaTemplateOptions> input) {
      checkState(nodeRunning.apply(input.get().getNodeMetadata()), "node never achieved state running %s", input.get().getNodeMetadata());
      NodeMetadata node = input.get().getNodeMetadata().get();
      // node's location is a host
      String regionId = node.getLocation().getParent().getId();
      FloatingIPApi floatingIpApi = novaApi.getFloatingIPApi(regionId).get();
      Optional<Set<String>> poolNames = input.get().getNovaTemplateOptions().get().getFloatingIpPoolNames();

      Optional<FloatingIP> ip = allocateFloatingIPForNode(floatingIpApi, poolNames, node.getId());
      if (!ip.isPresent()) {
         throw new InsufficientResourcesException("Failed to allocate a FloatingIP for node(" + node.getId() + ")");
      }
      logger.debug(">> adding floatingIp(%s) to node(%s)", ip.get().getIp(), node.getId());

      floatingIpApi.addToServer(ip.get().getIp(), node.getProviderId());
      input.get().getNodeMetadata().set(NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip.get().getIp())).build());
      floatingIpCache.invalidate(RegionAndId.fromSlashEncoded(node.getId()));
      return input.get().getNodeMetadata();
   }
View Full Code Here

      this.floatingIpCache = checkNotNull(floatingIpCache, "floatingIpCache");
   }

   @Override
   public RegionAndId apply(RegionAndId id) {
      FloatingIPApi floatingIpApi = novaApi.getFloatingIPApi(id.getRegion()).get();
      for (FloatingIP ip : floatingIpCache.getUnchecked(id)) {
         logger.debug(">> removing floatingIp(%s) from node(%s)", ip, id);
         floatingIpApi.removeFromServer(ip.getIp(), id.getId());
         logger.debug(">> deallocating floatingIp(%s)", ip);
         floatingIpApi.delete(ip.getId());
      }
      floatingIpCache.invalidate(id);
      return id;
   }
View Full Code Here

public class LoadFloatingIpsForInstanceTest {

   @Test
   public void testReturnsPublicIpOnMatch() throws Exception {
      NovaApi api = createMock(NovaApi.class);
      FloatingIPApi ipApi = createMock(FloatingIPApi.class);
      FloatingIP testIp = FloatingIP.builder().id("1").ip("1.1.1.1").fixedIp("10.1.1.1").instanceId("i-blah").build();

      expect(api.getFloatingIPApi("RegionOne")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
      expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of(testIp)))
               .atLeastOnce();

      replay(api);
      replay(ipApi);
View Full Code Here

   }

   @Test
   public void testReturnsNullWhenNotFound() throws Exception {
      NovaApi api = createMock(NovaApi.class);
      FloatingIPApi ipApi = createMock(FloatingIPApi.class);

      expect(api.getFloatingIPApi("region")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();

      expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of()))
      .atLeastOnce();

      replay(api);
      replay(ipApi);
View Full Code Here

   }

   @Test
   public void testReturnsNullWhenNotAssigned() throws Exception {
      NovaApi api = createMock(NovaApi.class);
      FloatingIPApi ipApi = createMock(FloatingIPApi.class);

      expect(api.getFloatingIPApi("region")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();

      expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of(FloatingIP.builder().id("1").ip("1.1.1.1").build())))
      .atLeastOnce();

      replay(api);
      replay(ipApi);
View Full Code Here

      ImageApi imageApi = api.getImageApiForZone(zoneId);
      return Iterables.getLast(imageApi.list().concat()).getId();
   }

   protected String flavorRefForZone(String zoneId) {
      FlavorApi flavorApi = api.getFlavorApiForZone(zoneId);
      return DEFAULT_FLAVOR_ORDERING.min(flavorApi.listInDetail().concat()).getId();
   }
View Full Code Here

         }
      }
   }
  
   protected String imageIdForZone(String zoneId) {
      ImageApi imageApi = api.getImageApiForZone(zoneId);
      return Iterables.getLast(imageApi.list().concat()).getId();
   }
View Full Code Here

   @Override
   public void setup() {
      super.setup();
      zones = api.getConfiguredZones();
      for (String zone : zones){
         ServerApi serverApi = api.getServerApiForZone(zone);
         for (Resource server : serverApi.list().concat()){
            if (server.getName().equals(hostName))
               serverApi.delete(server.getId());
         }
      }
   }
View Full Code Here

TOP

Related Classes of org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.