@Override public void validate(ConfigProblemSetBuilder p, AzureBaseImage n) { AzureCredentials credentials = credentialsList.get(0); // The first credentials should be fine since we're validating against public images VirtualMachineImagesOperations imagesOps = credentials.getComputeClient().getVmImageOps(); AzureBaseImage.AzureOperatingSystemSettings osSettings = n.getBaseImage(); String version = osSettings.getVersion(); try { if (version != null && version.equals("latest")) { imagesOps.list("westus", osSettings.getPublisher(), osSettings.getOffer(), osSettings.getSku(), null, 1, "name"); } else { imagesOps.get("westus", osSettings.getPublisher(), osSettings.getOffer(), osSettings.getSku(), version); } } catch (Exception e) { String message = CloudException.class.isInstance(e) ? CloudException.class.cast(e).getBody().getMessage() : e.getMessage(); p.addProblem(Problem.Severity.WARNING, "Error getting image '" + n.getNodeName() + "' in region 'westus': " + message) .setRemediation("If you are not targeting 'westus' and know the image is available in other regions, you can ignore this warning and select a different region when baking images. See available images here: https://aka.ms/azspinimage"); } } }
@Override public void validate(ConfigProblemSetBuilder p, AzureBaseImage n) { AzureCredentials credentials = credentialsList.get(0); // The first credentials should be fine since we're validating against public images VirtualMachineImagesOperations imagesOps = credentials.getComputeClient().getVmImageOps(); AzureBaseImage.AzureOperatingSystemSettings osSettings = n.getBaseImage(); String version = osSettings.getVersion(); try { if (version != null && version.equals("latest")) { imagesOps.list("westus", osSettings.getPublisher(), osSettings.getOffer(), osSettings.getSku(), null, 1, "name"); } else { imagesOps.get("westus", osSettings.getPublisher(), osSettings.getOffer(), osSettings.getSku(), version); } } catch (Exception e) { String message = CloudException.class.isInstance(e) ? CloudException.class.cast(e).getBody().getMessage() : e.getMessage(); p.addProblem(Problem.Severity.WARNING, "Error getting image '" + n.getNodeName() + "' in region 'westus': " + message) .setRemediation("If you are not targeting 'westus' and know the image is available in other regions, you can ignore this warning and select a different region when baking images. See available images here: https://aka.ms/azspinimage"); } } }