private static String getTaskRunnerId() { return EC2MetadataUtils.getNetworkInterfaces().get(0).getPublicIPv4s().get(0); }
/** * Get the list of network interfaces on the instance. */ public static List<NetworkInterface> getNetworkInterfaces() { List<NetworkInterface> networkInterfaces = new LinkedList<NetworkInterface>(); List<String> macs = getItems(EC2_METADATA_ROOT + "/network/interfaces/macs/"); if (macs != null) { for (String mac : macs) { String key = mac.trim(); if (key.endsWith("/")) { key = key.substring(0, key.length() - 1); } networkInterfaces.add(new NetworkInterface(key)); } } return networkInterfaces; }
/** * Get the list of network interfaces on the instance. */ public static List<NetworkInterface> getNetworkInterfaces() { List<NetworkInterface> networkInterfaces = new LinkedList<NetworkInterface>(); List<String> macs = getItems(EC2_METADATA_ROOT + "/network/interfaces/macs/"); if (macs != null) { for (String mac : macs) { String key = mac.trim(); if (key.endsWith("/")) { key = key.substring(0, key.length() - 1); } networkInterfaces.add(new NetworkInterface(key)); } } return networkInterfaces; }
private static Optional<String> findVpc() { try { Optional<String> maybeManuallySet = Optional.fromNullable(System.getenv("VPC_ID")); if (maybeManuallySet.isPresent()) { return maybeManuallySet; } List<EC2MetadataUtils.NetworkInterface> networkInterfaces = EC2MetadataUtils.getNetworkInterfaces(); if (EC2MetadataUtils.getNetworkInterfaces().isEmpty()) { return Optional.absent(); } else { return Optional.fromNullable(networkInterfaces.get(0).getVpcId()); } } catch (Exception e) { return Optional.absent(); } }
private static String getTaskRunnerId() { return EC2MetadataUtils.getNetworkInterfaces().get(0).getPublicIPv4s().get(0); }
private static String getTaskRunnerId() { return EC2MetadataUtils.getNetworkInterfaces().get(0).getPublicIPv4s().get(0); }
private static Optional<String> findSubnet() { try { List<EC2MetadataUtils.NetworkInterface> networkInterfaces = EC2MetadataUtils.getNetworkInterfaces(); if (EC2MetadataUtils.getNetworkInterfaces().isEmpty()) { return Optional.absent(); } else { return Optional.fromNullable(networkInterfaces.get(0).getSubnetId()); } } catch (Exception e) { return Optional.absent(); } }
/** * The CIDR block of the Amazon EC2-VPC in which the interface * resides.<br> * Returned only for Amazon EC2 instances launched into a VPC. */ public String getVpcIPv4CidrBlock() { return getData("vpc-ipv4-cidr-block"); }
/** * ID of the subnet in which the interface resides.<br> * Returned only for Amazon EC2 instances launched into a VPC. */ public String getSubnetId() { return getData("subnet-id"); }
/** * The interface's public hostname. */ public String getPublicHostname() { return getData("public-hostname"); }
/** * The elastic IP addresses associated with the interface.<br> * There may be multiple IP addresses on an instance. */ public List<String> getPublicIPv4s() { return getItems("public-ipv4s"); }
@Override public String getPublicIpAddress() { for (EC2MetadataUtils.NetworkInterface net : EC2MetadataUtils.getNetworkInterfaces()) { List<String> ips = net.getPublicIPv4s(); if (ips != null && ips.size() > 0) { return ips.get(0); } } return null; } };
/** * IDs of the security groups to which the network interface belongs. * Returned only for Amazon EC2 instances launched into a VPC. */ public List<String> getSecurityGroupIds() { return getItems("security-group-ids"); }
/** * Security groups to which the network interface belongs. */ public List<String> getSecurityGroups() { return getItems("security-groups"); }
/** * ID of the Amazon EC2-VPC in which the interface resides.<br> * Returned only for Amazon EC2 instances launched into a VPC. */ public String getVpcId() { return getData("vpc-id"); }
/** * The CIDR block of the Amazon EC2-VPC subnet in which the interface * resides.<br> * Returned only for Amazon EC2 instances launched into a VPC. */ public String getSubnetIPv4CidrBlock() { return getData("subnet-ipv4-cidr-block"); }
/** * The interface's local hostname. */ public String getHostname() { return getData("local-hostname"); }
/** * The ID of the owner of the network interface.<br> * In multiple-interface environments, an interface can be attached by a * third party, such as Elastic Load Balancing. Traffic on an interface * is always billed to the interface owner. */ public String getOwnerId() { return getData("owner-id"); }
/** * The private IP addresses associated with the interface. */ public List<String> getLocalIPv4s() { return getItems("local-ipv4s"); }
/** * The interface's profile. */ public String getProfile() { return getData("profile"); }