http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java new file mode 100644 index 0000000..4689064 --- /dev/null +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/features/VirtualMachineApi.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import org.jclouds.Fallbacks; +import org.jclouds.azurecompute.arm.domain.VirtualMachine; +import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance; +import org.jclouds.azurecompute.arm.domain.VirtualMachineProperties; +import org.jclouds.azurecompute.arm.functions.URIParser; +import org.jclouds.oauth.v2.filters.OAuthFilter; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.MapBinder; +import org.jclouds.rest.annotations.Payload; +import org.jclouds.rest.annotations.PayloadParam; +import org.jclouds.rest.annotations.QueryParams; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.SelectJson; +import org.jclouds.rest.binders.BindToJsonPayload; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.net.URI; +import java.util.List; + +/** + * The Virtual Machine API includes operations for managing the virtual machines in your subscription. + * + * @see <a href="https://msdn.microsoft.com/en-us/library/azure/mt163630.aspx">docs</a> + */ +@Path("/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines") +@RequestFilters(OAuthFilter.class) +@QueryParams(keys = "api-version", values = "2015-06-15") +@Consumes(MediaType.APPLICATION_JSON) +public interface VirtualMachineApi { + + /** + * The Get Virtual Machine details + */ + @Named("GetVirtualMachine") + @GET + @Path("/{name}") + @Fallback(Fallbacks.NullOnNotFoundOr404.class) + VirtualMachine get(@PathParam("name") String name); + + /** + * The Get Virtual Machine details + */ + @Named("GetVirtualMachineInstance") + @GET + @Path("/{name}/instanceView") + @Fallback(Fallbacks.NullOnNotFoundOr404.class) + VirtualMachineInstance getInstanceDetails(@PathParam("name") String name); + + /** + * The Create Virtual Machine + */ + @Named("CreateVirtualMachine") + @PUT + @Payload("%7B\"location\":\"{location}\",\"tags\":%7B%7D,\"properties\":{properties}%7D") + @MapBinder(BindToJsonPayload.class) + @Path("/{vmname}") + @QueryParams(keys = "validating", values = "false") + @Produces(MediaType.APPLICATION_JSON) + VirtualMachine create(@PathParam("vmname") String vmname, + @PayloadParam("location") String location, + @PayloadParam("properties") VirtualMachineProperties properties); + + /** + * The List Virtual Machines operation + */ + @Named("ListVirtualMachines") + @GET + @SelectJson("value") + @Fallback(Fallbacks.EmptyListOnNotFoundOr404.class) + List<VirtualMachine> list(); + + /** + * The Delete Virtual Machine operation + */ + @Named("DeleteVirtualMachine") + @DELETE + @Path("/{name}") + @ResponseParser(URIParser.class) + @Fallback(Fallbacks.NullOnNotFoundOr404.class) + URI delete(@PathParam("name") String name); + + /** + * The Restart Virtual Machine operation + */ + @Named("RestartVirtualMachine") + @POST + @Path("/{name}/restart") + void restart(@PathParam("name") String name); + + /** + * The start Virtual Machine operation + */ + @Named("StartVirtualMachine") + @POST + @Path("/{name}/start") + void start(@PathParam("name") String name); + + /** + * The stop Virtual Machine operation + */ + @Named("StopVirtualMachine") + @POST + @Path("/{name}/powerOff") + void stop(@PathParam("name") String name); + +} +
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiLiveTest.java new file mode 100644 index 0000000..c1e77a2 --- /dev/null +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiLiveTest.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import com.google.common.collect.ImmutableMap; +import org.jclouds.azurecompute.arm.domain.IdReference; +import org.jclouds.azurecompute.arm.domain.IpConfiguration; +import org.jclouds.azurecompute.arm.domain.IpConfigurationProperties; +import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard; +import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCardProperties; +import org.jclouds.azurecompute.arm.domain.Subnet; +import org.jclouds.azurecompute.arm.domain.VirtualNetwork; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; + +@Test(groups = "live", singleThreaded = true) +public class NetworkInterfaceCardApiLiveTest extends BaseAzureComputeApiLiveTest { + + private String resourcegroup; + private String subnetID; + + @BeforeClass + @Override + public void setup() { + super.setup(); + + resourcegroup = getResourceGroupName(); + + //Subnets belong to a virtual network so that needs to be created first + VirtualNetwork vn = getOrCreateVirtualNetwork(VIRTUAL_NETWORK_NAME); + assertNotNull(vn); + + //Subnet needs to be up & running before NIC can be created + Subnet subnet = getOrCreateSubnet(DEFAULT_SUBNET_NAME, VIRTUAL_NETWORK_NAME); + assertNotNull(subnet); + assertNotNull(subnet.id()); + subnetID = subnet.id(); + } + + + @Test(groups = "live") + public void deleteNetworkInterfaceCardResourceDoesNotExist() { + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + boolean status = nicApi.delete(NETWORKINTERFACECARD_NAME); + assertFalse(status); + } + + @Test(groups = "live", dependsOnMethods = "deleteNetworkInterfaceCardResourceDoesNotExist") + public void createNetworkInterfaceCard() { + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + + + //Create properties object + //Create properties object + final NetworkInterfaceCardProperties networkInterfaceCardProperties = + NetworkInterfaceCardProperties.builder().ipConfigurations( + Arrays.asList(IpConfiguration.builder() + .name("myipconfig") + .properties(IpConfigurationProperties.builder() + .privateIPAllocationMethod("Dynamic") + .subnet(IdReference.create(subnetID)).build() + ).build() + )).build(); + + final Map<String, String> tags = ImmutableMap.of("jclouds", "livetest"); + NetworkInterfaceCard nic = nicApi.createOrUpdate(NETWORKINTERFACECARD_NAME, LOCATION, networkInterfaceCardProperties, tags); + + assertEquals(nic.name(), NETWORKINTERFACECARD_NAME); + assertEquals(nic.location(), LOCATION); + assertTrue(nic.properties().ipConfigurations().size() > 0); + assertEquals(nic.properties().ipConfigurations().get(0).name(), "myipconfig"); + assertEquals(nic.properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic"); + assertEquals(nic.properties().ipConfigurations().get(0).properties().subnet().id(), subnetID); + assertEquals(nic.tags().get("jclouds"), "livetest"); + + } + + @Test(groups = "live", dependsOnMethods = "createNetworkInterfaceCard") + public void getNetworkInterfaceCard() { + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + + NetworkInterfaceCard nic = nicApi.get(NETWORKINTERFACECARD_NAME); + + assertEquals(nic.name(), NETWORKINTERFACECARD_NAME); + assertEquals(nic.location(), LOCATION); + assertTrue(nic.properties().ipConfigurations().size() > 0); + assertEquals(nic.properties().ipConfigurations().get(0).name(), "myipconfig"); + assertEquals(nic.properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic"); + assertEquals(nic.properties().ipConfigurations().get(0).properties().subnet().id(), subnetID); + } + + @Test(groups = "live", dependsOnMethods = "createNetworkInterfaceCard") + public void listNetworkInterfaceCards() { + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + + List<NetworkInterfaceCard> nicList = nicApi.list(); + + assertTrue(nicList.contains(nicApi.get(NETWORKINTERFACECARD_NAME))); + } + + + @Test(groups = "live", dependsOnMethods = {"listNetworkInterfaceCards", "getNetworkInterfaceCard"}, alwaysRun = true) + public void deleteNetworkInterfaceCard() { + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + + boolean status = nicApi.delete(NETWORKINTERFACECARD_NAME); + assertTrue(status); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java new file mode 100644 index 0000000..179a4ab --- /dev/null +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/NetworkInterfaceCardApiMockTest.java @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import com.google.common.collect.ImmutableMap; +import com.squareup.okhttp.mockwebserver.MockResponse; +import org.jclouds.azurecompute.arm.domain.IdReference; +import org.jclouds.azurecompute.arm.domain.IpConfiguration; +import org.jclouds.azurecompute.arm.domain.IpConfigurationProperties; +import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard; +import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCardProperties; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; +import org.testng.annotations.Test; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; + +@Test(groups = "unit", testName = "NetworkInterfaceCardApiMockTest", singleThreaded = true) +public class NetworkInterfaceCardApiMockTest extends BaseAzureComputeApiMockTest { + + private final String subscriptionid = "SUBSCRIPTIONID"; + private final String resourcegroup = "myresourcegroup"; + private final String apiVersion = "api-version=2015-06-15"; + private final String location = "northeurope"; + private final String nicName = "myNic"; + + public void getNetworkInterfaceCard() throws InterruptedException { + server.enqueue(jsonResponse("/getnetworkinterfacecard.json")); + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + NetworkInterfaceCard nic = nicApi.get(nicName); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion); + assertSent(server, "GET", path); + assertNotNull(nic); + assertEquals(nic.name(), nicName); + assertEquals(nic.properties().ipConfigurations().get(0).name(), "myip1"); + assertEquals(nic.tags().get("mycustomtag"), "foobar"); + } + + public void getNetworkInterfaceCardEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + + assertNull(nicApi.get(nicName)); + + assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourcegroups/myresourcegroup/providers/Microsoft.Network/networkInterfaces/myNic?api-version=2015-06-15"); + } + + public void listNetworkInterfaceCards() throws InterruptedException { + server.enqueue(jsonResponse("/listnetworkinterfaces.json")); + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + List<NetworkInterfaceCard> nicList = nicApi.list(); + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces?%s", subscriptionid, resourcegroup, apiVersion); + + assertSent(server, "GET", path); + assertTrue(nicList.size() == 2); + assertTrue(nicList.get(0).properties().ipConfigurations().size() > 0); + assertEquals(nicList.get(0).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Dynamic"); + assertTrue(nicList.get(1).properties().ipConfigurations().size() > 0); + assertEquals(nicList.get(1).properties().ipConfigurations().get(0).properties().privateIPAllocationMethod(), "Static"); + } + + public void listNetworkInterfaceCardsEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + + assertTrue(nicApi.list().isEmpty()); + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces?%s", subscriptionid, resourcegroup, apiVersion); + + assertSent(server, "GET", path); + } + + public void createNetworkInterfaceCard() throws InterruptedException { + + server.enqueue(jsonResponse("/createnetworkinterfacecard.json").setStatus("HTTP/1.1 201 Created")); + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + + + final String SubnetID = "/subscriptions/" + subscriptionid + "/resourceGroups/azurearmtesting/providers/Microsoft.Network/virtualNetworks/myvirtualnetwork/subnets/mysubnet"; + //Create properties object + final NetworkInterfaceCardProperties networkInterfaceCardProperties = + NetworkInterfaceCardProperties.create(null, null, null, + Arrays.asList(IpConfiguration.create("myipconfig", null, null, null, + IpConfigurationProperties.create(null, null, "Dynamic", IdReference.create(SubnetID), null)) + ) + ); + + final Map<String, String> tags = ImmutableMap.of("mycustomtag", "foobar"); + + NetworkInterfaceCard nic = nicApi.createOrUpdate(nicName, location, networkInterfaceCardProperties, tags); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion); + String json = String.format("{ \"location\":\"%s\", \"tags\": { \"mycustomtag\": \"foobar\" }, \"properties\":{ \"ipConfigurations\":[ { \"name\":\"%s\", \"properties\":{ \"subnet\":{ \"id\": \"%s\" }, \"privateIPAllocationMethod\":\"%s\" } } ] } }", location, "myipconfig", SubnetID, "Dynamic"); + assertSent(server, "PUT", path, json); + assertEquals(nic.tags().get("mycustomtag"), "foobar"); + } + + public void deleteNetworkInterfaceCard() throws InterruptedException { + + server.enqueue(response202()); + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + + boolean status = nicApi.delete(nicName); + assertTrue(status); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion); + assertSent(server, "DELETE", path); + + } + + public void deleteNetworkInterfaceCardResourceDoesNotExist() throws InterruptedException { + + server.enqueue(response204()); + + final NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(resourcegroup); + + boolean status = nicApi.delete(nicName); + assertFalse(status); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/networkInterfaces/%s?%s", subscriptionid, resourcegroup, nicName, apiVersion); + assertSent(server, "DELETE", path); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiLiveTest.java new file mode 100644 index 0000000..5443235 --- /dev/null +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiLiveTest.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import com.google.common.collect.ImmutableMap; +import org.jclouds.azurecompute.arm.domain.PublicIPAddress; +import org.jclouds.azurecompute.arm.domain.PublicIPAddressProperties; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; +import org.jclouds.util.Predicates2; +import com.google.common.base.Predicate; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + + +@Test(groups = "live", singleThreaded = true) +public class PublicIPAddressApiLiveTest extends BaseAzureComputeApiLiveTest { + + private final String publicIpAddressName = "myipaddress"; + private final String subscriptionid = getSubscriptionId(); + private String resourcegroup; + + @BeforeClass + @Override + public void setup() { + super.setup(); + resourcegroup = getResourceGroupName(); + } + + @Test(groups = "live") + public void deletePublicIPAddressResourceDoesNotExist() { + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + boolean status = ipApi.delete(publicIpAddressName); + assertFalse(status); + } + + @Test(groups = "live", dependsOnMethods = "deletePublicIPAddressResourceDoesNotExist") + public void createPublicIPAddress() { + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + + final Map<String, String> tags = ImmutableMap.of("testkey", "testvalue"); + + PublicIPAddressProperties properties = + PublicIPAddressProperties.builder() + .publicIPAllocationMethod("Static") + .idleTimeoutInMinutes(4) + .build(); + + PublicIPAddress ip = ipApi.createOrUpdate(publicIpAddressName, LOCATION, tags, properties); + + assertNotNull(ip); + assertEquals(ip.name(), publicIpAddressName); + assertEquals(ip.location(), LOCATION); + assertEquals(ip.id(), String.format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/publicIPAddresses/%s", subscriptionid, resourcegroup, publicIpAddressName)); + assertEquals(ip.tags().get("testkey"), "testvalue"); + assertNotNull(ip.properties()); + assertEquals(ip.properties().provisioningState(), "Updating"); + assertNull(ip.properties().ipAddress()); // as we don't get IP address until Succeeded state + assertEquals(ip.properties().publicIPAllocationMethod(), "Static"); + assertEquals(ip.properties().idleTimeoutInMinutes().intValue(), 4); + } + + @Test(groups = "live", dependsOnMethods = "createPublicIPAddress") + public void getPublicIPAddress() { + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + + //Poll until resource is ready to be used + boolean jobDone = Predicates2.retry(new Predicate<String>() { + @Override public boolean apply(String name) { + return ipApi.get(name).properties().provisioningState().equals("Succeeded"); + } + }, 10 * 1000).apply(publicIpAddressName); + assertTrue(jobDone, "get operation did not complete in the configured timeout"); + + PublicIPAddress ip = ipApi.get(publicIpAddressName); + assertNotNull(ip); + assertEquals(ip.name(), publicIpAddressName); + assertEquals(ip.location(), LOCATION); + assertEquals(ip.id(), String.format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/publicIPAddresses/%s", subscriptionid, resourcegroup, publicIpAddressName)); + assertEquals(ip.tags().get("testkey"), "testvalue"); + assertNotNull(ip.properties()); + assertEquals(ip.properties().provisioningState(), "Succeeded"); + assertNotNull(ip.properties().ipAddress()); // by this time we should have IP address already + assertEquals(ip.properties().publicIPAllocationMethod(), "Static"); + assertEquals(ip.properties().idleTimeoutInMinutes().intValue(), 4); + } + + @Test(groups = "live", dependsOnMethods = "createPublicIPAddress") + public void listPublicIPAddresses() { + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + + List<PublicIPAddress> ipList = ipApi.list(); + + assertTrue(ipList.size() > 0); + } + + @Test(groups = "live", dependsOnMethods = {"listPublicIPAddresses", "getPublicIPAddress"}, alwaysRun = true) + public void deletePublicIPAddress() { + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + boolean status = ipApi.delete(publicIpAddressName); + assertTrue(status); + } + +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiMockTest.java new file mode 100644 index 0000000..436cb91 --- /dev/null +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/PublicIPAddressApiMockTest.java @@ -0,0 +1,179 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import com.google.common.collect.ImmutableMap; +import com.squareup.okhttp.mockwebserver.MockResponse; +import org.jclouds.azurecompute.arm.domain.DnsSettings; +import org.jclouds.azurecompute.arm.domain.PublicIPAddress; +import org.jclouds.azurecompute.arm.domain.PublicIPAddressProperties; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; + + +@Test(groups = "unit", testName = "NetworkInterfaceCardApiMockTest", singleThreaded = true) +public class PublicIPAddressApiMockTest extends BaseAzureComputeApiMockTest { + + private final String subscriptionid = "SUBSCRIPTIONID"; + private final String resourcegroup = "myresourcegroup"; + private final String apiVersion = "api-version=2015-06-15"; + private final String location = "northeurope"; + private final String publicIpName = "mypublicaddress"; + + public void getPublicIPAddressInfo() throws InterruptedException { + server.enqueue(jsonResponse("/PublicIPAddressGetInfo.json")); + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + PublicIPAddress ip = ipApi.get(publicIpName); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/publicIPAddresses/%s?%s", subscriptionid, resourcegroup, publicIpName, apiVersion); + assertSent(server, "GET", path); + + assertNotNull(ip); + assertEquals(ip.name(), "mypublicaddress"); + assertEquals(ip.location(), "northeurope"); + assertEquals(ip.id(), "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/mypublicaddress"); + assertEquals(ip.tags().get("testkey"), "testvalue"); + assertNotNull(ip.properties()); + assertEquals(ip.properties().provisioningState(), "Succeeded"); + assertEquals(ip.properties().ipAddress(), "12.123.12.123"); + assertEquals(ip.properties().publicIPAllocationMethod(), "Static"); + assertEquals(ip.properties().idleTimeoutInMinutes().intValue(), 4); + assertNotNull(ip.properties().dnsSettings()); + assertEquals(ip.properties().dnsSettings().domainNameLabel(), "foobar"); + assertEquals(ip.properties().dnsSettings().fqdn(), "foobar.northeurope.cloudapp.azure.com"); + assertNotNull(ip.properties().ipConfiguration()); + assertEquals(ip.properties().ipConfiguration().id(), "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkInterfaces/myNic/ipConfigurations/myip1"); + } + + public void getPublicIPAddressInfoEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + PublicIPAddress ip = ipApi.get(publicIpName); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/publicIPAddresses/%s?%s", subscriptionid, resourcegroup, publicIpName, apiVersion); + assertSent(server, "GET", path); + + assertNull(ip); + } + + public void listPublicIPAddresses() throws InterruptedException { + server.enqueue(jsonResponse("/PublicIPAddressList.json")); + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + List<PublicIPAddress> ipList = ipApi.list(); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/publicIPAddresses?%s", subscriptionid, resourcegroup, apiVersion); + assertSent(server, "GET", path); + assertEquals(ipList.size(), 4); + } + + public void listPublicIPAddressesEmpty() throws InterruptedException { + server.enqueue(new MockResponse().setResponseCode(404)); + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + List<PublicIPAddress> ipList = ipApi.list(); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/publicIPAddresses?%s", subscriptionid, resourcegroup, apiVersion); + assertSent(server, "GET", path); + assertEquals(ipList.size(), 0); + } + + public void createPublicIPAddress() throws InterruptedException { + + server.enqueue(jsonResponse("/PublicIPAddressCreate.json").setStatus("HTTP/1.1 201 Created")); + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + + final Map<String, String> tags = ImmutableMap.of("testkey", "testvalue"); + + PublicIPAddressProperties properties = PublicIPAddressProperties.create(null, null, "Static", 4, null, + DnsSettings.create("foobar", "foobar.northeurope.cloudapp.azure.com", null)); + + PublicIPAddress ip = ipApi.createOrUpdate(publicIpName, location, tags, properties); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/publicIPAddresses/%s?%s", subscriptionid, resourcegroup, publicIpName, apiVersion); + String json = String.format("{ \"location\": \"%s\", \"tags\": { \"testkey\": \"testvalue\" }, \"properties\": { \"publicIPAllocationMethod\": \"Static\", \"idleTimeoutInMinutes\": 4, \"dnsSettings\": { \"domainNameLabel\": \"foobar\", \"fqdn\": \"foobar.northeurope.cloudapp.azure.com\" } } }", location); + assertSent(server, "PUT", path, json); + + assertNotNull(ip); + assertEquals(ip.name(), "mypublicaddress"); + assertEquals(ip.location(), "northeurope"); + assertEquals(ip.id(), "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/mypublicaddress"); + assertEquals(ip.tags().get("testkey"), "testvalue"); + assertNotNull(ip.properties()); + assertEquals(ip.properties().provisioningState(), "Updating"); + assertNull(ip.properties().ipAddress()); // as we don't get IP address until Succeeded state + assertEquals(ip.properties().publicIPAllocationMethod(), "Static"); + assertEquals(ip.properties().idleTimeoutInMinutes().intValue(), 4); + assertNotNull(ip.properties().dnsSettings()); + assertEquals(ip.properties().dnsSettings().domainNameLabel(), "foobar"); + assertEquals(ip.properties().dnsSettings().fqdn(), "foobar.northeurope.cloudapp.azure.com"); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void createPublicIPAddressDnsRecordInUse() throws IllegalArgumentException, InterruptedException { + + server.enqueue(jsonResponse("/PublicIPAddressCreateDnsRecordInUse.json").setStatus("HTTP/1.1 400 Bad Request")); + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + + final Map<String, String> tags = ImmutableMap.of("testkey", "testvalue"); + + PublicIPAddressProperties properties = PublicIPAddressProperties.create(null, null, "Static", 4, null, + DnsSettings.create("foobar", "foobar.northeurope.cloudapp.azure.com", null)); + + PublicIPAddress ip = ipApi.createOrUpdate(publicIpName, location, tags, properties); + + } + + public void deletePublicIPAddress() throws InterruptedException { + + server.enqueue(response202()); + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + boolean status = ipApi.delete(publicIpName); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/publicIPAddresses/%s?%s", subscriptionid, resourcegroup, publicIpName, apiVersion); + assertSent(server, "DELETE", path); + + assertTrue(status); + } + + public void deletePublicIPAddressResourceDoesNotExist() throws InterruptedException { + + server.enqueue(response204()); + + final PublicIPAddressApi ipApi = api.getPublicIPAddressApi(resourcegroup); + boolean status = ipApi.delete(publicIpName); + + String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Network/publicIPAddresses/%s?%s", subscriptionid, resourcegroup, publicIpName, apiVersion); + assertSent(server, "DELETE", path); + + assertFalse(status); + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java new file mode 100644 index 0000000..87b84d8 --- /dev/null +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiLiveTest.java @@ -0,0 +1,245 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import com.google.common.base.Predicate; +import org.jclouds.azurecompute.arm.domain.DataDisk; +import org.jclouds.azurecompute.arm.domain.DiagnosticsProfile; +import org.jclouds.azurecompute.arm.domain.HardwareProfile; +import org.jclouds.azurecompute.arm.domain.IdReference; +import org.jclouds.azurecompute.arm.domain.ImageReference; +import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard; +import org.jclouds.azurecompute.arm.domain.NetworkProfile; +import org.jclouds.azurecompute.arm.domain.OSDisk; +import org.jclouds.azurecompute.arm.domain.OSProfile; +import org.jclouds.azurecompute.arm.domain.StorageProfile; +import org.jclouds.azurecompute.arm.domain.StorageService; +import org.jclouds.azurecompute.arm.domain.VHD; +import org.jclouds.azurecompute.arm.domain.VirtualMachine; +import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance; +import org.jclouds.azurecompute.arm.domain.VirtualMachineProperties; +import org.jclouds.azurecompute.arm.functions.ParseJobStatus; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest; +import org.jclouds.util.Predicates2; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertNotNull; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import static org.testng.Assert.assertTrue; + +@Test(groups = "live", testName = "VirtualMachineApiLiveTest") +public class VirtualMachineApiLiveTest extends BaseAzureComputeApiLiveTest { + + private String subscriptionid = getSubscriptionId(); + private String vmName = null; + private String nicName = null; + + @BeforeClass + public void Setup() { + NetworkInterfaceCard nic = getOrCreateNetworkInterfaceCard(NETWORKINTERFACECARD_NAME); + assertNotNull(nic); + nicName = nic.name(); + } + + private String getName() { + if (vmName == null) { + vmName = String.format("%3.24s", + System.getProperty("user.name") + RAND + this.getClass().getSimpleName()).toLowerCase().substring(0, 15); + } + return vmName; + } + + @Test + public void testCreate(){ + + StorageAccountApi storageApi = api.getStorageAccountApi(getResourceGroupName()); + StorageService storageAccount = storageApi.get(getStorageServiceName()); + String blob = storageAccount.storageServiceProperties().primaryEndpoints().get("blob"); + + VirtualMachine vm = api().create(getName(), LOCATION, getProperties(blob, nicName)); + assertTrue(!vm.name().isEmpty()); + + //Poll until resource is ready to be used + boolean jobDone = Predicates2.retry(new Predicate<String>() { + @Override public boolean apply(String name) { + return !api().get(name).properties().provisioningState().equals("Creating"); + } + }, 60 * 20 * 1000).apply(getName()); + assertTrue(jobDone, "create operation did not complete in the configured timeout"); + + String status = api().get(vmName).properties().provisioningState(); + // Cannot be creating anymore. Should be succeeded or running but not failed. + assertTrue(!status.equals("Creating")); + assertTrue(!status.equals("Failed")); + } + + @Test(dependsOnMethods = "testCreate") + public void testGet() { + VirtualMachine vm = api().get(getName()); + assertTrue(!vm.name().isEmpty()); + } + + @Test(dependsOnMethods = "testCreate") + public void testGetInstanceView() { + VirtualMachineInstance vmi = api().getInstanceDetails(getName()); + assertTrue(!vmi.statuses().isEmpty()); + } + + @Test(dependsOnMethods = "testStart") + public void testStop() { + api().stop(getName()); + //Poll until resource is ready to be used + boolean jobDone = Predicates2.retry(new Predicate<String>() { + @Override public boolean apply(String name) { + String status = ""; + List<VirtualMachineInstance.VirtualMachineStatus> statuses = api().getInstanceDetails(name).statuses(); + for (int c = 0; c < statuses.size(); c++) { + if (statuses.get(c).code().substring(0, 10).equals("PowerState")) { + status = statuses.get(c).displayStatus(); + break; + } + } + return status.equals("VM stopped"); + } + }, 60 * 4 * 1000).apply(getName()); + assertTrue(jobDone, "stop operation did not complete in the configured timeout"); + + } + + @Test(dependsOnMethods = "testGet") + public void testStart() { + api().start(getName()); + + //Poll until resource is ready to be used + boolean jobDone = Predicates2.retry(new Predicate<String>() { + @Override public boolean apply(String name) { + String status = ""; + List<VirtualMachineInstance.VirtualMachineStatus> statuses = api().getInstanceDetails(name).statuses(); + for (int c = 0; c < statuses.size(); c++) { + if (statuses.get(c).code().substring(0, 10).equals("PowerState")) { + status = statuses.get(c).displayStatus(); + break; + } + } + return status.equals("VM running"); + } + }, 60 * 4 * 1000).apply(getName()); + assertTrue(jobDone, "start operation did not complete in the configured timeout"); + + } + + @Test(dependsOnMethods = "testStop") + public void testRestart() { + api().start(getName()); + + //Poll until resource is ready to be used + boolean jobDone = Predicates2.retry(new Predicate<String>() { + @Override public boolean apply(String name) { + String status = ""; + List<VirtualMachineInstance.VirtualMachineStatus> statuses = api().getInstanceDetails(name).statuses(); + for (int c = 0; c < statuses.size(); c++) { + if (statuses.get(c).code().substring(0, 10).equals("PowerState")) { + status = statuses.get(c).displayStatus(); + break; + } + } + return status.equals("VM running"); + } + }, 60 * 4 * 1000).apply(getName()); + assertTrue(jobDone, "start operation did not complete in the configured timeout"); + + api().restart(getName()); + + //Poll until resource is ready to be used + jobDone = Predicates2.retry(new Predicate<String>() { + @Override public boolean apply(String name) { + String status = ""; + List<VirtualMachineInstance.VirtualMachineStatus> statuses = api().getInstanceDetails(name).statuses(); + for (int c = 0; c < statuses.size(); c++) { + if (statuses.get(c).code().substring(0, 10).equals("PowerState")) { + status = statuses.get(c).displayStatus(); + break; + } + } + return status.equals("VM running"); + } + }, 60 * 4 * 1000).apply(getName()); + assertTrue(jobDone, "restart operation did not complete in the configured timeout"); + } + + @Test(dependsOnMethods = "testCreate") + public void testList() { + List<VirtualMachine> list = api().list(); + VirtualMachine vm = api().get(getName()); + assertTrue(list.contains(vm)); + } + + @Test(dependsOnMethods = {"testRestart", "testList", "testGet"}, alwaysRun = true) + public void testDelete() throws Exception { + URI uri = api().delete(getName()); + + if (uri != null) { + assertTrue(uri.toString().contains("api-version")); + + boolean jobDone = Predicates2.retry(new Predicate<URI>() { + @Override + public boolean apply(URI uri) { + return ParseJobStatus.JobStatus.DONE == api.getJobApi().jobStatus(uri); + } + }, 60 * 8 * 1000 /* 2 minutes timeout */).apply(uri); + assertTrue(jobDone, "delete operation did not complete in the configured timeout"); + } + } + + private VirtualMachineApi api() { + return api.getVirtualMachineApi(getResourceGroupName()); + } + + private VirtualMachineProperties getProperties(String blob, String nic) { + + HardwareProfile hwProf = HardwareProfile.create("Standard_D1"); + ImageReference imgRef = ImageReference.create("MicrosoftWindowsServerEssentials", + "WindowsServerEssentials", "WindowsServerEssentials", "latest"); + VHD vhd = VHD.create(blob + "vhds/" + getName() + ".vhd"); + VHD vhd2 = VHD.create(blob + "vhds/" + getName() + "data.vhd"); + DataDisk dataDisk = DataDisk.create(getName() + "data", "100", 0, vhd2, "Empty"); + OSDisk osDisk = OSDisk.create(null, getName(), vhd, "ReadWrite", "FromImage"); + StorageProfile storageProfile = StorageProfile.create(imgRef, osDisk, null); + OSProfile.WindowsConfiguration windowsConfig = OSProfile.WindowsConfiguration.create(false, null, null, true, + null); + OSProfile osProfile = OSProfile.create(getName(), "azureuser", "RFe3&432dg", null, null, windowsConfig); + IdReference networkInterface = + IdReference.create("/subscriptions/" + subscriptionid + + "/resourceGroups/" + getResourceGroupName() + "/providers/Microsoft.Network/networkInterfaces/" + + nic); + List<IdReference> networkInterfaces = + new ArrayList<IdReference>(); + networkInterfaces.add(networkInterface); + NetworkProfile networkProfile = NetworkProfile.create(networkInterfaces); + DiagnosticsProfile.BootDiagnostics bootDiagnostics = + DiagnosticsProfile.BootDiagnostics.create(true, blob); + DiagnosticsProfile diagnosticsProfile = DiagnosticsProfile.create(bootDiagnostics); + VirtualMachineProperties properties = VirtualMachineProperties.create(null, + null, null, hwProf, storageProfile, osProfile, networkProfile, diagnosticsProfile, "Creating"); + return properties; + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java new file mode 100644 index 0000000..a2be833 --- /dev/null +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/features/VirtualMachineApiMockTest.java @@ -0,0 +1,249 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.azurecompute.arm.features; + +import com.google.common.collect.ImmutableList; +import com.squareup.okhttp.mockwebserver.MockResponse; +import org.jclouds.azurecompute.arm.domain.HardwareProfile; +import org.jclouds.azurecompute.arm.domain.IdReference; +import org.jclouds.azurecompute.arm.domain.ImageReference; +import org.jclouds.azurecompute.arm.domain.VirtualMachine; +import org.jclouds.azurecompute.arm.domain.VHD; +import org.jclouds.azurecompute.arm.domain.OSDisk; +import org.jclouds.azurecompute.arm.domain.OSProfile; +import org.jclouds.azurecompute.arm.domain.DiagnosticsProfile; +import org.jclouds.azurecompute.arm.domain.NetworkProfile; +import org.jclouds.azurecompute.arm.domain.StorageProfile; +import org.jclouds.azurecompute.arm.domain.DataDisk; +import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance; +import org.jclouds.azurecompute.arm.domain.VirtualMachineProperties; +import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest; +import org.testng.annotations.Test; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; +import java.util.Date; +import java.text.SimpleDateFormat; +import java.text.DateFormat; + +import static com.google.common.collect.Iterables.isEmpty; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; + +@Test(groups = "unit", testName = "VirtualMachineApiMockTest", singleThreaded = true) +public class VirtualMachineApiMockTest extends BaseAzureComputeApiMockTest { + + public void testGet() throws Exception { + server.enqueue(jsonResponse("/virtualmachine.json")); + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + assertEquals(vmAPI.get("windowsmachine"), getVM()); + assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines/windowsmachine?api-version=2015-06-15"); + } + public void testGetEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + assertNull(vmAPI.get("windowsmachine")); + assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines/windowsmachine?api-version=2015-06-15"); + } + + public void testGetInstanceDetails() throws Exception { + server.enqueue(jsonResponse("/virtualmachineInstance.json")); + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + VirtualMachineInstance actual = vmAPI.getInstanceDetails("windowsmachine"); + VirtualMachineInstance expected = getVMInstance(); + + assertEquals(actual.statuses().get(0).code(), expected.statuses().get(0).code()); + assertEquals(actual.statuses().get(0).displayStatus(), expected.statuses().get(0).displayStatus()); + assertEquals(actual.statuses().get(0).level(), expected.statuses().get(0).level()); + 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=2015-06-15"); + } + + public void testGetInstanceDetailsEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + 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=2015-06-15"); + } + + public void testList() throws Exception { + server.enqueue(jsonResponse("/virtualmachines.json")); + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + assertEquals(vmAPI.list(), getVMList()); + assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines?api-version=2015-06-15"); + } + public void testListEmpty() throws Exception { + server.enqueue(new MockResponse().setResponseCode(404)); + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + assertTrue(isEmpty(vmAPI.list())); + assertSent(server, "GET", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines?api-version=2015-06-15"); + } + + public void testCreate() throws Exception { + server.enqueue(jsonResponse("/createvirtualmachineresponse.json")); + + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + VirtualMachine vm = vmAPI.create("windowsmachine", "westus", getProperties()); + assertEquals(vm, getVM()); + assertSent(server, "PUT", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines/windowsmachine?api-version=2015-06-15&validating=false", + "{\"location\":\"westus\",\"properties\":" + + "{\"vmId\":\"27ee085b-d707-xxxx-yyyy-2370e2eb1cc1\"," + + "\"hardwareProfile\":{\"vmSize\":\"Standard_D1\"}," + + "\"storageProfile\":{\"imageReference\":{\"publisher\":\"publisher\",\"offer\":\"offer\",\"sku\":\"sku\",\"version\":\"ver\"}," + + "\"osDisk\":{\"osType\":\"Windows\",\"name\":\"windowsmachine\"," + + "\"vhd\":{\"uri\":\"https://groupname2760.blob.core.windows.net/vhds/windowsmachine201624102936.vhd\"},\"caching\":\"ReadWrite\",\"createOption\":\"FromImage\"},\"dataDisks\":[]}," + + "\"osProfile\":{\"computerName\":\"windowsmachine\",\"adminUsername\":\"azureuser\",\"windowsConfiguration\":{\"provisionVMAgent\":false,\"enableAutomaticUpdates\":true}}," + + "\"networkProfile\":{\"networkInterfaces\":[{\"id\":\"/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Network/networkInterfaces/windowsmachine167\"}]}," + + "\"diagnosticsProfile\":{\"bootDiagnostics\":{\"enabled\":true,\"storageUri\":\"https://groupname2760.blob.core.windows.net/\"}},\"provisioningState\":\"Creating\"}}"); + + } + + public void testDeleteReturns404() throws Exception { + server.enqueue(response404()); + + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + + URI uri = vmAPI.delete("windowsmachine"); + + assertEquals(server.getRequestCount(), 1); + assertNull(uri); + + assertSent(server, "DELETE", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines/windowsmachine?api-version=2015-06-15"); + } + public void testDelete() throws Exception { + server.enqueue(response202WithHeader()); + + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + + URI uri = vmAPI.delete("windowsmachine"); + + assertEquals(server.getRequestCount(), 1); + assertNotNull(uri); + + assertSent(server, "DELETE", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines/windowsmachine?api-version=2015-06-15"); + } + + public void testStart() throws Exception { + server.enqueue(new MockResponse().setResponseCode(204)); + + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + + vmAPI.start("windowsmachine"); + + assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines/windowsmachine/start?api-version=2015-06-15"); + } + + public void testRestart() throws Exception { + server.enqueue(new MockResponse().setResponseCode(204)); + + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + + vmAPI.restart("windowsmachine"); + + assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines/windowsmachine/restart?api-version=2015-06-15"); + } + + public void testStop() throws Exception { + server.enqueue(new MockResponse().setResponseCode(204)); + + final VirtualMachineApi vmAPI = api.getVirtualMachineApi("groupname"); + + vmAPI.stop("windowsmachine"); + + assertSent(server, "POST", "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute" + + "/virtualMachines/windowsmachine/powerOff?api-version=2015-06-15"); + } + + private VirtualMachineProperties getProperties() { + HardwareProfile hwProf = HardwareProfile.create("Standard_D1"); + ImageReference imgRef = ImageReference.create("publisher", "offer", "sku", "ver"); + VHD vhd = VHD.create("https://groupname2760.blob.core.windows.net/vhds/windowsmachine201624102936.vhd"); + List<DataDisk> dataDisks = new ArrayList<DataDisk>(); + OSDisk osDisk = OSDisk.create("Windows", "windowsmachine", vhd, "ReadWrite", "FromImage"); + StorageProfile storageProfile = StorageProfile.create(imgRef, osDisk, dataDisks); + OSProfile.WindowsConfiguration windowsConfig = OSProfile.WindowsConfiguration.create(false, null, null, true, + null); + OSProfile osProfile = OSProfile.create("windowsmachine", "azureuser", null, null, null, windowsConfig); + IdReference networkInterface = + IdReference.create("/subscriptions/SUBSCRIPTIONID" + + "/resourceGroups/groupname/providers/Microsoft.Network/networkInterfaces/" + + "windowsmachine167"); + List<IdReference> networkInterfaces = new ArrayList<IdReference>(); + networkInterfaces.add(networkInterface); + NetworkProfile networkProfile = NetworkProfile.create(networkInterfaces); + DiagnosticsProfile.BootDiagnostics bootDiagnostics = DiagnosticsProfile.BootDiagnostics.create(true, + "https://groupname2760.blob.core.windows.net/"); + DiagnosticsProfile diagnosticsProfile = DiagnosticsProfile.create(bootDiagnostics); + VirtualMachineProperties properties = VirtualMachineProperties.create("27ee085b-d707-xxxx-yyyy-2370e2eb1cc1", + null, null, hwProf, storageProfile, osProfile, networkProfile, diagnosticsProfile, "Creating"); + return properties; + } + + private VirtualMachine getVM() { + VirtualMachineProperties properties = getProperties(); + VirtualMachine machine = VirtualMachine.create("/subscriptions/SUBSCRIPTIONID/" + "" + + "resourceGroups/groupname/providers/Microsoft.Compute/virtualMachines/windowsmachine", "windowsmachine", + "Microsoft.Compute/virtualMachines", "westus", null, properties); + return machine; + } + + private VirtualMachineInstance getVMInstance() { + List<VirtualMachineInstance.VirtualMachineStatus> statuses = new ArrayList<VirtualMachineInstance.VirtualMachineStatus>(); + String testDate = "Wed May 04 01:38:52 PDT 2016"; + DateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy"); + Date date = null; + try { + date = formatter.parse(testDate); + } catch (Exception e) { + e.printStackTrace(); + } + VirtualMachineInstance.VirtualMachineStatus vmStatus = + VirtualMachineInstance.VirtualMachineStatus.create("ProvisioningState/succeeded", "Info", "Provisioning succeeded", date); + statuses.add(vmStatus); + VirtualMachineInstance.VirtualMachineStatus vmStatus1 = + VirtualMachineInstance.VirtualMachineStatus.create("PowerState/running", "Info", "VM running", null); + statuses.add(vmStatus1); + + VirtualMachineInstance machineInstance = + VirtualMachineInstance.create(null, null, ImmutableList.copyOf(statuses)); + return machineInstance; + } + + private List<VirtualMachine> getVMList() { + VirtualMachineProperties properties = getProperties(); + VirtualMachine machine = VirtualMachine.create("/subscriptions/SUBSCRIPTIONID/" + "" + + "resourceGroups/groupname/providers/Microsoft.Compute/virtualMachines/windowsmachine", + "windowsmachine", "Microsoft.Compute/virtualMachines", "westus", null, properties); + List<VirtualMachine> list = new ArrayList<VirtualMachine>(); + list.add(machine); + return list; + } +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/AbstractAzureComputeApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/AbstractAzureComputeApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/AbstractAzureComputeApiLiveTest.java index aa0663a..bd55694 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/AbstractAzureComputeApiLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/AbstractAzureComputeApiLiveTest.java @@ -22,9 +22,9 @@ import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.OPERATI import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.OPERATION_TIMEOUT; import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TCP_RULE_FORMAT; import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TCP_RULE_REGEXP; + import java.util.Properties; import java.util.Random; - import org.jclouds.apis.BaseApiLiveTest; import org.jclouds.azurecompute.arm.AzureComputeApi; import org.jclouds.azurecompute.arm.AzureComputeProviderMetadata; http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/BaseAzureComputeApiLiveTest.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/BaseAzureComputeApiLiveTest.java b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/BaseAzureComputeApiLiveTest.java index b1d97b8..0768dab 100644 --- a/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/BaseAzureComputeApiLiveTest.java +++ b/azurecompute-arm/src/test/java/org/jclouds/azurecompute/arm/internal/BaseAzureComputeApiLiveTest.java @@ -20,11 +20,17 @@ import static org.testng.Assert.assertTrue; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; +import org.jclouds.azurecompute.arm.domain.IdReference; +import org.jclouds.azurecompute.arm.domain.IpConfiguration; +import org.jclouds.azurecompute.arm.domain.IpConfigurationProperties; +import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCard; +import org.jclouds.azurecompute.arm.domain.NetworkInterfaceCardProperties; import org.jclouds.azurecompute.arm.domain.ResourceGroup; import org.jclouds.azurecompute.arm.domain.StorageService; import org.jclouds.azurecompute.arm.domain.Subnet; import org.jclouds.azurecompute.arm.domain.VirtualNetwork; +import org.jclouds.azurecompute.arm.features.NetworkInterfaceCardApi; import org.jclouds.azurecompute.arm.features.StorageAccountApi; import org.jclouds.azurecompute.arm.features.SubnetApi; import org.jclouds.azurecompute.arm.features.VirtualNetworkApi; @@ -36,6 +42,7 @@ import org.testng.annotations.BeforeClass; import java.net.URI; import java.util.Arrays; +import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; @@ -50,13 +57,15 @@ public class BaseAzureComputeApiLiveTest extends AbstractAzureComputeApiLiveTest public static final String DEFAULT_VIRTUALNETWORK_ADDRESS_PREFIX = "10.2.0.0/16"; + public static final String NETWORKINTERFACECARD_NAME = "jcloudsNic"; + private String resourceGroupName = null; protected StorageService storageService; - private String storageServiceName = null; + protected String getStorageServiceName() { if (storageServiceName == null) { storageServiceName = String.format("%3.24s", @@ -74,6 +83,17 @@ public class BaseAzureComputeApiLiveTest extends AbstractAzureComputeApiLiveTest return endpoint; } + protected String getSubscriptionId() { + String subscriptionid = null; + String endpoint = null; + endpoint = getEndpoint(); + if (endpoint != null) { + subscriptionid = endpoint.substring(endpoint.lastIndexOf("/") + 1); + } + assertNotNull(subscriptionid); + return subscriptionid; + } + protected String getResourceGroupName() { if (resourceGroupName == null) { resourceGroupName = String.format("%3.24s", @@ -99,7 +119,6 @@ public class BaseAzureComputeApiLiveTest extends AbstractAzureComputeApiLiveTest @Override public void setup() { super.setup(); - storageService = getOrCreateStorageService(getStorageServiceName()); } @@ -169,4 +188,29 @@ public class BaseAzureComputeApiLiveTest extends AbstractAzureComputeApiLiveTest return subnet; } + + protected NetworkInterfaceCard getOrCreateNetworkInterfaceCard(final String networkInterfaceCardName){ + + NetworkInterfaceCardApi nicApi = api.getNetworkInterfaceCardApi(getResourceGroupName()); + NetworkInterfaceCard nic = nicApi.get(networkInterfaceCardName); + + if (nic != null){ + return nic; + } + + VirtualNetwork vn = getOrCreateVirtualNetwork(VIRTUAL_NETWORK_NAME); + + Subnet subnet = getOrCreateSubnet(DEFAULT_SUBNET_NAME, VIRTUAL_NETWORK_NAME); + + //Create properties object + final NetworkInterfaceCardProperties networkInterfaceCardProperties = + NetworkInterfaceCardProperties.builder() + .ipConfigurations(Arrays.asList(IpConfiguration.create("myipconfig", null, null, null, + IpConfigurationProperties.create(null, null, "Dynamic", IdReference.create(subnet.id()), null)) + )).build(); + + final Map<String, String> tags = ImmutableMap.of("jclouds", "livetest"); + nic = nicApi.createOrUpdate(NETWORKINTERFACECARD_NAME, LOCATION, networkInterfaceCardProperties, tags); + return nic; + } } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/PublicIPAddressCreate.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/PublicIPAddressCreate.json b/azurecompute-arm/src/test/resources/PublicIPAddressCreate.json new file mode 100644 index 0000000..d9e06aa --- /dev/null +++ b/azurecompute-arm/src/test/resources/PublicIPAddressCreate.json @@ -0,0 +1,20 @@ +{ + "name": "mypublicaddress", + "id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/mypublicaddress", + "etag": "W/\"f0bdaf62-456b-4338-8f65-05417b1a55e9\"", + "type": "Microsoft.Network/publicIPAddresses", + "location": "northeurope", + "tags": { + "testkey": "testvalue" + }, + "properties": { + "provisioningState": "Updating", + "resourceGuid": "ebe3f160-2484-447a-8980-c587b214b16f", + "publicIPAllocationMethod": "Static", + "idleTimeoutInMinutes": 4, + "dnsSettings": { + "domainNameLabel": "foobar", + "fqdn": "foobar.northeurope.cloudapp.azure.com" + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/PublicIPAddressCreateDnsRecordInUse.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/PublicIPAddressCreateDnsRecordInUse.json b/azurecompute-arm/src/test/resources/PublicIPAddressCreateDnsRecordInUse.json new file mode 100644 index 0000000..16a52c8 --- /dev/null +++ b/azurecompute-arm/src/test/resources/PublicIPAddressCreateDnsRecordInUse.json @@ -0,0 +1,7 @@ +{ + "error": { + "code": "DnsRecordInUse", + "message": "DNS record foobar.northeurope.cloudapp.azure.com is already used by another public IP.", + "details": [] + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/PublicIPAddressGetInfo.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/PublicIPAddressGetInfo.json b/azurecompute-arm/src/test/resources/PublicIPAddressGetInfo.json new file mode 100644 index 0000000..00ca989 --- /dev/null +++ b/azurecompute-arm/src/test/resources/PublicIPAddressGetInfo.json @@ -0,0 +1,24 @@ +{ + "name": "mypublicaddress", + "id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/mypublicaddress", + "etag": "W/\"0b020646-202f-4ac6-b1a7-f9645db7c371\"", + "type": "Microsoft.Network/publicIPAddresses", + "location": "northeurope", + "tags": { + "testkey": "testvalue" + }, + "properties": { + "provisioningState": "Succeeded", + "resourceGuid": "eb0da01e-2a30-4e84-b7a4-0ce9dde019f5", + "ipAddress": "12.123.12.123", + "publicIPAllocationMethod": "Static", + "idleTimeoutInMinutes": 4, + "dnsSettings": { + "domainNameLabel": "foobar", + "fqdn": "foobar.northeurope.cloudapp.azure.com" + }, + "ipConfiguration": { + "id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkInterfaces/myNic/ipConfigurations/myip1" + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/PublicIPAddressList.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/PublicIPAddressList.json b/azurecompute-arm/src/test/resources/PublicIPAddressList.json new file mode 100644 index 0000000..2b78b37 --- /dev/null +++ b/azurecompute-arm/src/test/resources/PublicIPAddressList.json @@ -0,0 +1,80 @@ +{ + "value": [ + { + "name": "my2ndpublicaddress", + "id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/my2ndpublicaddress", + "etag": "W/\"b83fa879-46ee-48a9-8120-26572449788f\"", + "type": "Microsoft.Network/publicIPAddresses", + "location": "northeurope", + "tags": { + "testkey": "testvalue" + }, + "properties": { + "provisioningState": "Succeeded", + "resourceGuid": "ebe3f160-2484-447a-8980-c587b214b16f", + "publicIPAllocationMethod": "Dynamic", + "idleTimeoutInMinutes": 4, + "dnsSettings": { + "domainNameLabel": "foobar123", + "fqdn": "foobar123.northeurope.cloudapp.azure.com" + } + } + }, + { + "name": "my3rdpublicaddress", + "id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/my3rdpublicaddress", + "etag": "W/\"17d2cf9a-7aa8-4c53-a5b8-ebc2ccb7bf93\"", + "type": "Microsoft.Network/publicIPAddresses", + "location": "northeurope", + "tags": { + "testkey": "testvalue" + }, + "properties": { + "provisioningState": "Succeeded", + "resourceGuid": "e1107240-79c5-4829-ba16-f7a00c2763df", + "ipAddress": "12.12.123.123", + "publicIPAllocationMethod": "Static", + "idleTimeoutInMinutes": 4 + } + }, + { + "name": "my4thpublicaddress", + "id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/my4thpublicaddress", + "etag": "W/\"c32275e9-e1fc-465a-a5de-728c1359e123\"", + "type": "Microsoft.Network/publicIPAddresses", + "location": "northeurope", + "tags": { + "testkey": "testvalue" + }, + "properties": { + "provisioningState": "Succeeded", + "resourceGuid": "dbde9a83-8c1a-43f4-8d81-0fa469703e8a", + "ipAddress": "12.12.123.124", + "publicIPAllocationMethod": "Static", + "idleTimeoutInMinutes": 4 + } + }, + { + "name": "mypublicaddress", + "id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/publicIPAddresses/mypublicaddress", + "etag": "W/\"0b020646-202f-4ac6-b1a7-f9645db7c371\"", + "type": "Microsoft.Network/publicIPAddresses", + "location": "northeurope", + "tags": {}, + "properties": { + "provisioningState": "Succeeded", + "resourceGuid": "eb0da01e-2a30-4e84-b7a4-0ce9dde019f5", + "ipAddress": "12.123.12.125", + "publicIPAllocationMethod": "Static", + "idleTimeoutInMinutes": 4, + "dnsSettings": { + "domainNameLabel": "foobar", + "fqdn": "foobar.northeurope.cloudapp.azure.com" + }, + "ipConfiguration": { + "id": "/subscriptions/fakeb2f5-4710-4e93-bdf4-419edbde2178/resourceGroups/myresourcegroup/providers/Microsoft.Network/networkInterfaces/myNic/ipConfigurations/myip1" + } + } + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/createnetworkinterfacecard.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/createnetworkinterfacecard.json b/azurecompute-arm/src/test/resources/createnetworkinterfacecard.json new file mode 100644 index 0000000..d08b8f6 --- /dev/null +++ b/azurecompute-arm/src/test/resources/createnetworkinterfacecard.json @@ -0,0 +1,35 @@ +{ + "name": "myNic", + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/myNic", + "etag": "W/\"6b51f6e7-232b-4289-b740-04a996929f5e\"", + "type": "Microsoft.Network/networkInterfaces", + "location": "northeurope", + "tags": { + "mycustomtag": "foobar" + }, + "properties": { + "provisioningState": "Succeeded", + "resourceGuid": "f3465472-536f-49e7-9e9c-fa91b971a618", + "ipConfigurations": [ + { + "name": "myip1", + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/myNic/ipConfigurations/myip1", + "etag": "W/\"6b51f6e7-232b-4289-b740-04a996929f5e\"", + "properties": { + "provisioningState": "Succeeded", + "privateIPAddress": "10.2.0.4", + "privateIPAllocationMethod": "Dynamic", + "subnet": { + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/virtualNetworks/myvirtualnetwork/subnets/mysubnet" + }, + "primary": true + } + } + ], + "dnsSettings": { + "dnsServers": [], + "appliedDnsServers": [] + }, + "enableIPForwarding": false + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/createvirtualmachineresponse.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/createvirtualmachineresponse.json b/azurecompute-arm/src/test/resources/createvirtualmachineresponse.json new file mode 100644 index 0000000..ae16bdb --- /dev/null +++ b/azurecompute-arm/src/test/resources/createvirtualmachineresponse.json @@ -0,0 +1,47 @@ +{ + "properties": { + "vmId": "27ee085b-d707-xxxx-yyyy-2370e2eb1cc1", + "hardwareProfile": { + "vmSize": "Standard_D1" + }, + "storageProfile": { + "imageReference": { + "publisher": "publisher", + "offer": "offer", + "sku": "sku", + "version": "ver" + }, + "osDisk": { + "osType": "Windows", + "name": "windowsmachine", + "createOption": "FromImage", + "vhd": { + "uri": "https://groupname2760.blob.core.windows.net/vhds/windowsmachine201624102936.vhd" + }, + "caching": "ReadWrite" + }, + "dataDisks": [] + }, + "osProfile": { + "computerName": "windowsmachine", + "adminUsername": "azureuser", + "windowsConfiguration": { + "provisionVMAgent": false, + "enableAutomaticUpdates": true + }, + "secrets": [] + }, + "networkProfile": {"networkInterfaces":[{"id":"/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Network/networkInterfaces/windowsmachine167"}]}, + "diagnosticsProfile": { + "bootDiagnostics": { + "enabled": true, + "storageUri": "https://groupname2760.blob.core.windows.net/" + } + }, + "provisioningState": "Creating" + }, + "id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute/virtualMachines/windowsmachine", + "name": "windowsmachine", + "type": "Microsoft.Compute/virtualMachines", + "location": "westus" +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/getnetworkinterfacecard.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/getnetworkinterfacecard.json b/azurecompute-arm/src/test/resources/getnetworkinterfacecard.json new file mode 100644 index 0000000..f613291 --- /dev/null +++ b/azurecompute-arm/src/test/resources/getnetworkinterfacecard.json @@ -0,0 +1,35 @@ +{ + "name": "myNic", + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/myNic", + "etag": "W/\"3dff0c55-a7a7-434f-837b-0cad946b755f\"", + "type": "Microsoft.Network/networkInterfaces", + "location": "northeurope", + "tags": { + "mycustomtag": "foobar" + }, + "properties": { + "provisioningState": "Succeeded", + "resourceGuid": "f3465472-536f-49e7-9e9c-fa91b971a618", + "ipConfigurations": [ + { + "name": "myip1", + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/myNic/ipConfigurations/myip1", + "etag": "W/\"3dff0c55-a7a7-434f-837b-0cad946b755f\"", + "properties": { + "provisioningState": "Succeeded", + "privateIPAddress": "10.2.0.4", + "privateIPAllocationMethod": "Dynamic", + "subnet": { + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/virtualNetworks/myvirtualnetwork/subnets/mysubnet" + }, + "primary": true + } + } + ], + "dnsSettings": { + "dnsServers": [], + "appliedDnsServers": [] + }, + "enableIPForwarding": false + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/listnetworkinterfaces.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/listnetworkinterfaces.json b/azurecompute-arm/src/test/resources/listnetworkinterfaces.json new file mode 100644 index 0000000..de4b1e3 --- /dev/null +++ b/azurecompute-arm/src/test/resources/listnetworkinterfaces.json @@ -0,0 +1,68 @@ +{ + "value": [ + { + "name": "AnotherNIC", + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/AnotherNIC", + "etag": "W/\"e4ed4253-64b6-4184-bfaa-554f470d20c5\"", + "type": "Microsoft.Network/networkInterfaces", + "location": "northeurope", + "properties": { + "provisioningState": "Succeeded", + "resourceGuid": "7fcf6704-21c5-4983-bd9f-017e0873f22f", + "ipConfigurations": [ + { + "name": "ipconfig1", + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/AnotherNIC/ipConfigurations/ipconfig1", + "etag": "W/\"e4ed4253-64b6-4184-bfaa-554f470d20c5\"", + "properties": { + "provisioningState": "Succeeded", + "privateIPAddress": "10.2.1.4", + "privateIPAllocationMethod": "Dynamic", + "subnet": { + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/armlivetesting/providers/Microsoft.Network/virtualNetworks/jclouds-virtual-network-live-test/subnets/anothersubnet" + }, + "primary": true + } + } + ], + "dnsSettings": { + "dnsServers": [], + "appliedDnsServers": [] + }, + "enableIPForwarding": false + } + }, + { + "name": "MyNic", + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/MyNic", + "etag": "W/\"a37d25ff-3f62-4ee2-a111-f355beb5ff69\"", + "type": "Microsoft.Network/networkInterfaces", + "location": "northeurope", + "properties": { + "provisioningState": "Succeeded", + "resourceGuid": "35908409-a081-4411-86a9-51f9ea99321f", + "ipConfigurations": [ + { + "name": "ipconfig1", + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/azurearmtesting/providers/Microsoft.Network/networkInterfaces/MyNic/ipConfigurations/ipconfig1", + "etag": "W/\"a37d25ff-3f62-4ee2-a111-f355beb5ff69\"", + "properties": { + "provisioningState": "Succeeded", + "privateIPAddress": "10.2.0.100", + "privateIPAllocationMethod": "Static", + "subnet": { + "id": "/subscriptions/12345678-2749-4e68-9dcf-123456789abc/resourceGroups/armlivetesting/providers/Microsoft.Network/virtualNetworks/jclouds-virtual-network-live-test/subnets/default" + }, + "primary": true + } + } + ], + "dnsSettings": { + "dnsServers": [], + "appliedDnsServers": [] + }, + "enableIPForwarding": false + } + } + ] +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/resourcegroups.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/resourcegroups.json b/azurecompute-arm/src/test/resources/resourcegroups.json index e21fdb7..56c2196 100644 --- a/azurecompute-arm/src/test/resources/resourcegroups.json +++ b/azurecompute-arm/src/test/resources/resourcegroups.json @@ -12,7 +12,6 @@ "id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/test2", "name": "test2", "location": "eastus", - "tags": {}, "properties": { "provisioningState": "Succeeded" } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/virtualmachine.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/virtualmachine.json b/azurecompute-arm/src/test/resources/virtualmachine.json new file mode 100644 index 0000000..4dda519 --- /dev/null +++ b/azurecompute-arm/src/test/resources/virtualmachine.json @@ -0,0 +1,47 @@ +{ + "properties": { + "vmId": "27ee085b-d707-xxxx-yyyy-2370e2eb1cc1", + "hardwareProfile": { + "vmSize": "Standard_D1" + }, + "storageProfile": { + "imageReference": { + "publisher": "publisher", + "offer": "offer", + "sku": "sku", + "version": "ver" + }, + "osDisk": { + "osType": "Windows", + "name": "windowsmachine", + "createOption": "FromImage", + "vhd": { + "uri": "https://groupname2760.blob.core.windows.net/vhds/windowsmachine201624102936.vhd" + }, + "caching": "ReadWrite" + }, + "dataDisks": [] + }, + "osProfile": { + "computerName": "windowsmachine", + "adminUsername": "azureuser", + "windowsConfiguration": { + "provisionVMAgent": false, + "enableAutomaticUpdates": true + }, + "secrets": [] + }, + "networkProfile": {"networkInterfaces":[{"id":"/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Network/networkInterfaces/windowsmachine167"}]}, + "diagnosticsProfile": { + "bootDiagnostics": { + "enabled": true, + "storageUri": "https://groupname2760.blob.core.windows.net/" + } + }, + "provisioningState": "Creating" + }, + "id": "/subscriptions/SUBSCRIPTIONID/resourceGroups/groupname/providers/Microsoft.Compute/virtualMachines/windowsmachine", + "name": "windowsmachine", + "type": "Microsoft.Compute/virtualMachines", + "location": "westus" +} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/3be36289/azurecompute-arm/src/test/resources/virtualmachineInstance.json ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/test/resources/virtualmachineInstance.json b/azurecompute-arm/src/test/resources/virtualmachineInstance.json new file mode 100644 index 0000000..f73cab6 --- /dev/null +++ b/azurecompute-arm/src/test/resources/virtualmachineInstance.json @@ -0,0 +1,40 @@ +{ + "vmAgent": { + "vmAgentVersion": "2.7.1198.766", + "statuses": [ + { + "code": "ProvisioningState/succeeded", + "level": "Info", + "displayStatus": "Ready", + "message": "GuestAgent is running and accepting new configurations.", + "time": "2016-05-04T08:42:15+00:00" + } + ] + }, + "disks": [ + { + "name": "windowsmachine", + "statuses": [ + { + "code": "ProvisioningState/succeeded", + "level": "Info", + "displayStatus": "Provisioning succeeded", + "time": "2016-05-04T08:31:45.2525129+00:00" + } + ] + } + ], + "statuses": [ + { + "code": "ProvisioningState/succeeded", + "level": "Info", + "displayStatus": "Provisioning succeeded", + "time": "2016-05-04T08:38:52.4310433+00:00" + }, + { + "code": "PowerState/running", + "level": "Info", + "displayStatus": "VM running" + } + ] +} \ No newline at end of file
