|
41 | 41 | import com.azure.resourcemanager.network.models.LoadBalancingRule; |
42 | 42 | import com.azure.resourcemanager.network.models.Network; |
43 | 43 | import com.azure.resourcemanager.network.models.NetworkSecurityGroup; |
| 44 | +import com.azure.resourcemanager.network.models.PublicIPSkuType; |
44 | 45 | import com.azure.resourcemanager.network.models.PublicIpAddress; |
45 | 46 | import com.azure.resourcemanager.network.models.SecurityRuleProtocol; |
46 | 47 | import com.azure.resourcemanager.network.models.VirtualMachineScaleSetNetworkInterface; |
@@ -1456,6 +1457,131 @@ public void canDeleteVMSSInstance() throws Exception { |
1456 | 1457 | computeManager.virtualMachineScaleSets().deleteInstances(rgName, vmssName, Collections.singleton(vmss.virtualMachines().list().stream().findFirst().get().instanceId()), false); |
1457 | 1458 | } |
1458 | 1459 |
|
| 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 | + |
1459 | 1585 | @Test |
1460 | 1586 | public void canGetOrchestrationType() { |
1461 | 1587 |
|
@@ -1503,24 +1629,18 @@ public void canGetOrchestrationType() { |
1503 | 1629 | .withLocation(euapRegion); |
1504 | 1630 |
|
1505 | 1631 | 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 | | - |
1517 | 1632 | VirtualMachineScaleSet vmss2 = this |
1518 | 1633 | .computeManager |
1519 | 1634 | .virtualMachineScaleSets() |
1520 | | - .getById(result.id()); |
| 1635 | + .define(vmssName2) |
| 1636 | + .withRegion(euapRegion) |
| 1637 | + .withExistingResourceGroup(rgName) |
| 1638 | + .withFlexibleOrchestrationMode() |
| 1639 | + .create(); |
1521 | 1640 |
|
1522 | 1641 | Assertions.assertNotNull(vmss2); |
1523 | 1642 | Assertions.assertEquals(vmss2.orchestrationMode(), OrchestrationMode.FLEXIBLE); |
| 1643 | + Assertions.assertNull(vmss2.innerModel().virtualMachineProfile()); |
1524 | 1644 | } |
1525 | 1645 |
|
1526 | 1646 | } |
0 commit comments