Examples of FloatingIPApi


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

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.getFloatingIPExtensionForZone("Zone")).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

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

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

   }

   @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

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

        .getContext();

    NovaApi novaClient = context.unwrap(NovaApiMetadata.CONTEXT_TOKEN).getApi();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);

    FloatingIPApi floatingIp = novaClient.getFloatingIPExtensionForZone(
        region).get();

    String ip = null;
    // first try to find an unassigned IP.
    ArrayList<FloatingIP> unassignedIps = Lists.newArrayList(Iterables
        .filter(floatingIp.list(),
            new Predicate<FloatingIP>() {

              @Override
              public boolean apply(FloatingIP arg0) {
                // FIXME is this the correct filter?
                return arg0.getFixedIp() == null;
              }

            }));

    if (!unassignedIps.isEmpty()) {
      // try to prevent multiple parallel launches from choosing the same
      // ip.
      Collections.shuffle(unassignedIps);
      ip = Iterables.getLast(unassignedIps).getIp();
    }

    // if no unassigned IP is available, we'll try to allocate an IP.
    if (ip == null || ip.isEmpty()) {
      FloatingIP allocatedFloatingIP = floatingIp.create();
      if (allocatedFloatingIP == null) {
        String msg = "Failed to allocate an IP address.";
        log.error(msg);
        throw new CloudControllerException(msg);
      }
View Full Code Here

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

        .getContext();

    NovaApi novaApi = context.unwrap(NovaApiMetadata.CONTEXT_TOKEN).getApi();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);

    FloatingIPApi floatingIPApi = novaApi
        .getFloatingIPExtensionForZone(region).get();

    for (FloatingIP floatingIP : floatingIPApi.list()) {
      if (floatingIP.getIp().equals(ip)) {
        floatingIPApi.delete(floatingIP.getId());
        break;
      }
    }

  }
View Full Code Here

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

        .getContext();

    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);

    RestContext<NovaApi, NovaAsyncApi> nova = context.unwrap();
    FloatingIPApi floatingIp = nova.getApi().getFloatingIPExtensionForZone(
        region).get();

    String ip = null;
    // first try to find an unassigned IP.
    ArrayList<FloatingIP> unassignedIps = Lists.newArrayList(Iterables
        .filter(floatingIp.list(),
            new Predicate<FloatingIP>() {

              @Override
              public boolean apply(FloatingIP arg0) {
                return arg0.getInstanceId() == null;
              }

            }));

    if (!unassignedIps.isEmpty()) {
      // try to prevent multiple parallel launches from choosing the same
      // ip.
      Collections.shuffle(unassignedIps);
      ip = Iterables.getLast(unassignedIps).getIp();
    }

    // if no unassigned IP is available, we'll try to allocate an IP.
    if (ip == null || ip.isEmpty()) {
      FloatingIP allocatedFloatingIP = floatingIp.create();
      if (allocatedFloatingIP == null) {
        String msg = "Failed to allocate an IP address.";
        log.error(msg);
        throw new CloudControllerException(msg);
      }
View Full Code Here

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

    @SuppressWarnings("deprecation")
        NovaApi novaClient = context.unwrap(NovaApiMetadata.CONTEXT_TOKEN).getApi();
    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);

    FloatingIPApi floatingIp = novaClient.getFloatingIPExtensionForZone(
        region).get();

    if(log.isDebugEnabled()) {
      log.debug("OpenstackNovaIaas:associatePredefinedAddress:floatingip:" + floatingIp);
    }
   
    // get the list of all unassigned IP.
    ArrayList<FloatingIP> unassignedIps = Lists.newArrayList(Iterables
        .filter(floatingIp.list(),
            new Predicate<FloatingIP>() {

              @Override
              public boolean apply(FloatingIP arg0) {
                // FIXME is this the correct filter?
View Full Code Here

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

    String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);

    @SuppressWarnings("deprecation")
    RestContext<NovaApi, NovaAsyncApi> nova = context.unwrap();
    @SuppressWarnings("deprecation")
    FloatingIPApi floatingIPApi = nova.getApi()
        .getFloatingIPExtensionForZone(region).get();

    for (FloatingIP floatingIP : floatingIPApi.list()) {
      if (floatingIP.getIp().equals(ip)) {
        floatingIPApi.delete(floatingIP.getId());
        break;
      }
    }

  }
View Full Code Here

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

          + "not attempting to release floating IPs.", region);
      return;
    }
    // attempt to release any floating IP addresses associated with
    // server
    FloatingIPApi floatingIpApi = api.getFloatingIPExtensionForZone(region)
        .get();
    List<FloatingIP> floatingIps = newArrayList(floatingIpApi.list());
    for (FloatingIP floatingIP : floatingIps) {
      if (server.getId().equals(floatingIP.getInstanceId())) {
        LOG.debug("releasing floating IP {} from '{}'",
            floatingIP.getIp(), server.getName());
        floatingIpApi.removeFromServer(floatingIP.getIp(),
            server.getId());
        floatingIpApi.delete(floatingIP.getId());
      }
    }
  }
View Full Code Here

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

    ServerApi serverApi = api.getServerApiForZone(getAccount().getRegion());
    // server must have a private IP address before a floating IP can be
    // assigned
    waitForPrivateIpAddress(serverApi, server);

    FloatingIPApi floatingIPApi = api.getFloatingIPExtensionForZone(
        getAccount().getRegion()).get();
    List<FloatingIP> floatingIps = newArrayList(floatingIPApi.list());
    List<FloatingIP> freeFloatingIps = getFreeFloatingIps(floatingIps);
    if (freeFloatingIps.isEmpty()) {
      freeFloatingIps.add(floatingIPApi.create());
    }
    if (freeFloatingIps.isEmpty()) {
      throw new FloatingIpAddressException(
          "no floating IP address(es) available");
    }
    FloatingIP ipToAllocate = Iterables.getLast(freeFloatingIps);
    String ip = ipToAllocate.getIp();
    LOG.debug("assigning floating ip {} to server {}", ip, server.getId());
    floatingIPApi.addToServer(ip, server.getId());
    return ip;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.