@Override public String getPrivateIpAddress() { return EC2MetadataUtils.getPrivateIpAddress(); }
private static Optional<String> findPrivateIp() { try { return Optional.fromNullable(EC2MetadataUtils.getPrivateIpAddress()); } catch (Exception e) { return Optional.absent(); } }
/** This will attempt to retrieve metadata about the instance this code is running on. */ public void fetchMetadata() { HttpClient httpClient = HttpClients.createDefault(); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(1000).build(); HttpUriRequest get = RequestBuilder.get().setUri(EC2MetadataUtils.getHostAddressForEC2MetadataService()) .setConfig(requestConfig).build(); try { httpClient.execute(get); machineImage = EC2MetadataUtils.getAmiId(); instanceType = EC2MetadataUtils.getInstanceType(); instanceId = EC2MetadataUtils.getInstanceId(); // There is a method to get a Region object, but stick to strings for deserialization simplicity. region = EC2MetadataUtils.getEC2InstanceRegion(); // IP address fetching should really not be tied to EC2 but for now this lets us get a useable IP. privateIp = EC2MetadataUtils.getPrivateIpAddress(); //EC2MetadataUtils.getInstanceInfo(); } catch (IOException ex) { LOG.warn("Connection to metadata URL failed, probably not running on EC2."); } }
/** This will attempt to retrieve metadata about the instance this code is running on. */ public void fetchMetadata() { HttpClient httpClient = HttpClients.createDefault(); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(1000).build(); HttpUriRequest get = RequestBuilder.get().setUri(EC2MetadataUtils.getHostAddressForEC2MetadataService()) .setConfig(requestConfig).build(); try { httpClient.execute(get); machineImage = EC2MetadataUtils.getAmiId(); instanceType = EC2MetadataUtils.getInstanceType(); instanceId = EC2MetadataUtils.getInstanceId(); // There is a method to get a Region object, but stick to strings for deserialization simplicity. region = EC2MetadataUtils.getEC2InstanceRegion(); // IP address fetching should really not be tied to EC2 but for now this lets us get a useable IP. privateIp = EC2MetadataUtils.getPrivateIpAddress(); //EC2MetadataUtils.getInstanceInfo(); } catch (IOException ex) { LOG.warn("Connection to metadata URL failed, probably not running on EC2."); } }
if (deployConfig.isAwsEnabled()) { command.add("-cluster-host"); command.add(EC2MetadataUtils.getPrivateIpAddress());