Skip to content

Commit 440f85c

Browse files
authored
Add parameter for "License Type" when using an advanced image. (#533)
1 parent 554454c commit 440f85c

7 files changed

Lines changed: 61 additions & 1 deletion

File tree

checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<!-- Checks for Size Violations. -->
3232
<!-- See http://checkstyle.sf.net/config_sizes.html -->
3333
<module name="FileLength">
34-
<property name="max" value="2100"/>
34+
<property name="max" value="2200"/>
3535
</module>
3636

3737
<!-- Checks for whitespace -->

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ public int hashCode() {
378378

379379
private int maxVirtualMachinesLimit;
380380

381+
private String licenseType;
382+
381383
// deprecated fields
382384
private transient boolean isInstallDocker;
383385
private transient boolean isInstallMaven;
@@ -1365,6 +1367,15 @@ public void setMaximumDeploymentSize(int maximumDeploymentSize) {
13651367
this.maximumDeploymentSize = maximumDeploymentSize;
13661368
}
13671369

1370+
public String getLicenseType() {
1371+
return licenseType;
1372+
}
1373+
1374+
@DataBoundSetter
1375+
public void setLicenseType(String licenseType) {
1376+
this.licenseType = licenseType;
1377+
}
1378+
13681379
/**
13691380
* Provision new agents using this template.
13701381
*
@@ -1533,6 +1544,15 @@ public ListBoxModel doFillOsTypeItems() throws IOException, ServletException {
15331544
return model;
15341545
}
15351546

1547+
@POST
1548+
public ListBoxModel doFillLicenseTypeItems() {
1549+
ListBoxModel model = new ListBoxModel();
1550+
model.add(Constants.LICENSE_TYPE_CLASSIC);
1551+
model.add(Constants.LICENSE_TYPE_WINDOWS_CLIENT);
1552+
model.add(Constants.LICENSE_TYPE_WINDOWS_SERVER);
1553+
return model;
1554+
}
1555+
15361556
private String getAzureCredentialsIdFromCloud(String cloudName) {
15371557
AzureVMCloud cloud = getAzureCloud(cloudName);
15381558

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,10 @@ public AzureVMDeploymentInfo createDeployment(
661661
putParameter(parameters, "authenticationType", "key");
662662
}
663663

664+
if (!Constants.LICENSE_TYPE_CLASSIC.equals(template.getLicenseType())) {
665+
addLicenseType(tmp, template.getLicenseType());
666+
}
667+
664668
// Register the deployment for cleanup
665669
deploymentRegistrar.registerDeployment(
666670
cloudName, template.getResourceGroupName(), deploymentName, scriptUri);
@@ -747,6 +751,20 @@ private void addAcceleratedNetworking(JsonNode template) {
747751
}
748752
}
749753

754+
private void addLicenseType(JsonNode template, String licenseType) {
755+
if (Constants.LICENSE_TYPE_WINDOWS_CLIENT.equals(licenseType) || Constants.LICENSE_TYPE_WINDOWS_SERVER.equals(licenseType)) {
756+
ArrayNode resources = (ArrayNode) template.get("resources");
757+
for (JsonNode resource : resources) {
758+
String type = resource.get("type").asText();
759+
if (type.contains("virtualMachine")) {
760+
ObjectNode properties = (ObjectNode) resource.get("properties");
761+
properties.put("licenseType", licenseType);
762+
return;
763+
}
764+
}
765+
}
766+
}
767+
750768
private void injectCustomTag(JsonNode resource, List<AzureTagPair> tags) {
751769
ObjectNode tagsNode = (ObjectNode) resource.get("tags");
752770
if (tags != null) {

src/main/java/com/microsoft/azure/vmagent/util/Constants.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ public final class Constants {
8787

8888
public static final String OS_TYPE_LINUX = "Linux";
8989

90+
/**
91+
* Windows License Types.
92+
*/
93+
public static final String LICENSE_TYPE_CLASSIC = "Classic";
94+
95+
public static final String LICENSE_TYPE_WINDOWS_CLIENT = "Windows_Client";
96+
97+
public static final String LICENSE_TYPE_WINDOWS_SERVER = "Windows_Server";
98+
9099
/**
91100
* Usage types for template names.
92101
**/

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@
233233
<f:select/>
234234
</f:entry>
235235

236+
<f:entry title="${%License_Type}" field="licenseType">
237+
<f:select/>
238+
</f:entry>
239+
236240
<f:dropdownDescriptorSelector
237241
title="${%Launch_Method}"
238242
field="launcher"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Advanced_Image=Use advanced image
2727
Custom_Image=Custom user image
2828
Image=Custom image URI
2929
Os_Type=OS type
30+
License_Type=License Type
3031

3132
Pre_Installed_Tools=Pre-installed tools
3233
Image_Reference=Image reference
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div>
2+
For Windows agents, if you want to use <a href="https://learn.microsoft.com/en-us/azure/virtual-machines/windows/hybrid-use-benefit-licensing">Azure Hybrid Benefit</a>, then you can specify one of the following values:
3+
<ul>
4+
<li>Windows_Client</li>
5+
<li>Windows_Server</li>
6+
</ul>
7+
Otherwise, leaving the value as <code>Classic</code> will not specify any license type.
8+
</div>

0 commit comments

Comments
 (0)