Skip to content

Commit 0a97a84

Browse files
ramakrishnaraovV R Ramakrishna Rao
andauthored
Support for Specialized image (#346)
Co-authored-by: V R Ramakrishna Rao <Ramakrishna.Rao@in.bosch.com>
1 parent eb454df commit 0a97a84

10 files changed

Lines changed: 58 additions & 3 deletions

File tree

src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public static class ImageReferenceTypeClass implements Serializable {
100100
private String galleryName;
101101
private String galleryImageDefinition;
102102
private String galleryImageVersion;
103+
private boolean galleryImageSpecialized;
103104
private String gallerySubscriptionId;
104105
private String galleryResourceGroup;
105106
private ImageReferenceType type;
@@ -189,6 +190,14 @@ public String getGalleryImageVersion() {
189190
return galleryImageVersion;
190191
}
191192

193+
public boolean getGalleryImageSpecialized() {
194+
return galleryImageSpecialized;
195+
}
196+
@DataBoundSetter
197+
public void setGalleryImageSpecialized(boolean galleryImageSpecialized) {
198+
this.galleryImageSpecialized = galleryImageSpecialized;
199+
}
200+
192201
public String getGallerySubscriptionId() {
193202
return gallerySubscriptionId;
194203
}
@@ -506,6 +515,14 @@ public String getGalleryImageVersion() {
506515
return imageReference != null ? imageReference.getGalleryImageVersion() : null;
507516
}
508517

518+
/**
519+
* Used by jelly for loading the data, not written to.
520+
*/
521+
@Restricted(NoExternalUse.class)
522+
public boolean getGalleryImageSpecialized() {
523+
return imageReference != null ? imageReference.getGalleryImageSpecialized() : false;
524+
}
525+
509526
/**
510527
* Used by jelly for loading the data, not written to.
511528
*/
@@ -1234,6 +1251,7 @@ public AdvancedImage getAdvancedImageInside() {
12341251
imageReference.galleryName,
12351252
imageReference.galleryImageDefinition,
12361253
imageReference.galleryImageVersion,
1254+
imageReference.galleryImageSpecialized,
12371255
imageReference.gallerySubscriptionId,
12381256
imageReference.galleryResourceGroup
12391257
)
@@ -1695,6 +1713,7 @@ public FormValidation doVerifyConfiguration(
16951713
@QueryParameter String galleryName,
16961714
@QueryParameter String galleryImageDefinition,
16971715
@QueryParameter String galleryImageVersion,
1716+
@QueryParameter boolean galleryImageSpecialized,
16981717
@QueryParameter String gallerySubscriptionId,
16991718
@QueryParameter String galleryResourceGroup,
17001719
@QueryParameter String agentLaunchMethod,

src/main/java/com/microsoft/azure/vmagent/AzureVMManagementServiceDelegate.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,11 @@ public AzureVMDeploymentInfo createDeployment(
400400

401401
boolean osDiskSizeChanged = osDiskSize > 0;
402402
boolean availabilitySetEnabled = availabilitySet != null;
403-
if (msiEnabled || uamiEnabled || osDiskSizeChanged || availabilitySetEnabled) {
403+
boolean isSpecializedImage = false;
404+
if (template.getImageReference() != null) {
405+
isSpecializedImage = template.getImageReference().getGalleryImageSpecialized();
406+
}
407+
if (msiEnabled || uamiEnabled || osDiskSizeChanged || availabilitySetEnabled || isSpecializedImage) {
404408
ArrayNode resources = (ArrayNode) tmp.get("resources");
405409
for (JsonNode resource : resources) {
406410
String type = resource.get("type").asText();
@@ -444,6 +448,11 @@ public AzureVMDeploymentInfo createDeployment(
444448
((ObjectNode) propertiesNode).replace("availabilitySet",
445449
availabilitySetNode);
446450
}
451+
if (isSpecializedImage) {
452+
// For specialized image remove the osProfile from the properties of the VirtualMachine resource
453+
JsonNode propertiesNode = resource.get("properties");
454+
((ObjectNode) propertiesNode).remove("osProfile");
455+
}
447456
}
448457
}
449458
}

src/main/java/com/microsoft/azure/vmagent/builders/AdvancedImage.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public class AdvancedImage {
2323

2424
private String galleryImageDefinition;
2525

26-
private String galleryImageVersion;
26+
private String galleryImageVersion;
27+
28+
private boolean galleryImageSpecialized;
2729

2830
private String gallerySubscriptionId;
2931

@@ -74,6 +76,7 @@ public AdvancedImage(String imageReferenceType,
7476
String galleryName,
7577
String galleryImageDefinition,
7678
String galleryImageVersion,
79+
boolean galleryImageSpecialized,
7780
String gallerySubscriptionId,
7881
String galleryResourceGroup,
7982
String agentLaunchMethod,
@@ -104,6 +107,7 @@ public AdvancedImage(String imageReferenceType,
104107
this.galleryName = galleryName;
105108
this.galleryImageDefinition = galleryImageDefinition;
106109
this.galleryImageVersion = galleryImageVersion;
110+
this.galleryImageSpecialized = galleryImageSpecialized;
107111
this.gallerySubscriptionId = gallerySubscriptionId;
108112
this.galleryResourceGroup = galleryResourceGroup;
109113
this.agentLaunchMethod = agentLaunchMethod;
@@ -169,6 +173,10 @@ public String getGalleryImageVersion() {
169173
return galleryImageVersion;
170174
}
171175

176+
public boolean getGalleryImageSpecialized() {
177+
return galleryImageSpecialized;
178+
}
179+
172180
public String getGallerySubscriptionId() {
173181
return gallerySubscriptionId;
174182
}

src/main/java/com/microsoft/azure/vmagent/builders/AdvancedImageBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public AdvancedImage build() {
8686
fluent.getGalleryName(),
8787
fluent.getGalleryImageDefinition(),
8888
fluent.getGalleryImageVersion(),
89+
fluent.getGalleryImageSpecialized(),
8990
fluent.getGallerySubscriptionId(),
9091
fluent.getGalleryResourceGroup(),
9192
fluent.getAgentLaunchMethod(),

src/main/java/com/microsoft/azure/vmagent/builders/AdvancedImageFluent.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class AdvancedImageFluent<T extends AdvancedImageFluent<T>> {
2828

2929
private String galleryImageVersion;
3030

31+
private boolean galleryImageSpecialized;
32+
3133
private String gallerySubscriptionId;
3234

3335
private String galleryResourceGroup;
@@ -110,12 +112,14 @@ public T withReferenceImage(String imagePublisher,
110112
public T withGalleryImage(String galleryName,
111113
String galleryImageDefinition,
112114
String galleryImageVersion,
115+
boolean galleryImageSpecialized,
113116
String gallerySubscriptionId,
114117
String galleryResourceGroup) {
115118
this.imageReferenceType = ImageReferenceType.GALLERY.getName();
116119
this.galleryName = galleryName;
117120
this.galleryImageDefinition = galleryImageDefinition;
118121
this.galleryImageVersion = galleryImageVersion;
122+
this.galleryImageSpecialized = galleryImageSpecialized;
119123
this.gallerySubscriptionId = gallerySubscriptionId;
120124
this.galleryResourceGroup = galleryResourceGroup;
121125
return (T) this;
@@ -255,6 +259,10 @@ public String getGalleryImageVersion() {
255259
return galleryImageVersion;
256260
}
257261

262+
public boolean getGalleryImageSpecialized() {
263+
return galleryImageSpecialized;
264+
}
265+
258266
public String getGallerySubscriptionId() {
259267
return gallerySubscriptionId;
260268
}

src/main/java/com/microsoft/azure/vmagent/builders/AzureVMTemplateBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ public AzureVMAgentTemplate build() {
132132
azureVMAgentTemplate.setUamiID(fluent.getAdvancedImage().getUamiID());
133133
azureVMAgentTemplate.setPreInstallSsh(fluent.getAdvancedImage().isPreInstallSsh());
134134
azureVMAgentTemplate.setTags(fluent.getCloudTags());
135+
azureVMAgentTemplate.getImageReference().setGalleryImageSpecialized(
136+
fluent.getAdvancedImage().getGalleryImageSpecialized());
135137
return azureVMAgentTemplate;
136138
}
137139
}

src/main/resources/com/microsoft/azure/vmagent/AzureVMAgentTemplate/config.jelly

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@
197197
<f:entry title="${%Gallery_Image_Version}" field="galleryImageVersion">
198198
<f:textbox/>
199199
</f:entry>
200+
<f:entry title="${%Gallery_Image_Specialized}" field="galleryImageSpecialized">
201+
<f:checkbox/>
202+
</f:entry>
200203
</f:dropdownListBlock>
201204
</f:dropdownList>
202205

@@ -302,6 +305,6 @@
302305
</div>
303306
</f:entry>
304307
<f:validateButton title="${%Verify_Template}" progress="${%Verifying_Template_MSG}" method="verifyConfiguration"
305-
with="azureCredentialsId,resourceGroupReferenceType,newResourceGroupName,existingResourceGroupName,maxVirtualMachinesLimit,deploymentTimeout,templateName,labels,location,virtualMachineSize,storageAccountNameReferenceType,newStorageAccountName,existingStorageAccountName,storageAccountType,noOfParallelJobs,imageTopLevelType,builtInImage,image,osType,id,uri,publisher,offer,sku,version,galleryName,galleryImageDefinition,galleryImageVersion,gallerySubscriptionId,galleryResourceGroup,agentLaunchMethod,initScript,credentialsId,virtualNetworkName,virtualNetworkResourceGroupName,subnetName,usePrivateIP,nsgName,jvmOptions"/>
308+
with="azureCredentialsId,resourceGroupReferenceType,newResourceGroupName,existingResourceGroupName,maxVirtualMachinesLimit,deploymentTimeout,templateName,labels,location,virtualMachineSize,storageAccountNameReferenceType,newStorageAccountName,existingStorageAccountName,storageAccountType,noOfParallelJobs,imageTopLevelType,builtInImage,image,osType,id,uri,publisher,offer,sku,version,galleryName,galleryImageDefinition,galleryImageVersion,galleryImageSpecialized,gallerySubscriptionId,galleryResourceGroup,agentLaunchMethod,initScript,credentialsId,virtualNetworkName,virtualNetworkResourceGroupName,subnetName,usePrivateIP,nsgName,jvmOptions"/>
306309
</div>
307310
</j:jelly>

src/main/resources/com/microsoft/azure/vmagent/AzureVMAgentTemplate/config.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Gallery_Subscription_Id=Gallery Subscription Id
4242
Gallery_Resource_Group=Resource Group
4343
Gallery_Image_Definition=Image Definition
4444
Gallery_Image_Version=Image Version
45+
Gallery_Image_Specialized=Specialized Image
4546

4647
Launch_Method=Launch Method
4748
Pre_Install_Ssh=Pre-Install SSH in Windows Agent (Check when using Windows and SSH)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
If your image is <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/shared-image-galleries#generalized-and-specialized-images">Specialized</a> then you need to enable this option.
3+
</div>

src/test/java/com/microsoft/azure/vmagent/test/IntegrationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ protected static class TestEnvironment {
114114
public String galleryName;
115115
public String galleryImageDefinition;
116116
public String galleryImageVersion;
117+
public boolean galleryImageSpecialized;
117118
public String gallerySubscriptionId;
118119
public String galleryResourceGroup;
119120
public List<AzureTagPair> customTags;

0 commit comments

Comments
 (0)