use of com.microsoft.azure.management.resources.ResourceGroup in project azure-sdk-for-java by Azure.
the class VirtualMachineScaleSetManagedDiskOperationsTests method canCreateVirtualMachineScaleSetFromCustomImageWithManagedDisk.
@Test
public void canCreateVirtualMachineScaleSetFromCustomImageWithManagedDisk() throws Exception {
final String userName = "tirekicker";
final String password = "12NewPA$$w0rd!";
final String publicIpDnsLabel = generateRandomResourceName("pip", 10);
final String customImageName = generateRandomResourceName("img", 10);
final String vmssName = generateRandomResourceName("vmss", 10);
ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(RG_NAME).withRegion(region).create();
VirtualMachine vm = this.computeManager.virtualMachines().define(generateRandomResourceName("vm", 10)).withRegion(region).withExistingResourceGroup(resourceGroup).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(publicIpDnsLabel).withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS).withRootUsername(userName).withRootPassword(password).withUnmanagedDisks().defineUnmanagedDataDisk("disk-1").withNewVhd(100).withLun(1).attach().defineUnmanagedDataDisk("disk-2").withNewVhd(50).withLun(2).attach().withSize(VirtualMachineSizeTypes.STANDARD_D3_V2).create();
Assert.assertNotNull(vm);
deprovisionAgentInLinuxVM(vm.getPrimaryPublicIPAddress().fqdn(), 22, userName, password);
vm.deallocate();
vm.generalize();
VirtualMachineCustomImage virtualMachineCustomImage = this.computeManager.virtualMachineCustomImages().define(customImageName).withRegion(region).withExistingResourceGroup(resourceGroup).fromVirtualMachine(vm).create();
Assert.assertNotNull(virtualMachineCustomImage);
Network network = this.networkManager.networks().define(generateRandomResourceName("vmssvnet", 15)).withRegion(region).withExistingResourceGroup(resourceGroup).withAddressSpace("10.0.0.0/28").withSubnet("subnet1", "10.0.0.0/28").create();
LoadBalancer publicLoadBalancer = createHttpLoadBalancers(region, resourceGroup, "1");
VirtualMachineScaleSet vmScaleSet = this.computeManager.virtualMachineScaleSets().define(vmssName).withRegion(region).withExistingResourceGroup(resourceGroup).withSku(VirtualMachineScaleSetSkuTypes.STANDARD_D5_V2).withExistingPrimaryNetworkSubnet(network, "subnet1").withExistingPrimaryInternetFacingLoadBalancer(publicLoadBalancer).withoutPrimaryInternalLoadBalancer().withLinuxCustomImage(virtualMachineCustomImage.id()).withRootUsername(userName).withRootPassword(password).create();
VirtualMachineScaleSetVMs virtualMachineScaleSetVMs = vmScaleSet.virtualMachines();
PagedList<VirtualMachineScaleSetVM> virtualMachines = virtualMachineScaleSetVMs.list();
Assert.assertEquals(virtualMachines.size(), vmScaleSet.capacity());
for (VirtualMachineScaleSetVM vm1 : virtualMachines) {
Assert.assertTrue(vm1.isOSBasedOnCustomImage());
Assert.assertFalse(vm1.isOSBasedOnPlatformImage());
Assert.assertFalse(vm1.isOSBasedOnStoredImage());
Assert.assertTrue(vm1.isManagedDiskEnabled());
Assert.assertNotNull(vm1.unmanagedDataDisks());
Assert.assertEquals(vm1.unmanagedDataDisks().size(), 0);
Assert.assertNotNull(vm1.dataDisks());
// Disks from data disk image from custom image
Assert.assertEquals(vm1.dataDisks().size(), 2);
Assert.assertTrue(vm1.dataDisks().containsKey(1));
VirtualMachineDataDisk disk = vm1.dataDisks().get(1);
Assert.assertEquals(disk.size(), 100);
Assert.assertTrue(vm1.dataDisks().containsKey(2));
disk = vm1.dataDisks().get(2);
Assert.assertEquals(disk.size(), 50);
}
vmScaleSet.deallocate();
// Updating and adding disk as part of VMSS Update seems consistency failing, CRP is aware of
// this, hence until it is fixed comment-out the test
//
// {
// "startTime": "2017-01-25T06:10:55.2243509+00:00",
// "endTime": "2017-01-25T06:11:07.8649525+00:00",
// "status": "Failed",
// "error": {
// "code": "InternalExecutionError",
// "message": "An internal execution error occurred."
// },
// "name": "6786df83-ed3f-4d7a-bf58-d295b96fef46"
// }
//
// vmScaleSet.update()
// .withDataDiskUpdated(1, 200) // update not supported
// .withNewDataDisk(100)
// .apply();
//
// vmScaleSet.start();
//
// virtualMachineScaleSetVMs = vmScaleSet.virtualMachines();
// virtualMachines = virtualMachineScaleSetVMs.list();
// for (VirtualMachineScaleSetVM vm1 : virtualMachines) {
// Assert.assertTrue(vm1.isOSBasedOnCustomImage());
// Assert.assertFalse(vm1.isOSBasedOnPlatformImage());
// Assert.assertFalse(vm1.isOSBasedOnStoredImage());
// Assert.assertTrue(vm1.isManagedDiskEnabled());
// Assert.assertNotNull(vm1.unmanagedDataDisks());
// Assert.assertEquals(vm1.unmanagedDataDisks().size(), 0);
// Assert.assertNotNull(vm1.dataDisks());
// Assert.assertEquals(vm1.dataDisks().size(), 3);
// Assert.assertTrue(vm1.dataDisks().containsKey(1));
// VirtualMachineDataDisk disk = vm1.dataDisks().get(1);
// Assert.assertEquals(disk.size(), 200);
// Assert.assertTrue(vm1.dataDisks().containsKey(2));
// disk = vm1.dataDisks().get(2);
// Assert.assertEquals(disk.size(), 50);
// Assert.assertTrue(vm1.dataDisks().containsKey(0));
// disk = vm1.dataDisks().get(0);
// Assert.assertEquals(disk.size(), 100);
// }
}
use of com.microsoft.azure.management.resources.ResourceGroup in project azure-sdk-for-java by Azure.
the class VirtualMachineScaleSetManagedDiskOperationsTests method canCreateUpdateVirtualMachineScaleSetFromPIRWithManagedDisk.
@Test
public void canCreateUpdateVirtualMachineScaleSetFromPIRWithManagedDisk() throws Exception {
final String vmssName = generateRandomResourceName("vmss", 10);
ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(RG_NAME).withRegion(region).create();
Network network = this.networkManager.networks().define(generateRandomResourceName("vmssvnet", 15)).withRegion(region).withExistingResourceGroup(resourceGroup).withAddressSpace("10.0.0.0/28").withSubnet("subnet1", "10.0.0.0/28").create();
LoadBalancer publicLoadBalancer = createHttpLoadBalancers(region, resourceGroup, "1");
VirtualMachineScaleSet vmScaleSet = this.computeManager.virtualMachineScaleSets().define(vmssName).withRegion(region).withExistingResourceGroup(resourceGroup).withSku(VirtualMachineScaleSetSkuTypes.STANDARD_D5_V2).withExistingPrimaryNetworkSubnet(network, "subnet1").withExistingPrimaryInternetFacingLoadBalancer(publicLoadBalancer).withoutPrimaryInternalLoadBalancer().withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS).withRootUsername("jvuser").withRootPassword("123OData!@#123").withNewDataDisk(100).withNewDataDisk(100, 1, CachingTypes.READ_WRITE).withNewDataDisk(100, 2, CachingTypes.READ_ONLY).create();
VirtualMachineScaleSetVMs virtualMachineScaleSetVMs = vmScaleSet.virtualMachines();
PagedList<VirtualMachineScaleSetVM> virtualMachines = virtualMachineScaleSetVMs.list();
Assert.assertEquals(virtualMachines.size(), vmScaleSet.capacity());
for (VirtualMachineScaleSetVM vm : virtualMachines) {
Assert.assertTrue(vm.isOSBasedOnPlatformImage());
Assert.assertFalse(vm.isOSBasedOnCustomImage());
Assert.assertFalse(vm.isOSBasedOnStoredImage());
Assert.assertTrue(vm.isManagedDiskEnabled());
Assert.assertNotNull(vm.unmanagedDataDisks());
Assert.assertEquals(vm.unmanagedDataDisks().size(), 0);
Assert.assertNotNull(vm.dataDisks());
Assert.assertEquals(vm.dataDisks().size(), 3);
}
vmScaleSet.update().withoutDataDisk(0).withNewDataDisk(50).apply();
virtualMachineScaleSetVMs = vmScaleSet.virtualMachines();
virtualMachines = virtualMachineScaleSetVMs.list();
Assert.assertEquals(virtualMachines.size(), vmScaleSet.capacity());
for (VirtualMachineScaleSetVM vm : virtualMachines) {
Assert.assertNotNull(vm.dataDisks());
Assert.assertEquals(vm.dataDisks().size(), 3);
}
}
use of com.microsoft.azure.management.resources.ResourceGroup in project azure-sdk-for-java by Azure.
the class VirtualMachineScaleSetOperationsTests method canCreateVirtualMachineScaleSet.
@Test
public void canCreateVirtualMachineScaleSet() throws Exception {
final String vmss_name = generateRandomResourceName("vmss", 10);
ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(RG_NAME).withRegion(REGION).create();
Network network = this.networkManager.networks().define("vmssvnet").withRegion(REGION).withExistingResourceGroup(resourceGroup).withAddressSpace("10.0.0.0/28").withSubnet("subnet1", "10.0.0.0/28").create();
LoadBalancer publicLoadBalancer = createInternetFacingLoadBalancer(REGION, resourceGroup, "1");
List<String> backends = new ArrayList<>();
for (String backend : publicLoadBalancer.backends().keySet()) {
backends.add(backend);
}
Assert.assertTrue(backends.size() == 2);
VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets().define(vmss_name).withRegion(REGION).withExistingResourceGroup(resourceGroup).withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0).withExistingPrimaryNetworkSubnet(network, "subnet1").withExistingPrimaryInternetFacingLoadBalancer(publicLoadBalancer).withPrimaryInternetFacingLoadBalancerBackends(backends.get(0), backends.get(1)).withoutPrimaryInternalLoadBalancer().withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS).withRootUsername("jvuser").withRootPassword("123OData!@#123").withUnmanagedDisks().withNewStorageAccount(generateRandomResourceName("stg", 15)).withNewStorageAccount(generateRandomResourceName("stg", 15)).create();
// Validate Network specific properties (LB, VNet, NIC, IPConfig etc..)
//
Assert.assertNull(virtualMachineScaleSet.getPrimaryInternalLoadBalancer());
Assert.assertTrue(virtualMachineScaleSet.listPrimaryInternalLoadBalancerBackends().size() == 0);
Assert.assertTrue(virtualMachineScaleSet.listPrimaryInternalLoadBalancerInboundNatPools().size() == 0);
Assert.assertNotNull(virtualMachineScaleSet.getPrimaryInternetFacingLoadBalancer());
Assert.assertTrue(virtualMachineScaleSet.listPrimaryInternetFacingLoadBalancerBackends().size() == 2);
Assert.assertTrue(virtualMachineScaleSet.listPrimaryInternetFacingLoadBalancerInboundNatPools().size() == 2);
Network primaryNetwork = virtualMachineScaleSet.getPrimaryNetwork();
Assert.assertNotNull(primaryNetwork.id());
List<VirtualMachineScaleSetNetworkInterface> nics = virtualMachineScaleSet.listNetworkInterfaces();
int nicCount = 0;
for (VirtualMachineScaleSetNetworkInterface nic : nics) {
nicCount++;
Assert.assertNotNull(nic.id());
Assert.assertTrue(nic.virtualMachineId().toLowerCase().startsWith(virtualMachineScaleSet.id().toLowerCase()));
Assert.assertNotNull(nic.macAddress());
Assert.assertNotNull(nic.dnsServers());
Assert.assertNotNull(nic.appliedDnsServers());
Map<String, VirtualMachineScaleSetNicIPConfiguration> ipConfigs = nic.ipConfigurations();
Assert.assertEquals(ipConfigs.size(), 1);
for (Map.Entry<String, VirtualMachineScaleSetNicIPConfiguration> entry : ipConfigs.entrySet()) {
VirtualMachineScaleSetNicIPConfiguration ipConfig = entry.getValue();
Assert.assertNotNull(ipConfig);
Assert.assertTrue(ipConfig.isPrimary());
Assert.assertNotNull(ipConfig.subnetName());
Assert.assertTrue(primaryNetwork.id().toLowerCase().equalsIgnoreCase(ipConfig.networkId()));
Assert.assertNotNull(ipConfig.privateIPAddress());
Assert.assertNotNull(ipConfig.privateIPAddressVersion());
Assert.assertNotNull(ipConfig.privateIPAllocationMethod());
List<LoadBalancerBackend> lbBackends = ipConfig.listAssociatedLoadBalancerBackends();
// VMSS is created with a internet facing LB with two Backend pools so there will be two
// backends in ip-config as well
Assert.assertEquals(lbBackends.size(), 2);
for (LoadBalancerBackend lbBackend : lbBackends) {
Map<String, LoadBalancingRule> lbRules = lbBackend.loadBalancingRules();
Assert.assertEquals(lbRules.size(), 1);
for (Map.Entry<String, LoadBalancingRule> ruleEntry : lbRules.entrySet()) {
LoadBalancingRule rule = ruleEntry.getValue();
Assert.assertNotNull(rule);
Assert.assertTrue((rule.frontendPort() == 80 && rule.backendPort() == 80) || (rule.frontendPort() == 443 && rule.backendPort() == 443));
}
}
List<LoadBalancerInboundNatRule> lbNatRules = ipConfig.listAssociatedLoadBalancerInboundNatRules();
// VMSS is created with a internet facing LB with two nat pools so there will be two
// nat rules in ip-config as well
Assert.assertEquals(lbNatRules.size(), 2);
for (LoadBalancerInboundNatRule lbNatRule : lbNatRules) {
Assert.assertTrue((lbNatRule.frontendPort() >= 5000 && lbNatRule.frontendPort() <= 5099) || (lbNatRule.frontendPort() >= 6000 && lbNatRule.frontendPort() <= 6099));
Assert.assertTrue(lbNatRule.backendPort() == 22 || lbNatRule.backendPort() == 23);
}
}
}
Assert.assertTrue(nicCount > 0);
// Validate other properties
//
Assert.assertEquals(virtualMachineScaleSet.vhdContainers().size(), 2);
Assert.assertEquals(virtualMachineScaleSet.sku(), VirtualMachineScaleSetSkuTypes.STANDARD_A0);
// Check defaults
Assert.assertTrue(virtualMachineScaleSet.upgradeModel() == UpgradeMode.AUTOMATIC);
Assert.assertEquals(virtualMachineScaleSet.capacity(), 2);
// Fetch the primary Virtual network
primaryNetwork = virtualMachineScaleSet.getPrimaryNetwork();
String inboundNatPoolToRemove = null;
for (String inboundNatPoolName : virtualMachineScaleSet.listPrimaryInternetFacingLoadBalancerInboundNatPools().keySet()) {
inboundNatPoolToRemove = inboundNatPoolName;
break;
}
LoadBalancer internalLoadBalancer = createInternalLoadBalancer(REGION, resourceGroup, primaryNetwork, "1");
virtualMachineScaleSet.update().withExistingPrimaryInternalLoadBalancer(internalLoadBalancer).withoutPrimaryInternetFacingLoadBalancerNatPools(// Remove one NatPool
inboundNatPoolToRemove).apply();
virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets().getByResourceGroup(RG_NAME, vmss_name);
// Check LB after update
//
Assert.assertNotNull(virtualMachineScaleSet.getPrimaryInternetFacingLoadBalancer());
Assert.assertTrue(virtualMachineScaleSet.listPrimaryInternetFacingLoadBalancerBackends().size() == 2);
Assert.assertTrue(virtualMachineScaleSet.listPrimaryInternetFacingLoadBalancerInboundNatPools().size() == 1);
Assert.assertNotNull(virtualMachineScaleSet.getPrimaryInternalLoadBalancer());
Assert.assertTrue(virtualMachineScaleSet.listPrimaryInternalLoadBalancerBackends().size() == 2);
Assert.assertTrue(virtualMachineScaleSet.listPrimaryInternalLoadBalancerInboundNatPools().size() == 2);
// Check NIC + IpConfig after update
//
nics = virtualMachineScaleSet.listNetworkInterfaces();
nicCount = 0;
for (VirtualMachineScaleSetNetworkInterface nic : nics) {
nicCount++;
Map<String, VirtualMachineScaleSetNicIPConfiguration> ipConfigs = nic.ipConfigurations();
Assert.assertEquals(ipConfigs.size(), 1);
for (Map.Entry<String, VirtualMachineScaleSetNicIPConfiguration> entry : ipConfigs.entrySet()) {
VirtualMachineScaleSetNicIPConfiguration ipConfig = entry.getValue();
Assert.assertNotNull(ipConfig);
List<LoadBalancerBackend> lbBackends = ipConfig.listAssociatedLoadBalancerBackends();
Assert.assertNotNull(lbBackends);
// Assert.assertEquals(lbBackends.size(), 4);
for (LoadBalancerBackend lbBackend : lbBackends) {
Map<String, LoadBalancingRule> lbRules = lbBackend.loadBalancingRules();
Assert.assertEquals(lbRules.size(), 1);
for (Map.Entry<String, LoadBalancingRule> ruleEntry : lbRules.entrySet()) {
LoadBalancingRule rule = ruleEntry.getValue();
Assert.assertNotNull(rule);
Assert.assertTrue((rule.frontendPort() == 80 && rule.backendPort() == 80) || (rule.frontendPort() == 443 && rule.backendPort() == 443) || (rule.frontendPort() == 1000 && rule.backendPort() == 1000) || (rule.frontendPort() == 1001 && rule.backendPort() == 1001));
}
}
List<LoadBalancerInboundNatRule> lbNatRules = ipConfig.listAssociatedLoadBalancerInboundNatRules();
// Assert.assertEquals(lbNatRules.size(), 3);
for (LoadBalancerInboundNatRule lbNatRule : lbNatRules) {
// As mentioned above some chnages are not propgating to all VM instances 6000+ should be there
Assert.assertTrue((lbNatRule.frontendPort() >= 6000 && lbNatRule.frontendPort() <= 6099) || (lbNatRule.frontendPort() >= 5000 && lbNatRule.frontendPort() <= 5099) || (lbNatRule.frontendPort() >= 8000 && lbNatRule.frontendPort() <= 8099) || (lbNatRule.frontendPort() >= 9000 && lbNatRule.frontendPort() <= 9099));
// Same as above
Assert.assertTrue(lbNatRule.backendPort() == 23 || lbNatRule.backendPort() == 22 || lbNatRule.backendPort() == 44 || lbNatRule.backendPort() == 45);
}
}
}
Assert.assertTrue(nicCount > 0);
}
use of com.microsoft.azure.management.resources.ResourceGroup in project azure-sdk-for-java by Azure.
the class VirtualMachineScaleSetOperationsTests method canUpdateVirtualMachineScaleSetWithExtensionProtectedSettings.
@Test
public void canUpdateVirtualMachineScaleSetWithExtensionProtectedSettings() throws Exception {
final String vmssName = generateRandomResourceName("vmss", 10);
final String uname = "jvuser";
final String password = "123OData!@#123";
ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(RG_NAME).withRegion(REGION).create();
StorageAccount storageAccount = this.storageManager.storageAccounts().define(generateRandomResourceName("stg", 15)).withRegion(REGION).withExistingResourceGroup(resourceGroup).create();
List<StorageAccountKey> keys = storageAccount.getKeys();
Assert.assertNotNull(keys);
Assert.assertTrue(keys.size() > 0);
String storageAccountKey = keys.get(0).value();
final String storageConnectionString = String.format("DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=%s", storageAccount.name(), storageAccountKey);
// Get the script to upload
//
InputStream scriptFileAsStream = VirtualMachineScaleSetOperationsTests.class.getResourceAsStream("/install_apache.sh");
// Get the size of the stream
//
int fileSize;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[256];
int bytesRead;
while ((bytesRead = scriptFileAsStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
fileSize = outputStream.size();
outputStream.close();
// Upload the script file as block blob
//
URI fileUri;
if (IS_MOCKED) {
fileUri = new URI("http://nonexisting.blob.core.windows.net/scripts/install_apache.sh");
} else {
CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient cloudBlobClient = account.createCloudBlobClient();
CloudBlobContainer container = cloudBlobClient.getContainerReference("scripts");
container.createIfNotExists();
CloudBlockBlob blob = container.getBlockBlobReference("install_apache.sh");
blob.upload(scriptFileAsStream, fileSize);
fileUri = blob.getUri();
}
List<String> fileUris = new ArrayList<>();
fileUris.add(fileUri.toString());
Network network = this.networkManager.networks().define(generateRandomResourceName("vmssvnet", 15)).withRegion(REGION).withExistingResourceGroup(resourceGroup).withAddressSpace("10.0.0.0/28").withSubnet("subnet1", "10.0.0.0/28").create();
VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets().define(vmssName).withRegion(REGION).withExistingResourceGroup(resourceGroup).withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0).withExistingPrimaryNetworkSubnet(network, "subnet1").withoutPrimaryInternetFacingLoadBalancer().withoutPrimaryInternalLoadBalancer().withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS).withRootUsername(uname).withRootPassword(password).withUnmanagedDisks().withNewStorageAccount(generateRandomResourceName("stg", 15)).withExistingStorageAccount(storageAccount).defineNewExtension("CustomScriptForLinux").withPublisher("Microsoft.OSTCExtensions").withType("CustomScriptForLinux").withVersion("1.4").withMinorVersionAutoUpgrade().withPublicSetting("fileUris", fileUris).withProtectedSetting("commandToExecute", "bash install_apache.sh").withProtectedSetting("storageAccountName", storageAccount.name()).withProtectedSetting("storageAccountKey", storageAccountKey).attach().create();
// Validate extensions after create
//
Map<String, VirtualMachineScaleSetExtension> extensions = virtualMachineScaleSet.extensions();
Assert.assertNotNull(extensions);
Assert.assertEquals(1, extensions.size());
Assert.assertTrue(extensions.containsKey("CustomScriptForLinux"));
VirtualMachineScaleSetExtension extension = extensions.get("CustomScriptForLinux");
Assert.assertNotNull(extension.publicSettings());
Assert.assertEquals(1, extension.publicSettings().size());
Assert.assertNotNull(extension.publicSettingsAsJsonString());
// Retrieve scale set
VirtualMachineScaleSet scaleSet = this.computeManager.virtualMachineScaleSets().getById(virtualMachineScaleSet.id());
// Validate extensions after get
//
extensions = virtualMachineScaleSet.extensions();
Assert.assertNotNull(extensions);
Assert.assertEquals(1, extensions.size());
Assert.assertTrue(extensions.containsKey("CustomScriptForLinux"));
extension = extensions.get("CustomScriptForLinux");
Assert.assertNotNull(extension.publicSettings());
Assert.assertEquals(1, extension.publicSettings().size());
Assert.assertNotNull(extension.publicSettingsAsJsonString());
// Update VMSS capacity
//
int newCapacity = (int) (scaleSet.capacity() + 1);
virtualMachineScaleSet.update().withCapacity(newCapacity).apply();
// Validate extensions after update
//
extensions = virtualMachineScaleSet.extensions();
Assert.assertNotNull(extensions);
Assert.assertEquals(1, extensions.size());
Assert.assertTrue(extensions.containsKey("CustomScriptForLinux"));
extension = extensions.get("CustomScriptForLinux");
Assert.assertNotNull(extension.publicSettings());
Assert.assertEquals(1, extension.publicSettings().size());
Assert.assertNotNull(extension.publicSettingsAsJsonString());
}
use of com.microsoft.azure.management.resources.ResourceGroup in project azure-sdk-for-java by Azure.
the class VirtualMachineScaleSetOperationsTests method canCreateVirtualMachineScaleSetWithCustomScriptExtension.
@Test
public void canCreateVirtualMachineScaleSetWithCustomScriptExtension() throws Exception {
final String vmssName = generateRandomResourceName("vmss", 10);
final String uname = "jvuser";
final String password = "123OData!@#123";
final String apacheInstallScript = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/azure-mgmt-compute/src/test/assets/install_apache.sh";
final String installCommand = "bash install_apache.sh Abc.123x(";
List<String> fileUris = new ArrayList<>();
fileUris.add(apacheInstallScript);
ResourceGroup resourceGroup = this.resourceManager.resourceGroups().define(RG_NAME).withRegion(REGION).create();
Network network = this.networkManager.networks().define(generateRandomResourceName("vmssvnet", 15)).withRegion(REGION).withExistingResourceGroup(resourceGroup).withAddressSpace("10.0.0.0/28").withSubnet("subnet1", "10.0.0.0/28").create();
LoadBalancer publicLoadBalancer = createHttpLoadBalancers(REGION, resourceGroup, "1");
VirtualMachineScaleSet virtualMachineScaleSet = this.computeManager.virtualMachineScaleSets().define(vmssName).withRegion(REGION).withExistingResourceGroup(resourceGroup).withSku(VirtualMachineScaleSetSkuTypes.STANDARD_A0).withExistingPrimaryNetworkSubnet(network, "subnet1").withExistingPrimaryInternetFacingLoadBalancer(publicLoadBalancer).withoutPrimaryInternalLoadBalancer().withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS).withRootUsername(uname).withRootPassword(password).withUnmanagedDisks().withNewStorageAccount(generateRandomResourceName("stg", 15)).withNewStorageAccount(generateRandomResourceName("stg", 15)).defineNewExtension("CustomScriptForLinux").withPublisher("Microsoft.OSTCExtensions").withType("CustomScriptForLinux").withVersion("1.4").withMinorVersionAutoUpgrade().withPublicSetting("fileUris", fileUris).withPublicSetting("commandToExecute", installCommand).attach().create();
checkVMInstances(virtualMachineScaleSet);
List<String> publicIPAddressIds = virtualMachineScaleSet.primaryPublicIPAddressIds();
PublicIPAddress publicIPAddress = this.networkManager.publicIPAddresses().getById(publicIPAddressIds.get(0));
String fqdn = publicIPAddress.fqdn();
// Assert public load balancing connection
if (!IS_MOCKED) {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url("http://" + fqdn).build();
Response response = client.newCall(request).execute();
Assert.assertEquals(response.code(), 200);
}
//
for (VirtualMachineScaleSetVM vm : virtualMachineScaleSet.virtualMachines().list()) {
PagedList<VirtualMachineScaleSetNetworkInterface> networkInterfaces = vm.listNetworkInterfaces();
Assert.assertEquals(networkInterfaces.size(), 1);
VirtualMachineScaleSetNetworkInterface networkInterface = networkInterfaces.get(0);
VirtualMachineScaleSetNicIPConfiguration primaryIpConfig = null;
primaryIpConfig = networkInterface.primaryIPConfiguration();
Assert.assertNotNull(primaryIpConfig);
Integer sshFrontendPort = null;
List<LoadBalancerInboundNatRule> natRules = primaryIpConfig.listAssociatedLoadBalancerInboundNatRules();
for (LoadBalancerInboundNatRule natRule : natRules) {
if (natRule.backendPort() == 22) {
sshFrontendPort = natRule.frontendPort();
break;
}
}
Assert.assertNotNull(sshFrontendPort);
// Wait some time for VM to be available
this.sleep(1000 * 60);
this.ensureCanDoSsh(fqdn, sshFrontendPort, uname, password);
}
}
Aggregations