本文整理汇总了Java中com.google.api.services.compute.model.Instance.getNetworkInterfaces方法的典型用法代码示例。如果您正苦于以下问题:Java Instance.getNetworkInterfaces方法的具体用法?Java Instance.getNetworkInterfaces怎么用?Java Instance.getNetworkInterfaces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.api.services.compute.model.Instance
的用法示例。
在下文中一共展示了Instance.getNetworkInterfaces方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPrivateIpAddress
import com.google.api.services.compute.model.Instance; //导入方法依赖的package包/类
/**
* Returns the private IP address of the specified Google instance.
*
* @param instance the instance
* @return the private IP address of the specified Google 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");
List<NetworkInterface> networkInterfaceList = instance.getNetworkInterfaces();
if (networkInterfaceList == null || networkInterfaceList.isEmpty()) {
throw new IllegalArgumentException("No network interfaces found for instance '" + instance.getName() + "'.");
} else {
try {
return InetAddress.getByName(networkInterfaceList.get(0).getNetworkIP());
} catch (UnknownHostException e) {
throw new IllegalArgumentException("Invalid private IP address", e);
}
}
}
示例2: getPropertyValue
import com.google.api.services.compute.model.Instance; //导入方法依赖的package包/类
@Override
protected String getPropertyValue(Instance instance, Disk bootDisk) {
List<NetworkInterface> networkInterfaceList = instance.getNetworkInterfaces();
if (networkInterfaceList != null && networkInterfaceList.size() > 0) {
return networkInterfaceList.get(0).getNetworkIP();
}
return null;
}
示例3: apply
import com.google.api.services.compute.model.Instance; //导入方法依赖的package包/类
@Override
public Machine apply(Instance instance) {
Builder builder = Machine.builder();
// instance URL is machine id: For example,
// https://www.googleapis.com/compute/v1/projects/<project>/zones/europe-west1-d/instances/webservers-d58p
builder.id(instance.getSelfLink());
builder.cloudProvider(CloudProviders.GCE);
builder.region(ZoneUtils.regionName(ZoneUtils.zoneName(instance.getZone())));
builder.machineSize(UrlUtils.basename(instance.getMachineType()));
builder.machineState(new InstanceStatusToMachineStatus().apply(instance.getStatus()));
builder.launchTime(UtcTime.parse(instance.getCreationTimestamp()));
// only one network interface per instance appears to be supported
List<NetworkInterface> networkInterfaces = instance.getNetworkInterfaces();
if (networkInterfaces != null && !networkInterfaces.isEmpty()) {
NetworkInterface networkInterface = networkInterfaces.get(0);
String privateIp = networkInterface.getNetworkIP();
if (privateIp != null) {
builder.privateIp(privateIp);
}
List<AccessConfig> accessConfigs = networkInterface.getAccessConfigs();
if (accessConfigs != null && !accessConfigs.isEmpty()) {
String publicIp = accessConfigs.get(0).getNatIP();
if (publicIp != null) {
builder.publicIp(publicIp);
}
}
}
ServiceState serviceState = extractServiceState(instance);
if (serviceState != null) {
builder.serviceState(serviceState);
}
MembershipStatus membershipStatus = extractMembershipStatus(instance);
if (membershipStatus != null) {
builder.membershipStatus(membershipStatus);
}
return builder.build();
}