From 38e3535dcf9c4bdd5aad83f77ad946b0b0ee458f Mon Sep 17 00:00:00 2001 From: Dani Estevez Date: Mon, 12 Nov 2018 16:59:58 -0500 Subject: [PATCH] Adds method listAvailableSizes to VirtualMachineApi Updates API version for VirtualMachineApi --- .../arm/AzureComputeProviderMetadata.java | 2 +- .../arm/features/VirtualMachineApi.java | 12 ++++- .../features/VirtualMachineApiLiveTest.java | 10 ++++ .../features/VirtualMachineApiMockTest.java | 46 ++++++++++++------- .../virtualmachineavailablesizes.json | 20 ++++++++ 5 files changed, 70 insertions(+), 20 deletions(-) create mode 100644 providers/azurecompute-arm/src/test/resources/virtualmachineavailablesizes.json diff --git a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java index 95856e6d67..85ec8b933d 100644 --- a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java +++ b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java @@ -123,7 +123,7 @@ public class AzureComputeProviderMetadata extends BaseProviderMetadata { properties.put(API_VERSION_PREFIX + SubnetApi.class.getSimpleName(), "2017-03-01"); properties.put(API_VERSION_PREFIX + VirtualNetworkApi.class.getSimpleName(), "2015-06-15"); properties.put(API_VERSION_PREFIX + VMSizeApi.class.getSimpleName(), "2015-06-15"); - properties.put(API_VERSION_PREFIX + VirtualMachineApi.class.getSimpleName(), "2016-04-30-preview"); + properties.put(API_VERSION_PREFIX + VirtualMachineApi.class.getSimpleName(), "2018-06-01"); properties.put(API_VERSION_PREFIX + LoadBalancerApi.class.getSimpleName(), "2016-03-30"); properties.put(API_VERSION_PREFIX + AvailabilitySetApi.class.getSimpleName(), "2016-04-30-preview"); properties.put(API_VERSION_PREFIX + DiskApi.class.getSimpleName(), "2017-03-30"); diff --git a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java index e8dc0658ea..bc8c0e5168 100644 --- a/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java +++ b/providers/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java @@ -32,6 +32,7 @@ import javax.ws.rs.core.MediaType; import org.jclouds.Fallbacks; import org.jclouds.azurecompute.arm.domain.Plan; +import org.jclouds.azurecompute.arm.domain.VMSize; import org.jclouds.azurecompute.arm.domain.VirtualMachine; import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance; import org.jclouds.azurecompute.arm.domain.VirtualMachineProperties; @@ -52,7 +53,7 @@ import org.jclouds.rest.binders.BindToJsonPayload; /** * The Virtual Machine API includes operations for managing the virtual machines in your subscription. * - * @see docs + * @see docs */ @Path("/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines") @RequestFilters({ OAuthFilter.class, ApiVersionFilter.class }) @@ -91,6 +92,13 @@ public interface VirtualMachineApi { @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class) List list(); + @Named("ListAvailableSizes") + @GET + @SelectJson("value") + @Path("/{name}/vmSizes") + @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class) + List listAvailableSizes(@PathParam("name") String name); + @Named("DeleteVirtualMachine") @DELETE @Path("/{name}") @@ -139,6 +147,6 @@ public interface VirtualMachineApi { URI capture(@PathParam("name") String name, @PayloadParam("vhdPrefix") String vhdPrefix, @PayloadParam("destinationContainerName") String destinationContainerName); - + } diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java index 27bdc75f55..c2f2781c38 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java @@ -19,6 +19,7 @@ package org.jclouds.azurecompute.arm.features; import static org.assertj.core.api.Assertions.assertThat; import static org.jclouds.util.Predicates2.retry; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import static org.testng.util.Strings.isNullOrEmpty; @@ -53,6 +54,7 @@ import org.jclouds.azurecompute.arm.domain.StorageProfile; import org.jclouds.azurecompute.arm.domain.StorageService; import org.jclouds.azurecompute.arm.domain.Subnet; import org.jclouds.azurecompute.arm.domain.VHD; +import org.jclouds.azurecompute.arm.domain.VMSize; import org.jclouds.azurecompute.arm.domain.VaultCertificate; import org.jclouds.azurecompute.arm.domain.VirtualMachine; import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance; @@ -191,6 +193,14 @@ public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { assertTrue(vmPresent); } + @Test(dependsOnMethods = "testCreate") + public void testListAvailableSizes() { + List vmSizes = api().listAvailableSizes(vmName); + + assertNotNull(vmSizes); + assertFalse(vmSizes.isEmpty()); + } + @Test(dependsOnMethods = "testRestart") public void testGeneralize() throws IllegalStateException { api().stop(vmName); diff --git a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java index 737129427c..642d38d159 100644 --- a/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java +++ b/providers/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java @@ -48,6 +48,7 @@ import org.jclouds.azurecompute.arm.domain.Secrets.SourceVault; import org.jclouds.azurecompute.arm.domain.Status; import org.jclouds.azurecompute.arm.domain.StorageProfile; import org.jclouds.azurecompute.arm.domain.VHD; +import org.jclouds.azurecompute.arm.domain.VMSize; import org.jclouds.azurecompute.arm.domain.VaultCertificate; import org.jclouds.azurecompute.arm.domain.VirtualMachine; import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance; @@ -68,7 +69,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { assertEquals(vmAPI.get("windowsmachine"), getVM(Plan.create("thinkboxsoftware", "deadline-slave-7-2", "deadline7-2"))); assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine?api-version=2018-06-01"); } public void testGetEmpty() throws Exception { @@ -76,7 +77,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); assertNull(vmAPI.get("windowsmachine")); assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine?api-version=2018-06-01"); } public void testGetInstanceDetails() throws Exception { @@ -91,7 +92,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { // assertEquals(actual.statuses().get(0).time().toString(), // expected.statuses().get(0).time().toString()); assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine/instanceView?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine/instanceView?api-version=2018-06-01"); } public void testGetInstanceDetailsEmpty() throws Exception { @@ -99,7 +100,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); assertNull(vmAPI.getInstanceDetails("windowsmachine")); assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine/instanceView?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine/instanceView?api-version=2018-06-01"); } public void testList() throws Exception { @@ -107,7 +108,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); assertEquals(vmAPI.list(), getVMList()); assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines?api-version=2016-04-30-preview"); + + "/virtualMachines?api-version=2018-06-01"); } public void testListEmpty() throws Exception { @@ -115,7 +116,17 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); assertTrue(isEmpty(vmAPI.list())); assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines?api-version=2016-04-30-preview"); + + "/virtualMachines?api-version=2018-06-01"); + } + + public void testListAvailableSizes() throws Exception { + server.enqueue(jsonResponse("/virtualmachineavailablesizes.json")); + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + assertEquals(vmAPI.listAvailableSizes("windowsmachine"), ImmutableList.of(VMSize.create("Standard_A0", 1, + 1047552, 20480, 768, 1), VMSize.create("Standard_A1", 1, + 1047552, 71680, 1792, 2))); + assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines/windowsmachine/vmSizes?api-version=2018-06-01"); } public void testCreateWithPlan() throws Exception { @@ -129,7 +140,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { server, "PUT", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine?validating=false&api-version=2016-04-30-preview", + + "/virtualMachines/windowsmachine?validating=false&api-version=2018-06-01", "{\"location\":\"westus\",\"properties\":" + "{\"vmId\":\"27ee085b-d707-xxxx-yyyy-2370e2eb1cc1\",\"licenseType\":\"Windows_Server\"," + "\"availabilitySet\":{\"id\":\"/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/myAVSet\"}," @@ -164,7 +175,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { server, "PUT", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine?validating=false&api-version=2016-04-30-preview", + + "/virtualMachines/windowsmachine?validating=false&api-version=2018-06-01", "{\"location\":\"westus\",\"properties\":" + "{\"vmId\":\"27ee085b-d707-xxxx-yyyy-2370e2eb1cc1\",\"licenseType\":\"Windows_Server\"," + "\"availabilitySet\":{\"id\":\"/subscriptions/SUBSCRIPTIONID/resourceGroups/myResourceGroup/providers/Microsoft.Compute/availabilitySets/myAVSet\"}," @@ -195,7 +206,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { assertNull(uri); assertSent(server, "DELETE", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine?api-version=2018-06-01"); } public void testDelete() throws Exception { @@ -209,7 +220,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { assertNotNull(uri); assertSent(server, "DELETE", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine?api-version=2018-06-01"); } public void testStart() throws Exception { @@ -220,7 +231,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { vmAPI.start("windowsmachine"); assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine/start?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine/start?api-version=2018-06-01"); } public void testRestart() throws Exception { @@ -231,7 +242,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { vmAPI.restart("windowsmachine"); assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine/restart?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine/restart?api-version=2018-06-01"); } public void testStop() throws Exception { @@ -242,7 +253,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { vmAPI.stop("windowsmachine"); assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine/powerOff?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine/powerOff?api-version=2018-06-01"); } public void testDeallocate() throws Exception { @@ -253,7 +264,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { vmAPI.deallocate("windowsmachine"); assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/windowsmachine/deallocate?api-version=2016-04-30-preview"); + + "/virtualMachines/windowsmachine/deallocate?api-version=2018-06-01"); } public void testGeneralize() throws Exception { @@ -261,7 +272,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); vmAPI.generalize("vm"); // IllegalStateException if failed assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/vm/generalize?api-version=2016-04-30-preview"); + + "/virtualMachines/vm/generalize?api-version=2018-06-01"); } public void testCapture() throws Exception { @@ -271,7 +282,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { URI uri = vmAPI.capture("vm", "prefix", "container"); assertNotNull(uri); assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/vm/capture?api-version=2016-04-30-preview", + + "/virtualMachines/vm/capture?api-version=2018-06-01", "{\"vhdPrefix\":\"prefix\",\"destinationContainerName\":\"container\",\"overwriteVhds\":\"true\"}"); } @@ -282,7 +293,7 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { URI uri = vmAPI.capture("vm", "prefix", "container"); assertNull(uri); assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" - + "/virtualMachines/vm/capture?api-version=2016-04-30-preview", + + "/virtualMachines/vm/capture?api-version=2018-06-01", "{\"vhdPrefix\":\"prefix\",\"destinationContainerName\":\"container\",\"overwriteVhds\":\"true\"}"); } @@ -417,4 +428,5 @@ public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { list.add(machineWithBlobDisks); return list; } + } diff --git a/providers/azurecompute-arm/src/test/resources/virtualmachineavailablesizes.json b/providers/azurecompute-arm/src/test/resources/virtualmachineavailablesizes.json new file mode 100644 index 0000000000..f54423bd41 --- /dev/null +++ b/providers/azurecompute-arm/src/test/resources/virtualmachineavailablesizes.json @@ -0,0 +1,20 @@ +{ + "value": [ + { + "name": "Standard_A0", + "numberOfCores": 1, + "osDiskSizeInMB": 1047552, + "resourceDiskSizeInMB": 20480, + "memoryInMB": 768, + "maxDataDiskCount": 1 + }, + { + "name": "Standard_A1", + "numberOfCores": 1, + "osDiskSizeInMB": 1047552, + "resourceDiskSizeInMB": 71680, + "memoryInMB": 1792, + "maxDataDiskCount": 2 + } + ] +} \ No newline at end of file