Java Code Examples for org.jclouds.compute.domain.NodeMetadata#getProviderId()
The following examples show how to use
org.jclouds.compute.domain.NodeMetadata#getProviderId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CloudDistributedTLCJob.java From tlaplus with MIT License | 4 votes |
public WrapperNodeMetadata(final NodeMetadata m, final LoginCredentials credentials) { super(m.getProviderId(), m.getName(), m.getId(), m.getLocation(), m.getUri(), m.getUserMetadata(), m.getTags(), m.getGroup(), m.getHardware(), m.getImageId(), m.getOperatingSystem(), m.getStatus(), m.getBackendStatus(), m.getLoginPort(), m.getPublicAddresses(), m.getPrivateAddresses(), credentials, m.getHostname()); }
Example 2
Source File: CloudStackIaas.java From attic-stratos with Apache License 2.0 | 4 votes |
/** * IMPORTANT * In cloudstack we can assign public IPs, if we are using an advanced zone only. If we are using a basic zone * we cannot assign public ips. * <p/> * When we use an advanced zone, a public IP address will get automatically assigned to the vm. So we don't need * to find an unallocated IP address and assign that address to the vm. If you are using a basic zone you cannot * assign public IPs * <p/> * So this method will find the IP that has been assigned to the vm and return it. */ @Override public List<String> associateAddresses(NodeMetadata node) { IaasProvider iaasInfo = getIaasProvider(); ComputeServiceContext context = iaasInfo.getComputeService().getContext(); CloudStackApi cloudStackApi = context.unwrapApi(CloudStackApi.class); String ip = null; // get all allocated IPs ListPublicIPAddressesOptions listPublicIPAddressesOptions = new ListPublicIPAddressesOptions(); listPublicIPAddressesOptions.zoneId(iaasInfo.getProperty(CloudControllerConstants.AVAILABILITY_ZONE)); Set<PublicIPAddress> publicIPAddresses = cloudStackApi.getAddressApi() .listPublicIPAddresses(listPublicIPAddressesOptions); String id = node.getProviderId(); //vm ID for (PublicIPAddress publicIPAddress : publicIPAddresses) { if (publicIPAddress.getVirtualMachineId().equals(id)) { //check whether this instance has // already got an public ip or not ip = publicIPAddress.getIPAddress(); //A public ip has been successfully assigned to the vm log.info("Successfully associated an IP address " + ip + " for node with id: " + node.getId()); break; } } if (ip == null || ip.isEmpty()) { //IP has not been successfully assigned to VM(That means there are // no more IPs available for the VM) String msg = "No address associated for node with id: " + node.getId(); log.warn(msg); throw new CloudControllerException(msg); } List<String> associatedIPs = new ArrayList<String>(); associatedIPs.add(ip); return associatedIPs; }
Example 3
Source File: EC2Iaas.java From attic-stratos with Apache License 2.0 | 4 votes |
@Override public synchronized List<String> associateAddresses(NodeMetadata node) { IaasProvider iaasInfo = getIaasProvider(); ComputeServiceContext context = iaasInfo.getComputeService().getContext(); ElasticIPAddressApi elasticIPAddressApi = context.unwrapApi(AWSEC2Api.class).getElasticIPAddressApi().get(); String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo); String ip = null; // first try to find an unassigned IP. ArrayList<PublicIpInstanceIdPair> unassignedIps = Lists.newArrayList(Iterables .filter(elasticIPAddressApi.describeAddressesInRegion(region), new Predicate<PublicIpInstanceIdPair>() { @Override public boolean apply(PublicIpInstanceIdPair 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).getPublicIp(); } // if no unassigned IP is available, we'll try to allocate an IP. if (ip == null || ip.isEmpty()) { try { ip = elasticIPAddressApi.allocateAddressInRegion(region); log.info("Allocated ip [" + ip + "]"); } catch (Exception e) { String msg = "Failed to allocate an IP address. All IP addresses are in use."; log.error(msg, e); throw new CloudControllerException(msg, e); } } String id = node.getProviderId(); // wait till the fixed IP address gets assigned - this is needed before // we associate a // public IP while (node.getPrivateAddresses() == null) { CloudControllerUtil.sleep(1000); } int retries = 0; while (retries < 12 && !associatePublicIp(elasticIPAddressApi, region, ip, id)) { // wait for 5s CloudControllerUtil.sleep(5000); retries++; } log.debug("Successfully associated an IP address " + ip + " for node with id: " + node.getId()); List<String> associatedIPs = new ArrayList<String>(); associatedIPs.add(ip); return associatedIPs; }