mirror of https://github.com/apache/jclouds.git
Add tag support to azure disks
This commit is contained in:
parent
130c0df5ce
commit
bd59263d47
|
@ -18,6 +18,7 @@ package org.jclouds.azurecompute.arm.features;
|
|||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.ws.rs.Consumes;
|
||||
|
@ -34,6 +35,7 @@ import org.jclouds.azurecompute.arm.domain.Disk;
|
|||
import org.jclouds.azurecompute.arm.domain.DiskProperties;
|
||||
import org.jclouds.azurecompute.arm.filters.ApiVersionFilter;
|
||||
import org.jclouds.azurecompute.arm.functions.URIParser;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.oauth.v2.filters.OAuthFilter;
|
||||
import org.jclouds.rest.annotations.Fallback;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
|
@ -62,6 +64,15 @@ public interface DiskApi {
|
|||
@PayloadParam("location") String location,
|
||||
@PayloadParam("properties") DiskProperties properties);
|
||||
|
||||
@Named("disk:create_or_update")
|
||||
@PUT
|
||||
@MapBinder(BindToJsonPayload.class)
|
||||
@Path("/{diskName}")
|
||||
Disk createOrUpdate(@PathParam("diskName") String diskName,
|
||||
@PayloadParam("location") String location,
|
||||
@Nullable @PayloadParam("tags") Map<String, String> tags,
|
||||
@PayloadParam("properties") DiskProperties properties);
|
||||
|
||||
@Named("disk:get")
|
||||
@Path("/{diskName}")
|
||||
@GET
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.testng.annotations.Test;
|
|||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
@ -58,9 +59,10 @@ public class DiskApiLiveTest extends BaseAzureComputeApiLiveTest {
|
|||
@Test
|
||||
public void createDisk() {
|
||||
DiskProperties properties = DiskProperties.builder().creationData(CreationData.create(CreationData.CreateOptions.EMPTY)).diskSizeGB(2).build();
|
||||
Disk dataDisk = api().createOrUpdate(diskName, LOCATION, properties);
|
||||
Disk dataDisk = api().createOrUpdate(diskName, LOCATION, ImmutableMap.of("exampleTag", "jclouds-test-tag"), properties);
|
||||
assertTrue(waitUntilAvailable(diskName), "creation operation did not complete in the configured timeout");
|
||||
assertTrue(dataDisk.properties().diskSizeGB() == 2);
|
||||
assertTrue(dataDisk.tags().containsValue("jclouds-test-tag"));
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "createDisk")
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jclouds.azurecompute.arm.features;
|
|||
import java.net.URI;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jclouds.azurecompute.arm.domain.CreationData;
|
||||
import org.jclouds.azurecompute.arm.domain.Disk;
|
||||
import org.jclouds.azurecompute.arm.domain.DiskProperties;
|
||||
|
@ -58,6 +59,25 @@ public class DiskApiMockTest extends BaseAzureComputeApiMockTest {
|
|||
assertTrue(dataDisk.properties().diskSizeGB() == 2);
|
||||
}
|
||||
|
||||
public void createDiskWithTags() throws InterruptedException {
|
||||
|
||||
server.enqueue(jsonResponse("/creatediskwithtagsresponse.json").setResponseCode(200));
|
||||
|
||||
final DiskApi diskApi = api.getDiskApi(resourcegroup);
|
||||
|
||||
DiskProperties properties = DiskProperties.builder().diskSizeGB(2).creationData(CreationData.create(CreationData.CreateOptions.EMPTY)).build();
|
||||
|
||||
Disk dataDisk = diskApi.createOrUpdate(diskName, "westus", ImmutableMap.of("exampleTag", "jclouds-test-tag"), properties);
|
||||
|
||||
String path = String.format("/subscriptions/%s/resourcegroups/%s/providers/Microsoft.Compute/disks/%s?%s", subscriptionid, resourcegroup, diskName, apiVersion);
|
||||
String json = "{\"location\":\"westus\",\"tags\":{\"exampleTag\":\"jclouds-test-tag\"},\"properties\":{\"diskSizeGB\":2,\"creationData\":{\"createOption\":\"Empty\"}}}";
|
||||
assertSent(server, "PUT", path, json);
|
||||
|
||||
assertEquals(dataDisk.properties().provisioningState(), "Updating");
|
||||
assertTrue(dataDisk.properties().diskSizeGB() == 2);
|
||||
assertTrue(dataDisk.tags().containsValue("jclouds-test-tag"));
|
||||
}
|
||||
|
||||
public void getDisk() throws InterruptedException {
|
||||
|
||||
server.enqueue(jsonResponse("/getdisk.json").setResponseCode(200));
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"properties": {
|
||||
"creationData": {
|
||||
"createOption": "Empty"
|
||||
},
|
||||
"diskSizeGB": 2,
|
||||
"provisioningState": "Updating",
|
||||
"isArmResource": true
|
||||
},
|
||||
"tags": {
|
||||
"exampleTag": "jclouds-test-tag"
|
||||
},
|
||||
"location": "westeurope"
|
||||
}
|
Loading…
Reference in New Issue