extensions needed to get snapshots/volumes working (from grkvlt) and tidies

This commit is contained in:
Alex Heneveld 2011-12-02 02:32:04 +00:00
parent 269754c3c9
commit f329db5786
5 changed files with 244 additions and 117 deletions

View File

@ -48,6 +48,18 @@ public class BindTemplateMetadataToQueryParams implements Binder {
request = ModifyRequest.addQueryParam(request, "name", metadata.getName(), uriBuilderProvider.get());
request = ModifyRequest.addQueryParam(request, "ostypeid", metadata.getOsTypeId(), uriBuilderProvider.get());
request = ModifyRequest.addQueryParam(request, "displaytext", metadata.getDisplayText(), uriBuilderProvider.get());
if (metadata.getSnapshotId() != null) {
request = ModifyRequest.addQueryParam(request, "snapshotid", metadata.getSnapshotId(), uriBuilderProvider.get());
}
if (metadata.getVolumeId() != null) {
request = ModifyRequest.addQueryParam(request, "volumeid", metadata.getVolumeId(), uriBuilderProvider.get());
}
if (metadata.getVirtualMachineId() != null) {
request = ModifyRequest.addQueryParam(request, "virtualmachineid", metadata.getVirtualMachineId(), uriBuilderProvider.get());
}
if (metadata.getPasswordEnabled() != null) {
request = ModifyRequest.addQueryParam(request, "passwordenabled", metadata.getPasswordEnabled(), uriBuilderProvider.get());
}
return request;
}
}

View File

@ -18,11 +18,11 @@
*/
package org.jclouds.cloudstack.domain;
import com.google.gson.annotations.SerializedName;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.gson.annotations.SerializedName;
/**
* @author Richard Downer

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.cloudstack.domain;
import com.google.common.base.Objects;
/**
* @author Richard Downer
*/
@ -28,13 +30,17 @@ public class TemplateMetadata {
}
public static class Builder {
private String name;
private long osTypeId;
private String displayText;
private Long snapshotId;
private Long volumeId;
private Long virtualMachineId;
private Boolean passwordEnabled;
/**
* @param name the name of the template
* @param name
* the name of the template
*/
public Builder name(String name) {
this.name = name;
@ -42,7 +48,8 @@ public class TemplateMetadata {
}
/**
* @param osTypeId the ID of the OS Type that best represents the OS of this template.
* @param osTypeId
* the ID of the OS Type that best represents the OS of this template.
*/
public Builder osTypeId(long osTypeId) {
this.osTypeId = osTypeId;
@ -50,15 +57,58 @@ public class TemplateMetadata {
}
/**
* @param displayText the display text of the template. This is usually used for display purposes.
* @param displayText
* the display text of the template. This is usually used for display purposes.
*/
public Builder displayText(String displayText) {
this.displayText = displayText;
return this;
}
/**
* @param snapshotId
* the ID of the snapshot the template is being created from.
* Either this parameter, or volumeId has to be passed in
*/
public Builder snapshotId(Long snapshotId) {
this.snapshotId = snapshotId;
return this;
}
/**
* @param volumeId
* the ID of the disk volume the template is being created from.
* Either this parameter, or snapshotId has to be passed in
*/
public Builder volumeId(Long volumeId) {
this.volumeId = volumeId;
return this;
}
/**
* @param virtualMachineId
* the ID of the disk volume the template is being created from
*/
public Builder virtualMachineId(Long virtualMachineId) {
this.virtualMachineId = virtualMachineId;
return this;
}
/**
* the template supports the password reset feature.
*/
public Builder passwordEnabled() {
this.passwordEnabled = true;
return this;
}
public TemplateMetadata build() {
return new TemplateMetadata(name, osTypeId, displayText);
TemplateMetadata template = new TemplateMetadata(name, osTypeId, displayText);
template.setPasswordEnabled(passwordEnabled);
template.setSnapshotId(snapshotId);
template.setVirtualMachineId(virtualMachineId);
template.setVolumeId(volumeId);
return template;
}
}
@ -66,6 +116,11 @@ public class TemplateMetadata {
private long osTypeId;
private String displayText;
private Long snapshotId;
private Long volumeId;
private Long virtualMachineId;;
private Boolean passwordEnabled;
public TemplateMetadata(String name, long osTypeId, String displayText) {
this.name = name;
this.osTypeId = osTypeId;
@ -78,6 +133,50 @@ public class TemplateMetadata {
TemplateMetadata() {
}
/**
* @return the ID of the snapshot the template is being created from
*/
public Long getSnapshotId() {
return snapshotId;
}
public void setSnapshotId(Long snapshotId) {
this.snapshotId = snapshotId;
}
/**
* @return the ID of the disk volume the template is being created from
*/
public Long getVolumeId() {
return volumeId;
}
public void setVolumeId(Long volumeId) {
this.volumeId = volumeId;
}
/**
* @return Optional, VM ID
*/
public Long getVirtualMachineId() {
return virtualMachineId;
}
public void setVirtualMachineId(Long virtualMachineId) {
this.virtualMachineId = virtualMachineId;
}
/**
* @return true if the template supports the password reset feature; default is false
*/
public Boolean getPasswordEnabled() {
return passwordEnabled;
}
public void setPasswordEnabled(Boolean passwordEnabled) {
this.passwordEnabled = passwordEnabled;
}
/**
* @return the name of the template
*/
@ -101,33 +200,39 @@ public class TemplateMetadata {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
TemplateMetadata that = (TemplateMetadata) o;
if (osTypeId != that.osTypeId) return false;
if (displayText != null ? !displayText.equals(that.displayText) : that.displayText != null) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (osTypeId != that.osTypeId)
return false;
if (snapshotId != null ? !snapshotId.equals(that.snapshotId) : that.snapshotId != null)
return false;
if (volumeId != null ? !volumeId.equals(that.volumeId) : that.volumeId != null)
return false;
if (virtualMachineId != null ? !virtualMachineId.equals(that.virtualMachineId) : that.virtualMachineId != null)
return false;
if (passwordEnabled != null ? !passwordEnabled.equals(that.passwordEnabled) : that.passwordEnabled != null)
return false;
if (displayText != null ? !displayText.equals(that.displayText) : that.displayText != null)
return false;
if (name != null ? !name.equals(that.name) : that.name != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (int) (osTypeId ^ (osTypeId >>> 32));
result = 31 * result + (displayText != null ? displayText.hashCode() : 0);
return result;
return Objects.hashCode(name, displayText, osTypeId, snapshotId, volumeId, passwordEnabled, virtualMachineId);
}
@Override
public String toString() {
return "[" +
"name='" + name + '\'' +
", osTypeId=" + osTypeId +
", displayText='" + displayText + '\'' +
']';
return "[" + "name='" + name + '\'' + ", osTypeId=" + osTypeId + ", displayText='" + displayText + '\'' + ']';
}
}

View File

@ -955,18 +955,23 @@ public class VirtualMachine implements Comparable<VirtualMachine> {
@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 + ", serviceOfferingId=" + serviceOfferingId + ", serviceOfferingName="
+ serviceOfferingName + ", state=" + state + ", templateDisplayText=" + templateDisplayText
+ ", templateId=" + templateId + ", templateName=" + templateName + ", zoneId=" + zoneId + ", zoneName="
+ zoneName + ", nics=" + nics + ", hypervisor=" + hypervisor + ", securityGroups=" + securityGroups + "]";
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 + ", serviceOfferingId=" + serviceOfferingId + ", serviceOfferingName=" + serviceOfferingName
+ ", state=" + state
// + ", templateDisplayText=" + templateDisplayText
// + ", templateId=" + templateId + ", templateName=" + templateName + ", zoneId=" + zoneId + ", zoneName="
// + zoneName + ", nics=" + nics + ", hypervisor=" + hypervisor + ", securityGroups=" + securityGroups
+ "]";
}
@Override

View File

@ -535,6 +535,11 @@ public class Volume implements Comparable<Volume> {
return result;
}
@Override
public String toString() {
return getClass().getCanonicalName()+"["+id+"; "+name+"; "+vmState+"]";
}
public enum VolumeType {
ROOT(0),
DATADISK(1),