mirror of https://github.com/apache/jclouds.git
Merge pull request #216 from andreisavu/disk-offering
Implement the Cloudstack global admin disk offerings API
This commit is contained in:
commit
16c6fadc0a
|
@ -23,10 +23,12 @@ import org.jclouds.cloudstack.domain.DiskOffering;
|
|||
import org.jclouds.cloudstack.domain.NetworkOffering;
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.CreateDiskOfferingOptions;
|
||||
import org.jclouds.cloudstack.options.CreateServiceOfferingOptions;
|
||||
import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions;
|
||||
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
|
@ -85,4 +87,33 @@ public interface GlobalOfferingAsyncClient extends OfferingAsyncClient {
|
|||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deleteServiceOffering(@QueryParam("id") long id);
|
||||
|
||||
/**
|
||||
* @see GlobalOfferingClient#createDiskOffering
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "createDiskOffering")
|
||||
@SelectJson("diskoffering")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<DiskOffering> createDiskOffering(@QueryParam("name") String name,
|
||||
@QueryParam("displaytext") String displayText, CreateDiskOfferingOptions... options);
|
||||
|
||||
/**
|
||||
* @see GlobalOfferingClient#updateDiskOffering
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "updateDiskOffering")
|
||||
@SelectJson("diskoffering")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<DiskOffering> updateDiskOffering(@QueryParam("id") long id, UpdateDiskOfferingOptions... options);
|
||||
|
||||
/**
|
||||
* @see GlobalOfferingClient#deleteDiskOffering
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "deleteDiskOffering")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deleteDiskOffering(@QueryParam("id") long id);
|
||||
}
|
||||
|
|
|
@ -18,8 +18,11 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import org.jclouds.cloudstack.domain.DiskOffering;
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
import org.jclouds.cloudstack.options.CreateDiskOfferingOptions;
|
||||
import org.jclouds.cloudstack.options.CreateServiceOfferingOptions;
|
||||
import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions;
|
||||
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
|
@ -76,4 +79,38 @@ public interface GlobalOfferingClient extends OfferingClient {
|
|||
* the ID of the service offering
|
||||
*/
|
||||
Void deleteServiceOffering(long id);
|
||||
|
||||
/**
|
||||
* Create a new disk offering
|
||||
*
|
||||
* @param name
|
||||
* name of the disk offering
|
||||
* @param displayText
|
||||
* display text for disk offering
|
||||
* @param options
|
||||
* optional arguments
|
||||
* @return
|
||||
* disk offering instance
|
||||
*/
|
||||
DiskOffering createDiskOffering(String name, String displayText, CreateDiskOfferingOptions... options);
|
||||
|
||||
/**
|
||||
* Update a disk offering
|
||||
*
|
||||
* @param id
|
||||
* disk offering ID
|
||||
* @param options
|
||||
* optional arguments
|
||||
* @return
|
||||
* disk offering instance
|
||||
*/
|
||||
DiskOffering updateDiskOffering(long id, UpdateDiskOfferingOptions... options);
|
||||
|
||||
/**
|
||||
* Delete disk offering
|
||||
*
|
||||
* @param id
|
||||
* the ID of the disk offering
|
||||
*/
|
||||
Void deleteDiskOffering(long id);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.cloudstack.options;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Options to control how disk offerings are created
|
||||
*
|
||||
* @see <a
|
||||
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/global_admin/createDiskOffering.html"
|
||||
* />
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public class CreateDiskOfferingOptions extends AccountInDomainOptions {
|
||||
|
||||
public static final CreateDiskOfferingOptions NONE = new CreateDiskOfferingOptions();
|
||||
|
||||
/**
|
||||
* @param customized
|
||||
* whether disk offering is custom or not
|
||||
*/
|
||||
public CreateDiskOfferingOptions customized(boolean customized) {
|
||||
this.queryParameters.replaceValues("customized", ImmutableSet.<String>of(customized + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param diskSizeInGB
|
||||
* size of the disk offering in GB
|
||||
*/
|
||||
public CreateDiskOfferingOptions diskSizeInGB(int diskSizeInGB) {
|
||||
this.queryParameters.replaceValues("disksize", ImmutableSet.<String>of(diskSizeInGB + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tags
|
||||
* the tags for this service offering
|
||||
*/
|
||||
public CreateDiskOfferingOptions tags(Set<String> tags) {
|
||||
this.queryParameters.replaceValues("tags", ImmutableSet.copyOf(tags));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see CreateDiskOfferingOptions#customized
|
||||
*/
|
||||
public static CreateDiskOfferingOptions customized(boolean customized) {
|
||||
CreateDiskOfferingOptions options = new CreateDiskOfferingOptions();
|
||||
return options.customized(customized);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateDiskOfferingOptions#diskSizeInGB
|
||||
*/
|
||||
public static CreateDiskOfferingOptions diskSizeInGB(int diskSizeInGB) {
|
||||
CreateDiskOfferingOptions options = new CreateDiskOfferingOptions();
|
||||
return options.diskSizeInGB(diskSizeInGB);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateDiskOfferingOptions#tags
|
||||
*/
|
||||
public static CreateDiskOfferingOptions tags(Set<String> tags) {
|
||||
CreateDiskOfferingOptions options = new CreateDiskOfferingOptions();
|
||||
return options.tags(tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateDiskOfferingOptions#accountInDomain
|
||||
*/
|
||||
public static CreateDiskOfferingOptions accountInDomain(String account, long domain) {
|
||||
CreateDiskOfferingOptions options = new CreateDiskOfferingOptions();
|
||||
return options.accountInDomain(account, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateDiskOfferingOptions#domainId
|
||||
*/
|
||||
public static CreateDiskOfferingOptions domainId(long domainId) {
|
||||
CreateDiskOfferingOptions options = new CreateDiskOfferingOptions();
|
||||
return options.domainId(domainId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CreateDiskOfferingOptions accountInDomain(String account, long domain) {
|
||||
return CreateDiskOfferingOptions.class.cast(super.accountInDomain(account, domain));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CreateDiskOfferingOptions domainId(long domainId) {
|
||||
return CreateDiskOfferingOptions.class.cast(super.domainId(domainId));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,103 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.cloudstack.options;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
/**
|
||||
* Options to control how disk offerings are created
|
||||
*
|
||||
* @see <a
|
||||
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/global_admin/updateDiskOffering.html"
|
||||
* />
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public class UpdateDiskOfferingOptions extends AccountInDomainOptions {
|
||||
|
||||
public static final UpdateDiskOfferingOptions NONE = new UpdateDiskOfferingOptions();
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* service offering name
|
||||
*/
|
||||
public UpdateDiskOfferingOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.<String>of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param displayText
|
||||
* service offering display text
|
||||
*/
|
||||
public UpdateDiskOfferingOptions displayText(String displayText) {
|
||||
this.queryParameters.replaceValues("displaytext", ImmutableSet.<String>of(displayText));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see org.jclouds.cloudstack.options.UpdateDiskOfferingOptions#name
|
||||
*/
|
||||
public static UpdateDiskOfferingOptions name(String name) {
|
||||
UpdateDiskOfferingOptions options = new UpdateDiskOfferingOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.cloudstack.options.UpdateDiskOfferingOptions#displayText
|
||||
*/
|
||||
public static UpdateDiskOfferingOptions displayText(String displayText) {
|
||||
UpdateDiskOfferingOptions options = new UpdateDiskOfferingOptions();
|
||||
return options.displayText(displayText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.cloudstack.options.UpdateDiskOfferingOptions#accountInDomain
|
||||
*/
|
||||
public static UpdateDiskOfferingOptions accountInDomain(String account, long domain) {
|
||||
UpdateDiskOfferingOptions options = new UpdateDiskOfferingOptions();
|
||||
return options.accountInDomain(account, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.jclouds.cloudstack.options.UpdateDiskOfferingOptions#domainId
|
||||
*/
|
||||
public static UpdateDiskOfferingOptions domainId(long domainId) {
|
||||
UpdateDiskOfferingOptions options = new UpdateDiskOfferingOptions();
|
||||
return options.domainId(domainId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UpdateDiskOfferingOptions accountInDomain(String account, long domain) {
|
||||
return UpdateDiskOfferingOptions.class.cast(super.accountInDomain(account, domain));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UpdateDiskOfferingOptions domainId(long domainId) {
|
||||
return UpdateDiskOfferingOptions.class.cast(super.domainId(domainId));
|
||||
}
|
||||
}
|
|
@ -18,13 +18,17 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.features;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.jclouds.cloudstack.domain.DiskOffering;
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
import org.jclouds.cloudstack.domain.StorageType;
|
||||
import org.jclouds.cloudstack.options.UpdateDiskOfferingOptions;
|
||||
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.jclouds.cloudstack.options.CreateDiskOfferingOptions.Builder.diskSizeInGB;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable;
|
||||
import static org.jclouds.cloudstack.options.UpdateServiceOfferingOptions.Builder.name;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
|
@ -53,7 +57,8 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
checkServiceOffering(offering);
|
||||
|
||||
offering = globalAdminClient.getOfferingClient()
|
||||
.updateServiceOffering(offering.getId(), name(name + "-2").displayText(displayText + "-2"));
|
||||
.updateServiceOffering(offering.getId(),
|
||||
UpdateServiceOfferingOptions.Builder.name(name + "-2").displayText(displayText + "-2"));
|
||||
|
||||
assertEquals(offering.getName(), name + "-2");
|
||||
assertEquals(offering.getDisplayText(), displayText + "-2");
|
||||
|
@ -75,4 +80,41 @@ public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assertEquals(offering.getStorageType(), StorageType.LOCAL);
|
||||
}
|
||||
|
||||
@Test(groups = "live", enabled = true)
|
||||
public void testCreateDiskOffering() throws Exception {
|
||||
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
|
||||
|
||||
String name = prefix + "-test-create-disk-offering";
|
||||
String displayText = name + "-display";
|
||||
DiskOffering offering = null;
|
||||
try {
|
||||
offering = globalAdminClient.getOfferingClient().
|
||||
createDiskOffering(name, displayText,
|
||||
diskSizeInGB(100).customized(true).tags(ImmutableSet.<String>of("dummy-tag")));
|
||||
|
||||
assertEquals(offering.getName(), name);
|
||||
assertEquals(offering.getDisplayText(), displayText);
|
||||
checkDiskOffering(offering);
|
||||
|
||||
offering = globalAdminClient.getOfferingClient().
|
||||
updateDiskOffering(offering.getId(),
|
||||
UpdateDiskOfferingOptions.Builder.name(name + "-2").displayText(displayText + "-2"));
|
||||
|
||||
assertEquals(offering.getName(), name + "-2");
|
||||
assertEquals(offering.getDisplayText(), displayText + "-2");
|
||||
checkDiskOffering(offering);
|
||||
|
||||
} finally {
|
||||
if (offering != null) {
|
||||
globalAdminClient.getOfferingClient().deleteDiskOffering(offering.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDiskOffering(DiskOffering offering) {
|
||||
assertTrue(offering.isCustomized());
|
||||
assertEquals(offering.getDiskSize(), 100);
|
||||
assertTrue(offering.getTags().contains("dummy-tag"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.cloudstack.options;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.jclouds.cloudstack.options.CreateDiskOfferingOptions.Builder.customized;
|
||||
import static org.jclouds.cloudstack.options.CreateDiskOfferingOptions.Builder.diskSizeInGB;
|
||||
import static org.jclouds.cloudstack.options.CreateDiskOfferingOptions.Builder.tags;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CreateDiskOfferingOptions}
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class CreateDiskOfferingOptionsTest {
|
||||
|
||||
public void testTags() {
|
||||
CreateDiskOfferingOptions options =
|
||||
new CreateDiskOfferingOptions().tags(ImmutableSet.<String>of("tag1", "tag2"));
|
||||
assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("tags"));
|
||||
}
|
||||
|
||||
public void testTagsStatic() {
|
||||
CreateDiskOfferingOptions options = tags(ImmutableSet.<String>of("tag1", "tag2"));
|
||||
assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("tags"));
|
||||
}
|
||||
|
||||
public void testCustomized() {
|
||||
CreateDiskOfferingOptions options =
|
||||
new CreateDiskOfferingOptions().customized(true);
|
||||
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("customized"));
|
||||
}
|
||||
|
||||
public void testCustomizedStatic() {
|
||||
CreateDiskOfferingOptions options = customized(true);
|
||||
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("customized"));
|
||||
}
|
||||
|
||||
public void testDiskSizeInGB() {
|
||||
CreateDiskOfferingOptions options =
|
||||
new CreateDiskOfferingOptions().diskSizeInGB(100);
|
||||
assertEquals(ImmutableSet.of("100"), options.buildQueryParameters().get("disksize"));
|
||||
}
|
||||
|
||||
public void testDiskSizeInGBStatic() {
|
||||
CreateDiskOfferingOptions options = diskSizeInGB(100);
|
||||
assertEquals(ImmutableSet.of("100"), options.buildQueryParameters().get("disksize"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue