From 5df7f7d14878073d2d8fc43c61c107a233dd3a3d Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 13 Feb 2011 00:07:34 +0100 Subject: [PATCH] updated cloudstack to include virtualmachine commands --- .../cloudstack/CloudStackAsyncClient.java | 7 + .../jclouds/cloudstack/CloudStackClient.java | 6 + .../config/CloudStackRestClientModule.java | 3 + .../org/jclouds/cloudstack/domain/NIC.java | 218 +++++ .../cloudstack/domain/VirtualMachine.java | 744 ++++++++++++++++++ .../features/VirtualMachineAsyncClient.java | 73 ++ .../features/VirtualMachineClient.java | 56 ++ .../options/ListVirtualMachinesOptions.java | 235 ++++++ .../features/TemplateClientLiveTest.java | 6 +- .../VirtualMachineAsyncClientTest.java | 104 +++ .../VirtualMachineClientLiveTest.java | 88 +++ .../features/ZoneClientLiveTest.java | 13 +- .../options/ListVirtualMachesOptionsTest.java | 157 ++++ 13 files changed, 1701 insertions(+), 9 deletions(-) create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/NIC.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java create mode 100644 sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListVirtualMachinesOptions.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClientTest.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java create mode 100644 sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/options/ListVirtualMachesOptionsTest.java diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java index 5197225349..39e25d6be9 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackAsyncClient.java @@ -22,6 +22,7 @@ package org.jclouds.cloudstack; import org.jclouds.cloudstack.features.NetworkAsyncClient; import org.jclouds.cloudstack.features.OfferingAsyncClient; import org.jclouds.cloudstack.features.TemplateAsyncClient; +import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; import org.jclouds.cloudstack.features.ZoneAsyncClient; import org.jclouds.rest.annotations.Delegate; @@ -58,4 +59,10 @@ public interface CloudStackAsyncClient { */ @Delegate NetworkAsyncClient getNetworkClient(); + + /** + * Provides asynchronous access to VirtualMachine features. + */ + @Delegate + VirtualMachineAsyncClient getVirtualMachineClient(); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java index 84613de911..f459d9f689 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/CloudStackClient.java @@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit; import org.jclouds.cloudstack.features.NetworkClient; import org.jclouds.cloudstack.features.OfferingClient; import org.jclouds.cloudstack.features.TemplateClient; +import org.jclouds.cloudstack.features.VirtualMachineClient; import org.jclouds.cloudstack.features.ZoneClient; import org.jclouds.concurrent.Timeout; import org.jclouds.rest.annotations.Delegate; @@ -62,4 +63,9 @@ public interface CloudStackClient { @Delegate NetworkClient getNetworkClient(); + /** + * Provides synchronous access to VirtualMachine features. + */ + @Delegate + VirtualMachineClient getVirtualMachineClient(); } diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java index 6a058f964b..734ec7fbae 100644 --- a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/config/CloudStackRestClientModule.java @@ -29,6 +29,8 @@ import org.jclouds.cloudstack.features.OfferingAsyncClient; import org.jclouds.cloudstack.features.OfferingClient; import org.jclouds.cloudstack.features.TemplateAsyncClient; import org.jclouds.cloudstack.features.TemplateClient; +import org.jclouds.cloudstack.features.VirtualMachineAsyncClient; +import org.jclouds.cloudstack.features.VirtualMachineClient; import org.jclouds.cloudstack.features.ZoneAsyncClient; import org.jclouds.cloudstack.features.ZoneClient; import org.jclouds.cloudstack.handlers.CloudStackErrorHandler; @@ -58,6 +60,7 @@ public class CloudStackRestClientModule extends RestClientModule + * + * ==================================================================== + * 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.net.URI; + +import com.google.gson.annotations.SerializedName; + +/** + * + * @author Adrian Cole + */ +public class NIC { + private String id; + @SerializedName("broadcasturi") + private URI broadcastURI; + private String gateway; + @SerializedName("ipaddress") + private String IPAddress; + @SerializedName("isdefault") + private boolean isDefault; + @SerializedName("isolationuri") + private URI isolationURI; + private String netmask; + @SerializedName("networkid") + private String networkId; + @SerializedName("traffictype") + private TrafficType trafficType; + @SerializedName("type") + private GuestIPType guestIPType; + + /** + * present only for serializer + * + */ + NIC() { + + } + + public NIC(String id, URI broadcastURI, String gateway, String iPAddress, boolean isDefault, URI isolationURI, + String netmask, String networkId, TrafficType trafficType, GuestIPType guestIPType) { + this.id = id; + this.broadcastURI = broadcastURI; + this.gateway = gateway; + this.IPAddress = iPAddress; + this.isDefault = isDefault; + this.isolationURI = isolationURI; + this.netmask = netmask; + this.networkId = networkId; + this.trafficType = trafficType; + this.guestIPType = guestIPType; + } + + /** + * the ID of the nic + */ + public String getId() { + return id; + } + + /** + * the broadcast uri of the nic + */ + public URI getBroadcastURI() { + return broadcastURI; + } + + /** + * the gateway of the nic + */ + public String getGateway() { + return gateway; + } + + /** + * the ip address of the nic + */ + public String getIPAddress() { + return IPAddress; + } + + /** + * true if nic is default, false otherwise + */ + public boolean isDefault() { + return isDefault; + } + + /** + * the isolation uri of the nic + */ + public URI getIsolationURI() { + return isolationURI; + } + + /** + * the netmask of the nic + */ + public String getNetmask() { + return netmask; + } + + /** + * the ID of the corresponding network + */ + public String getNetworkId() { + return networkId; + } + + /** + * the traffic type of the nic + */ + public TrafficType getTrafficType() { + return trafficType; + } + + /** + * the type of the nic + */ + public GuestIPType getGuestIPType() { + return guestIPType; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((IPAddress == null) ? 0 : IPAddress.hashCode()); + result = prime * result + ((broadcastURI == null) ? 0 : broadcastURI.hashCode()); + result = prime * result + ((gateway == null) ? 0 : gateway.hashCode()); + result = prime * result + ((guestIPType == null) ? 0 : guestIPType.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + (isDefault ? 1231 : 1237); + result = prime * result + ((isolationURI == null) ? 0 : isolationURI.hashCode()); + result = prime * result + ((netmask == null) ? 0 : netmask.hashCode()); + result = prime * result + ((networkId == null) ? 0 : networkId.hashCode()); + result = prime * result + ((trafficType == null) ? 0 : trafficType.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; + NIC other = (NIC) obj; + if (IPAddress == null) { + if (other.IPAddress != null) + return false; + } else if (!IPAddress.equals(other.IPAddress)) + return false; + if (broadcastURI == null) { + if (other.broadcastURI != null) + return false; + } else if (!broadcastURI.equals(other.broadcastURI)) + return false; + if (gateway == null) { + if (other.gateway != null) + return false; + } else if (!gateway.equals(other.gateway)) + return false; + if (guestIPType != other.guestIPType) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (isDefault != other.isDefault) + return false; + if (isolationURI == null) { + if (other.isolationURI != null) + return false; + } else if (!isolationURI.equals(other.isolationURI)) + return false; + if (netmask == null) { + if (other.netmask != null) + return false; + } else if (!netmask.equals(other.netmask)) + return false; + if (networkId == null) { + if (other.networkId != null) + return false; + } else if (!networkId.equals(other.networkId)) + return false; + if (trafficType != other.trafficType) + return false; + return true; + } + + @Override + public String toString() { + return "[id=" + id + ", broadcastURI=" + broadcastURI + ", gateway=" + gateway + ", IPAddress=" + IPAddress + + ", isDefault=" + isDefault + ", isolationURI=" + isolationURI + ", netmask=" + netmask + ", networkId=" + + networkId + ", trafficType=" + trafficType + ", guestIPType=" + guestIPType + "]"; + } + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java new file mode 100644 index 0000000000..86acf8feb5 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/domain/VirtualMachine.java @@ -0,0 +1,744 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.Date; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.base.CaseFormat; +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableSet; +import com.google.gson.annotations.SerializedName; + +/** + * + * @author Adrian Cole + */ +public class VirtualMachine { + public static enum State { + STARTING, RUNNING, STOPPING, STOPPED, DESTROYED, EXPUNGING, MIGRATING, ERROR, UNKNOWN, SHUTDOWNED, UNRECOGNIZED; + @Override + public String toString() { + return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name()); + } + + public static State fromValue(String state) { + try { + return valueOf(CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull(state, "state"))); + } catch (IllegalArgumentException e) { + return UNRECOGNIZED; + } + } + + } + + private String id; + private String account; + @SerializedName("cpunumber") + private long cpuCount; + @SerializedName("cpuspeed") + private long cpuSpeed; + @SerializedName("cpuused") + private String cpuUsed; + @SerializedName("displayname") + private String displayName; + private Date created; + private String domain; + @SerializedName("domainid") + private String domainId; + @SerializedName("forvirtualnetwork") + private boolean usesVirtualNetwork; + private String group; + @SerializedName("groupid") + private String groupId; + @SerializedName("guestosid") + private String guestOSId; + @SerializedName("haenable") + private boolean HAEnabled; + @SerializedName("hostid") + private String hostId; + private String hostname; + @SerializedName("ipaddress") + private String IPAddress; + @SerializedName("isodisplaytext") + private String ISODisplayText; + @SerializedName("isoid") + private String ISOId; + @SerializedName("isoname") + private String ISOName; + @SerializedName("jobid") + @Nullable + private String jobId; + @SerializedName("jobstatus") + @Nullable + private String jobStatus; + private long memory; + private String name; + @SerializedName("networkkbsread") + private Long networkKbsRead; + @SerializedName("networkkbswrite") + private Long networkKbsWrite; + @Nullable + private String password; + @SerializedName("passwordenabled") + private boolean passwordEnabled; + @SerializedName("rootdeviceid") + private String rootDeviceId; + @SerializedName("rootdevicetype") + private String rootDeviceType; + @SerializedName("securitygrouplist") + private String securityGroupList; + @SerializedName("serviceofferingid") + private String serviceOfferingId; + @SerializedName("serviceofferingname") + private String serviceOfferingName; + private State state; + @SerializedName("templatedisplaytext") + private String templateDisplayText; + @SerializedName("templateid") + private String templateId; + @SerializedName("templatename") + private String templateName; + @SerializedName("zoneid") + private String zoneId; + @SerializedName("zonename") + private String zoneName; + @SerializedName("nic") + private Set nics = ImmutableSet. of(); + private String hypervisor; + + public VirtualMachine(String id, String account, long cpuCount, long cpuSpeed, long cpuUsed, String displayName, + Date created, String domain, String domainId, boolean usesVirtualNetwork, String group, String groupId, + String guestOSId, boolean hAEnabled, String hostId, String hostname, String iPAddress, String iSODisplayText, + String iSOId, String iSOName, String jobId, String jobStatus, long memory, String name, Long networkKbsRead, + Long networkKbsWrite, String password, boolean passwordEnabled, String rootDeviceId, String rootDeviceType, + Set securityGroupList, String serviceOfferingId, String serviceOfferingName, State state, + String templateDisplayText, String templateId, String templateName, String zoneId, String zoneName, + Set nics, String hypervisor) { + this.id = id; + this.account = account; + this.cpuCount = cpuCount; + this.cpuSpeed = cpuSpeed; + this.cpuUsed = cpuUsed + ""; + this.displayName = displayName; + this.created = created; + this.domain = domain; + this.domainId = domainId; + this.usesVirtualNetwork = usesVirtualNetwork; + this.group = group; + this.groupId = groupId; + this.guestOSId = guestOSId; + this.HAEnabled = hAEnabled; + this.hostId = hostId; + this.hostname = hostname; + this.IPAddress = iPAddress; + this.ISODisplayText = iSODisplayText; + this.ISOId = iSOId; + this.ISOName = iSOName; + this.jobId = jobId; + this.jobStatus = jobStatus; + this.memory = memory; + this.name = name; + this.networkKbsRead = networkKbsRead; + this.networkKbsWrite = networkKbsWrite; + this.password = password; + this.passwordEnabled = passwordEnabled; + this.rootDeviceId = rootDeviceId; + this.rootDeviceType = rootDeviceType; + this.securityGroupList = Joiner.on(',').join(checkNotNull(securityGroupList, "securityGroupList")); + this.serviceOfferingId = serviceOfferingId; + this.serviceOfferingName = serviceOfferingName; + this.state = state; + this.templateDisplayText = templateDisplayText; + this.templateId = templateId; + this.templateName = templateName; + this.zoneId = zoneId; + this.zoneName = zoneName; + this.nics = nics; + this.hypervisor = hypervisor; + } + + /** + * present only for serializer + * + */ + VirtualMachine() { + } + + /** + * @return the ID of the virtual machine + */ + public String getId() { + return id; + } + + /** + * @return the account associated with the virtual machine + */ + public String getAccount() { + return account; + } + + /** + * @return the number of cpu this virtual machine is running with + */ + public long getCpuCount() { + return cpuCount; + } + + /** + * @return the speed of each cpu + */ + public long getCpuSpeed() { + return cpuSpeed; + } + + /** + * @return the amount of the vm's CPU currently used + */ + public float getCpuUsed() { + return cpuUsed != null ? Float.parseFloat(cpuUsed.substring(9, cpuUsed.length() - 1)) : 0.0f; + } + + /** + * @return user generated name. The name of the virtual machine is returned if no displayname + * exists. + */ + public String getDisplayName() { + return displayName; + } + + /** + * @return the date when this virtual machine was created + */ + public Date getCreated() { + return created; + } + + /** + * @return the name of the domain in which the virtual machine exists + */ + public String getDomain() { + return domain; + } + + /** + * @return the ID of the domain in which the virtual machine exists + */ + public String getDomainId() { + return domainId; + } + + /** + * @return the virtual network for the service offering + */ + public boolean isUsesVirtualNetwork() { + return usesVirtualNetwork; + } + + /** + * @return the group name of the virtual machine + */ + public String getGroup() { + return group; + } + + /** + * @return the group ID of the virtual machine + */ + public String getGroupId() { + return groupId; + } + + /** + * @return Os type ID of the virtual machine + */ + public String getGuestOSId() { + return guestOSId; + } + + /** + * @return true if high-availability is enabled, false otherwise + */ + public boolean isHAEnabled() { + return HAEnabled; + } + + /** + * @return the ID of the host for the virtual machine + */ + public String getHostId() { + return hostId; + } + + /** + * @return the name of the host for the virtual machine + */ + public String getHostname() { + return hostname; + } + + /** + * @return the ip address of the virtual machine + */ + public String getIPAddress() { + return IPAddress; + } + + /** + * @return an alternate display text of the ISO attached to the virtual machine + */ + public String getISODisplayText() { + return ISODisplayText; + } + + /** + * @return the ID of the ISO attached to the virtual machine + */ + public String getISOId() { + return ISOId; + } + + /** + * @return the name of the ISO attached to the virtual machine + */ + public String getISOName() { + return ISOName; + } + + /** + * @return shows the current pending asynchronous job ID. This tag is not returned if no current + * pending jobs are acting on the virtual machine + */ + @Nullable + public String getJobId() { + return jobId; + } + + /** + * @return shows the current pending asynchronous job status + */ + @Nullable + public String getJobStatus() { + return jobStatus; + } + + /** + * @return the memory allocated for the virtual machine + */ + public long getMemory() { + return memory; + } + + /** + * @return the name of the virtual machine + */ + public String getName() { + return name; + } + + /** + * @return the incoming network traffic on the vm + */ + public Long getNetworkKbsRead() { + return networkKbsRead; + } + + /** + * @return the outgoing network traffic on the host + */ + public Long getNetworkKbsWrite() { + return networkKbsWrite; + } + + /** + * @return the password (if exists) of the virtual machine + */ + @Nullable + public String getPassword() { + return password; + } + + /** + * @return true if the password rest feature is enabled, false otherwise + */ + public boolean isPasswordEnabled() { + return passwordEnabled; + } + + /** + * @return device ID of the root volume + */ + public String getRootDeviceId() { + return rootDeviceId; + } + + /** + * @return device type of the root volume + */ + public String getRootDeviceType() { + return rootDeviceType; + } + + /** + * @return list of security groups associated with the virtual machine + */ + public Set getSecurityGroupList() { + return securityGroupList == null ? ImmutableSet. of() : ImmutableSet.copyOf(Splitter.on(',').split( + securityGroupList)); + } + + /** + * @return the ID of the service offering of the virtual machine + */ + public String getServiceOfferingId() { + return serviceOfferingId; + } + + /** + * @return the name of the service offering of the virtual machine + */ + public String getServiceOfferingName() { + return serviceOfferingName; + } + + /** + * @return the state of the virtual machine + */ + public State getState() { + return state; + } + + /** + * @return an alternate display text of the template for the virtual machine + */ + public String getTemplateDisplayText() { + return templateDisplayText; + } + + /** + * @return the ID of the template for the virtual machine. A -1 is returned if the virtual + * machine was created from an ISO file. + */ + public String getTemplateId() { + return templateId; + } + + /** + * @return the name of the template for the virtual machine + */ + public String getTemplateName() { + return templateName; + } + + /** + * @return the ID of the availablility zone for the virtual machine + */ + public String getZoneId() { + return zoneId; + } + + /** + * @return the name of the availability zone for the virtual machine + */ + public String getZoneName() { + return zoneName; + } + + /** + * @return the list of nics associated with vm + */ + public Set getNICs() { + return nics; + } + + /** + * @return type of the hypervisor + */ + public String getHypervisor() { + return hypervisor; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (HAEnabled ? 1231 : 1237); + result = prime * result + ((IPAddress == null) ? 0 : IPAddress.hashCode()); + result = prime * result + ((ISODisplayText == null) ? 0 : ISODisplayText.hashCode()); + result = prime * result + ((ISOId == null) ? 0 : ISOId.hashCode()); + result = prime * result + ((ISOName == null) ? 0 : ISOName.hashCode()); + result = prime * result + ((account == null) ? 0 : account.hashCode()); + result = prime * result + (int) (cpuCount ^ (cpuCount >>> 32)); + result = prime * result + (int) (cpuSpeed ^ (cpuSpeed >>> 32)); + result = prime * result + ((cpuUsed == null) ? 0 : cpuUsed.hashCode()); + result = prime * result + ((created == null) ? 0 : created.hashCode()); + result = prime * result + ((displayName == null) ? 0 : displayName.hashCode()); + result = prime * result + ((domain == null) ? 0 : domain.hashCode()); + result = prime * result + ((domainId == null) ? 0 : domainId.hashCode()); + result = prime * result + ((group == null) ? 0 : group.hashCode()); + result = prime * result + ((groupId == null) ? 0 : groupId.hashCode()); + result = prime * result + ((guestOSId == null) ? 0 : guestOSId.hashCode()); + result = prime * result + ((hostId == null) ? 0 : hostId.hashCode()); + result = prime * result + ((hostname == null) ? 0 : hostname.hashCode()); + result = prime * result + ((hypervisor == null) ? 0 : hypervisor.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((jobId == null) ? 0 : jobId.hashCode()); + result = prime * result + ((jobStatus == null) ? 0 : jobStatus.hashCode()); + result = prime * result + (int) (memory ^ (memory >>> 32)); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((networkKbsRead == null) ? 0 : networkKbsRead.hashCode()); + result = prime * result + ((networkKbsWrite == null) ? 0 : networkKbsWrite.hashCode()); + result = prime * result + ((nics == null) ? 0 : nics.hashCode()); + result = prime * result + ((password == null) ? 0 : password.hashCode()); + result = prime * result + (passwordEnabled ? 1231 : 1237); + result = prime * result + ((rootDeviceId == null) ? 0 : rootDeviceId.hashCode()); + result = prime * result + ((rootDeviceType == null) ? 0 : rootDeviceType.hashCode()); + result = prime * result + ((securityGroupList == null) ? 0 : securityGroupList.hashCode()); + result = prime * result + ((serviceOfferingId == null) ? 0 : serviceOfferingId.hashCode()); + result = prime * result + ((serviceOfferingName == null) ? 0 : serviceOfferingName.hashCode()); + result = prime * result + ((state == null) ? 0 : state.hashCode()); + result = prime * result + ((templateDisplayText == null) ? 0 : templateDisplayText.hashCode()); + result = prime * result + ((templateId == null) ? 0 : templateId.hashCode()); + result = prime * result + ((templateName == null) ? 0 : templateName.hashCode()); + result = prime * result + (usesVirtualNetwork ? 1231 : 1237); + result = prime * result + ((zoneId == null) ? 0 : zoneId.hashCode()); + result = prime * result + ((zoneName == null) ? 0 : zoneName.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; + VirtualMachine other = (VirtualMachine) obj; + if (HAEnabled != other.HAEnabled) + return false; + if (IPAddress == null) { + if (other.IPAddress != null) + return false; + } else if (!IPAddress.equals(other.IPAddress)) + return false; + if (ISODisplayText == null) { + if (other.ISODisplayText != null) + return false; + } else if (!ISODisplayText.equals(other.ISODisplayText)) + return false; + if (ISOId == null) { + if (other.ISOId != null) + return false; + } else if (!ISOId.equals(other.ISOId)) + return false; + if (ISOName == null) { + if (other.ISOName != null) + return false; + } else if (!ISOName.equals(other.ISOName)) + return false; + if (account == null) { + if (other.account != null) + return false; + } else if (!account.equals(other.account)) + return false; + if (cpuCount != other.cpuCount) + return false; + if (cpuSpeed != other.cpuSpeed) + return false; + if (cpuUsed == null) { + if (other.cpuUsed != null) + return false; + } else if (!cpuUsed.equals(other.cpuUsed)) + return false; + if (created == null) { + if (other.created != null) + return false; + } else if (!created.equals(other.created)) + return false; + if (displayName == null) { + if (other.displayName != null) + return false; + } else if (!displayName.equals(other.displayName)) + return false; + if (domain == null) { + if (other.domain != null) + return false; + } else if (!domain.equals(other.domain)) + return false; + if (domainId == null) { + if (other.domainId != null) + return false; + } else if (!domainId.equals(other.domainId)) + return false; + if (group == null) { + if (other.group != null) + return false; + } else if (!group.equals(other.group)) + return false; + if (groupId == null) { + if (other.groupId != null) + return false; + } else if (!groupId.equals(other.groupId)) + return false; + if (guestOSId == null) { + if (other.guestOSId != null) + return false; + } else if (!guestOSId.equals(other.guestOSId)) + return false; + if (hostId == null) { + if (other.hostId != null) + return false; + } else if (!hostId.equals(other.hostId)) + return false; + if (hostname == null) { + if (other.hostname != null) + return false; + } else if (!hostname.equals(other.hostname)) + return false; + if (hypervisor == null) { + if (other.hypervisor != null) + return false; + } else if (!hypervisor.equals(other.hypervisor)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (jobId == null) { + if (other.jobId != null) + return false; + } else if (!jobId.equals(other.jobId)) + return false; + if (jobStatus == null) { + if (other.jobStatus != null) + return false; + } else if (!jobStatus.equals(other.jobStatus)) + return false; + if (memory != other.memory) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (networkKbsRead == null) { + if (other.networkKbsRead != null) + return false; + } else if (!networkKbsRead.equals(other.networkKbsRead)) + return false; + if (networkKbsWrite == null) { + if (other.networkKbsWrite != null) + return false; + } else if (!networkKbsWrite.equals(other.networkKbsWrite)) + return false; + if (nics == null) { + if (other.nics != null) + return false; + } else if (!nics.equals(other.nics)) + return false; + if (password == null) { + if (other.password != null) + return false; + } else if (!password.equals(other.password)) + return false; + if (passwordEnabled != other.passwordEnabled) + return false; + if (rootDeviceId == null) { + if (other.rootDeviceId != null) + return false; + } else if (!rootDeviceId.equals(other.rootDeviceId)) + return false; + if (rootDeviceType == null) { + if (other.rootDeviceType != null) + return false; + } else if (!rootDeviceType.equals(other.rootDeviceType)) + return false; + if (securityGroupList == null) { + if (other.securityGroupList != null) + return false; + } else if (!securityGroupList.equals(other.securityGroupList)) + return false; + if (serviceOfferingId == null) { + if (other.serviceOfferingId != null) + return false; + } else if (!serviceOfferingId.equals(other.serviceOfferingId)) + return false; + if (serviceOfferingName == null) { + if (other.serviceOfferingName != null) + return false; + } else if (!serviceOfferingName.equals(other.serviceOfferingName)) + return false; + if (state != other.state) + return false; + if (templateDisplayText == null) { + if (other.templateDisplayText != null) + return false; + } else if (!templateDisplayText.equals(other.templateDisplayText)) + return false; + if (templateId == null) { + if (other.templateId != null) + return false; + } else if (!templateId.equals(other.templateId)) + return false; + if (templateName == null) { + if (other.templateName != null) + return false; + } else if (!templateName.equals(other.templateName)) + return false; + if (usesVirtualNetwork != other.usesVirtualNetwork) + return false; + if (zoneId == null) { + if (other.zoneId != null) + return false; + } else if (!zoneId.equals(other.zoneId)) + return false; + if (zoneName == null) { + if (other.zoneName != null) + return false; + } else if (!zoneName.equals(other.zoneName)) + return false; + return true; + } + + @Override + public String toString() { + return "[id=" + id + ", account=" + account + ", cpuCount=" + cpuCount + ", cpuSpeed=" + cpuSpeed + ", cpuUsed=" + + cpuUsed + ", displayName=" + displayName + ", created=" + created + ", domain=" + domain + ", domainId=" + + domainId + ", usesVirtualNetwork=" + usesVirtualNetwork + ", group=" + group + ", groupId=" + groupId + + ", guestOSId=" + guestOSId + ", HAEnabled=" + HAEnabled + ", hostId=" + hostId + ", hostname=" + hostname + + ", IPAddress=" + IPAddress + ", ISODisplayText=" + ISODisplayText + ", ISOId=" + ISOId + ", ISOName=" + + ISOName + ", jobId=" + jobId + ", jobStatus=" + jobStatus + ", memory=" + memory + ", name=" + name + + ", networkKbsRead=" + networkKbsRead + ", networkKbsWrite=" + networkKbsWrite + ", password=" + password + + ", passwordEnabled=" + passwordEnabled + ", rootDeviceId=" + rootDeviceId + ", rootDeviceType=" + + rootDeviceType + ", securityGroupList=" + securityGroupList + ", serviceOfferingId=" + serviceOfferingId + + ", serviceOfferingName=" + serviceOfferingName + ", state=" + state + ", templateDisplayText=" + + templateDisplayText + ", templateId=" + templateId + ", templateName=" + templateName + ", zoneId=" + + zoneId + ", zoneName=" + zoneName + ", nics=" + nics + ", hypervisor=" + hypervisor + "]"; + } + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java new file mode 100644 index 0000000000..e36fd6d5f4 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineAsyncClient.java @@ -0,0 +1,73 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.VirtualMachine; +import org.jclouds.cloudstack.filters.QuerySigner; +import org.jclouds.cloudstack.options.ListVirtualMachinesOptions; +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. + *

+ * + * @see VirtualMachineClient + * @see + * @author Adrian Cole + */ +@RequestFilters(QuerySigner.class) +@QueryParams(keys = "response", values = "json") +public interface VirtualMachineAsyncClient { + + /** + * @see VirtualMachineClient#listVirtualMachines + */ + @GET + @QueryParams(keys = "command", values = "listVirtualMachines") + @Unwrap(depth = 2) + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) + ListenableFuture> listVirtualMachines(ListVirtualMachinesOptions... options); + + /** + * @see VirtualMachineClient#getVirtualMachine + */ + @GET + @QueryParams(keys = "command", values = "listVirtualMachines") + @Unwrap(depth = 3, edgeCollection = Set.class) + @Consumes(MediaType.APPLICATION_JSON) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVirtualMachine(@QueryParam("id") String id); + +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java new file mode 100644 index 0000000000..76837a3bd6 --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/features/VirtualMachineClient.java @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.VirtualMachine; +import org.jclouds.cloudstack.options.ListVirtualMachinesOptions; +import org.jclouds.concurrent.Timeout; + +/** + * Provides synchronous access to CloudStack VirtualMachine features. + *

+ * + * @see VirtualMachineAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface VirtualMachineClient { + /** + * Lists VirtualMachines + * + * @param options + * if present, how to constrain the list. + * @return VirtualMachines matching query, or empty set, if no VirtualMachines are found + */ + Set listVirtualMachines(ListVirtualMachinesOptions... options); + + /** + * get a specific VirtualMachine by id + * + * @param id + * VirtualMachine to get + * @return VirtualMachine or null if not found + */ + VirtualMachine getVirtualMachine(String id); +} diff --git a/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListVirtualMachinesOptions.java b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListVirtualMachinesOptions.java new file mode 100644 index 0000000000..8b59f0b0ec --- /dev/null +++ b/sandbox-apis/cloudstack/src/main/java/org/jclouds/cloudstack/options/ListVirtualMachinesOptions.java @@ -0,0 +1,235 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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 org.jclouds.http.options.BaseHttpRequestOptions; + +import com.google.common.collect.ImmutableSet; + +/** + * Options used to control what virtual machines information is returned + * + * @see + * @author Adrian Cole + */ +public class ListVirtualMachinesOptions extends BaseHttpRequestOptions { + + public static final ListVirtualMachinesOptions NONE = new ListVirtualMachinesOptions(); + + /** + * @param id + * the ID of the virtual machine + */ + public ListVirtualMachinesOptions id(String id) { + this.queryParameters.replaceValues("id", ImmutableSet.of(id)); + return this; + } + + /** + * @param name + * the virtual machine name + */ + public ListVirtualMachinesOptions name(String name) { + this.queryParameters.replaceValues("name", ImmutableSet.of(name)); + return this; + } + + /** + * @param state + * state of the virtual machine + */ + public ListVirtualMachinesOptions state(String state) { + this.queryParameters.replaceValues("state", ImmutableSet.of(state)); + return this; + } + + /** + * @param domainId + * the ID of the domain associated with the virtual machine + */ + public ListVirtualMachinesOptions domainId(String domainId) { + this.queryParameters.replaceValues("domainid", ImmutableSet.of(domainId)); + return this; + + } + + /** + * + * @param account + * account id + * @param domain + * domain id + */ + public ListVirtualMachinesOptions accountInDomain(String account, String domain) { + this.queryParameters.replaceValues("account", ImmutableSet.of(account)); + return domainId(domain); + } + + /** + * @param groupId + * list virtual machines by groupId. + */ + public ListVirtualMachinesOptions groupId(String groupId) { + this.queryParameters.replaceValues("groupid", ImmutableSet.of(groupId)); + return this; + + } + + /** + * @param hostId + * list virtual machines by hostId. + */ + public ListVirtualMachinesOptions hostId(String hostId) { + this.queryParameters.replaceValues("hostid", ImmutableSet.of(hostId)); + return this; + + } + + /** + * @param networkId + * list virtual machines by networkId. + */ + public ListVirtualMachinesOptions networkId(String networkId) { + this.queryParameters.replaceValues("networkid", ImmutableSet.of(networkId)); + return this; + + } + + /** + * @param podId + * list virtual machines by podId. + */ + public ListVirtualMachinesOptions podId(String podId) { + this.queryParameters.replaceValues("podid", ImmutableSet.of(podId)); + return this; + + } + + /** + * @param zoneId + * list virtual machines by zoneId. + */ + public ListVirtualMachinesOptions zoneId(String zoneId) { + this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId)); + return this; + + } + + /** + * @param usesVirtualNetwork + * list by network type; true if need to list vms using Virtual Network, false + * otherwise + */ + public ListVirtualMachinesOptions usesVirtualNetwork(boolean usesVirtualNetwork) { + this.queryParameters.replaceValues("forvirtualnetwork", ImmutableSet.of(usesVirtualNetwork + "")); + return this; + } + + public static class Builder { + + /** + * @see ListVirtualMachinesOptions#accountInDomain + */ + public static ListVirtualMachinesOptions accountInDomain(String account, String domain) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.accountInDomain(account, domain); + } + + /** + * @see ListVirtualMachinesOptions#domainId + */ + public static ListVirtualMachinesOptions domainId(String id) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.domainId(id); + } + + /** + * @see ListVirtualMachinesOptions#id + */ + public static ListVirtualMachinesOptions id(String id) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.id(id); + } + + /** + * @see ListVirtualMachinesOptions#name + */ + public static ListVirtualMachinesOptions name(String name) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.name(name); + } + + /** + * @see ListVirtualMachinesOptions#state + */ + public static ListVirtualMachinesOptions state(String state) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.state(state); + } + + /** + * @see ListVirtualMachinesOptions#groupId + */ + public static ListVirtualMachinesOptions groupId(String id) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.groupId(id); + } + + /** + * @see ListVirtualMachinesOptions#hostId + */ + public static ListVirtualMachinesOptions hostId(String id) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.hostId(id); + } + + /** + * @see ListVirtualMachinesOptions#networkId + */ + public static ListVirtualMachinesOptions networkId(String id) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.networkId(id); + } + + /** + * @see ListVirtualMachinesOptions#podId + */ + public static ListVirtualMachinesOptions podId(String id) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.podId(id); + } + + /** + * @see ListVirtualMachinesOptions#zoneId + */ + public static ListVirtualMachinesOptions zoneId(String id) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.zoneId(id); + } + + /** + * @see ListVirtualMachinesOptions#usesVirtualNetwork + */ + public static ListVirtualMachinesOptions usesVirtualNetwork(boolean usesVirtualNetwork) { + ListVirtualMachinesOptions options = new ListVirtualMachinesOptions(); + return options.usesVirtualNetwork(usesVirtualNetwork); + } + } +} diff --git a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java index 44a47c488b..8df56c4b96 100644 --- a/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java +++ b/sandbox-apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/TemplateClientLiveTest.java @@ -41,8 +41,8 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest { public void testListTemplates() throws Exception { Set