当前位置: 首页>>代码示例>>Java>>正文


Java Instance.getNetworkInterfaces方法代码示例

本文整理汇总了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);
    }
  }
}
 
开发者ID:cloudera,项目名称:director-google-plugin,代码行数:23,代码来源:GoogleComputeInstance.java

示例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;
}
 
开发者ID:cloudera,项目名称:director-google-plugin,代码行数:11,代码来源:GoogleComputeInstance.java

示例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();
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:44,代码来源:InstanceToMachine.java


注:本文中的com.google.api.services.compute.model.Instance.getNetworkInterfaces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。