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)); }
static public void resize(AccountDeploymentDetails<GoogleAccount> details, String zone, String managedInstaceGroupName, int targetSize) { Compute compute = getCompute(details); try { compute.instanceGroupManagers().resize(details.getAccount().getProject(), zone, managedInstaceGroupName, targetSize); } catch (IOException e) { throw new HalException(FATAL, "Unable to resize instance group manager " + managedInstaceGroupName + ": " + e.getMessage(), e); } }
static public void resize(AccountDeploymentDetails<GoogleAccount> details, String zone, String managedInstaceGroupName, int targetSize) { Compute compute = getCompute(details); try { compute.instanceGroupManagers().resize(details.getAccount().getProject(), zone, managedInstaceGroupName, targetSize); } catch (IOException e) { throw new HalException(FATAL, "Unable to resize instance group manager " + managedInstaceGroupName + ": " + e.getMessage(), e); } }
@JsonIgnore public GoogleNamedAccountCredentials getNamedAccountCredentials(String version, ConfigProblemSetBuilder p) { String jsonKey = null; if (!StringUtils.isEmpty(getJsonPath())) { jsonKey = ValidatingFileReader.contents(p, getJsonPath()); if (jsonKey == null) { return null; } else if (jsonKey.isEmpty()) { p.addProblem(Problem.Severity.WARNING, "The supplied credentials file is empty."); } } if (StringUtils.isEmpty(getProject())) { p.addProblem(Problem.Severity.ERROR, "No google project supplied."); return null; } try { return new GoogleNamedAccountCredentials.Builder() .jsonKey(jsonKey) .project(getProject()) .computeVersion(isAlphaListed() ? ComputeVersion.ALPHA : ComputeVersion.DEFAULT) .imageProjects(getImageProjects()) .applicationName("halyard " + version) .liveLookupsEnabled(false) .build(); } catch (Exception e) { p.addProblem(Problem.Severity.ERROR, "Error instantiating Google credentials: " + e.getMessage() + ".") .setRemediation("Do the provided credentials have access to project " + getProject() + "?"); return null; } }
@JsonIgnore public GoogleNamedAccountCredentials getNamedAccountCredentials(String version, ConfigProblemSetBuilder p) { String jsonKey = null; if (!StringUtils.isEmpty(getJsonPath())) { jsonKey = ValidatingFileReader.contents(p, getJsonPath()); if (jsonKey == null) { return null; } else if (jsonKey.isEmpty()) { p.addProblem(Problem.Severity.WARNING, "The supplied credentials file is empty."); } } if (StringUtils.isEmpty(getProject())) { p.addProblem(Problem.Severity.ERROR, "No google project supplied."); return null; } try { return new GoogleNamedAccountCredentials.Builder() .jsonKey(jsonKey) .project(getProject()) .computeVersion(isAlphaListed() ? ComputeVersion.ALPHA : ComputeVersion.DEFAULT) .imageProjects(getImageProjects()) .applicationName("halyard " + version) .liveLookupsEnabled(false) .build(); } catch (Exception e) { p.addProblem(Problem.Severity.ERROR, "Error instantiating Google credentials: " + e.getMessage() + ".") .setRemediation("Do the provided credentials have access to project " + getProject() + "?"); return null; } }
Compute compute = credentials.getCompute(); compute.projects().get(n.getProject()).execute(); p.addProblem(Severity.ERROR, "Failed to load project \"" + n.getProject() + "\": " + e.getMessage() + ".");
Compute compute = credentials.getCompute(); compute.projects().get(n.getProject()).execute(); p.addProblem(Severity.ERROR, "Failed to load project \"" + n.getProject() + "\": " + e.getMessage() + ".");
static String defaultServiceAccount(AccountDeploymentDetails<GoogleAccount> details) { GoogleAccount account = details.getAccount(); String project = account.getProject(); Compute compute = getCompute(details); try { return compute.projects().get(project).execute().getDefaultServiceAccount(); } catch (IOException e) { throw new HalException(FATAL, "Unable to get default compute service account"); } }
static String defaultServiceAccount(AccountDeploymentDetails<GoogleAccount> details) { GoogleAccount account = details.getAccount(); String project = account.getProject(); Compute compute = getCompute(details); try { return compute.projects().get(project).execute().getDefaultServiceAccount(); } catch (IOException e) { throw new HalException(FATAL, "Unable to get default compute service account"); } }
List<InstanceGroupManager> migs; try { migs = compute.instanceGroupManagers().list(account.getProject(), settings.getLocation()).execute().getItems(); if (migs == null) { migs = Collections.emptyList(); try { List<ManagedInstance> managedInstances = compute.instanceGroupManagers() .listManagedInstances(account.getProject(), settings.getLocation(), mig.getName()) .execute() .getManagedInstances();
List<InstanceGroupManager> migs; try { migs = compute.instanceGroupManagers().list(account.getProject(), settings.getLocation()).execute().getItems(); if (migs == null) { migs = Collections.emptyList(); try { List<ManagedInstance> managedInstances = compute.instanceGroupManagers() .listManagedInstances(account.getProject(), settings.getLocation(), mig.getName()) .execute() .getManagedInstances();
@Override protected Account editAccount(GoogleAccount account) { account.setJsonPath(isSet(jsonPath) ? jsonPath : account.getJsonPath()); account.setProject(isSet(project) ? project : account.getProject()); account.setAlphaListed(alphaListed != null ? alphaListed : account.isAlphaListed()); try { account.setImageProjects( updateStringList(account.getImageProjects(), imageProjects, addImageProject, removeImageProject)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Set either --image-projects or --[add/remove]-image-project"); } try { account.setRegions( updateStringList(account.getRegions(), regions, addRegion, removeRegion)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Set either --regions or --[add/remove]-region"); } return account; } }
@Override protected Account editAccount(GoogleAccount account) { account.setJsonPath(isSet(jsonPath) ? jsonPath : account.getJsonPath()); account.setProject(isSet(project) ? project : account.getProject()); account.setAlphaListed(alphaListed != null ? alphaListed : account.isAlphaListed()); account.setUserDataFile(userDataFile != null ? userDataFile : account.getUserDataFile()); try { account.setImageProjects( updateStringList(account.getImageProjects(), imageProjects, addImageProject, removeImageProject)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Set either --image-projects or --[add/remove]-image-project"); } try { account.setRegions( updateStringList(account.getRegions(), regions, addRegion, removeRegion)); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Set either --regions or --[add/remove]-region"); } return account; } }
static String ensureSpinnakerNetworkExists(AccountDeploymentDetails<GoogleAccount> details) { String networkName = getNetworkName(); String project = details.getAccount().getProject();
static String ensureSpinnakerNetworkExists(AccountDeploymentDetails<GoogleAccount> details) { String networkName = getNetworkName(); String project = details.getAccount().getProject();
String migName = getVersionedName(version); String zone = settings.getLocation(); String project = details.getAccount().getProject(); Compute compute = GoogleProviderUtils.getCompute(details); InstanceGroupManager mig;
String migName = getVersionedName(version); String zone = settings.getLocation(); String project = details.getAccount().getProject(); Compute compute = GoogleProviderUtils.getCompute(details); InstanceGroupManager mig;
String project = account.getProject(); String zone = settings.getLocation();
String project = account.getProject(); String zone = settings.getLocation();