Skip to content

Commit 302572d

Browse files
authored
mgmt, create method for vmss (Azure#25662)
* mgmt, support create method for vmss
1 parent c3daf00 commit 302572d

File tree

37 files changed

+11945
-9441
lines changed

37 files changed

+11945
-9441
lines changed

sdk/resourcemanager/azure-resourcemanager-compute/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
- Supported Flexible orchestration mode for `VirtualMachineScaleSet` during create.
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/resourcemanager/azure-resourcemanager-compute/src/main/java/com/azure/resourcemanager/compute/implementation/VMSSPatchPayload.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static VirtualMachineScaleSetUpdate preparePatchPayload(VirtualMachineScaleSet s
9191
// -- --
9292
VirtualMachineScaleSetUpdateNetworkProfile networkProfile =
9393
new VirtualMachineScaleSetUpdateNetworkProfile();
94-
94+
networkProfile.withNetworkApiVersion(scaleSet.innerModel().virtualMachineProfile().networkProfile().networkApiVersion());
9595
if (scaleSet.innerModel().virtualMachineProfile().networkProfile().networkInterfaceConfigurations()
9696
!= null) {
9797
networkProfile

sdk/resourcemanager/azure-resourcemanager-compute/src/main/java/com/azure/resourcemanager/compute/implementation/VirtualMachineScaleSetImpl.java

Lines changed: 174 additions & 106 deletions
Large diffs are not rendered by default.

sdk/resourcemanager/azure-resourcemanager-compute/src/main/java/com/azure/resourcemanager/compute/models/VirtualMachineScaleSet.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,31 @@ interface Blank
471471
interface WithGroup extends GroupableResource.DefinitionStages.WithGroup<WithSku> {
472472
}
473473

474+
/**
475+
* The stage of a virtual machine scale set definition allowing to specify orchestration mode for the virtual machine scale set.
476+
*
477+
*/
478+
interface WithOrchestrationMode {
479+
/**
480+
* Specifies the virtual machine scale set's orchestration mode to be Flexible and fault domain count to default 1.
481+
* Virtual machine scale sets with Flexible orchestration allows you to combine the scalability of virtual
482+
* machine scale sets in Uniform orchestration mode with the regional availability guarantees of availability sets.
483+
* @return The next stage of the definition
484+
*/
485+
DefinitionShared withFlexibleOrchestrationMode();
486+
487+
/**
488+
* Specifies the virtual machine scale set's orchestration mode to be Flexible.
489+
* Virtual machine scale sets with Flexible orchestration allows you to combine the scalability of virtual
490+
* machine scale sets in Uniform orchestration mode with the regional availability guarantees of availability sets.
491+
* @param faultDomainCount By default, when you add a VM to a Flexible scale set, Azure evenly spreads instances across fault domains.
492+
* @return The next stage of the definition
493+
*/
494+
DefinitionShared withFlexibleOrchestrationMode(int faultDomainCount);
495+
}
496+
474497
/** The stage of a virtual machine scale set definition allowing to specify SKU for the virtual machines. */
475-
interface WithSku {
498+
interface WithSku extends WithOrchestrationMode {
476499
/**
477500
* Specifies the SKU for the virtual machines in the scale set.
478501
*
@@ -548,6 +571,7 @@ interface WithAdditionalCapabilities extends WithNetworkSubnet {
548571
WithNetworkSubnet withAdditionalCapabilities(AdditionalCapabilities additionalCapabilities);
549572
}
550573

574+
551575
/**
552576
* The stage of a virtual machine scale set definition allowing to specify the virtual network subnet for the
553577
* primary network configuration.

sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/ComputeManagementTest.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,33 @@ protected void sleep(long milli) {
131131
}
132132
}
133133

134-
protected LoadBalancer createHttpLoadBalancers(Region region, ResourceGroup resourceGroup, String id)
134+
protected LoadBalancer createHttpLoadBalancers(Region region, ResourceGroup resourceGroup, String id) throws Exception {
135+
return createHttpLoadBalancers(region, resourceGroup, id, LoadBalancerSkuType.BASIC, PublicIPSkuType.BASIC, false);
136+
}
137+
138+
protected LoadBalancer createHttpLoadBalancers(Region region, ResourceGroup resourceGroup, String id, LoadBalancerSkuType loadBalancerSkuType, PublicIPSkuType publicIPSkuType, boolean staticIp)
135139
throws Exception {
136140
final String loadBalancerName = generateRandomResourceName("extlb" + id + "-", 18);
137141
final String publicIpName = "pip-" + loadBalancerName;
138142
final String frontendName = loadBalancerName + "-FE1";
139143
final String backendPoolName = loadBalancerName + "-BAP1";
140144
final String natPoolName = loadBalancerName + "-INP1";
141145

146+
PublicIpAddress.DefinitionStages.WithCreate pipCreate = this
147+
.networkManager
148+
.publicIpAddresses()
149+
.define(publicIpName)
150+
.withRegion(region)
151+
.withExistingResourceGroup(resourceGroup)
152+
.withLeafDomainLabel(publicIpName)
153+
.withSku(publicIPSkuType);
154+
155+
if (staticIp) {
156+
pipCreate.withStaticIP();
157+
}
158+
142159
PublicIpAddress publicIPAddress =
143-
this
144-
.networkManager
145-
.publicIpAddresses()
146-
.define(publicIpName)
147-
.withRegion(region)
148-
.withExistingResourceGroup(resourceGroup)
149-
.withLeafDomainLabel(publicIpName)
160+
pipCreate
150161
.create();
151162

152163
LoadBalancer loadBalancer =
@@ -178,6 +189,7 @@ protected LoadBalancer createHttpLoadBalancers(Region region, ResourceGroup reso
178189
.defineHttpProbe("httpProbe")
179190
.withRequestPath("/")
180191
.attach()
192+
.withSku(loadBalancerSkuType)
181193
.create();
182194
return loadBalancer;
183195
}

sdk/resourcemanager/azure-resourcemanager-compute/src/test/java/com/azure/resourcemanager/compute/VirtualMachineScaleSetOperationsTests.java

Lines changed: 132 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.azure.resourcemanager.network.models.LoadBalancingRule;
4242
import com.azure.resourcemanager.network.models.Network;
4343
import com.azure.resourcemanager.network.models.NetworkSecurityGroup;
44+
import com.azure.resourcemanager.network.models.PublicIPSkuType;
4445
import com.azure.resourcemanager.network.models.PublicIpAddress;
4546
import com.azure.resourcemanager.network.models.SecurityRuleProtocol;
4647
import com.azure.resourcemanager.network.models.VirtualMachineScaleSetNetworkInterface;
@@ -1456,6 +1457,131 @@ public void canDeleteVMSSInstance() throws Exception {
14561457
computeManager.virtualMachineScaleSets().deleteInstances(rgName, vmssName, Collections.singleton(vmss.virtualMachines().list().stream().findFirst().get().instanceId()), false);
14571458
}
14581459

1460+
@Test
1461+
public void canCreateFlexibleVMSS() throws Exception {
1462+
// create vmss with flexible orchestration type
1463+
VirtualMachineScaleSetInner options = new VirtualMachineScaleSetInner();
1464+
options.withOrchestrationMode(OrchestrationMode.FLEXIBLE)
1465+
.withPlatformFaultDomainCount(1)
1466+
.withLocation(region.name());
1467+
1468+
ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(rgName)
1469+
.withRegion(region.name())
1470+
.create();
1471+
1472+
Network network =
1473+
this
1474+
.networkManager
1475+
.networks()
1476+
.define("vmssvnet")
1477+
.withRegion(region.name())
1478+
.withExistingResourceGroup(resourceGroup)
1479+
.withAddressSpace("10.0.0.0/28")
1480+
.withSubnet("subnet1", "10.0.0.0/28")
1481+
.create();
1482+
final String vmssName = generateRandomResourceName("vmss", 10);
1483+
LoadBalancer publicLoadBalancer = createHttpLoadBalancers(region, resourceGroup, "1", LoadBalancerSkuType.STANDARD, PublicIPSkuType.STANDARD, true);
1484+
1485+
VirtualMachineScaleSet vmss = this
1486+
.computeManager
1487+
.virtualMachineScaleSets()
1488+
.define(vmssName)
1489+
.withRegion(region.name())
1490+
.withExistingResourceGroup(resourceGroup)
1491+
.withFlexibleOrchestrationMode()
1492+
.withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0)
1493+
.withExistingPrimaryNetworkSubnet(network, "subnet1")
1494+
.withExistingPrimaryInternetFacingLoadBalancer(publicLoadBalancer)
1495+
.withoutPrimaryInternalLoadBalancer()
1496+
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.CENTOS_8_3)
1497+
.withRootUsername("jvuser")
1498+
.withSsh(sshPublicKey())
1499+
.create();
1500+
1501+
Assertions.assertNotNull(vmss.innerModel().virtualMachineProfile());
1502+
Assertions.assertNotNull(vmss.getPrimaryInternetFacingLoadBalancer());
1503+
Assertions.assertNotNull(vmss.getPrimaryNetwork());
1504+
Assertions.assertEquals(vmss.orchestrationMode(), OrchestrationMode.FLEXIBLE);
1505+
1506+
}
1507+
1508+
@Test
1509+
public void canUpdateVMSSInCreateOrUpdateMode() throws Exception {
1510+
// create vmss with empty profile
1511+
//create vmss with uniform orchestration type
1512+
String euapRegion = "eastus2euap";
1513+
1514+
final String vmssName = generateRandomResourceName("vmss", 10);
1515+
ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(rgName)
1516+
.withRegion(euapRegion)
1517+
.create();
1518+
1519+
VirtualMachineScaleSet vmss = this.computeManager
1520+
.virtualMachineScaleSets()
1521+
.define(vmssName)
1522+
.withRegion(euapRegion)
1523+
.withExistingResourceGroup(resourceGroup)
1524+
.withFlexibleOrchestrationMode()
1525+
.create();
1526+
1527+
Assertions.assertEquals(vmss.orchestrationMode(), OrchestrationMode.FLEXIBLE);
1528+
Assertions.assertNull(vmss.innerModel().virtualMachineProfile());
1529+
1530+
// update tag on vmss flex with no profile
1531+
vmss.update()
1532+
.withTag("tag1", "value1")
1533+
.apply();
1534+
1535+
Assertions.assertNotNull(vmss.tags());
1536+
Assertions.assertEquals(vmss.tags().get("tag1"), "value1");
1537+
1538+
Network network =
1539+
this
1540+
.networkManager
1541+
.networks()
1542+
.define("vmssvnet")
1543+
.withRegion(euapRegion)
1544+
.withExistingResourceGroup(resourceGroup)
1545+
.withAddressSpace("10.0.0.0/28")
1546+
.withSubnet("subnet1", "10.0.0.0/28")
1547+
.create();
1548+
LoadBalancer publicLoadBalancer = createHttpLoadBalancers(Region.fromName(euapRegion), resourceGroup, "1", LoadBalancerSkuType.STANDARD, PublicIPSkuType.STANDARD, true);
1549+
1550+
// update vmss, attach profile
1551+
vmss = this.computeManager
1552+
.virtualMachineScaleSets()
1553+
.define(vmssName)
1554+
.withRegion(euapRegion)
1555+
.withExistingResourceGroup(resourceGroup)
1556+
.withFlexibleOrchestrationMode()
1557+
.withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0)
1558+
.withExistingPrimaryNetworkSubnet(network, "subnet1")
1559+
.withExistingPrimaryInternetFacingLoadBalancer(publicLoadBalancer)
1560+
.withoutPrimaryInternalLoadBalancer()
1561+
.withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
1562+
.withRootUsername("jvuser")
1563+
.withSsh(sshPublicKey())
1564+
.withCapacity(1)
1565+
.create();
1566+
Assertions.assertNotNull(vmss.innerModel().virtualMachineProfile());
1567+
Assertions.assertEquals(vmss.orchestrationMode(), OrchestrationMode.FLEXIBLE);
1568+
Assertions.assertNotNull(vmss.getPrimaryInternetFacingLoadBalancer());
1569+
Assertions.assertNotNull(vmss.getPrimaryNetwork());
1570+
1571+
// update tag on vmss flex with profile
1572+
vmss = this.computeManager
1573+
.virtualMachineScaleSets()
1574+
.getById(vmss.id());
1575+
Assertions.assertNotNull(vmss);
1576+
vmss.update()
1577+
.withTag("tag1", "value2")
1578+
.apply();
1579+
Assertions.assertNotNull(vmss.innerModel().virtualMachineProfile());
1580+
Assertions.assertNotNull(vmss.tags());
1581+
Assertions.assertEquals(vmss.tags().get("tag1"), "value2");
1582+
1583+
}
1584+
14591585
@Test
14601586
public void canGetOrchestrationType() {
14611587

@@ -1503,24 +1629,18 @@ public void canGetOrchestrationType() {
15031629
.withLocation(euapRegion);
15041630

15051631
final String vmssName2 = generateRandomResourceName("vmss", 10);
1506-
// create resource through raw method
1507-
VirtualMachineScaleSetInner result = this
1508-
.computeManager
1509-
.virtualMachineScaleSets()
1510-
.manager()
1511-
.serviceClient()
1512-
.getVirtualMachineScaleSets()
1513-
.createOrUpdate(
1514-
rgName, vmssName2, options
1515-
);
1516-
15171632
VirtualMachineScaleSet vmss2 = this
15181633
.computeManager
15191634
.virtualMachineScaleSets()
1520-
.getById(result.id());
1635+
.define(vmssName2)
1636+
.withRegion(euapRegion)
1637+
.withExistingResourceGroup(rgName)
1638+
.withFlexibleOrchestrationMode()
1639+
.create();
15211640

15221641
Assertions.assertNotNull(vmss2);
15231642
Assertions.assertEquals(vmss2.orchestrationMode(), OrchestrationMode.FLEXIBLE);
1643+
Assertions.assertNull(vmss2.innerModel().virtualMachineProfile());
15241644
}
15251645

15261646
}

0 commit comments

Comments
 (0)