当前位置: 首页>>代码示例>>Java>>正文


Java FloatingIP类代码示例

本文整理汇总了Java中org.openstack4j.model.compute.FloatingIP的典型用法代码示例。如果您正苦于以下问题:Java FloatingIP类的具体用法?Java FloatingIP怎么用?Java FloatingIP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FloatingIP类属于org.openstack4j.model.compute包,在下文中一共展示了FloatingIP类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: build

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
@Override
public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image,
        List<CloudResource> buildableResource, Map<String, String> tags) throws Exception {
    CloudResource resource = buildableResource.get(0);
    try {
        String publicNetId = context.getStringParameter(OpenStackConstants.PUBLIC_NET_ID);
        if (publicNetId != null) {
            OSClient osClient = createOSClient(auth);
            List<CloudResource> computeResources = context.getComputeResources(privateId);
            CloudResource instance = getInstance(computeResources);
            FloatingIP unusedIp = osClient.compute().floatingIps().allocateIP(publicNetId);
            ActionResponse response = osClient.compute().floatingIps().addFloatingIP(instance.getParameter(OpenStackConstants.SERVER, Server.class),
                    unusedIp.getFloatingIpAddress());
            if (!response.isSuccess()) {
                throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(),
                        auth.getCloudContext().getId(), response.getFault());
            }
            return Collections.singletonList(createPersistedResource(resource, group.getName(), unusedIp.getId()));
        }
        return Collections.emptyList();
    } catch (OS4JException ex) {
        throw new OpenStackResourceException("Add floating-ip to server failed", resourceType(), resource.getName(), ex);
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:25,代码来源:OpenStackFloatingIPBuilder.java

示例2: printFloatingIpDetails

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
public static void printFloatingIpDetails(List<? extends FloatingIP> ips){
    TableBuilder tb=getTableBuilder("Floating");
    for (final FloatingIP ip : ips) {
        addFloatingIpRow(tb, ip);
    }
    System.out.println(tb.toString());
    System.out.println("TOTAL RECORDS: "+tb.totalrecords());
}
 
开发者ID:vinodborole,项目名称:openstack4j-shell,代码行数:9,代码来源:NeutronAPI.java

示例3: allocateFromPool

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
private FloatingIP allocateFromPool(ComputeFloatingIPService computeFloatingIPService,
    String virtualMachineId) {
  final Optional<String> floatingIpPool = floatingIpPoolStrategy.apply(virtualMachineId);
  if (floatingIpPool.isPresent()) {
    return computeFloatingIPService.allocateIP(floatingIpPool.get());
  }
  throw new IllegalStateException(String.format(
      "Need to allocate floatingIp but pool could not be resolved. Try to configure %s.",
      Openstack4JConstants.FLOATING_IP_POOL_PROPERTY));
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:11,代码来源:Openstack4JPublicIpExtension.java

示例4: findPublicIp

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
private String findPublicIp(ComputeFloatingIPService computeFloatingIPService,
    String virtualMachineId) {

  final Optional<? extends FloatingIP> any = computeFloatingIPService.list().stream()
      .filter((Predicate<FloatingIP>) floatingIP -> floatingIP.getInstanceId() == null)
      .findAny();

  if (!any.isPresent()) {
    //no floating ip is present, allocate one from the pool.
    return allocateFromPool(computeFloatingIPService, virtualMachineId)
        .getFloatingIpAddress();
  }
  return any.get().getFloatingIpAddress();
}
 
开发者ID:cloudiator,项目名称:sword,代码行数:15,代码来源:Openstack4JPublicIpExtension.java

示例5: releaseFloatingIps

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
/**
 * Releases any floating IP addresses associated with a {@link Server}.
 *
 * @param api
 *            An OpenStack API client.
 * @param server
 *            The server for which to release any assigned floating IP
 *            address(es).
 */
private void releaseFloatingIps(OSClient api, Server server) {
    LOG.debug("releasing floating IP addresses associated with {}", server.getName());
    ComputeFloatingIPService floatingIpApi = api.compute().floatingIps();
    Map<String, FloatingIP> tenantFloatingIps = tenantFloatingIps(floatingIpApi);
    Collection<String> serverIps = serverIps(server);
    for (String serverIp : serverIps) {
        if (tenantFloatingIps.containsKey(serverIp)) {
            FloatingIP floatingIp = tenantFloatingIps.get(serverIp);
            LOG.debug("releasing floating IP {} from '{}'", floatingIp.getFloatingIpAddress(), server.getName());
            floatingIpApi.removeFloatingIP(server, floatingIp.getFloatingIpAddress());
            floatingIpApi.deallocateIP(floatingIp.getId());
        }
    }
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:24,代码来源:DeleteServerRequest.java

示例6: tenantFloatingIps

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
/**
 * Returns all floating IP addresses allocated to the tenant.
 *
 * @param floatingIpApi
 * @return A {@link Map} of floating IP addresses, where keys are IP
 *         addresses and values are {@link FloatingIP} objects.
 */
private Map<String, FloatingIP> tenantFloatingIps(ComputeFloatingIPService floatingIpApi) {
    Map<String, FloatingIP> ipToFloatingIp = new HashMap<>();
    List<? extends FloatingIP> floatingIps = floatingIpApi.list();
    for (FloatingIP floatingIP : floatingIps) {
        ipToFloatingIp.put(floatingIP.getFloatingIpAddress(), floatingIP);
    }
    return ipToFloatingIp;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:16,代码来源:DeleteServerRequest.java

示例7: assignFloatingIp

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
private String assignFloatingIp(OSClient api, Server server) throws ResponseException, NotFoundException {
    LOG.debug("assigning a floating IP address to {} ...", server.getId());
    // It appears as though a server must have a private IP address before a
    // floating IP can be assigned
    waitForPrivateIpAddress(api, server.getId());

    ComputeFloatingIPService floatingIpApi = api.compute().floatingIps();
    FloatingIP floatingIp = acquireFloatingIp(floatingIpApi);
    String ipAddress = floatingIp.getFloatingIpAddress();
    LOG.debug("assigning floating IP {} to server {}", ipAddress, server.getId());
    floatingIpApi.addFloatingIP(server, ipAddress);
    return ipAddress;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:14,代码来源:AssignFloatingIpRequest.java

示例8: acquireFloatingIp

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
/**
 * Tries to allocate a free floating IP address. Throws a
 * {@link CloudPoolDriverException} on failure to do so.
 *
 * @param floatingIpApi
 * @return
 * @throws NotFoundException
 *             on failure to allocate a floating IP
 * @throws ResponseException
 *             On communication errors.
 */
private FloatingIP acquireFloatingIp(ComputeFloatingIPService floatingIpApi)
        throws ResponseException, NotFoundException {
    for (String floatingIpPool : floatingIpApi.getPoolNames()) {
        LOG.debug("checking floating IP pool {}", floatingIpPool);
        try {
            LOG.debug("trying to allocate a floating IP from floating IP pool {}", floatingIpPool);
            return floatingIpApi.allocateIP(floatingIpPool);
        } catch (Exception e) {
            LOG.debug("failed to allocate floating IP from {}: {}", floatingIpPool, e.getMessage());
        }
    }
    throw new NotFoundException("failed to allocate floating IP address for server");
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:25,代码来源:AssignFloatingIpRequest.java

示例9: deleteServer

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
@Override
public void deleteServer(String serverId) {
	try {

		Server server = this.getServer(serverId);

		// Get Floating IP if there is one associated.
		String floatingIpAddr = null;
		for(Address novaAddress : server.getAddresses().getAddresses().get(properties.getProperty(Constants.OS_NETWORK_NAME))) {
			novaAddress = (NovaAddress) novaAddress;
			if(novaAddress.getType().equals(IPType.FLOATING.toString())) {
				floatingIpAddr = novaAddress.getAddr();
				break;
			}
		}

		if(server != null) {
			os.compute().servers().delete(serverId);

			// Deallocating Floating IP.
			if(floatingIpAddr != null) {
				for(FloatingIP floatIp : os.compute().floatingIps().list()) {
					if(floatIp.getFloatingIpAddress().equals(floatingIpAddr)) {
						os.compute().floatingIps().deallocateIP(floatIp.getId());
					}
				}
			}

			logger.info("Server deleted successfully for ID: " + serverId);
		}

	}
	catch( Exception ex ) {
		ex.printStackTrace();
		// TODO: Check with the team on how to handle exceptions.
		logger.error("Failed to delete server with ID: " + serverId);
	}
}
 
开发者ID:apache,项目名称:airavata,代码行数:39,代码来源:OpenstackIntfImpl.java

示例10: isFloatingIPUsed

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
public static Boolean isFloatingIPUsed(FloatingIP floatIp) {

		try {

			Boolean isUsed = floatIp.getInstanceId() != null;

			return isUsed;

		} catch( Exception ex ) {
			ex.printStackTrace();
			// TODO: Check with the team on how to handle exceptions.
			logger.error("Failed to check if the Floating IP " + floatIp.getFloatingIpAddress() + "is used.");
			return null;
		}
	}
 
开发者ID:apache,项目名称:airavata,代码行数:16,代码来源:OpenstackIntfUtil.java

示例11: listfloatingIps

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
public static void listfloatingIps() throws Exception {
    OSClient os=Osp4jSession.getOspSession();
    final List<? extends FloatingIP> ips = os.compute().floatingIps().list();
    printFloatingIpDetails(ips);
}
 
开发者ID:vinodborole,项目名称:openstack4j-shell,代码行数:6,代码来源:NeutronAPI.java

示例12: addFloatingIpRow

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
private static void addFloatingIpRow(TableBuilder tb, FloatingIP ip){
    tb.addRow(ip.getId(),ip.getFixedIpAddress(),ip.getFloatingIpAddress(),ip.getInstanceId(),ip.getPool());
}
 
开发者ID:vinodborole,项目名称:openstack4j-shell,代码行数:4,代码来源:NeutronAPI.java

示例13: addFloatingIP

import org.openstack4j.model.compute.FloatingIP; //导入依赖的package包/类
@Override
public void addFloatingIP(String serverId) {

	try {
		Server server = this.getServer(serverId);

		// Floating IP to allocate.
		FloatingIP floatIp = null;

		if(server != null) {
			List<? extends FloatingIP> floatIPList = os.compute().floatingIps().list();

			// Iterate through the floating ips from the pool present if any.
			if(floatIPList.size() > 0) {
				for(FloatingIP ip : floatIPList) {
					logger.info("Checking if floating ip : " + ip.getFloatingIpAddress() + " is free to use.");
					Boolean isFloatingIpUsed = OpenstackIntfUtil.isFloatingIPUsed(ip);
					if( isFloatingIpUsed != null && !isFloatingIpUsed ) {
						floatIp = ip;
						logger.info("Floating ip " + ip.getFloatingIpAddress() + " found to be free.");
						break;
					}
				}
			}
			// If all floating IPs are used, or there are no free floating ips, create new one.
			if(floatIp == null){
				floatIp = os.compute().floatingIps().allocateIP(properties.getProperty(Constants.OS_FLOATING_IP_POOL));
				logger.info("Created new floating ip " + floatIp.getFloatingIpAddress());
			}

			if(floatIp != null) {
				String ipAddr = floatIp.getFloatingIpAddress();

				if(ipAddr != null) {
					ActionResponse response = os.compute().floatingIps().addFloatingIP(server, ipAddr);
					logger.info(response.isSuccess() + ":" + response.getCode() + ":" + response.getFault() + ":" + response.toString());

					if(response.isSuccess()) {
						logger.info("Floating IP "+ ipAddr + " assigned successfully to server with ID: " + serverId);
					}
					else {
						logger.error("Failed to associate Floating IP.");
					}
				}
			}

		}
	}
	catch( Exception ex ) {
		ex.printStackTrace();
		// TODO: Check with the team on how to handle exceptions.
		logger.error("Failed to associate floating IP to server with ID: " + serverId);
	}
}
 
开发者ID:apache,项目名称:airavata,代码行数:55,代码来源:OpenstackIntfImpl.java


注:本文中的org.openstack4j.model.compute.FloatingIP类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。