static NetworkInterface fromPb( com.google.api.services.compute.model.NetworkInterface interfacePb) { Builder builder = newBuilder(NetworkId.fromUrl(interfacePb.getNetwork())).setName(interfacePb.getName()); if (interfacePb.getSubnetwork() != null) { builder.setSubnetwork(SubnetworkId.fromUrl(interfacePb.getSubnetwork())); } builder.setNetworkIp(interfacePb.getNetworkIP()); builder.setAccessConfigurations( interfacePb.getAccessConfigs() != null ? Lists.transform(interfacePb.getAccessConfigs(), AccessConfig.FROM_PB_FUNCTION) : ImmutableList.<AccessConfig>of()); return builder.build(); } }
static String getInstanceIp(AccountDeploymentDetails<GoogleAccount> details, String instanceName) { Compute compute = getCompute(details); Instance instance = null; try { instance = compute.instances().get(details.getAccount().getProject(), "us-central1-f", instanceName).execute(); } catch (IOException e) { throw new HalException(FATAL, "Unable to get instance " + instanceName); } return instance.getNetworkInterfaces() .stream() .map(i -> i.getAccessConfigs().stream() .map(AccessConfig::getNatIP) .filter(ip -> !StringUtils.isEmpty(ip)) .findFirst() ).filter(Optional::isPresent) .map(Optional::get) .findFirst() .orElseThrow(() -> new HalException(FATAL, "No public IP associated with" + instanceName)); }
static String getInstanceIp(AccountDeploymentDetails<GoogleAccount> details, String instanceName) { Compute compute = getCompute(details); Instance instance = null; try { instance = compute.instances().get(details.getAccount().getProject(), "us-central1-f", instanceName).execute(); } catch (IOException e) { throw new HalException(FATAL, "Unable to get instance " + instanceName); } return instance.getNetworkInterfaces() .stream() .map(i -> i.getAccessConfigs().stream() .map(AccessConfig::getNatIP) .filter(ip -> !StringUtils.isEmpty(ip)) .findFirst() ).filter(Optional::isPresent) .map(Optional::get) .findFirst() .orElseThrow(() -> new HalException(FATAL, "No public IP associated with" + instanceName)); }
String networkName = path.getFileName().toString(); if (network.equals(networkName)) { for (AccessConfig accessConfig : networkInterface.getAccessConfigs()) { if (accessConfig.getNatIP() != null) { properties.put("ip.external", accessConfig.getNatIP());
static NetworkInterface fromPb( com.google.api.services.compute.model.NetworkInterface interfacePb) { Builder builder = newBuilder(NetworkId.fromUrl(interfacePb.getNetwork())) .setName(interfacePb.getName()); if (interfacePb.getSubnetwork() != null) { builder.setSubnetwork(SubnetworkId.fromUrl(interfacePb.getSubnetwork())); } builder.setNetworkIp(interfacePb.getNetworkIP()); builder.setAccessConfigurations(interfacePb.getAccessConfigs() != null ? Lists.transform(interfacePb.getAccessConfigs(), AccessConfig.FROM_PB_FUNCTION) : ImmutableList.<AccessConfig>of()); return builder.build(); } }
/** * For the given zone and client type, we add the instances created to the clients array, for the * base controller. */ private void addInstanceGroupInfo(String zone, ClientParams params) throws IOException { InstanceGroupManagersListManagedInstancesResponse response; do { response = compute.instanceGroupManagers(). listManagedInstances(projectName, zone, "cps-loadtest-" + params.getClientType() + "-" + cores).execute(); // If we are not instantiating any instances of this type, just return. if (response.getManagedInstances() == null) { return; } } while (!response.getManagedInstances().stream() .allMatch(i -> i.getCurrentAction().equals("NONE"))); for (ManagedInstance managedInstance : response.getManagedInstances()) { String instanceName = managedInstance.getInstance() .substring(managedInstance.getInstance().lastIndexOf('/') + 1); Instance instance = compute.instances().get(projectName, zone, instanceName).execute(); synchronized (this) { clients.add(new Client( params.getClientType(), instance.getNetworkInterfaces().get(0).getAccessConfigs().get(0).getNatIP(), projectName, params.subscription, executor)); } } }
builder.privateIp(privateIp); List<AccessConfig> accessConfigs = networkInterface.getAccessConfigs(); if (accessConfigs != null && !accessConfigs.isEmpty()) { String publicIp = accessConfigs.get(0).getNatIP();