本文整理汇总了Java中com.amazonaws.services.ec2.model.Instance.getPrivateIpAddress方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.getPrivateIpAddress方法的具体用法?Java Instance.getPrivateIpAddress怎么用?Java Instance.getPrivateIpAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.ec2.model.Instance
的用法示例。
在下文中一共展示了Instance.getPrivateIpAddress方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
/**
* Converts the ec2 instance to a turbine instance.
* @param ec2 EC2 instance.
* @return Turbine instance.
*/
public com.netflix.turbine.discovery.Instance convert(final Instance ec2) {
final boolean state = InstanceStateName.fromValue(
ec2.getState().getName()
) == InstanceStateName.Running;
return new com.netflix.turbine.discovery.Instance(
ec2.getPrivateIpAddress(), this.cluster, state
);
}
示例2: getPrivateIpAddress
import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
/**
* Returns the private IP address of the specified EC2 instance.
*
* @param instance the instance
* @return the private IP address of the specified EC2 instance
* @throws IllegalArgumentException if the instance does not have a valid private IP address
*/
private static InetAddress getPrivateIpAddress(Instance instance) {
Preconditions.checkNotNull(instance, "instance is null");
InetAddress privateIpAddress = null;
try {
String privateIpString = instance.getPrivateIpAddress();
if (privateIpString != null && !privateIpString.isEmpty()) {
privateIpAddress = InetAddress.getByName(privateIpString);
}
} catch (UnknownHostException e) {
throw new IllegalArgumentException("Invalid private IP address", e);
}
return privateIpAddress;
}
示例3: getPreferredHostName
import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
private String getPreferredHostName(Instance instance) {
if (preferPrivateIpHostnames) {
return instance.getPrivateIpAddress();
}
return instance.getPublicDnsName();
}
示例4: getEC2HostAddress
import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
private String getEC2HostAddress(EC2Computer computer, Instance inst) {
if (computer.getNode().usePrivateDnsName) {
return inst.getPrivateDnsName();
} else {
String host = inst.getPublicDnsName();
// If we fail to get a public DNS name, use the private IP.
if (host == null || host.equals("")) {
host = inst.getPrivateIpAddress();
}
return host;
}
}
示例5: addNewSlave
import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
private void addNewSlave(final AmazonEC2 ec2, final String instanceId) throws Exception {
// Generate a random FS root if one isn't specified
String fsRoot = this.fsRoot;
if (fsRoot == null || fsRoot.equals("")) {
fsRoot = "/tmp/jenkins-"+UUID.randomUUID().toString().substring(0, 8);
}
final DescribeInstancesResult result=ec2.describeInstances(
new DescribeInstancesRequest().withInstanceIds(instanceId));
if (result.getReservations().isEmpty()) //Can't find this instance, skip it
return;
final Instance instance=result.getReservations().get(0).getInstances().get(0);
final String address = isPrivateIpUsed() ?
instance.getPrivateIpAddress() : instance.getPublicIpAddress();
// Check if we have the address to use. Nodes don't get it immediately.
if (address == null)
return; // Wait some more...
final FleetNode slave = new FleetNode(instanceId, "Fleet slave for" + instanceId,
fsRoot, this.numExecutors.toString(), Node.Mode.NORMAL, this.labelString, new ArrayList<NodeProperty<?>>(),
FLEET_CLOUD_ID, computerConnector.launch(address, TaskListener.NULL));
// Initialize our retention strategy
if (getIdleMinutes() != null)
slave.setRetentionStrategy(new IdleRetentionStrategy(getIdleMinutes(), this));
final Jenkins jenkins=Jenkins.getInstance();
//noinspection SynchronizationOnLocalVariableOrMethodParameter
synchronized (jenkins) {
// Try to avoid duplicate nodes
final Node n = jenkins.getNode(instanceId);
if (n != null)
jenkins.removeNode(n);
jenkins.addNode(slave);
}
//A new node, wheee!
instancesSeen.add(instanceId);
if (!plannedNodes.isEmpty())
{
//If we're waiting for a new node - mark it as ready
final NodeProvisioner.PlannedNode curNode=plannedNodes.iterator().next();
plannedNodes.remove(curNode);
((SettableFuture<Node>)curNode.future).set(slave);
}
}
示例6: getPropertyValue
import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
@Override
protected String getPropertyValue(Instance instance) {
return instance.getPrivateIpAddress();
}
示例7: connectToWinRM
import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
private WinConnection connectToWinRM(EC2Computer computer, PrintStream logger) throws AmazonClientException,
InterruptedException {
final long timeout = computer.getNode().getLaunchTimeoutInMillis();
final long startTime = System.currentTimeMillis();
logger.println(computer.getNode().getDisplayName() + " booted at " + computer.getNode().getCreatedTime());
boolean alreadyBooted = (startTime - computer.getNode().getCreatedTime()) > TimeUnit.MINUTES.toMillis(3);
while (true) {
try {
long waitTime = System.currentTimeMillis() - startTime;
if (waitTime > timeout) {
throw new AmazonClientException("Timed out after " + (waitTime / 1000)
+ " seconds of waiting for winrm to be connected");
}
Instance instance = computer.updateInstanceDescription();
String vpc_id = instance.getVpcId();
String ip, host;
if (computer.getNode().usePrivateDnsName) {
host = instance.getPrivateDnsName();
ip = instance.getPrivateIpAddress(); // SmbFile doesn't quite work with hostnames
} else {
host = instance.getPublicDnsName();
if (host == null || host.equals("")) {
host = instance.getPrivateDnsName();
ip = instance.getPrivateIpAddress(); // SmbFile doesn't quite work with hostnames
}
else {
host = instance.getPublicDnsName();
ip = instance.getPublicIpAddress(); // SmbFile doesn't quite work with hostnames
}
}
if ("0.0.0.0".equals(host)) {
logger.println("Invalid host 0.0.0.0, your host is most likely waiting for an ip address.");
throw new IOException("goto sleep");
}
logger.println("Connecting to " + host + "(" + ip + ") with WinRM as " + computer.getNode().remoteAdmin);
WinConnection connection = new WinConnection(ip, computer.getNode().remoteAdmin, computer.getNode().getAdminPassword());
connection.setUseHTTPS(computer.getNode().isUseHTTPS());
if (!connection.ping()) {
logger.println("Waiting for WinRM to come up. Sleeping 10s.");
Thread.sleep(sleepBetweenAttemps);
continue;
}
if (!alreadyBooted || computer.getNode().stopOnTerminate) {
logger.println("WinRM service responded. Waiting for WinRM service to stabilize on " + computer.getNode().getDisplayName());
Thread.sleep(computer.getNode().getBootDelay());
alreadyBooted = true;
logger.println("WinRM should now be ok on " + computer.getNode().getDisplayName());
if (!connection.ping()) {
logger.println("WinRM not yet up. Sleeping 10s.");
Thread.sleep(sleepBetweenAttemps);
continue;
}
}
logger.println("Connected with WinRM.");
return connection; // successfully connected
} catch (IOException e) {
logger.println("Waiting for WinRM to come up. Sleeping 10s.");
Thread.sleep(sleepBetweenAttemps);
}
}
}
示例8: hostName
import com.amazonaws.services.ec2.model.Instance; //导入方法依赖的package包/类
private String hostName(Instance instance) {
String publicDNS = instance.getPublicDnsName();
return Strings.notEmpty(publicDNS) ? publicDNS : instance.getPrivateIpAddress();
}