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, "name", metadata.getName(), uriBuilderProvider.get());
request = ModifyRequest.addQueryParam(request, "ostypeid", metadata.getOsTypeId(), uriBuilderProvider.get()); request = ModifyRequest.addQueryParam(request, "ostypeid", metadata.getOsTypeId(), uriBuilderProvider.get());
request = ModifyRequest.addQueryParam(request, "displaytext", metadata.getDisplayText(), 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; return request;
} }
} }

View File

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

View File

@ -18,6 +18,8 @@
*/ */
package org.jclouds.cloudstack.domain; package org.jclouds.cloudstack.domain;
import com.google.common.base.Objects;
/** /**
* @author Richard Downer * @author Richard Downer
*/ */
@ -28,13 +30,17 @@ public class TemplateMetadata {
} }
public static class Builder { public static class Builder {
private String name; private String name;
private long osTypeId; private long osTypeId;
private String displayText; 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) { public Builder name(String name) {
this.name = 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) { public Builder osTypeId(long osTypeId) {
this.osTypeId = 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) { public Builder displayText(String displayText) {
this.displayText = displayText; this.displayText = displayText;
return this; 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() { 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 long osTypeId;
private String displayText; private String displayText;
private Long snapshotId;
private Long volumeId;
private Long virtualMachineId;;
private Boolean passwordEnabled;
public TemplateMetadata(String name, long osTypeId, String displayText) { public TemplateMetadata(String name, long osTypeId, String displayText) {
this.name = name; this.name = name;
this.osTypeId = osTypeId; this.osTypeId = osTypeId;
@ -78,6 +133,50 @@ public class TemplateMetadata {
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 * @return the name of the template
*/ */
@ -101,33 +200,39 @@ public class TemplateMetadata {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o)
if (o == null || getClass() != o.getClass()) return false; return true;
if (o == null || getClass() != o.getClass())
return false;
TemplateMetadata that = (TemplateMetadata) o; TemplateMetadata that = (TemplateMetadata) o;
if (osTypeId != that.osTypeId) return false; if (osTypeId != that.osTypeId)
if (displayText != null ? !displayText.equals(that.displayText) : that.displayText != null) return false; return false;
if (name != null ? !name.equals(that.name) : that.name != null) 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; return true;
} }
@Override @Override
public int hashCode() { public int hashCode() {
int result = name != null ? name.hashCode() : 0; return Objects.hashCode(name, displayText, osTypeId, snapshotId, volumeId, passwordEnabled, virtualMachineId);
result = 31 * result + (int) (osTypeId ^ (osTypeId >>> 32));
result = 31 * result + (displayText != null ? displayText.hashCode() : 0);
return result;
} }
@Override @Override
public String toString() { public String toString() {
return "[" + return "[" + "name='" + name + '\'' + ", osTypeId=" + osTypeId + ", displayText='" + displayText + '\'' + ']';
"name='" + name + '\'' +
", osTypeId=" + osTypeId +
", displayText='" + displayText + '\'' +
']';
} }
} }

View File

@ -955,18 +955,23 @@ public class VirtualMachine implements Comparable<VirtualMachine> {
@Override @Override
public String toString() { public String toString() {
return "[id=" + id + ", account=" + account + ", cpuCount=" + cpuCount + ", cpuSpeed=" + cpuSpeed + ", cpuUsed=" return "[id=" + id
+ cpuUsed + ", displayName=" + displayName + ", created=" + created + ", domain=" + domain + ", domainId=" // + ", account=" + account + ", cpuCount=" + cpuCount + ", cpuSpeed=" + cpuSpeed + ", cpuUsed=" + cpuUsed
+ domainId + ", usesVirtualNetwork=" + usesVirtualNetwork + ", group=" + group + ", groupId=" + groupId + ", displayName=" + displayName + ", created=" + created
+ ", guestOSId=" + guestOSId + ", HAEnabled=" + HAEnabled + ", hostId=" + hostId + ", hostname=" + hostname // + ", domain=" + domain + ", domainId="
+ ", IPAddress=" + IPAddress + ", ISODisplayText=" + ISODisplayText + ", ISOId=" + ISOId + ", ISOName=" // + domainId + ", usesVirtualNetwork=" + usesVirtualNetwork + ", group=" + group + ", groupId=" + groupId
+ ISOName + ", jobId=" + jobId + ", jobStatus=" + jobStatus + ", memory=" + memory + ", name=" + name // + ", guestOSId=" + guestOSId + ", HAEnabled=" + HAEnabled + ", hostId=" + hostId + ", hostname=" + hostname
+ ", networkKbsRead=" + networkKbsRead + ", networkKbsWrite=" + networkKbsWrite + ", password=" + password + ", IPAddress=" + IPAddress
+ ", passwordEnabled=" + passwordEnabled + ", rootDeviceId=" + rootDeviceId + ", rootDeviceType=" // + ", ISODisplayText=" + ISODisplayText + ", ISOId=" + ISOId + ", ISOName="
+ rootDeviceType + ", serviceOfferingId=" + serviceOfferingId + ", serviceOfferingName=" // + ISOName + ", jobId=" + jobId + ", jobStatus=" + jobStatus + ", memory=" + memory + ", name=" + name
+ serviceOfferingName + ", state=" + state + ", templateDisplayText=" + templateDisplayText // + ", networkKbsRead=" + networkKbsRead + ", networkKbsWrite=" + networkKbsWrite + ", password=" + password
+ ", templateId=" + templateId + ", templateName=" + templateName + ", zoneId=" + zoneId + ", zoneName=" // + ", passwordEnabled=" + passwordEnabled + ", rootDeviceId=" + rootDeviceId + ", rootDeviceType="
+ zoneName + ", nics=" + nics + ", hypervisor=" + hypervisor + ", securityGroups=" + securityGroups + "]"; // + rootDeviceType + ", serviceOfferingId=" + serviceOfferingId + ", serviceOfferingName=" + serviceOfferingName
+ ", state=" + state
// + ", templateDisplayText=" + templateDisplayText
// + ", templateId=" + templateId + ", templateName=" + templateName + ", zoneId=" + zoneId + ", zoneName="
// + zoneName + ", nics=" + nics + ", hypervisor=" + hypervisor + ", securityGroups=" + securityGroups
+ "]";
} }
@Override @Override

View File

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