mirror of https://github.com/apache/jclouds.git
Implement the Cloudstack global admin service offerings API
This commit is contained in:
parent
0068fbbd63
commit
0a14171a52
|
@ -20,6 +20,7 @@ package org.jclouds.cloudstack;
|
|||
|
||||
import org.jclouds.cloudstack.features.GlobalAccountAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertAsyncClient;
|
||||
import org.jclouds.cloudstack.features.GlobalOfferingAsyncClient;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
/**
|
||||
|
@ -47,4 +48,11 @@ public interface CloudStackGlobalAsyncClient extends CloudStackDomainAsyncClient
|
|||
@Delegate
|
||||
GlobalAlertAsyncClient getAlertClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Offerings
|
||||
*/
|
||||
@Delegate
|
||||
@Override
|
||||
GlobalOfferingAsyncClient getOfferingClient();
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.cloudstack.features.GlobalAccountClient;
|
||||
import org.jclouds.cloudstack.features.GlobalAlertClient;
|
||||
import org.jclouds.cloudstack.features.GlobalOfferingClient;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
|
||||
|
@ -51,4 +52,11 @@ public interface CloudStackGlobalClient extends CloudStackDomainClient {
|
|||
@Delegate
|
||||
GlobalAlertClient getAlertClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Offerings
|
||||
*/
|
||||
@Delegate
|
||||
@Override
|
||||
GlobalOfferingClient getOfferingClient();
|
||||
|
||||
}
|
||||
|
|
|
@ -130,6 +130,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
|||
.put(VolumeClient.class, VolumeAsyncClient.class)//
|
||||
.put(SnapshotClient.class, SnapshotAsyncClient.class)//
|
||||
.put(GlobalAlertClient.class, GlobalAlertAsyncClient.class)//
|
||||
.put(GlobalOfferingClient.class, GlobalOfferingAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* 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.domain;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public enum SystemVmType {
|
||||
DOMAIN_ROUTER,
|
||||
|
||||
CONSOLE_PROXY,
|
||||
|
||||
SECONDARY_STORAGE_VM,
|
||||
|
||||
UNRECOGNIZED;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, name()).toLowerCase();
|
||||
}
|
||||
|
||||
public static SystemVmType fromValue(String type) {
|
||||
try {
|
||||
return valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(type, "type")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* 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.features;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
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.CreateServiceOfferingOptions;
|
||||
import org.jclouds.cloudstack.options.ListDiskOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.ListServiceOfferingsOptions;
|
||||
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.OnlyElement;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to cloudstack via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see GlobalOfferingClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html" />
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface GlobalOfferingAsyncClient extends OfferingAsyncClient {
|
||||
|
||||
/**
|
||||
* @see GlobalOfferingClient#createServiceOffering
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "createServiceOffering")
|
||||
@SelectJson("serviceoffering")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<ServiceOffering> createServiceOffering(@QueryParam("name") String name, @QueryParam("displaytext") String displayText,
|
||||
@QueryParam("cpunumber") int cpuNumber, @QueryParam("cpuspeed") int cpuSpeedInMHz, @QueryParam("memory") int memoryInMB, CreateServiceOfferingOptions... options);
|
||||
|
||||
|
||||
/**
|
||||
* @see GlobalOfferingClient#updateServiceOffering
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "updateServiceOffering")
|
||||
@SelectJson("serviceoffering")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<ServiceOffering> updateServiceOffering(@QueryParam("id") long id, UpdateServiceOfferingOptions... options);
|
||||
|
||||
/**
|
||||
* @see GlobalOfferingClient#deleteServiceOffering
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "deleteServiceOffering")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Void> deleteServiceOffering(@QueryParam("id") long id);
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* 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.features;
|
||||
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
import org.jclouds.cloudstack.options.CreateServiceOfferingOptions;
|
||||
import org.jclouds.cloudstack.options.UpdateServiceOfferingOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack zone features.
|
||||
* <p/>
|
||||
*
|
||||
* @see GlobalOfferingAsyncClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2.0/api_2.2.12/TOC_Global_Admin.html" />
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface GlobalOfferingClient extends OfferingClient {
|
||||
|
||||
/**
|
||||
* Create a new service offering
|
||||
*
|
||||
* @param name
|
||||
* name of the service offering
|
||||
* @param displayText
|
||||
* display name
|
||||
* @param cpuNumber
|
||||
* number of CPUs
|
||||
* @param cpuSpeedInMHz
|
||||
* CPU speed in MHz
|
||||
* @param memoryInMB
|
||||
* the total memory of the service offering in MB
|
||||
* @param options
|
||||
* optional arguments
|
||||
* @return
|
||||
* service offering instance
|
||||
*/
|
||||
ServiceOffering createServiceOffering(String name, String displayText, int cpuNumber,
|
||||
int cpuSpeedInMHz, int memoryInMB, CreateServiceOfferingOptions... options);
|
||||
|
||||
/**
|
||||
* Update an existing service offering
|
||||
*
|
||||
* @param id
|
||||
* service offering ID
|
||||
* @param options
|
||||
* optional arguments
|
||||
* @return
|
||||
* service offering instance
|
||||
*/
|
||||
ServiceOffering updateServiceOffering(long id, UpdateServiceOfferingOptions... options);
|
||||
|
||||
/**
|
||||
* Delete service offering
|
||||
*
|
||||
* @param id
|
||||
* the ID of the service offering
|
||||
*/
|
||||
Void deleteServiceOffering(long id);
|
||||
}
|
|
@ -0,0 +1,211 @@
|
|||
/**
|
||||
* 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.jclouds.cloudstack.domain.StorageType;
|
||||
import org.jclouds.cloudstack.domain.SystemVmType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Options to control how service offerings are created
|
||||
*
|
||||
* @see <a
|
||||
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/global_admin/createServiceOffering.html"
|
||||
* />
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public class CreateServiceOfferingOptions extends AccountInDomainOptions {
|
||||
|
||||
public static final CreateServiceOfferingOptions NONE = new CreateServiceOfferingOptions();
|
||||
|
||||
/**
|
||||
* @param hostTags
|
||||
* the host tag for this service offering
|
||||
*/
|
||||
public CreateServiceOfferingOptions hostTags(Set<String> hostTags) {
|
||||
this.queryParameters.replaceValues("hosttags", ImmutableSet.copyOf(hostTags));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isSystem
|
||||
* is this a system vm offering
|
||||
*/
|
||||
public CreateServiceOfferingOptions isSystem(boolean isSystem) {
|
||||
this.queryParameters.replaceValues("issystem", ImmutableSet.<String>of(isSystem + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param limitCpuUse
|
||||
* restrict the CPU usage to committed service offering
|
||||
*/
|
||||
public CreateServiceOfferingOptions limitCpuUse(boolean limitCpuUse) {
|
||||
this.queryParameters.replaceValues("limitcpuuse", ImmutableSet.<String>of(limitCpuUse + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param networkRateInMb
|
||||
* data transfer rate in megabits per second allowed. Supported only
|
||||
* for non-System offering and system offerings having "domainrouter"
|
||||
* systemvmtype
|
||||
*/
|
||||
public CreateServiceOfferingOptions networkRateInMb(int networkRateInMb) {
|
||||
this.queryParameters.replaceValues("networkrate", ImmutableSet.<String>of(networkRateInMb + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param highlyAvailable
|
||||
* the HA for the service offering
|
||||
*/
|
||||
public CreateServiceOfferingOptions highlyAvailable(boolean highlyAvailable) {
|
||||
this.queryParameters.replaceValues("offerha", ImmutableSet.<String>of(highlyAvailable + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param storageType
|
||||
* the storage type of the service offering
|
||||
*/
|
||||
public CreateServiceOfferingOptions storageType(StorageType storageType) {
|
||||
this.queryParameters.replaceValues("storagetype", ImmutableSet.<String>of(storageType.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param systemVmType
|
||||
* the system VM type. Possible types are "domainrouter", "consoleproxy" and "secondarystoragevm"
|
||||
*/
|
||||
public CreateServiceOfferingOptions systemVmType(SystemVmType systemVmType) {
|
||||
this.queryParameters.replaceValues("systemvmtype", ImmutableSet.<String>of(systemVmType.toString()));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tags
|
||||
* the tags for this service offering
|
||||
*/
|
||||
public CreateServiceOfferingOptions tags(Set<String> tags) {
|
||||
this.queryParameters.replaceValues("tags", ImmutableSet.copyOf(tags));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#hostTags
|
||||
*/
|
||||
public static CreateServiceOfferingOptions hostTags(Set<String> hostTags) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.hostTags(hostTags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#isSystem
|
||||
*/
|
||||
public static CreateServiceOfferingOptions isSystem(boolean isSystem) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.isSystem(isSystem);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#limitCpuUse
|
||||
*/
|
||||
public static CreateServiceOfferingOptions limitCpuUse(boolean limitCpuUse) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.limitCpuUse(limitCpuUse);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#networkRateInMb
|
||||
*/
|
||||
public static CreateServiceOfferingOptions networkRateInMb(int networkRate) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.networkRateInMb(networkRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#highlyAvailable
|
||||
*/
|
||||
public static CreateServiceOfferingOptions highlyAvailable(boolean highlyAvailable) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.highlyAvailable(highlyAvailable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#storageType
|
||||
*/
|
||||
public static CreateServiceOfferingOptions storageType(StorageType storageType) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.storageType(storageType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#systemVmType
|
||||
*/
|
||||
public static CreateServiceOfferingOptions systemVmType(SystemVmType systemVmType) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.systemVmType(systemVmType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#tags
|
||||
*/
|
||||
public static CreateServiceOfferingOptions tags(Set<String> tags) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.tags(tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#accountInDomain
|
||||
*/
|
||||
public static CreateServiceOfferingOptions accountInDomain(String account, long domain) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.accountInDomain(account, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateServiceOfferingOptions#domainId
|
||||
*/
|
||||
public static CreateServiceOfferingOptions domainId(long domainId) {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions();
|
||||
return options.domainId(domainId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CreateServiceOfferingOptions accountInDomain(String account, long domain) {
|
||||
return CreateServiceOfferingOptions.class.cast(super.accountInDomain(account, domain));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public CreateServiceOfferingOptions domainId(long domainId) {
|
||||
return CreateServiceOfferingOptions.class.cast(super.domainId(domainId));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
* 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.jclouds.cloudstack.domain.StorageType;
|
||||
import org.jclouds.cloudstack.domain.SystemVmType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Options to control how service offerings are created
|
||||
*
|
||||
* @see <a
|
||||
* href="http://download.cloud.com/releases/2.2.0/api_2.2.12/global_admin/createServiceOffering.html"
|
||||
* />
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
public class UpdateServiceOfferingOptions extends AccountInDomainOptions {
|
||||
|
||||
public static final UpdateServiceOfferingOptions NONE = new UpdateServiceOfferingOptions();
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* service offering name
|
||||
*/
|
||||
public UpdateServiceOfferingOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.<String>of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param displayText
|
||||
* service offering display text
|
||||
*/
|
||||
public UpdateServiceOfferingOptions displayText(String displayText) {
|
||||
this.queryParameters.replaceValues("displaytext", ImmutableSet.<String>of(displayText));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see UpdateServiceOfferingOptions#name
|
||||
*/
|
||||
public static UpdateServiceOfferingOptions name(String name) {
|
||||
UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UpdateServiceOfferingOptions#displayText
|
||||
*/
|
||||
public static UpdateServiceOfferingOptions displayText(String displayText) {
|
||||
UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions();
|
||||
return options.displayText(displayText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UpdateServiceOfferingOptions#accountInDomain
|
||||
*/
|
||||
public static UpdateServiceOfferingOptions accountInDomain(String account, long domain) {
|
||||
UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions();
|
||||
return options.accountInDomain(account, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UpdateServiceOfferingOptions#domainId
|
||||
*/
|
||||
public static UpdateServiceOfferingOptions domainId(long domainId) {
|
||||
UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions();
|
||||
return options.domainId(domainId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UpdateServiceOfferingOptions accountInDomain(String account, long domain) {
|
||||
return UpdateServiceOfferingOptions.class.cast(super.accountInDomain(account, domain));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public UpdateServiceOfferingOptions domainId(long domainId) {
|
||||
return UpdateServiceOfferingOptions.class.cast(super.domainId(domainId));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* 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.features;
|
||||
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
import org.jclouds.cloudstack.domain.StorageType;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code GlobalOfferingClient}
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "GlobalOfferingClientLiveTest")
|
||||
public class GlobalOfferingClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
@Test(groups = "live", enabled = true)
|
||||
public void testCreateServiceOffering() throws Exception {
|
||||
assertTrue(globalAdminEnabled, "Test cannot run without global admin identity and credentials");
|
||||
|
||||
String name = prefix + "-test-create-service-offering";
|
||||
String displayText = name + "-display";
|
||||
ServiceOffering offering = null;
|
||||
try {
|
||||
offering = globalAdminClient.getOfferingClient().
|
||||
createServiceOffering(name, displayText, 2, 1024, 2048, highlyAvailable(true).storageType(StorageType.LOCAL));
|
||||
Logger.CONSOLE.info("Created Service Offering: " + offering);
|
||||
|
||||
assertEquals(offering.getName(), name);
|
||||
assertEquals(offering.getDisplayText(), displayText);
|
||||
checkServiceOffering(offering);
|
||||
|
||||
offering = globalAdminClient.getOfferingClient()
|
||||
.updateServiceOffering(offering.getId(), name(name + "-2").displayText(displayText + "-2"));
|
||||
|
||||
assertEquals(offering.getName(), name + "-2");
|
||||
assertEquals(offering.getDisplayText(), displayText + "-2");
|
||||
checkServiceOffering(offering);
|
||||
|
||||
} finally {
|
||||
if (offering != null) {
|
||||
globalAdminClient.getOfferingClient().deleteServiceOffering(offering.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkServiceOffering(ServiceOffering offering) {
|
||||
assertTrue(offering.getId() > 0);
|
||||
assertEquals(offering.getCpuNumber(), 2);
|
||||
assertEquals(offering.getCpuSpeed(), 1024);
|
||||
assertEquals(offering.getMemory(), 2048);
|
||||
assertTrue(offering.supportsHA());
|
||||
assertEquals(offering.getStorageType(), StorageType.LOCAL);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
/**
|
||||
* 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.jclouds.cloudstack.domain.StorageType;
|
||||
import org.jclouds.cloudstack.domain.SystemVmType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.hostTags;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.isSystem;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.limitCpuUse;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.networkRateInMb;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.storageType;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.systemVmType;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.tags;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CreateServiceOfferingOptions}
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class CreateServiceOfferingOptionsTest {
|
||||
|
||||
public void testHostTags() {
|
||||
CreateServiceOfferingOptions options =
|
||||
new CreateServiceOfferingOptions().hostTags(ImmutableSet.of("tag1", "tag2"));
|
||||
assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("hosttags"));
|
||||
}
|
||||
|
||||
public void testHostTagsStatic() {
|
||||
CreateServiceOfferingOptions options = hostTags(ImmutableSet.of("tag1", "tag2"));
|
||||
assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("hosttags"));
|
||||
}
|
||||
|
||||
public void testIsSystem() {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().isSystem(true);
|
||||
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("issystem"));
|
||||
}
|
||||
|
||||
public void testIsSystemStatic() {
|
||||
CreateServiceOfferingOptions options = isSystem(true);
|
||||
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("issystem"));
|
||||
}
|
||||
|
||||
public void testLimitCpuUse() {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().limitCpuUse(true);
|
||||
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("limitcpuuse"));
|
||||
}
|
||||
|
||||
public void testLimitCpuUseStatic() {
|
||||
CreateServiceOfferingOptions options = limitCpuUse(true);
|
||||
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("limitcpuuse"));
|
||||
}
|
||||
|
||||
public void testNetworkRate() {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().networkRateInMb(200);
|
||||
assertEquals(ImmutableSet.of("200"), options.buildQueryParameters().get("networkrate"));
|
||||
}
|
||||
|
||||
public void testNetworkRateStatic() {
|
||||
CreateServiceOfferingOptions options = networkRateInMb(200);
|
||||
assertEquals(ImmutableSet.of("200"), options.buildQueryParameters().get("networkrate"));
|
||||
}
|
||||
|
||||
public void testHighlyAvailable() {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().highlyAvailable(true);
|
||||
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("offerha"));
|
||||
}
|
||||
|
||||
public void testHighlyAvailableStatic() {
|
||||
CreateServiceOfferingOptions options = highlyAvailable(true);
|
||||
assertEquals(ImmutableSet.of("true"), options.buildQueryParameters().get("offerha"));
|
||||
}
|
||||
|
||||
public void testStorageType() {
|
||||
CreateServiceOfferingOptions options = new CreateServiceOfferingOptions().storageType(StorageType.LOCAL);
|
||||
assertEquals(ImmutableSet.of("local"), options.buildQueryParameters().get("storagetype"));
|
||||
}
|
||||
|
||||
public void testStorageTypeStatic() {
|
||||
CreateServiceOfferingOptions options = storageType(StorageType.LOCAL);
|
||||
assertEquals(ImmutableSet.of("local"), options.buildQueryParameters().get("storagetype"));
|
||||
}
|
||||
|
||||
public void testSystemVmType() {
|
||||
CreateServiceOfferingOptions options =
|
||||
new CreateServiceOfferingOptions().systemVmType(SystemVmType.DOMAIN_ROUTER);
|
||||
assertEquals(ImmutableSet.of("domainrouter"), options.buildQueryParameters().get("systemvmtype"));
|
||||
}
|
||||
|
||||
public void testSystemVmTypeStatic() {
|
||||
CreateServiceOfferingOptions options = systemVmType(SystemVmType.DOMAIN_ROUTER);
|
||||
assertEquals(ImmutableSet.of("domainrouter"), options.buildQueryParameters().get("systemvmtype"));
|
||||
}
|
||||
|
||||
public void testTags() {
|
||||
CreateServiceOfferingOptions options =
|
||||
new CreateServiceOfferingOptions().tags(ImmutableSet.<String>of("tag1", "tag2"));
|
||||
assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("tags"));
|
||||
}
|
||||
|
||||
public void testTagsStatic() {
|
||||
CreateServiceOfferingOptions options = tags(ImmutableSet.<String>of("tag1", "tag2"));
|
||||
assertEquals(ImmutableSet.of("tag1", "tag2"), options.buildQueryParameters().get("tags"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* 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.jclouds.cloudstack.domain.StorageType;
|
||||
import org.jclouds.cloudstack.domain.SystemVmType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.highlyAvailable;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.hostTags;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.isSystem;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.limitCpuUse;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.networkRateInMb;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.storageType;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.systemVmType;
|
||||
import static org.jclouds.cloudstack.options.CreateServiceOfferingOptions.Builder.tags;
|
||||
import static org.jclouds.cloudstack.options.UpdateServiceOfferingOptions.Builder.displayText;
|
||||
import static org.jclouds.cloudstack.options.UpdateServiceOfferingOptions.Builder.name;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code UpdateServiceOfferingOptions}
|
||||
*
|
||||
* @author Andrei Savu
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class UpdateServiceOfferingOptionsTest {
|
||||
|
||||
public void testName() {
|
||||
UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions().name("test-name");
|
||||
assertEquals(ImmutableSet.of("test-name"), options.buildQueryParameters().get("name"));
|
||||
}
|
||||
|
||||
public void testNameStatic() {
|
||||
UpdateServiceOfferingOptions options = name("test-name");
|
||||
assertEquals(ImmutableSet.of("test-name"), options.buildQueryParameters().get("name"));
|
||||
}
|
||||
|
||||
public void testDisplayText() {
|
||||
UpdateServiceOfferingOptions options = new UpdateServiceOfferingOptions().displayText("test-display-text");
|
||||
assertEquals(ImmutableSet.of("test-display-text"), options.buildQueryParameters().get("displaytext"));
|
||||
}
|
||||
|
||||
public void testDisplayTextStatic() {
|
||||
UpdateServiceOfferingOptions options = displayText("test-display-text");
|
||||
assertEquals(ImmutableSet.of("test-display-text"), options.buildQueryParameters().get("displaytext"));
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue