From bb06c11c3f36bd55a9985df13d2f151b74d2bc6e Mon Sep 17 00:00:00 2001 From: smirgel Date: Sun, 3 Sep 2023 10:19:28 +0200 Subject: [PATCH] Supply purchase plan for gallery images (#452) Co-authored-by: Magnus Lundin --- .../AzureVMManagementServiceDelegate.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/microsoft/azure/vmagent/AzureVMManagementServiceDelegate.java b/src/main/java/com/microsoft/azure/vmagent/AzureVMManagementServiceDelegate.java index f93a1f10..9b1217d6 100644 --- a/src/main/java/com/microsoft/azure/vmagent/AzureVMManagementServiceDelegate.java +++ b/src/main/java/com/microsoft/azure/vmagent/AzureVMManagementServiceDelegate.java @@ -533,6 +533,27 @@ public AzureVMDeploymentInfo createDeployment( imageId = galleryImageVersion.id(); LOGGER.log(Level.INFO, "Create VM with gallery image id {0}", new Object[]{imageId}); putVariableIfNotBlank(tmp, "imageId", imageId); + + Map imageTags = galleryImageVersion.tags(); + if (imageTags != null) { + String planInfo = imageTags.get("PlanInfo"); + String planProduct = imageTags.get("PlanProduct"); + String planPublisher = imageTags.get("PlanPublisher"); + + if (StringUtils.isNotBlank(planInfo) && StringUtils.isNotBlank(planProduct) + && StringUtils.isNotBlank(planPublisher)) { + for (JsonNode resource : resources) { + String type = resource.get("type").asText(); + if (type.contains("virtualMachine")) { + ObjectNode planNode = MAPPER.createObjectNode(); + planNode.put("name", planInfo); + planNode.put("publisher", planPublisher); + planNode.put("product", planProduct); + ((ObjectNode) resource).replace("plan", planNode); + } + } + } + } } if (imageId != null) {