mirror of
https://github.com/apache/jclouds.git
synced 2025-02-21 09:44:59 +00:00
Add azure disk sku (#45)
* Add azure disk SKU * Add tests * Fix review adding a disk type enum * Fix review using storage account type enum
This commit is contained in:
parent
7b1efdc307
commit
6a076fe0c8
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.domain;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.json.SerializedNames;
|
||||
|
||||
@AutoValue
|
||||
public abstract class DiskSku
|
||||
{
|
||||
@Nullable
|
||||
public abstract StorageAccountType name();
|
||||
|
||||
@SerializedNames({"name"})
|
||||
public static DiskSku create(final StorageAccountType storageAccountType) {
|
||||
return builder()
|
||||
.name(storageAccountType)
|
||||
.build();
|
||||
}
|
||||
|
||||
public abstract Builder toBuilder();
|
||||
|
||||
public static Builder builder() {
|
||||
return new AutoValue_DiskSku.Builder();
|
||||
}
|
||||
|
||||
@AutoValue.Builder
|
||||
public abstract static class Builder {
|
||||
public abstract Builder name(StorageAccountType storageAccountType);
|
||||
public abstract DiskSku build();
|
||||
}
|
||||
}
|
@ -17,11 +17,17 @@
|
||||
package org.jclouds.azurecompute.arm.domain;
|
||||
|
||||
public enum StorageAccountType {
|
||||
/** Enum value Standard_LRS. */
|
||||
/** Enum value Standard HDD. */
|
||||
STANDARD_LRS("Standard_LRS"),
|
||||
|
||||
/** Enum value Premium_LRS. */
|
||||
PREMIUM_LRS("Premium_LRS");
|
||||
/** Enum value Standard SSD. */
|
||||
STANDARD_SSD_LRS("StandardSSD_LRS"),
|
||||
|
||||
/** Enum value Premium SSD. */
|
||||
PREMIUM_LRS("Premium_LRS"),
|
||||
|
||||
/** Enum value Ultra SSD (Available only if your subscription is enabled for ultra disks). */
|
||||
ULTRA_SSD_LRS("UltraSSD_LRS");
|
||||
|
||||
/** The actual serialized value for a StorageAccountTypes instance. */
|
||||
private String value;
|
||||
|
@ -33,6 +33,7 @@ import org.jclouds.Fallbacks.EmptyListOnNotFoundOr404;
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.azurecompute.arm.domain.Disk;
|
||||
import org.jclouds.azurecompute.arm.domain.DiskProperties;
|
||||
import org.jclouds.azurecompute.arm.domain.DiskSku;
|
||||
import org.jclouds.azurecompute.arm.filters.ApiVersionFilter;
|
||||
import org.jclouds.azurecompute.arm.functions.URIParser;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
@ -73,6 +74,16 @@ public interface DiskApi {
|
||||
@Nullable @PayloadParam("tags") Map<String, String> tags,
|
||||
@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,
|
||||
@Nullable @PayloadParam("sku") DiskSku sku);
|
||||
|
||||
@Named("disk:get")
|
||||
@Path("/{diskName}")
|
||||
@GET
|
||||
|
@ -23,6 +23,7 @@ import java.util.UUID;
|
||||
import org.jclouds.azurecompute.arm.domain.CreationData;
|
||||
import org.jclouds.azurecompute.arm.domain.Disk;
|
||||
import org.jclouds.azurecompute.arm.domain.DiskProperties;
|
||||
import org.jclouds.azurecompute.arm.domain.DiskSku;
|
||||
import org.jclouds.azurecompute.arm.domain.Provisionable;
|
||||
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiLiveTest;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
@ -33,6 +34,7 @@ import com.google.common.base.Supplier;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import static org.jclouds.azurecompute.arm.domain.StorageAccountType.PREMIUM_LRS;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
@ -59,7 +61,8 @@ 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, ImmutableMap.of("exampleTag", "jclouds-test-tag"), properties);
|
||||
DiskSku sku = DiskSku.builder().name(PREMIUM_LRS).build();
|
||||
Disk dataDisk = api().createOrUpdate(diskName, LOCATION, ImmutableMap.of("exampleTag", "jclouds-test-tag"), properties, sku);
|
||||
assertTrue(waitUntilAvailable(diskName), "creation operation did not complete in the configured timeout");
|
||||
assertTrue(dataDisk.properties().diskSizeGB() == 2);
|
||||
assertTrue(dataDisk.tags().containsValue("jclouds-test-tag"));
|
||||
|
@ -23,11 +23,13 @@ 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;
|
||||
import org.jclouds.azurecompute.arm.domain.DiskSku;
|
||||
import org.jclouds.azurecompute.arm.internal.BaseAzureComputeApiMockTest;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static com.google.common.collect.Iterables.isEmpty;
|
||||
import static org.jclouds.azurecompute.arm.domain.StorageAccountType.PREMIUM_LRS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
@ -78,6 +80,27 @@ public class DiskApiMockTest extends BaseAzureComputeApiMockTest {
|
||||
assertTrue(dataDisk.tags().containsValue("jclouds-test-tag"));
|
||||
}
|
||||
|
||||
public void createDiskWithTagsAndSku() throws InterruptedException {
|
||||
|
||||
server.enqueue(jsonResponse("/creatediskwithtagsandskuresponse.json").setResponseCode(200));
|
||||
|
||||
final DiskApi diskApi = api.getDiskApi(resourcegroup);
|
||||
|
||||
DiskProperties properties = DiskProperties.builder().diskSizeGB(2).creationData(CreationData.create(CreationData.CreateOptions.EMPTY)).build();
|
||||
|
||||
DiskSku sku = DiskSku.builder().name(PREMIUM_LRS).build();
|
||||
|
||||
Disk dataDisk = diskApi.createOrUpdate(diskName, "westus", ImmutableMap.of("exampleTag", "jclouds-test-tag"), properties, sku);
|
||||
|
||||
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\"}},\"sku\":{\"name\":\"Premium_LRS\"}}";
|
||||
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,17 @@
|
||||
{
|
||||
"properties": {
|
||||
"creationData": {
|
||||
"createOption": "Empty"
|
||||
},
|
||||
"diskSizeGB": 2,
|
||||
"provisioningState": "Updating",
|
||||
"isArmResource": true
|
||||
},
|
||||
"tags": {
|
||||
"exampleTag": "jclouds-test-tag"
|
||||
},
|
||||
"sku": {
|
||||
"name": "Premium_LRS"
|
||||
},
|
||||
"location": "westeurope"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user