mirror of https://github.com/apache/jclouds.git
added account features to cloudstack
This commit is contained in:
parent
440660335d
commit
bd5da6104d
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack;
|
||||
|
||||
import org.jclouds.cloudstack.features.AccountAsyncClient;
|
||||
import org.jclouds.cloudstack.features.AddressAsyncClient;
|
||||
import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
|
||||
import org.jclouds.cloudstack.features.ConfigurationAsyncClient;
|
||||
|
@ -127,4 +128,10 @@ public interface CloudStackAsyncClient {
|
|||
*/
|
||||
@Delegate
|
||||
ConfigurationAsyncClient getConfigurationClient();
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to Account features.
|
||||
*/
|
||||
@Delegate
|
||||
AccountAsyncClient getAccountClient();
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.jclouds.cloudstack;
|
|||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.features.AccountClient;
|
||||
import org.jclouds.cloudstack.features.AddressClient;
|
||||
import org.jclouds.cloudstack.features.AsyncJobClient;
|
||||
import org.jclouds.cloudstack.features.ConfigurationClient;
|
||||
|
@ -130,4 +131,10 @@ public interface CloudStackClient {
|
|||
*/
|
||||
@Delegate
|
||||
ConfigurationClient getConfigurationClient();
|
||||
|
||||
/**
|
||||
* Provides synchronous access to Account features.
|
||||
*/
|
||||
@Delegate
|
||||
AccountClient getAccountClient();
|
||||
}
|
||||
|
|
|
@ -18,10 +18,19 @@
|
|||
*/
|
||||
package org.jclouds.cloudstack.config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cloudstack.CloudStackAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.cloudstack.domain.Account.State;
|
||||
import org.jclouds.cloudstack.features.AccountAsyncClient;
|
||||
import org.jclouds.cloudstack.features.AccountClient;
|
||||
import org.jclouds.cloudstack.features.AddressAsyncClient;
|
||||
import org.jclouds.cloudstack.features.AddressClient;
|
||||
import org.jclouds.cloudstack.features.AsyncJobAsyncClient;
|
||||
|
@ -64,6 +73,14 @@ import org.jclouds.rest.ConfiguresRestClient;
|
|||
import org.jclouds.rest.config.RestClientModule;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Configures the cloudstack connection.
|
||||
|
@ -89,12 +106,98 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
|||
.put(GuestOSClient.class, GuestOSAsyncClient.class)//
|
||||
.put(HypervisorClient.class, HypervisorAsyncClient.class)//
|
||||
.put(ConfigurationClient.class, ConfigurationAsyncClient.class)//
|
||||
.put(AccountClient.class, AccountAsyncClient.class)//
|
||||
.build();
|
||||
|
||||
public CloudStackRestClientModule() {
|
||||
super(CloudStackClient.class, CloudStackAsyncClient.class, DELEGATE_MAP);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
public static class BreakGenericSetAdapter implements JsonSerializer<Account>, JsonDeserializer<Account> {
|
||||
|
||||
public JsonElement serialize(Account src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
return context.serialize(src);
|
||||
}
|
||||
|
||||
public Account deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
return apply(context.<AccountInternal> deserialize(json, AccountInternal.class));
|
||||
}
|
||||
|
||||
public Account apply(AccountInternal in) {
|
||||
return Account.builder().id(in.id).type(in.type).domain(in.domain).domainId(in.domainId).IPsAvailable(
|
||||
nullIfUnlimited(in.IPsAvailable)).IPLimit(nullIfUnlimited(in.IPLimit)).IPs(in.IPs).cleanupRequired(
|
||||
in.cleanupRequired).name(in.name).receivedBytes(in.receivedBytes).sentBytes(in.sentBytes)
|
||||
.snapshotsAvailable(nullIfUnlimited(in.snapshotsAvailable)).snapshotLimit(
|
||||
nullIfUnlimited(in.snapshotLimit)).snapshots(in.snapshots).state(in.state)
|
||||
.templatesAvailable(nullIfUnlimited(in.templatesAvailable)).templateLimit(
|
||||
nullIfUnlimited(in.templateLimit)).templates(in.templates).VMsAvailable(
|
||||
nullIfUnlimited(in.VMsAvailable)).VMLimit(nullIfUnlimited(in.VMLimit)).VMsRunning(
|
||||
in.VMsRunning).VMsStopped(in.VMsStopped).VMs(in.VMs).volumesAvailable(
|
||||
nullIfUnlimited(in.volumesAvailable)).volumeLimit(nullIfUnlimited(in.volumeLimit)).volumes(
|
||||
in.volumes).users(in.users).build();
|
||||
}
|
||||
|
||||
static final class AccountInternal {
|
||||
private long id;
|
||||
@SerializedName("accounttype")
|
||||
private Account.Type type;
|
||||
private String domain;
|
||||
@SerializedName("domainid")
|
||||
private long domainId;
|
||||
@SerializedName("ipavailable")
|
||||
private String IPsAvailable;
|
||||
@SerializedName("iplimit")
|
||||
private String IPLimit;
|
||||
@SerializedName("iptotal")
|
||||
private long IPs;
|
||||
@SerializedName("iscleanuprequired")
|
||||
private boolean cleanupRequired;
|
||||
private String name;
|
||||
@SerializedName("receivedbytes")
|
||||
private long receivedBytes;
|
||||
@SerializedName("sentBytes")
|
||||
private long sentBytes;
|
||||
@SerializedName("snapshotavailable")
|
||||
private String snapshotsAvailable;
|
||||
@SerializedName("snapshotlimit")
|
||||
private String snapshotLimit;
|
||||
@SerializedName("snapshottotal")
|
||||
private long snapshots;
|
||||
@SerializedName("state")
|
||||
private State state;
|
||||
@SerializedName("templateavailable")
|
||||
private String templatesAvailable;
|
||||
@SerializedName("templatelimit")
|
||||
private String templateLimit;
|
||||
@SerializedName("templatetotal")
|
||||
private long templates;
|
||||
@SerializedName("vmavailable")
|
||||
private String VMsAvailable;
|
||||
@SerializedName("vmlimit")
|
||||
private String VMLimit;
|
||||
@SerializedName("vmrunning")
|
||||
private long VMsRunning;
|
||||
@SerializedName("vmstopped")
|
||||
private long VMsStopped;
|
||||
@SerializedName("vmtotal")
|
||||
private long VMs;
|
||||
@SerializedName("volumeavailable")
|
||||
private String volumesAvailable;
|
||||
@SerializedName("volumelimit")
|
||||
private String volumeLimit;
|
||||
@SerializedName("volumetotal")
|
||||
private long volumes;
|
||||
@SerializedName("user")
|
||||
private Set<User> users;
|
||||
}
|
||||
|
||||
private static Long nullIfUnlimited(String in) {
|
||||
return in == null || "Unlimited".equals(in) ? null : new Long(in);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DateAdapter.class).to(Iso8601DateAdapter.class);
|
||||
|
@ -106,6 +209,8 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
|
|||
}
|
||||
|
||||
});
|
||||
bind(new TypeLiteral<Map<Type, Object>>() {
|
||||
}).toInstance(ImmutableMap.<Type, Object> of(Account.class, new BreakGenericSetAdapter()));
|
||||
super.configure();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,643 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Account extends ForwardingSet<User> implements Comparable<Account> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private long id;
|
||||
private Type type;
|
||||
private String domain;
|
||||
private long domainId;
|
||||
private Long IPsAvailable;
|
||||
private Long IPLimit;
|
||||
private long IPs;
|
||||
private boolean cleanupRequired;
|
||||
private String name;
|
||||
private long receivedBytes;
|
||||
private long sentBytes;
|
||||
private Long snapshotsAvailable;
|
||||
private Long snapshotLimit;
|
||||
private long snapshots;
|
||||
private State state;
|
||||
private Long templatesAvailable;
|
||||
private Long templateLimit;
|
||||
private long templates;
|
||||
private Long VMsAvailable;
|
||||
private Long VMLimit;
|
||||
private long VMsRunning;
|
||||
private long VMsStopped;
|
||||
private long VMs;
|
||||
private Long volumesAvailable;
|
||||
private Long volumeLimit;
|
||||
private long volumes;
|
||||
private Set<User> users = ImmutableSet.of();
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder type(Type type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder domain(String domain) {
|
||||
this.domain = domain;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder domainId(long domainId) {
|
||||
this.domainId = domainId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder IPsAvailable(Long IPsAvailable) {
|
||||
this.IPsAvailable = IPsAvailable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder IPLimit(Long IPLimit) {
|
||||
this.IPLimit = IPLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder IPs(long IPs) {
|
||||
this.IPs = IPs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder cleanupRequired(boolean cleanupRequired) {
|
||||
this.cleanupRequired = cleanupRequired;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder receivedBytes(long receivedBytes) {
|
||||
this.receivedBytes = receivedBytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder sentBytes(long sentBytes) {
|
||||
this.sentBytes = sentBytes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder snapshotsAvailable(Long snapshotsAvailable) {
|
||||
this.snapshotsAvailable = snapshotsAvailable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder snapshotLimit(Long snapshotLimit) {
|
||||
this.snapshotLimit = snapshotLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder snapshots(long snapshots) {
|
||||
this.snapshots = snapshots;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder state(State state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder templatesAvailable(Long templatesAvailable) {
|
||||
this.templatesAvailable = templatesAvailable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder templateLimit(Long templateLimit) {
|
||||
this.templateLimit = templateLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder templates(long templates) {
|
||||
this.templates = templates;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder VMsAvailable(Long VMsAvailable) {
|
||||
this.VMsAvailable = VMsAvailable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder VMLimit(Long VMLimit) {
|
||||
this.VMLimit = VMLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder VMsRunning(long VMsRunning) {
|
||||
this.VMsRunning = VMsRunning;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder VMsStopped(long VMsStopped) {
|
||||
this.VMsStopped = VMsStopped;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder VMs(long VMs) {
|
||||
this.VMs = VMs;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder volumesAvailable(Long volumesAvailable) {
|
||||
this.volumesAvailable = volumesAvailable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder volumeLimit(Long volumeLimit) {
|
||||
this.volumeLimit = volumeLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder volumes(long volumes) {
|
||||
this.volumes = volumes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder users(Set<User> users) {
|
||||
this.users = ImmutableSet.copyOf(checkNotNull(users, "users"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Account build() {
|
||||
return new Account(id, type, domain, domainId, IPsAvailable, IPLimit, IPs, cleanupRequired, name,
|
||||
receivedBytes, sentBytes, snapshotsAvailable, snapshotLimit, snapshots, state, templatesAvailable,
|
||||
templateLimit, templates, VMsAvailable, VMLimit, VMsRunning, VMsStopped, VMs, volumesAvailable,
|
||||
volumeLimit, volumes, users);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static enum State {
|
||||
ENABLED, DISABLED, LOCKED, UNRECOGNIZED;
|
||||
@Override
|
||||
public String toString() {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name());
|
||||
}
|
||||
|
||||
public static State fromValue(String state) {
|
||||
try {
|
||||
return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state")));
|
||||
} catch (IllegalArgumentException e) {
|
||||
return UNRECOGNIZED;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static enum Type {
|
||||
|
||||
/**
|
||||
* full API access. This is typically a service administrator or code that executes with
|
||||
* complete trust in the service operator's environment.
|
||||
*/
|
||||
ADMIN(1),
|
||||
/**
|
||||
* full API access within a domain. This is the most privileged user that a given customer
|
||||
* has. This may be a reseller for the service provider.
|
||||
*/
|
||||
DOMAIN_ADMIN(2),
|
||||
// TODO get code for read-only user.
|
||||
// /**
|
||||
// * API access limited to viewing most entities. No access is given to create or update those
|
||||
// * entities. This may be useful for monitoring programs in the service operator's
|
||||
// environment.
|
||||
// */
|
||||
// READ_ONLY_ADMIN(?)
|
||||
/**
|
||||
* API access for all the resources associated with their account. There may be many users in
|
||||
* a domain, many domains in a deployment, and many users in a deployment. This is typically
|
||||
* the end user
|
||||
*/
|
||||
USER(0), UNRECOGNIZED(Integer.MAX_VALUE);
|
||||
|
||||
private int code;
|
||||
|
||||
private static final Map<Integer, Type> INDEX = Maps.uniqueIndex(ImmutableSet.copyOf(Type.values()),
|
||||
new Function<Type, Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer apply(Type input) {
|
||||
return input.code;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Type(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name();
|
||||
}
|
||||
|
||||
public static Type fromValue(String type) {
|
||||
Integer code = new Integer(checkNotNull(type, "type"));
|
||||
return INDEX.containsKey(code) ? INDEX.get(code) : UNRECOGNIZED;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private long id;
|
||||
private Type type;
|
||||
private String domain;
|
||||
private long domainId;
|
||||
private Long IPsAvailable;
|
||||
private Long IPLimit;
|
||||
private long IPs;
|
||||
private boolean cleanupRequired;
|
||||
private String name;
|
||||
private long receivedBytes;
|
||||
private long sentBytes;
|
||||
private Long snapshotsAvailable;
|
||||
private Long snapshotLimit;
|
||||
private long snapshots;
|
||||
private State state;
|
||||
private Long templatesAvailable;
|
||||
private Long templateLimit;
|
||||
private long templates;
|
||||
private Long VMsAvailable;
|
||||
private Long VMLimit;
|
||||
private long VMsRunning;
|
||||
private long VMsStopped;
|
||||
private long VMs;
|
||||
private Long volumesAvailable;
|
||||
private Long volumeLimit;
|
||||
private long volumes;
|
||||
private Set<User> users;
|
||||
|
||||
public Account(long id, Type type, String domain, long domainId, Long IPsAvailable, Long IPLimit, long iPs,
|
||||
boolean cleanupRequired, String name, long receivedBytes, long sentBytes, Long snapshotsAvailable,
|
||||
Long snapshotLimit, long snapshots, org.jclouds.cloudstack.domain.Account.State state,
|
||||
Long templatesAvailable, Long templateLimit, long templates, Long VMsAvailable, Long VMLimit,
|
||||
long vMsRunning, long vMsStopped, long vMs, Long volumesAvailable, Long volumeLimit, long volumes,
|
||||
Set<User> users) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.IPsAvailable = IPsAvailable;
|
||||
this.IPLimit = IPLimit;
|
||||
this.IPs = iPs;
|
||||
this.cleanupRequired = cleanupRequired;
|
||||
this.name = name;
|
||||
this.receivedBytes = receivedBytes;
|
||||
this.sentBytes = sentBytes;
|
||||
this.snapshotsAvailable = snapshotsAvailable;
|
||||
this.snapshotLimit = snapshotLimit;
|
||||
this.snapshots = snapshots;
|
||||
this.state = state;
|
||||
this.templatesAvailable = templatesAvailable;
|
||||
this.templateLimit = templateLimit;
|
||||
this.templates = templates;
|
||||
this.VMsAvailable = VMsAvailable;
|
||||
this.VMLimit = VMLimit;
|
||||
this.VMsRunning = vMsRunning;
|
||||
this.VMsStopped = vMsStopped;
|
||||
this.VMs = vMs;
|
||||
this.volumesAvailable = volumesAvailable;
|
||||
this.volumeLimit = volumeLimit;
|
||||
this.volumes = volumes;
|
||||
this.users = ImmutableSet.copyOf(checkNotNull(users, "users"));
|
||||
}
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*
|
||||
*/
|
||||
Account() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the id of the account
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the account
|
||||
*/
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return account type (admin, domain-admin, user)
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return name of the Domain the account belongs to
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return id of the Domain the account belongs to
|
||||
*/
|
||||
public long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if the account requires cleanup
|
||||
*/
|
||||
public boolean isCleanupRequired() {
|
||||
return cleanupRequired;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the list of users associated with account
|
||||
*/
|
||||
public Set<User> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of public ip addresses available for this account to acquire, or null
|
||||
* if unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getIPsAvailable() {
|
||||
return IPsAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of public ip addresses this account can acquire, or null if unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getIPLimit() {
|
||||
return IPLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of public ip addresses allocated for this account
|
||||
*/
|
||||
public long getIPs() {
|
||||
return IPs;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of network traffic bytes received
|
||||
*/
|
||||
public long getReceivedBytes() {
|
||||
return receivedBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of network traffic bytes sent
|
||||
*/
|
||||
public long getSentBytes() {
|
||||
return sentBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of snapshots available for this account, or null if unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getSnapshotsAvailable() {
|
||||
return snapshotsAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of snapshots which can be stored by this account, or null if
|
||||
* unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getSnapshotLimit() {
|
||||
return snapshotLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of snapshots stored by this account
|
||||
*/
|
||||
public long getSnapshots() {
|
||||
return snapshots;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the state of the account
|
||||
*/
|
||||
public State getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of templates available to be created by this account, or null if
|
||||
* unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getTemplatesAvailable() {
|
||||
return templatesAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of templates which can be created by this account, or null if
|
||||
* unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getTemplateLimit() {
|
||||
return templateLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of templates which have been created by this account
|
||||
*/
|
||||
public long getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of virtual machines available for this account to acquire, or null if
|
||||
* unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getVMsAvailable() {
|
||||
return VMsAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of virtual machines that can be deployed by this account, or null if
|
||||
* unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getVMLimit() {
|
||||
return VMLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of virtual machines running for this account
|
||||
*/
|
||||
public long getVMsRunning() {
|
||||
return VMsRunning;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of virtual machines stopped for this account
|
||||
*/
|
||||
public long getVMsStopped() {
|
||||
return VMsStopped;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total number of virtual machines deployed by this account
|
||||
*/
|
||||
public long getVMs() {
|
||||
return VMs;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total volume available for this account, or null if unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getVolumesAvailable() {
|
||||
return volumesAvailable;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total volume which can be used by this account, or null if unlimited
|
||||
*/
|
||||
@Nullable
|
||||
public Long getVolumeLimit() {
|
||||
return volumeLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the total volume being used by this account
|
||||
*/
|
||||
public long getVolumes() {
|
||||
return volumes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Account arg0) {
|
||||
return new Long(id).compareTo(arg0.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String
|
||||
.format(
|
||||
"[id=%s, name=%s, type=%s, state=%s, domain=%s, domainId=%s, cleanupRequired=%s, sentBytes=%s, receivedBytes=%s, IPs=%s, IPsAvailable=%s, IPLimit=%s, VMs=%s, VMsAvailable=%s, VMsRunning=%s, VMsStopped=%s, VMLimit=%s, snapshots=%s, snapshotLimit=%s, snapshotsAvailable=%s, templateLimit=%s, templates=%s, templatesAvailable=%s, volumes=%s, volumeLimit=%s, volumesAvailable=%s, users=%s]",
|
||||
id, name, type, state, domain, domainId, cleanupRequired, sentBytes, receivedBytes, IPs,
|
||||
IPsAvailable, IPLimit, VMs, VMsAvailable, VMsRunning, VMsStopped, VMLimit, snapshots,
|
||||
snapshotLimit, snapshotsAvailable, templateLimit, templates, templatesAvailable, volumes,
|
||||
volumeLimit, volumesAvailable, users);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (int) (domainId ^ (domainId >>> 32));
|
||||
result = prime * result + (int) (id ^ (id >>> 32));
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Account other = (Account) obj;
|
||||
if (domainId != other.domainId)
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<User> delegate() {
|
||||
return users;
|
||||
}
|
||||
}
|
|
@ -37,24 +37,16 @@ public class Template implements Comparable<Template> {
|
|||
|
||||
public static class Builder {
|
||||
private long id;
|
||||
@SerializedName("displaytext")
|
||||
private String displayText;
|
||||
private String domain;
|
||||
@SerializedName("domainid")
|
||||
private long domainId;
|
||||
private String account;
|
||||
@SerializedName("accountid")
|
||||
private long accountId;
|
||||
@SerializedName("zonename")
|
||||
private String zone;
|
||||
@SerializedName("zoneid")
|
||||
private long zoneId;
|
||||
@SerializedName("ostypename")
|
||||
private String OSType;
|
||||
@SerializedName("ostypeid")
|
||||
private long OSTypeId;
|
||||
private String name;
|
||||
@SerializedName("templatetype")
|
||||
private Type type;
|
||||
private String status;
|
||||
private Format format;
|
||||
|
@ -62,24 +54,14 @@ public class Template implements Comparable<Template> {
|
|||
private Long size;
|
||||
private Date created;
|
||||
private Date removed;
|
||||
@SerializedName("crossZones")
|
||||
private boolean crossZones;
|
||||
@SerializedName("bootable")
|
||||
private boolean bootable;
|
||||
@SerializedName("isextractable")
|
||||
private boolean extractable;
|
||||
@SerializedName("isfeatured")
|
||||
private boolean featured;
|
||||
@SerializedName("ispublic")
|
||||
private boolean isPublic;
|
||||
@SerializedName("isready")
|
||||
private boolean ready;
|
||||
@SerializedName("passwordenabled")
|
||||
private boolean passwordEnabled;
|
||||
@Nullable
|
||||
@SerializedName("jobid")
|
||||
private Long jobId;
|
||||
@SerializedName("jobstatus")
|
||||
private String jobStatus;
|
||||
|
||||
public Builder id(long id) {
|
||||
|
|
|
@ -0,0 +1,336 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 java.util.Date;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Account.Type;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class User implements Comparable<User> {
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private long id;
|
||||
private String name;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String email;
|
||||
private Date created;
|
||||
private String state;
|
||||
private String account;
|
||||
private Account.Type accountType;
|
||||
private String domain;
|
||||
private long domainId;
|
||||
private String timeZone;
|
||||
private String apiKey;
|
||||
private String secretKey;
|
||||
|
||||
public Builder id(long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder firstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder lastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder email(String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder created(Date created) {
|
||||
this.created = created;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder state(String state) {
|
||||
this.state = state;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder account(String account) {
|
||||
this.account = account;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder accountType(Account.Type accountType) {
|
||||
this.accountType = accountType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder domain(String domain) {
|
||||
this.domain = domain;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder domainId(long domainId) {
|
||||
this.domainId = domainId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder timeZone(String timeZone) {
|
||||
this.timeZone = timeZone;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder apiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder secretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
public User build() {
|
||||
return new User(id, name, firstName, lastName, email, created, state, account, accountType, domain, domainId,
|
||||
timeZone, apiKey, secretKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* present only for serializer
|
||||
*
|
||||
*/
|
||||
User() {
|
||||
|
||||
}
|
||||
|
||||
private long id;
|
||||
@SerializedName("username")
|
||||
private String name;
|
||||
@SerializedName("firstname")
|
||||
private String firstName;
|
||||
@SerializedName("lastname")
|
||||
private String lastName;
|
||||
private String email;
|
||||
private Date created;
|
||||
private String state;
|
||||
private String account;
|
||||
@SerializedName("accounttype")
|
||||
private Account.Type accountType;
|
||||
private String domain;
|
||||
@SerializedName("domainid")
|
||||
private long domainId;
|
||||
@SerializedName("timezone")
|
||||
private String timeZone;
|
||||
@SerializedName("apikey")
|
||||
private String apiKey;
|
||||
@SerializedName("secretkey")
|
||||
private String secretKey;
|
||||
|
||||
public User(long id, String name, String firstname, String lastname, String email, Date created, String state,
|
||||
String account, Type accountType, String domain, long domainId, String timeZone, String apiKey,
|
||||
String secretKey) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.firstName = firstname;
|
||||
this.lastName = lastname;
|
||||
this.email = email;
|
||||
this.created = created;
|
||||
this.state = state;
|
||||
this.account = account;
|
||||
this.accountType = accountType;
|
||||
this.domain = domain;
|
||||
this.domainId = domainId;
|
||||
this.timeZone = timeZone;
|
||||
this.apiKey = apiKey;
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the user ID
|
||||
*/
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the user name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the user firstname
|
||||
*/
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the user lastname
|
||||
*/
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the user email address
|
||||
*/
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the date and time the user account was created
|
||||
*/
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the user state
|
||||
*/
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the account name of the user
|
||||
*/
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the account type of the user
|
||||
*/
|
||||
public Account.Type getAccountType() {
|
||||
return accountType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the domain name of the user
|
||||
*/
|
||||
public String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the domain ID of the user
|
||||
*/
|
||||
public long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the timezone user was created in
|
||||
*/
|
||||
public String getTimeZone() {
|
||||
return timeZone;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the api key of the user
|
||||
*/
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the secret key of the user
|
||||
*/
|
||||
public String getSecretKey() {
|
||||
return secretKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(User arg0) {
|
||||
return new Long(id).compareTo(arg0.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((account == null) ? 0 : account.hashCode());
|
||||
result = prime * result + (int) (domainId ^ (domainId >>> 32));
|
||||
result = prime * result + (int) (id ^ (id >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
User other = (User) obj;
|
||||
if (account == null) {
|
||||
if (other.account != null)
|
||||
return false;
|
||||
} else if (!account.equals(other.account))
|
||||
return false;
|
||||
if (domainId != other.domainId)
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String
|
||||
.format(
|
||||
"[id=%s, name=%s, state=%s, created=%s, account=%s, accountType=%s, domain=%s, domainId=%s, email=%s, firstName=%s, lastName=%s, apiKey=%s, secretKey=%s, timeZone=%s]",
|
||||
id, name, state, created, account, accountType, domain, domainId, email, firstName, lastName,
|
||||
apiKey, secretKey, timeZone);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.filters.QuerySigner;
|
||||
import org.jclouds.cloudstack.options.ListAccountsOptions;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.QueryParams;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.Unwrap;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* Provides asynchronous access to cloudstack via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see AccountClient
|
||||
* @see <a href="http://download.cloud.com/releases/2.2.0/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@RequestFilters(QuerySigner.class)
|
||||
@QueryParams(keys = "response", values = "json")
|
||||
public interface AccountAsyncClient {
|
||||
/**
|
||||
* @see AccountClient#listAccounts
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listAccounts")
|
||||
@Unwrap(depth = 2)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
|
||||
ListenableFuture<Set<Account>> listAccounts(ListAccountsOptions... options);
|
||||
|
||||
/**
|
||||
* @see AccountClient#getAccount
|
||||
*/
|
||||
@GET
|
||||
@QueryParams(keys = "command", values = "listAccounts")
|
||||
@Unwrap(depth = 3, edgeCollection = Set.class)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<Account> getAccount(@QueryParam("id") long id);
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.options.ListAccountsOptions;
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
|
||||
/**
|
||||
* Provides synchronous access to CloudStack Account features.
|
||||
* <p/>
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2.0/api/TOC_User.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
|
||||
public interface AccountClient {
|
||||
/**
|
||||
* Lists Accounts
|
||||
*
|
||||
* @param options
|
||||
* if present, how to constrain the list.
|
||||
* @return Accounts matching query, or empty set, if no Accounts are found
|
||||
*/
|
||||
Set<Account> listAccounts(ListAccountsOptions... options);
|
||||
|
||||
/**
|
||||
* get a specific Account by id
|
||||
*
|
||||
* @param id
|
||||
* Account to get
|
||||
* @return Account or null if not found
|
||||
*/
|
||||
Account getAccount(long id);
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 used to control what account information is returned
|
||||
*
|
||||
* @see <a href="http://download.cloud.com/releases/2.2.0/api/user/listAccounts.html" />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class ListAccountsOptions extends AccountInDomainOptions {
|
||||
|
||||
public static final ListAccountsOptions NONE = new ListAccountsOptions();
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* list account by account ID
|
||||
*/
|
||||
public ListAccountsOptions id(long id) {
|
||||
this.queryParameters.replaceValues("id", ImmutableSet.of(id + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* list account by account name
|
||||
*/
|
||||
public ListAccountsOptions name(String name) {
|
||||
this.queryParameters.replaceValues("name", ImmutableSet.of(name));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state
|
||||
* list accounts by state. Valid states are enabled, disabled, and locked.
|
||||
*/
|
||||
public ListAccountsOptions state(String state) {
|
||||
this.queryParameters.replaceValues("state", ImmutableSet.of(state));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cleanupRequired
|
||||
* list accounts by cleanuprequred attribute
|
||||
*/
|
||||
public ListAccountsOptions cleanupRequired(boolean cleanupRequired) {
|
||||
this.queryParameters.replaceValues("iscleanuprequired", ImmutableSet.of(cleanupRequired + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param recursive
|
||||
* defaults to false, but if true, lists all accounts from the parent specified by the
|
||||
* domain id till leaves.
|
||||
*/
|
||||
public ListAccountsOptions recursive(boolean recursive) {
|
||||
this.queryParameters.replaceValues("isrecursive", ImmutableSet.of(recursive + ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see ListAccountsOptions#accountInDomain
|
||||
*/
|
||||
public static ListAccountsOptions accountInDomain(String account, long domain) {
|
||||
ListAccountsOptions options = new ListAccountsOptions();
|
||||
return options.accountInDomain(account, domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListAccountsOptions#domainId
|
||||
*/
|
||||
public static ListAccountsOptions domainId(long id) {
|
||||
ListAccountsOptions options = new ListAccountsOptions();
|
||||
return options.domainId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListAccountsOptions#id
|
||||
*/
|
||||
public static ListAccountsOptions id(long id) {
|
||||
ListAccountsOptions options = new ListAccountsOptions();
|
||||
return options.id(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListAccountsOptions#name
|
||||
*/
|
||||
public static ListAccountsOptions name(String name) {
|
||||
ListAccountsOptions options = new ListAccountsOptions();
|
||||
return options.name(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListAccountsOptions#state
|
||||
*/
|
||||
public static ListAccountsOptions state(String state) {
|
||||
ListAccountsOptions options = new ListAccountsOptions();
|
||||
return options.state(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListAccountsOptions#cleanupRequired
|
||||
*/
|
||||
public static ListAccountsOptions cleanupRequired(boolean cleanupRequired) {
|
||||
ListAccountsOptions options = new ListAccountsOptions();
|
||||
return options.cleanupRequired(cleanupRequired);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ListAccountsOptions#recursive
|
||||
*/
|
||||
public static ListAccountsOptions recursive(boolean recursive) {
|
||||
ListAccountsOptions options = new ListAccountsOptions();
|
||||
return options.recursive(recursive);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ListAccountsOptions accountInDomain(String account, long domain) {
|
||||
return ListAccountsOptions.class.cast(super.accountInDomain(account, domain));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public ListAccountsOptions domainId(long domainId) {
|
||||
return ListAccountsOptions.class.cast(super.domainId(domainId));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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.predicates;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class UserPredicates {
|
||||
|
||||
public static class ApiKeyEquals implements Predicate<User> {
|
||||
private final String apiKey;
|
||||
|
||||
public ApiKeyEquals(String apiKey) {
|
||||
this.apiKey = checkNotNull(apiKey, "apiKey");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(User input) {
|
||||
return apiKey.equals(checkNotNull(input, "user").getApiKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "apiKeyEquals(" + apiKey + ")";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true, if the user's apiKey is the following
|
||||
*/
|
||||
public static Predicate<User> apiKeyEquals(String apiKey) {
|
||||
return new ApiKeyEquals(apiKey);
|
||||
}
|
||||
|
||||
public static enum IsUserAccount implements Predicate<User> {
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public boolean apply(User input) {
|
||||
return checkNotNull(input, "user").getAccountType() == Account.Type.USER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "isUserAccount()";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true, if the user's apiKey is the following
|
||||
*/
|
||||
public static Predicate<User> isUserAccount() {
|
||||
return IsUserAccount.INSTANCE;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,13 +22,7 @@ import java.io.IOException;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.jclouds.cloudstack.features.BaseCloudStackAsyncClientTest;
|
||||
import org.jclouds.cloudstack.features.FirewallClient;
|
||||
import org.jclouds.cloudstack.features.GuestOSClient;
|
||||
import org.jclouds.cloudstack.features.HypervisorClient;
|
||||
import org.jclouds.cloudstack.features.LoadBalancerClient;
|
||||
import org.jclouds.cloudstack.features.NATClient;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.annotations.Delegate;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -61,6 +55,8 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
|
|||
assert syncClient.getLoadBalancerClient() != null;
|
||||
assert syncClient.getGuestOSClient() != null;
|
||||
assert syncClient.getHypervisorClient() != null;
|
||||
assert syncClient.getConfigurationClient() != null;
|
||||
assert syncClient.getAccountClient() != null;
|
||||
}
|
||||
|
||||
public void testAsync() throws SecurityException, NoSuchMethodException, InterruptedException, ExecutionException {
|
||||
|
@ -77,6 +73,8 @@ public class CloudStackAsyncClientTest extends BaseCloudStackAsyncClientTest<Clo
|
|||
assert asyncClient.getLoadBalancerClient() != null;
|
||||
assert asyncClient.getGuestOSClient() != null;
|
||||
assert asyncClient.getHypervisorClient() != null;
|
||||
assert asyncClient.getConfigurationClient() != null;
|
||||
assert asyncClient.getAccountClient() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
// *
|
||||
// * @author Adrian Cole
|
||||
// */
|
||||
//@Test(groups = "live", sequential = true, testName = "CloudStackClientLiveTest")
|
||||
//@Test(groups = "live", singleThreaded = true, testName = "CloudStackClientLiveTest")
|
||||
//public class CloudStackClientLiveTest extends ReadOnlyCloudStackClientLiveTest {
|
||||
//
|
||||
// protected String prefix = System.getProperty("user.name") + ".test";
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.jclouds.cloudstack.options.ListAccountsOptions;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
|
||||
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
|
||||
import org.jclouds.rest.functions.ReturnEmptySetOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code AccountAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
@Test(groups = "unit", testName = "AccountAsyncClientTest")
|
||||
public class AccountAsyncClientTest extends BaseCloudStackAsyncClientTest<AccountAsyncClient> {
|
||||
|
||||
public void testListAccounts() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AccountAsyncClient.class.getMethod("listAccounts", ListAccountsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listAccounts HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testListAccountsOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AccountAsyncClient.class.getMethod("listAccounts", ListAccountsOptions[].class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, ListAccountsOptions.Builder.accountInDomain("jclouds",
|
||||
123));
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listAccounts&account=jclouds&domainid=123 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValue.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnEmptySetOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
public void testGetAccount() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = AccountAsyncClient.class.getMethod("getAccount", long.class);
|
||||
HttpRequest httpRequest = processor.createRequest(method, 3l);
|
||||
|
||||
assertRequestLineEquals(httpRequest,
|
||||
"GET http://localhost:8080/client/api?response=json&command=listAccounts&id=3 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
|
||||
assertPayloadEquals(httpRequest, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyNestedJsonValueInSet.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<AccountAsyncClient>> createTypeLiteral() {
|
||||
return new TypeLiteral<RestAnnotationProcessor<AccountAsyncClient>>() {
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code AccountClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "AccountClientLiveTest")
|
||||
public class AccountClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListAccount() throws Exception {
|
||||
for (Account securityAccount : client.getAccountClient().listAccounts())
|
||||
checkAccount(securityAccount);
|
||||
}
|
||||
|
||||
protected void checkAccount(Account account) {
|
||||
assert account.getId() > 0 : account;
|
||||
assertEquals(account.toString(), client.getAccountClient().getAccount(account.getId()).toString());
|
||||
assert account.getName() != null : account;
|
||||
assert account.getType() != null && account.getType() != Account.Type.UNRECOGNIZED : account;
|
||||
assert account.getDomain() != null : account;
|
||||
assert account.getDomainId() >= 0 : account;
|
||||
assert account.getUsers() != null : account;
|
||||
for (User user : account.getUsers()) {
|
||||
assert user.getName() != null : user;
|
||||
assert user.getAccountType().equals(account.getType()) : user;
|
||||
assert user.getDomain().equals(account.getDomain()) : user;
|
||||
assert user.getDomainId() == account.getDomainId() : user;
|
||||
assert user.getApiKey() != null : user;
|
||||
assert user.getCreated() != null : user;
|
||||
assert user.getEmail() != null : user;
|
||||
assert user.getLastName() != null : user;
|
||||
assert user.getFirstName() != null : user;
|
||||
assert user.getId() > 0 : user;
|
||||
assert user.getSecretKey() != null : user;
|
||||
assert user.getState() != null : user;
|
||||
}
|
||||
assert account.getIPsAvailable() == null || account.getIPsAvailable() >= 0 : account;
|
||||
assert account.getIPLimit() == null || account.getIPLimit() >= 0 : account;
|
||||
assert account.getIPs() >= 0 : account;
|
||||
assert account.getReceivedBytes() >= 0 : account;
|
||||
assert account.getSentBytes() >= 0 : account;
|
||||
assert account.getSnapshotsAvailable() == null || account.getSnapshotsAvailable() >= 0 : account;
|
||||
assert account.getSnapshotLimit() == null || account.getSnapshotLimit() >= 0 : account;
|
||||
assert account.getSnapshots() >= 0 : account;
|
||||
assert account.getState() != null && account.getState() != Account.State.UNRECOGNIZED : account;
|
||||
assert account.getTemplatesAvailable() == null || account.getTemplatesAvailable() >= 0 : account;
|
||||
assert account.getTemplateLimit() == null || account.getTemplateLimit() >= 0 : account;
|
||||
assert account.getTemplates() >= 0 : account;
|
||||
assert account.getVMsAvailable() == null || account.getVMsAvailable() >= 0 : account;
|
||||
assert account.getVMLimit() == null || account.getVMLimit() >= 0 : account;
|
||||
assert account.getVMsRunning() >= 0 : account;
|
||||
assert account.getVMsStopped() >= 0 : account;
|
||||
assert account.getVMs() >= 0 : account;
|
||||
assert account.getVolumesAvailable() == null || account.getVolumesAvailable() >= 0 : account;
|
||||
assert account.getVolumeLimit() == null || account.getVolumeLimit() >= 0 : account;
|
||||
assert account.getVolumes() >= 0 : account;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,17 +30,16 @@ import org.jclouds.cloudstack.domain.PublicIPAddress;
|
|||
import org.jclouds.cloudstack.options.ListPublicIPAddressesOptions;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code PublicIPAddressClientLiveTest}
|
||||
* Tests behavior of {@code AddressClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "PublicIPAddressClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "AddressClientLiveTest")
|
||||
public class AddressClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
private boolean networksEnabled;
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import org.testng.annotations.Test;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "AsyncJobClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "AsyncJobClientLiveTest")
|
||||
public class AsyncJobClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
// disabled as it takes too long
|
||||
@Test(enabled = false)
|
||||
|
|
|
@ -27,9 +27,12 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.jclouds.Constants;
|
||||
import org.jclouds.cloudstack.CloudStackAsyncClient;
|
||||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.domain.Account;
|
||||
import org.jclouds.cloudstack.domain.User;
|
||||
import org.jclouds.cloudstack.domain.VirtualMachine;
|
||||
import org.jclouds.cloudstack.functions.ReuseOrAssociateNewPublicIPAddress;
|
||||
import org.jclouds.cloudstack.predicates.JobComplete;
|
||||
import org.jclouds.cloudstack.predicates.UserPredicates;
|
||||
import org.jclouds.cloudstack.predicates.VirtualMachineDestroyed;
|
||||
import org.jclouds.cloudstack.predicates.VirtualMachineRunning;
|
||||
import org.jclouds.compute.domain.ExecResponse;
|
||||
|
@ -47,6 +50,7 @@ import org.testng.annotations.BeforeGroups;
|
|||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
|
@ -120,7 +124,16 @@ public class BaseCloudStackClientLiveTest {
|
|||
overrides);
|
||||
|
||||
client = context.getApi();
|
||||
injector = Guice.createInjector(new JschSshClientModule(),new Log4JLoggingModule());
|
||||
// check access
|
||||
Iterable<User> users = Iterables.concat(client.getAccountClient().listAccounts());
|
||||
User currentUser = Iterables.find(users, UserPredicates.apiKeyEquals(identity));
|
||||
|
||||
if (currentUser.getAccountType() != Account.Type.USER)
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"invalid account type: %s, please specify an apiKey of a USER, for example: %s", currentUser
|
||||
.getAccountType(), Iterables.filter(users, UserPredicates.isUserAccount())));
|
||||
|
||||
injector = Guice.createInjector(new JschSshClientModule(), new Log4JLoggingModule());
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, 1, TimeUnit.SECONDS);
|
||||
injector.injectMembers(socketTester);
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.testng.annotations.Test;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "ConfigurationClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "ConfigurationClientLiveTest")
|
||||
public class ConfigurationClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListCapabilities() throws Exception {
|
||||
|
|
|
@ -43,7 +43,7 @@ import com.google.common.base.Predicate;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "FirewallClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "FirewallClientLiveTest")
|
||||
public class FirewallClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
private PublicIPAddress ip = null;
|
||||
private VirtualMachine vm;
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.testng.annotations.Test;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "GuestOSClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "GuestOSClientLiveTest")
|
||||
public class GuestOSClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListOSTypes() throws Exception {
|
||||
|
|
|
@ -30,7 +30,7 @@ import org.testng.annotations.Test;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "HypervisorClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "HypervisorClientLiveTest")
|
||||
public class HypervisorClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListHypervisors() throws Exception {
|
||||
|
|
|
@ -49,7 +49,7 @@ import com.google.common.base.Predicate;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "LoadBalancerClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "LoadBalancerClientLiveTest")
|
||||
public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
private PublicIPAddress ip = null;
|
||||
private VirtualMachine vm;
|
||||
|
|
|
@ -46,7 +46,7 @@ import org.testng.annotations.Test;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "NATClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "NATClientLiveTest")
|
||||
public class NATClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
private PublicIPAddress ip = null;
|
||||
private VirtualMachine vm;
|
||||
|
|
|
@ -35,7 +35,7 @@ import com.google.common.collect.Iterables;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "NetworkClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "NetworkClientLiveTest")
|
||||
public class NetworkClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListNetworks() throws Exception {
|
||||
|
|
|
@ -40,7 +40,7 @@ import com.google.common.collect.Iterables;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "OfferingClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "OfferingClientLiveTest")
|
||||
public class OfferingClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListDiskOfferings() throws Exception {
|
||||
|
|
|
@ -45,7 +45,7 @@ import com.google.common.collect.Iterables;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "SecurityGroupClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "SecurityGroupClientLiveTest")
|
||||
public class SecurityGroupClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
public SecurityGroupClientLiveTest() {
|
||||
prefix += "2";
|
||||
|
@ -63,7 +63,7 @@ public class SecurityGroupClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
|
||||
@Override
|
||||
public boolean apply(Zone arg0) {
|
||||
return arg0.isSecurityGroupsEnabled();
|
||||
return true;// return arg0.isSecurityGroupsEnabled();
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -34,7 +34,7 @@ import com.google.common.collect.Iterables;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "TemplateClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "TemplateClientLiveTest")
|
||||
public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListTemplates() throws Exception {
|
||||
|
|
|
@ -34,7 +34,6 @@ import java.util.concurrent.ExecutionException;
|
|||
import org.jclouds.cloudstack.CloudStackClient;
|
||||
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
|
||||
import org.jclouds.cloudstack.domain.AsyncJob;
|
||||
import org.jclouds.cloudstack.domain.GuestIPType;
|
||||
import org.jclouds.cloudstack.domain.NIC;
|
||||
import org.jclouds.cloudstack.domain.Network;
|
||||
import org.jclouds.cloudstack.domain.ServiceOffering;
|
||||
|
@ -67,7 +66,7 @@ import com.google.common.net.HostSpecifier;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "VirtualMachineClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "VirtualMachineClientLiveTest")
|
||||
public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
private VirtualMachine vm = null;
|
||||
|
||||
|
@ -132,7 +131,6 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
throw new NoSuchElementException(templatePredicate.toString());
|
||||
}
|
||||
long templateId = get(templates, 0).getId();
|
||||
|
||||
long serviceOfferingId = DEFAULT_SIZE_ORDERING.min(client.getOfferingClient().listServiceOfferings()).getId();
|
||||
|
||||
System.out.printf("serviceOfferingId %d, templateId %d, zoneId %d, options %s%n", serviceOfferingId, templateId,
|
||||
|
@ -187,11 +185,13 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
vm = client.getVirtualMachineClient().getVirtualMachine(vm.getId());
|
||||
assertEquals(vm.getState(), VirtualMachine.State.STOPPED);
|
||||
|
||||
job = client.getVirtualMachineClient().resetPasswordForVirtualMachine(vm.getId());
|
||||
assert jobComplete.apply(job);
|
||||
vm = client.getAsyncJobClient().<VirtualMachine> getAsyncJob(job).getResult();
|
||||
if (vm.getPassword() != null) {
|
||||
conditionallyCheckSSH();
|
||||
if (vm.isPasswordEnabled()) {
|
||||
job = client.getVirtualMachineClient().resetPasswordForVirtualMachine(vm.getId());
|
||||
assert jobComplete.apply(job);
|
||||
vm = client.getAsyncJobClient().<VirtualMachine> getAsyncJob(job).getResult();
|
||||
if (vm.getPassword() != null) {
|
||||
conditionallyCheckSSH();
|
||||
}
|
||||
}
|
||||
|
||||
job = client.getVirtualMachineClient().startVirtualMachine(vm.getId());
|
||||
|
@ -263,17 +263,15 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
|
|||
assert nic.getGateway() != null : vm;
|
||||
assert nic.getIPAddress() != null : vm;
|
||||
break;
|
||||
default:
|
||||
if (nic.getGuestIPType() == GuestIPType.VIRTUAL) {
|
||||
assert nic.getNetmask() != null : vm;
|
||||
assert nic.getGateway() != null : vm;
|
||||
assert nic.getIPAddress() != null : vm;
|
||||
} else {
|
||||
assert nic.getNetmask() == null : vm;
|
||||
assert nic.getGateway() == null : vm;
|
||||
assert nic.getIPAddress() == null : vm;
|
||||
}
|
||||
case STARTING:
|
||||
assert nic.getNetmask() == null : vm;
|
||||
assert nic.getGateway() == null : vm;
|
||||
assert nic.getIPAddress() == null : vm;
|
||||
break;
|
||||
default:
|
||||
assert nic.getNetmask() != null : vm;
|
||||
assert nic.getGateway() != null : vm;
|
||||
assert nic.getIPAddress() != null : vm;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import com.google.common.collect.Iterables;
|
|||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "live", sequential = true, testName = "ZoneClientLiveTest")
|
||||
@Test(groups = "live", singleThreaded = true, testName = "ZoneClientLiveTest")
|
||||
public class ZoneClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||
|
||||
public void testListZones() throws Exception {
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed 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 static org.jclouds.cloudstack.options.ListAccountsOptions.Builder.accountInDomain;
|
||||
import static org.jclouds.cloudstack.options.ListAccountsOptions.Builder.cleanupRequired;
|
||||
import static org.jclouds.cloudstack.options.ListAccountsOptions.Builder.domainId;
|
||||
import static org.jclouds.cloudstack.options.ListAccountsOptions.Builder.id;
|
||||
import static org.jclouds.cloudstack.options.ListAccountsOptions.Builder.recursive;
|
||||
import static org.jclouds.cloudstack.options.ListAccountsOptions.Builder.state;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code ListAccountsOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ListAccountsOptionsTest {
|
||||
|
||||
public void testAccountInDomainId() {
|
||||
ListAccountsOptions options = new ListAccountsOptions().accountInDomain("adrian", 6);
|
||||
assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account"));
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testAccountInDomainIdStatic() {
|
||||
ListAccountsOptions options = accountInDomain("adrian", 6);
|
||||
assertEquals(ImmutableList.of("adrian"), options.buildQueryParameters().get("account"));
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testName() {
|
||||
ListAccountsOptions options = new ListAccountsOptions().id(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testNameStatic() {
|
||||
ListAccountsOptions options = id(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testRecursive() {
|
||||
ListAccountsOptions options = new ListAccountsOptions().recursive(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isrecursive"));
|
||||
}
|
||||
|
||||
public void testRecursiveStatic() {
|
||||
ListAccountsOptions options = recursive(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("isrecursive"));
|
||||
}
|
||||
|
||||
public void testState() {
|
||||
ListAccountsOptions options = new ListAccountsOptions().state("state");
|
||||
assertEquals(ImmutableList.of("state"), options.buildQueryParameters().get("state"));
|
||||
}
|
||||
|
||||
public void testStateStatic() {
|
||||
ListAccountsOptions options = state("state");
|
||||
assertEquals(ImmutableList.of("state"), options.buildQueryParameters().get("state"));
|
||||
}
|
||||
|
||||
public void testCleanupRequired() {
|
||||
ListAccountsOptions options = new ListAccountsOptions().cleanupRequired(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("iscleanuprequired"));
|
||||
}
|
||||
|
||||
public void testCleanupRequiredStatic() {
|
||||
ListAccountsOptions options = cleanupRequired(true);
|
||||
assertEquals(ImmutableList.of("true"), options.buildQueryParameters().get("iscleanuprequired"));
|
||||
}
|
||||
|
||||
public void testId() {
|
||||
ListAccountsOptions options = new ListAccountsOptions().id(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testDomainId() {
|
||||
ListAccountsOptions options = new ListAccountsOptions().domainId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
|
||||
public void testIdStatic() {
|
||||
ListAccountsOptions options = id(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("id"));
|
||||
}
|
||||
|
||||
public void testDomainIdStatic() {
|
||||
ListAccountsOptions options = domainId(6);
|
||||
assertEquals(ImmutableList.of("6"), options.buildQueryParameters().get("domainid"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue