Merge pull request #134 from richardcloudsoft/cloudstack-iso

Cloudstack ISO API
This commit is contained in:
Adrian Cole 2011-11-11 00:47:51 -08:00
commit 1ed16c7166
22 changed files with 2729 additions and 25 deletions

View File

@ -26,6 +26,7 @@ import org.jclouds.cloudstack.features.EventAsyncClient;
import org.jclouds.cloudstack.features.FirewallAsyncClient; import org.jclouds.cloudstack.features.FirewallAsyncClient;
import org.jclouds.cloudstack.features.GuestOSAsyncClient; import org.jclouds.cloudstack.features.GuestOSAsyncClient;
import org.jclouds.cloudstack.features.HypervisorAsyncClient; import org.jclouds.cloudstack.features.HypervisorAsyncClient;
import org.jclouds.cloudstack.features.ISOAsyncClient;
import org.jclouds.cloudstack.features.LimitAsyncClient; import org.jclouds.cloudstack.features.LimitAsyncClient;
import org.jclouds.cloudstack.features.LoadBalancerAsyncClient; import org.jclouds.cloudstack.features.LoadBalancerAsyncClient;
import org.jclouds.cloudstack.features.NATAsyncClient; import org.jclouds.cloudstack.features.NATAsyncClient;
@ -164,4 +165,9 @@ public interface CloudStackAsyncClient {
@Delegate @Delegate
LimitAsyncClient getLimitClient(); LimitAsyncClient getLimitClient();
/**
* Provides asynchronous access to ISOs
*/
@Delegate
ISOAsyncClient getISOClient();
} }

View File

@ -28,6 +28,7 @@ import org.jclouds.cloudstack.features.EventClient;
import org.jclouds.cloudstack.features.FirewallClient; import org.jclouds.cloudstack.features.FirewallClient;
import org.jclouds.cloudstack.features.GuestOSClient; import org.jclouds.cloudstack.features.GuestOSClient;
import org.jclouds.cloudstack.features.HypervisorClient; import org.jclouds.cloudstack.features.HypervisorClient;
import org.jclouds.cloudstack.features.ISOClient;
import org.jclouds.cloudstack.features.LimitClient; import org.jclouds.cloudstack.features.LimitClient;
import org.jclouds.cloudstack.features.LoadBalancerClient; import org.jclouds.cloudstack.features.LoadBalancerClient;
import org.jclouds.cloudstack.features.NATClient; import org.jclouds.cloudstack.features.NATClient;
@ -167,4 +168,9 @@ public interface CloudStackClient {
@Delegate @Delegate
LimitClient getLimitClient(); LimitClient getLimitClient();
/**
* Provides synchronous access to ISOs
*/
@Delegate
ISOClient getISOClient();
} }

View File

@ -39,6 +39,8 @@ import org.jclouds.cloudstack.features.GuestOSAsyncClient;
import org.jclouds.cloudstack.features.GuestOSClient; import org.jclouds.cloudstack.features.GuestOSClient;
import org.jclouds.cloudstack.features.HypervisorAsyncClient; import org.jclouds.cloudstack.features.HypervisorAsyncClient;
import org.jclouds.cloudstack.features.HypervisorClient; import org.jclouds.cloudstack.features.HypervisorClient;
import org.jclouds.cloudstack.features.ISOAsyncClient;
import org.jclouds.cloudstack.features.ISOClient;
import org.jclouds.cloudstack.features.LimitAsyncClient; import org.jclouds.cloudstack.features.LimitAsyncClient;
import org.jclouds.cloudstack.features.LimitClient; import org.jclouds.cloudstack.features.LimitClient;
import org.jclouds.cloudstack.features.LoadBalancerAsyncClient; import org.jclouds.cloudstack.features.LoadBalancerAsyncClient;
@ -101,6 +103,7 @@ public class CloudStackRestClientModule extends RestClientModule<CloudStackClien
.put(LimitClient.class, LimitAsyncClient.class)// .put(LimitClient.class, LimitAsyncClient.class)//
.put(SSHKeyPairClient.class, SSHKeyPairAsyncClient.class)// .put(SSHKeyPairClient.class, SSHKeyPairAsyncClient.class)//
.put(VMGroupClient.class, VMGroupAsyncClient.class)// .put(VMGroupClient.class, VMGroupAsyncClient.class)//
.put(ISOClient.class, ISOAsyncClient.class)//
.build(); .build();
public CloudStackRestClientModule() { public CloudStackRestClientModule() {

View File

@ -0,0 +1,37 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Richard Downer
*/
public enum ExtractMode {
HTTP_DOWNLOAD, FTP_UPLOAD, UNRECOGNIZED;
public static ExtractMode fromValue(String format) {
try {
return valueOf(checkNotNull(format, "format"));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -0,0 +1,747 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.domain;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Richard Downer
*/
public class ISO implements Comparable<ISO> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String account;
private long accountId;
private boolean bootable;
private String checksum;
private Date created;
private boolean crossZones;
private String displayText;
private String domain;
private long domainid;
private String format;
private long hostId;
private String hostName;
private String hypervisor;
private boolean isExtractable;
private boolean isFeatured;
private boolean isPublic;
private boolean isReady;
private long jobId;
private String jobStatus;
private String name;
private long osTypeId;
private String osTypeName;
private boolean passwordEnabled;
private Date removed;
private long size;
private long sourceTemplateId;
private String status;
private String templateTag;
private String templateType;
private long zoneId;
private String zoneName;
/**
* @param id the template ID
*/
public Builder id(long id) {
this.id = id;
return this;
}
/**
* @param account the account name to which the template belongs
*/
public Builder account(String account) {
this.account = account;
return this;
}
/**
* @param accountId the account id to which the template belongs
*/
public Builder accountId(long accountId) {
this.accountId = accountId;
return this;
}
/**
* @param bootable true if the ISO is bootable, false otherwise
*/
public Builder bootable(boolean bootable) {
this.bootable = bootable;
return this;
}
/**
* @param checksum checksum of the template
*/
public Builder checksum(String checksum) {
this.checksum = checksum;
return this;
}
/**
* @param created the date this template was created
*/
public Builder created(Date created) {
this.created = created;
return this;
}
/**
* @param crossZones true if the template is managed across all Zones, false otherwise
*/
public Builder crossZones(boolean crossZones) {
this.crossZones = crossZones;
return this;
}
/**
* @param displayText the template display text
*/
public Builder displayText(String displayText) {
this.displayText = displayText;
return this;
}
/**
* @param domain the name of the domain to which the template belongs
*/
public Builder domain(String domain) {
this.domain = domain;
return this;
}
/**
* @param domainid the ID of the domain to which the template belongs
*/
public Builder domainid(long domainid) {
this.domainid = domainid;
return this;
}
/**
* @param format the format of the template.
*/
public Builder format(String format) {
this.format = format;
return this;
}
/**
* @param hostId the ID of the secondary storage host for the template
*/
public Builder hostId(long hostId) {
this.hostId = hostId;
return this;
}
/**
* @param hostName the name of the secondary storage host for the template
*/
public Builder hostName(String hostName) {
this.hostName = hostName;
return this;
}
/**
* @param hypervisor the hypervisor on which the template runs
*/
public Builder hypervisor(String hypervisor) {
this.hypervisor = hypervisor;
return this;
}
/**
* @param isExtractable true if the template is extractable, false otherwise
*/
public Builder isExtractable(boolean isExtractable) {
this.isExtractable = isExtractable;
return this;
}
/**
* @param isFeatured true if this template is a featured template, false otherwise
*/
public Builder isFeatured(boolean isFeatured) {
this.isFeatured = isFeatured;
return this;
}
/**
* @param isPublic true if this template is a public template, false otherwise
*/
public Builder isPublic(boolean isPublic) {
this.isPublic = isPublic;
return this;
}
/**
* @param isReady true if the template is ready to be deployed from, false otherwise.
*/
public Builder isReady(boolean isReady) {
this.isReady = isReady;
return this;
}
/**
* @param jobId shows the current pending asynchronous job ID. This tag is not returned if no current pending jobs are acting on the template
*/
public Builder jobId(long jobId) {
this.jobId = jobId;
return this;
}
/**
* @param jobStatus shows the current pending asynchronous job status
*/
public Builder jobStatus(String jobStatus) {
this.jobStatus = jobStatus;
return this;
}
/**
* @param name the template name
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @param osTypeId the ID of the OS type for this template.
*/
public Builder osTypeId(long osTypeId) {
this.osTypeId = osTypeId;
return this;
}
/**
* @param osTypeName the name of the OS type for this template.
*/
public Builder osTypeName(String osTypeName) {
this.osTypeName = osTypeName;
return this;
}
/**
* @param passwordEnabled true if the reset password feature is enabled, false otherwise
*/
public Builder passwordEnabled(boolean passwordEnabled) {
this.passwordEnabled = passwordEnabled;
return this;
}
/**
* @param removed the date this template was removed
*/
public Builder removed(Date removed) {
this.removed = removed;
return this;
}
/**
* @param size the size of the template
*/
public Builder size(long size) {
this.size = size;
return this;
}
/**
* @param sourceTemplateId the template ID of the parent template if present
*/
public Builder sourceTemplateId(long sourceTemplateId) {
this.sourceTemplateId = sourceTemplateId;
return this;
}
/**
* @param status the status of the template
*/
public Builder status(String status) {
this.status = status;
return this;
}
/**
* @param templateTag the tag of this template
*/
public Builder templateTag(String templateTag) {
this.templateTag = templateTag;
return this;
}
/**
* @param templateType the type of the template
*/
public Builder templateType(String templateType) {
this.templateType = templateType;
return this;
}
/**
* @param zoneId the ID of the zone for this template
*/
public Builder zoneId(long zoneId) {
this.zoneId = zoneId;
return this;
}
/**
* @param zoneName the name of the zone for this template
*/
public Builder zoneName(String zoneName) {
this.zoneName = zoneName;
return this;
}
}
private long id;
private String account;
@SerializedName("accountid")
private long accountId;
private boolean bootable;
private String checksum;
private Date created;
private boolean crossZones;
@SerializedName("displaytext")
private String displayText;
private String domain;
@SerializedName("domainId")
private long domainid;
private String format;
@SerializedName("hostid")
private long hostId;
@SerializedName("hostname")
private String hostName;
@SerializedName("")
private String hypervisor;
@SerializedName("isextractable")
private boolean isExtractable;
@SerializedName("isfeatured")
private boolean isFeatured;
@SerializedName("ispublic")
private boolean isPublic;
@SerializedName("isready")
private boolean isReady;
@SerializedName("jobid")
private long jobId;
@SerializedName("jobstatus")
private String jobStatus;
private String name;
@SerializedName("ostypeid")
private long osTypeId;
@SerializedName("ostypename")
private String osTypeName;
@SerializedName("passwordenabled")
private boolean passwordEnabled;
private Date removed;
private long size;
@SerializedName("sourcetemplateid")
private long sourceTemplateId;
private String status;
@SerializedName("templatetag")
private String templateTag;
@SerializedName("templatetype")
private String templateType;
@SerializedName("zoneid")
private long zoneId;
@SerializedName("zonename")
private String zoneName;
/**
* present only for serializer
*/
ISO() {
}
/**
* @return the template ID
*/
public long getId() {
return id;
}
/**
* @return the account name to which the template belongs
*/
public String getAccount() {
return account;
}
/**
* @return the account id to which the template belongs
*/
public long getAccountId() {
return accountId;
}
/**
* @return true if the ISO is bootable, false otherwise
*/
public boolean getBootable() {
return bootable;
}
/**
* @return checksum of the template
*/
public String getChecksum() {
return checksum;
}
/**
* @return the date this template was created
*/
public Date getCreated() {
return created;
}
/**
* @return true if the template is managed across all Zones, false otherwise
*/
public boolean getCrossZones() {
return crossZones;
}
/**
* @return the template display text
*/
public String getDisplayText() {
return displayText;
}
/**
* @return the name of the domain to which the template belongs
*/
public String getDomain() {
return domain;
}
/**
* @return the ID of the domain to which the template belongs
*/
public long getDomainid() {
return domainid;
}
/**
* @return the format of the template.
*/
public String getFormat() {
return format;
}
/**
* @return the ID of the secondary storage host for the template
*/
public long getHostId() {
return hostId;
}
/**
* @return the name of the secondary storage host for the template
*/
public String getHostName() {
return hostName;
}
/**
* @return the hypervisor on which the template runs
*/
public String getHypervisor() {
return hypervisor;
}
/**
* @return true if the template is extractable, false otherwise
*/
public boolean getIsExtractable() {
return isExtractable;
}
/**
* @return true if this template is a featured template, false otherwise
*/
public boolean getIsFeatured() {
return isFeatured;
}
/**
* @return true if this template is a public template, false otherwise
*/
public boolean getIsPublic() {
return isPublic;
}
/**
* @return true if the template is ready to be deployed from, false otherwise.
*/
public boolean getIsReady() {
return isReady;
}
/**
* @return shows the current pending asynchronous job ID. This tag is not returned if no current pending jobs are acting on the template
*/
public long getJobId() {
return jobId;
}
/**
* @return shows the current pending asynchronous job status
*/
public String getJobStatus() {
return jobStatus;
}
/**
* @return the template name
*/
public String getName() {
return name;
}
/**
* @return the ID of the OS type for this template.
*/
public long getOsTypeId() {
return osTypeId;
}
/**
* @return the name of the OS type for this template.
*/
public String getOsTypeName() {
return osTypeName;
}
/**
* @return true if the reset password feature is enabled, false otherwise
*/
public boolean getPasswordEnabled() {
return passwordEnabled;
}
/**
* @return the date this template was removed
*/
public Date getRemoved() {
return removed;
}
/**
* @return the size of the template
*/
public long getSize() {
return size;
}
/**
* @return the template ID of the parent template if present
*/
public long getSourceTemplateId() {
return sourceTemplateId;
}
/**
* @return the status of the template
*/
public String getStatus() {
return status;
}
/**
* @return the tag of this template
*/
public String getTemplateTag() {
return templateTag;
}
/**
* @return the type of the template
*/
public String getTemplateType() {
return templateType;
}
/**
* @return the ID of the zone for this template
*/
public long getZoneId() {
return zoneId;
}
/**
* @return the name of the zone for this template
*/
public String getZoneName() {
return zoneName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ISO iso = (ISO) o;
if (accountId != iso.accountId) return false;
if (bootable != iso.bootable) return false;
if (crossZones != iso.crossZones) return false;
if (domainid != iso.domainid) return false;
if (hostId != iso.hostId) return false;
if (id != iso.id) return false;
if (isExtractable != iso.isExtractable) return false;
if (isFeatured != iso.isFeatured) return false;
if (isPublic != iso.isPublic) return false;
if (isReady != iso.isReady) return false;
if (jobId != iso.jobId) return false;
if (osTypeId != iso.osTypeId) return false;
if (passwordEnabled != iso.passwordEnabled) return false;
if (size != iso.size) return false;
if (sourceTemplateId != iso.sourceTemplateId) return false;
if (zoneId != iso.zoneId) return false;
if (account != null ? !account.equals(iso.account) : iso.account != null) return false;
if (checksum != null ? !checksum.equals(iso.checksum) : iso.checksum != null) return false;
if (created != null ? !created.equals(iso.created) : iso.created != null) return false;
if (displayText != null ? !displayText.equals(iso.displayText) : iso.displayText != null) return false;
if (domain != null ? !domain.equals(iso.domain) : iso.domain != null) return false;
if (format != null ? !format.equals(iso.format) : iso.format != null) return false;
if (hostName != null ? !hostName.equals(iso.hostName) : iso.hostName != null) return false;
if (hypervisor != null ? !hypervisor.equals(iso.hypervisor) : iso.hypervisor != null) return false;
if (jobStatus != null ? !jobStatus.equals(iso.jobStatus) : iso.jobStatus != null) return false;
if (name != null ? !name.equals(iso.name) : iso.name != null) return false;
if (osTypeName != null ? !osTypeName.equals(iso.osTypeName) : iso.osTypeName != null) return false;
if (removed != null ? !removed.equals(iso.removed) : iso.removed != null) return false;
if (status != null ? !status.equals(iso.status) : iso.status != null) return false;
if (templateTag != null ? !templateTag.equals(iso.templateTag) : iso.templateTag != null) return false;
if (templateType != null ? !templateType.equals(iso.templateType) : iso.templateType != null) return false;
if (zoneName != null ? !zoneName.equals(iso.zoneName) : iso.zoneName != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (account != null ? account.hashCode() : 0);
result = 31 * result + (int) (accountId ^ (accountId >>> 32));
result = 31 * result + (bootable ? 1 : 0);
result = 31 * result + (checksum != null ? checksum.hashCode() : 0);
result = 31 * result + (created != null ? created.hashCode() : 0);
result = 31 * result + (crossZones ? 1 : 0);
result = 31 * result + (displayText != null ? displayText.hashCode() : 0);
result = 31 * result + (domain != null ? domain.hashCode() : 0);
result = 31 * result + (int) (domainid ^ (domainid >>> 32));
result = 31 * result + (format != null ? format.hashCode() : 0);
result = 31 * result + (int) (hostId ^ (hostId >>> 32));
result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
result = 31 * result + (hypervisor != null ? hypervisor.hashCode() : 0);
result = 31 * result + (isExtractable ? 1 : 0);
result = 31 * result + (isFeatured ? 1 : 0);
result = 31 * result + (isPublic ? 1 : 0);
result = 31 * result + (isReady ? 1 : 0);
result = 31 * result + (int) (jobId ^ (jobId >>> 32));
result = 31 * result + (jobStatus != null ? jobStatus.hashCode() : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (int) (osTypeId ^ (osTypeId >>> 32));
result = 31 * result + (osTypeName != null ? osTypeName.hashCode() : 0);
result = 31 * result + (passwordEnabled ? 1 : 0);
result = 31 * result + (removed != null ? removed.hashCode() : 0);
result = 31 * result + (int) (size ^ (size >>> 32));
result = 31 * result + (int) (sourceTemplateId ^ (sourceTemplateId >>> 32));
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + (templateTag != null ? templateTag.hashCode() : 0);
result = 31 * result + (templateType != null ? templateType.hashCode() : 0);
result = 31 * result + (int) (zoneId ^ (zoneId >>> 32));
result = 31 * result + (zoneName != null ? zoneName.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[" +
"id=" + id +
", account='" + account + '\'' +
", accountId=" + accountId +
", bootable=" + bootable +
", checksum='" + checksum + '\'' +
", created=" + created +
", crossZones=" + crossZones +
", displayText='" + displayText + '\'' +
", domain='" + domain + '\'' +
", domainid=" + domainid +
", format='" + format + '\'' +
", hostId=" + hostId +
", hostName='" + hostName + '\'' +
", hypervisor='" + hypervisor + '\'' +
", isExtractable=" + isExtractable +
", isFeatured=" + isFeatured +
", isPublic=" + isPublic +
", isReady=" + isReady +
", jobId=" + jobId +
", jobStatus='" + jobStatus + '\'' +
", name='" + name + '\'' +
", osTypeId=" + osTypeId +
", osTypeName='" + osTypeName + '\'' +
", passwordEnabled=" + passwordEnabled +
", removed=" + removed +
", size=" + size +
", sourceTemplateId=" + sourceTemplateId +
", status='" + status + '\'' +
", templateTag='" + templateTag + '\'' +
", templateType='" + templateType + '\'' +
", zoneId=" + zoneId +
", zoneName='" + zoneName + '\'' +
']';
}
@Override
public int compareTo(ISO other) {
return new Long(id).compareTo(other.getId());
}
public enum ISOFilter {
featured, self, self_executable, executable, community, UNRECOGNIZED;
public static ISOFilter fromValue(String format) {
try {
return valueOf(checkNotNull(format, "format"));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
}

View File

@ -0,0 +1,338 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.domain;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
/**
* @author Richard Downer
*/
public class ISOExtraction implements Comparable<ISOExtraction> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private long accountId;
private Date created;
private long extractId;
private ExtractMode extractMode;
private String name;
private String state;
private String status;
private String storageType;
private int uploadPercentage;
private String url;
private long zoneId;
private String zoneName;
/**
* @param id the id of extracted object
*/
public Builder id(long id) {
this.id = id;
return this;
}
/**
* @param accountId the account id to which the extracted object belongs
*/
public Builder accountId(long accountId) {
this.accountId = accountId;
return this;
}
/**
* @param created the time and date the object was created
*/
public Builder created(Date created) {
this.created = created;
return this;
}
/**
* @param extractId the upload id of extracted object
*/
public Builder extractId(long extractId) {
this.extractId = extractId;
return this;
}
/**
* @param extractMode the mode of extraction - upload or download
*/
public Builder extractMode(ExtractMode extractMode) {
this.extractMode = extractMode;
return this;
}
/**
* @param name the name of the extracted object
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @param state the state of the extracted object
*/
public Builder state(String state) {
this.state = state;
return this;
}
/**
* @param status the status of the extraction
*/
public Builder status(String status) {
this.status = status;
return this;
}
/**
* @param storageType type of the storage
*/
public Builder storageType(String storageType) {
this.storageType = storageType;
return this;
}
/**
* @param uploadPercentage the percentage of the entity uploaded to the specified location
*/
public Builder uploadPercentage(int uploadPercentage) {
this.uploadPercentage = uploadPercentage;
return this;
}
/**
* @param url if mode = upload then url of the uploaded entity. if mode = download the url from which the entity can be downloaded
*/
public Builder url(String url) {
this.url = url;
return this;
}
/**
* @param zoneId zone ID the object was extracted from
*/
public Builder zoneId(long zoneId) {
this.zoneId = zoneId;
return this;
}
/**
* @param zoneName zone name the object was extracted from
*/
public Builder zoneName(String zoneName) {
this.zoneName = zoneName;
return this;
}
}
private long id;
@SerializedName("accountid")
private long accountId;
private Date created;
private long extractId;
private ExtractMode extractMode;
private String name;
private String state;
private String status;
@SerializedName("storagetype")
private String storageType;
@SerializedName("uploadpercentage")
private int uploadPercentage;
private String url;
@SerializedName("zoneid")
private long zoneId;
@SerializedName("zonename")
private String zoneName;
/**
* present only for serializer
*/
ISOExtraction() {
}
/**
* @return the id of extracted object
*/
public long getId() {
return id;
}
/**
* @return the account id to which the extracted object belongs
*/
public long getAccountId() {
return accountId;
}
/**
* @return the time and date the object was created
*/
public Date getCreated() {
return created;
}
/**
* @return the upload id of extracted object
*/
public long getExtractId() {
return extractId;
}
/**
* @return the mode of extraction - upload or download
*/
public ExtractMode getExtractMode() {
return extractMode;
}
/**
* @return the name of the extracted object
*/
public String getName() {
return name;
}
/**
* @return the state of the extracted object
*/
public String getState() {
return state;
}
/**
* @return the status of the extraction
*/
public String getStatus() {
return status;
}
/**
* @return type of the storage
*/
public String getStorageType() {
return storageType;
}
/**
* @return the percentage of the entity uploaded to the specified location
*/
public int getUploadPercentage() {
return uploadPercentage;
}
/**
* @return if mode = upload then url of the uploaded entity. if mode = download the url from which the entity can be downloaded
*/
public String getUrl() {
return url;
}
/**
* @return zone ID the object was extracted from
*/
public long getZoneId() {
return zoneId;
}
/**
* @return zone name the object was extracted from
*/
public String getZoneName() {
return zoneName;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ISOExtraction that = (ISOExtraction) o;
if (accountId != that.accountId) return false;
if (extractId != that.extractId) return false;
if (id != that.id) return false;
if (uploadPercentage != that.uploadPercentage) return false;
if (zoneId != that.zoneId) return false;
if (created != null ? !created.equals(that.created) : that.created != null) return false;
if (extractMode != that.extractMode) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (state != null ? !state.equals(that.state) : that.state != null) return false;
if (status != null ? !status.equals(that.status) : that.status != null) return false;
if (storageType != null ? !storageType.equals(that.storageType) : that.storageType != null) return false;
if (url != null ? !url.equals(that.url) : that.url != null) return false;
if (zoneName != null ? !zoneName.equals(that.zoneName) : that.zoneName != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (int) (accountId ^ (accountId >>> 32));
result = 31 * result + (created != null ? created.hashCode() : 0);
result = 31 * result + (int) (extractId ^ (extractId >>> 32));
result = 31 * result + (extractMode != null ? extractMode.hashCode() : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (state != null ? state.hashCode() : 0);
result = 31 * result + (status != null ? status.hashCode() : 0);
result = 31 * result + (storageType != null ? storageType.hashCode() : 0);
result = 31 * result + uploadPercentage;
result = 31 * result + (url != null ? url.hashCode() : 0);
result = 31 * result + (int) (zoneId ^ (zoneId >>> 32));
result = 31 * result + (zoneName != null ? zoneName.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[" +
"id=" + id +
", accountId=" + accountId +
", created=" + created +
", extractId=" + extractId +
", extractMode=" + extractMode +
", name='" + name + '\'' +
", state='" + state + '\'' +
", status='" + status + '\'' +
", storageType='" + storageType + '\'' +
", uploadPercentage=" + uploadPercentage +
", url='" + url + '\'' +
", zoneId=" + zoneId +
", zoneName='" + zoneName + '\'' +
']';
}
@Override
public int compareTo(ISOExtraction other) {
return new Long(id).compareTo(other.getId());
}
}

View File

@ -0,0 +1,153 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.domain;
import com.google.gson.annotations.SerializedName;
/**
* @author Richard Downer
*/
public class ISOPermissions implements Comparable<ISOPermissions> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private long id;
private String account;
private long domainId;
private boolean isPublic;
/**
* @param id the template ID
*/
public Builder id(long id) {
this.id = id;
return this;
}
/**
* @param account the list of accounts the template is available for
*/
public Builder account(String account) {
this.account = account;
return this;
}
/**
* @param domainId the ID of the domain to which the template belongs
*/
public Builder domainId(long domainId) {
this.domainId = domainId;
return this;
}
/**
* @param isPublic true if this template is a public template, false otherwise
*/
public Builder isPublic(boolean isPublic) {
this.isPublic = isPublic;
return this;
}
}
private long id;
private String account;
@SerializedName("domainid")
private long domainId;
@SerializedName("ispublic")
private boolean isPublic;
/**
* present only for serializer
*/
ISOPermissions() {
}
/**
* @return the template ID
*/
public long getId() {
return id;
}
/**
* @return the list of accounts the template is available for
*/
public String getAccount() {
return account;
}
/**
* @return the ID of the domain to which the template belongs
*/
public long getDomainId() {
return domainId;
}
/**
* @return true if this template is a public template, false otherwise
*/
public boolean getIsPublic() {
return isPublic;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ISOPermissions that = (ISOPermissions) o;
if (domainId != that.domainId) return false;
if (id != that.id) return false;
if (isPublic != that.isPublic) return false;
if (account != null ? !account.equals(that.account) : that.account != null) return false;
return true;
}
@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + (account != null ? account.hashCode() : 0);
result = 31 * result + (int) (domainId ^ (domainId >>> 32));
result = 31 * result + (isPublic ? 1 : 0);
return result;
}
@Override
public String toString() {
return "[" +
"id=" + id +
", account='" + account + '\'' +
", domainId=" + domainId +
", isPublic=" + isPublic +
']';
}
@Override
public int compareTo(ISOPermissions other) {
return new Long(id).compareTo(other.getId());
}
}

View File

@ -0,0 +1,37 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.domain;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Richard Downer
*/
public enum PermissionOperation {
add, remove, reset, UNRECOGNIZED;
public static PermissionOperation fromValue(String format) {
try {
return valueOf(checkNotNull(format, "format"));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}

View File

@ -148,22 +148,47 @@ public class SnapshotPolicy implements Comparable<SnapshotPolicy> {
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
throw new RuntimeException("FIXME: Implement me"); if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SnapshotPolicy that = (SnapshotPolicy) o;
if (id != that.id) return false;
if (numberToRetain != that.numberToRetain) return false;
if (volumeId != that.volumeId) return false;
if (interval != that.interval) return false;
if (schedule != null ? !schedule.equals(that.schedule) : that.schedule != null) return false;
if (timezone != null ? !timezone.equals(that.timezone) : that.timezone != null) return false;
return true;
} }
@Override @Override
public int hashCode() { public int hashCode() {
throw new RuntimeException("FIXME: Implement me"); int result = (int) (id ^ (id >>> 32));
result = 31 * result + (interval != null ? interval.hashCode() : 0);
result = 31 * result + (int) (numberToRetain ^ (numberToRetain >>> 32));
result = 31 * result + (schedule != null ? schedule.hashCode() : 0);
result = 31 * result + (timezone != null ? timezone.hashCode() : 0);
result = 31 * result + (int) (volumeId ^ (volumeId >>> 32));
return result;
} }
@Override @Override
public String toString() { public String toString() {
throw new RuntimeException("FIXME: Implement me"); return "[" +
"id=" + id +
", interval=" + interval +
", numberToRetain=" + numberToRetain +
", schedule='" + schedule + '\'' +
", timezone='" + timezone + '\'' +
", volumeId=" + volumeId +
']';
} }
@Override @Override
public int compareTo(SnapshotPolicy other) { public int compareTo(SnapshotPolicy other) {
throw new RuntimeException("FIXME: Implement me"); return new Long(id).compareTo(other.getId());
} }
} }

View File

@ -233,19 +233,6 @@ public class Template implements Comparable<Template> {
} }
} }
public enum ExtractMode {
HTTP_DOWNLOAD, FTP_UPLOAD, UNRECOGNIZED;
public static ExtractMode fromValue(String format) {
try {
return valueOf(checkNotNull(format, "format"));
} catch (IllegalArgumentException e) {
return UNRECOGNIZED;
}
}
}
private long id; private long id;
@SerializedName("displaytext") @SerializedName("displaytext")
private String displayText; private String displayText;

View File

@ -0,0 +1,204 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.features;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.ExtractMode;
import org.jclouds.cloudstack.domain.ISO;
import org.jclouds.cloudstack.domain.ISOPermissions;
import org.jclouds.cloudstack.filters.QuerySigner;
import org.jclouds.cloudstack.options.AccountInDomainOptions;
import org.jclouds.cloudstack.options.DeleteISOOptions;
import org.jclouds.cloudstack.options.ExtractISOOptions;
import org.jclouds.cloudstack.options.ListISOsOptions;
import org.jclouds.cloudstack.options.RegisterISOOptions;
import org.jclouds.cloudstack.options.UpdateISOOptions;
import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions;
import org.jclouds.rest.annotations.QueryParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.annotations.Unwrap;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.util.Set;
/**
*
* <p/>
*
* @see ISOClient
* @see http://download.cloud.com/releases/2.2.12/api/TOC_User.html
* @author Richard Downer
*/
@RequestFilters(QuerySigner.class)
@QueryParams(keys = "response", values = "json")
@SkipEncoding({'/', ','})
public interface ISOAsyncClient {
/**
* Attaches an ISO to a virtual machine.
*
* @param isoId the ID of the ISO file
* @param vmId the ID of the virtual machine
* @return an asynchronous job response.
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "attachISO")
@Unwrap
ListenableFuture<AsyncCreateResponse> attachISO(@QueryParam("id") long isoId, @QueryParam("virtualmachineid") long vmId);
/**
* Detaches any ISO file (if any) currently attached to a virtual machine.
*
* @param vmId The ID of the virtual machine
* @return an asynchronous job response.
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "detachISO")
@Unwrap
ListenableFuture<AsyncCreateResponse> detachISO(@QueryParam("virtualmachineid") long vmId);
/**
* Gets information about an ISO by its ID.
*
* @param id the ID of the ISO file
* @return the ISO object matching the ID
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "listISOs")
@Unwrap
ListenableFuture<ISO> getISO(@QueryParam("id") long id);
/**
* Lists all available ISO files.
*
* @param options optional arguments
* @return a set of ISO objects the match the filter
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "listISOs")
@Unwrap
ListenableFuture<Set<ISO>> listISOs(ListISOsOptions... options);
/**
* Registers an existing ISO into the Cloud.com Cloud.
*
* @param name the name of the ISO
* @param displayText the display text of the ISO. This is usually used for display purposes.
* @param url the URL to where the ISO is currently being hosted
* @param zoneId the ID of the zone you wish to register the ISO to.
* @param options optional arguments
* @return the newly-added ISO
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "registerISO")
@Unwrap
ListenableFuture<ISO> registerISO(@QueryParam("name") String name, @QueryParam("displaytext") String displayText, @QueryParam("url") String url, @QueryParam("zoneid") long zoneId, RegisterISOOptions... options);
/**
*
*
* @param id the ID of the ISO file
* @param options optional arguments
* @return the ISO object matching the ID
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "updateISO")
@Unwrap
ListenableFuture<ISO> updateISO(@QueryParam("id") long id, UpdateISOOptions... options);
/**
* Deletes an ISO file.
*
* @param id the ID of the ISO file
* @param options optional arguments
* @return an asynchronous job response.
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "deleteISO")
@Unwrap
ListenableFuture<AsyncCreateResponse> deleteISO(@QueryParam("id") long id, DeleteISOOptions... options);
/**
* Copies a template from one zone to another.
*
* @param isoId Template ID.
* @param sourceZoneId ID of the zone the template is currently hosted on.
* @param destZoneId ID of the zone the template is being copied to.
* @return an asynchronous job response.
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "copyISO")
@Unwrap
ListenableFuture<AsyncCreateResponse> copyISO(@QueryParam("id") long isoId, @QueryParam("sourcezoneid") long sourceZoneId, @QueryParam("destzoneid") long destZoneId);
/**
* Updates iso permissions
*
* @param id the template ID
* @param options optional arguments
* @return
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "updateISOPermissions")
@Unwrap
ListenableFuture<Void> updateISOPermissions(@QueryParam("id") long id, UpdateISOPermissionsOptions... options);
/**
* List template visibility and all accounts that have permissions to view this template.
*
* @param id the template ID
* @param options optional arguments
* @return A set of the permissions on this ISO
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "listISOPermissions")
@Unwrap
ListenableFuture<Set<ISOPermissions>> listISOPermissions(@QueryParam("id") long id, AccountInDomainOptions... options);
/**
* Extracts an ISO
*
* @param id the ID of the ISO file
* @param mode the mode of extraction - HTTP_DOWNLOAD or FTP_UPLOAD
* @param zoneId the ID of the zone where the ISO is originally located
* @param options optional arguments
* @return an asynchronous job response.
*/
@GET
@Consumes(MediaType.APPLICATION_JSON)
@QueryParams(keys = "command", values = "extractISO")
@Unwrap
ListenableFuture<AsyncCreateResponse> extractISO(@QueryParam("id") long id, @QueryParam("mode") ExtractMode mode, @QueryParam("zoneid") long zoneId, ExtractISOOptions... options);
}

View File

@ -0,0 +1,150 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.features;
import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.ExtractMode;
import org.jclouds.cloudstack.domain.ISO;
import org.jclouds.cloudstack.domain.ISOPermissions;
import org.jclouds.cloudstack.options.AccountInDomainOptions;
import org.jclouds.cloudstack.options.DeleteISOOptions;
import org.jclouds.cloudstack.options.ExtractISOOptions;
import org.jclouds.cloudstack.options.ListISOsOptions;
import org.jclouds.cloudstack.options.RegisterISOOptions;
import org.jclouds.cloudstack.options.UpdateISOOptions;
import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions;
import org.jclouds.concurrent.Timeout;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
*
* <p/>
*
* @see ISOAsyncClient
* @see http://download.cloud.com/releases/2.2.12/api/TOC_User.html
* @author Richard Downer
*/
@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS)
public interface ISOClient {
/**
* Attaches an ISO to a virtual machine.
*
* @param isoId the ID of the ISO file
* @param vmId the ID of the virtual machine
* @return an asynchronous job response.
*/
AsyncCreateResponse attachISO(long isoId, long vmId);
/**
* Detaches any ISO file (if any) currently attached to a virtual machine.
*
* @param vmId The ID of the virtual machine
* @return an asynchronous job response.
*/
AsyncCreateResponse detachISO(long vmId);
/**
* Gets information about an ISO by its ID.
*
* @param id the ID of the ISO file
* @return the ISO object matching the ID
*/
ISO getISO(long id);
/**
* Lists all available ISO files.
*
* @param options optional arguments
* @return a set of ISO objects the match the filter
*/
Set<ISO> listISOs(ListISOsOptions... options);
/**
* Registers an existing ISO into the Cloud.com Cloud.
*
* @param name the name of the ISO
* @param displayText the display text of the ISO. This is usually used for display purposes.
* @param url the URL to where the ISO is currently being hosted
* @param zoneId the ID of the zone you wish to register the ISO to.
* @param options optional arguments
* @return the newly-added ISO
*/
ISO registerISO(String name, String displayText, String url, long zoneId, RegisterISOOptions... options);
/**
*
*
* @param id the ID of the ISO file
* @param options optional arguments
* @return the ISO object matching the ID
*/
ISO updateISO(long id, UpdateISOOptions... options);
/**
* Deletes an ISO file.
*
* @param id the ID of the ISO file
* @param options optional arguments
* @return an asynchronous job response.
*/
AsyncCreateResponse deleteISO(long id, DeleteISOOptions... options);
/**
* Copies a template from one zone to another.
*
* @param isoId Template ID.
* @param sourceZoneId ID of the zone the template is currently hosted on.
* @param destZoneId ID of the zone the template is being copied to.
* @return an asynchronous job response.
*/
AsyncCreateResponse copyISO(long isoId, long sourceZoneId, long destZoneId);
/**
* Updates iso permissions
*
* @param id the template ID
* @param options optional arguments
* @return
*/
void updateISOPermissions(long id, UpdateISOPermissionsOptions... options);
/**
* List template visibility and all accounts that have permissions to view this template.
*
* @param id the template ID
* @param options optional arguments
* @return A set of the permissions on this ISO
*/
Set<ISOPermissions> listISOPermissions(long id, AccountInDomainOptions... options);
/**
* Extracts an ISO
*
* @param id the ID of the ISO file
* @param mode the mode of extraction - HTTP_DOWNLOAD or FTP_UPLOAD
* @param zoneId the ID of the zone where the ISO is originally located
* @param options optional arguments
* @return an asynchronous job response.
*/
AsyncCreateResponse extractISO(long id, ExtractMode mode, long zoneId, ExtractISOOptions... options);
}

View File

@ -27,6 +27,7 @@ import javax.ws.rs.core.MediaType;
import org.jclouds.cloudstack.binders.BindTemplateMetadataToQueryParams; import org.jclouds.cloudstack.binders.BindTemplateMetadataToQueryParams;
import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.ExtractMode;
import org.jclouds.cloudstack.domain.Template; import org.jclouds.cloudstack.domain.Template;
import org.jclouds.cloudstack.domain.TemplateMetadata; import org.jclouds.cloudstack.domain.TemplateMetadata;
import org.jclouds.cloudstack.domain.TemplatePermission; import org.jclouds.cloudstack.domain.TemplatePermission;
@ -164,5 +165,5 @@ public interface TemplateAsyncClient {
@QueryParams(keys = "command", values = "extractTemplate") @QueryParams(keys = "command", values = "extractTemplate")
@Unwrap @Unwrap
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<AsyncCreateResponse> extractTemplate(@QueryParam("id") long id, @QueryParam("mode") Template.ExtractMode mode, @QueryParam("zoneid") long zoneId, ExtractTemplateOptions... options); ListenableFuture<AsyncCreateResponse> extractTemplate(@QueryParam("id") long id, @QueryParam("mode") ExtractMode mode, @QueryParam("zoneid") long zoneId, ExtractTemplateOptions... options);
} }

View File

@ -22,6 +22,7 @@ import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.AsyncCreateResponse;
import org.jclouds.cloudstack.domain.ExtractMode;
import org.jclouds.cloudstack.domain.Template; import org.jclouds.cloudstack.domain.Template;
import org.jclouds.cloudstack.domain.TemplateFilter; import org.jclouds.cloudstack.domain.TemplateFilter;
import org.jclouds.cloudstack.domain.TemplateMetadata; import org.jclouds.cloudstack.domain.TemplateMetadata;
@ -211,6 +212,6 @@ public interface TemplateClient {
* optional arguments * optional arguments
* @return an asynchronous job response * @return an asynchronous job response
*/ */
AsyncCreateResponse extractTemplate(long id, Template.ExtractMode mode, long zoneId, AsyncCreateResponse extractTemplate(long id, ExtractMode mode, long zoneId,
ExtractTemplateOptions... options); ExtractTemplateOptions... options);
} }

View File

@ -0,0 +1,53 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options for the ISO deleteISO method.
*
* @see org.jclouds.cloudstack.features.ISOClient#deleteISO
* @see org.jclouds.cloudstack.features.ISOAsyncClient#deleteISO
* @author Richard Downer
*/
public class DeleteISOOptions extends BaseHttpRequestOptions {
public static final DeleteISOOptions NONE = new DeleteISOOptions();
/**
* @param zoneId the ID of the zone of the ISO file. If not specified, the ISO will be deleted from all the zones
*/
public DeleteISOOptions zoneId(long zoneId) {
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + ""));
return this;
}
public static class Builder {
/**
* @param zoneId the ID of the zone of the ISO file. If not specified, the ISO will be deleted from all the zones
*/
public static DeleteISOOptions zoneId(long zoneId) {
return new DeleteISOOptions().zoneId(zoneId);
}
}
}

View File

@ -0,0 +1,53 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options for the ISO extractISO method.
*
* @see org.jclouds.cloudstack.features.ISOClient#extractISO
* @see org.jclouds.cloudstack.features.ISOAsyncClient#extractISO
* @author Richard Downer
*/
public class ExtractISOOptions extends BaseHttpRequestOptions {
public static final ExtractISOOptions NONE = new ExtractISOOptions();
/**
* @param url the url to which the ISO would be extracted
*/
public ExtractISOOptions url(String url) {
this.queryParameters.replaceValues("url", ImmutableSet.of(url + ""));
return this;
}
public static class Builder {
/**
* @param url the url to which the ISO would be extracted
*/
public static ExtractISOOptions url(String url) {
return new ExtractISOOptions().url(url);
}
}
}

View File

@ -0,0 +1,188 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.ISO;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options for the ISO listISOs method.
*
* @see org.jclouds.cloudstack.features.ISOClient#listISOs
* @see org.jclouds.cloudstack.features.ISOAsyncClient#listISOs
* @author Richard Downer
*/
public class ListISOsOptions extends AccountInDomainOptions {
public static final ListISOsOptions NONE = new ListISOsOptions();
/**
* @param bootable true if the ISO is bootable, false otherwise
*/
public ListISOsOptions bootable(boolean bootable) {
this.queryParameters.replaceValues("bootable", ImmutableSet.of(bootable + ""));
return this;
}
/**
* @param hypervisor the hypervisor for which to restrict the search
*/
public ListISOsOptions hypervisor(String hypervisor) {
this.queryParameters.replaceValues("hypervisor", ImmutableSet.of(hypervisor + ""));
return this;
}
/**
* @param id list all isos by id
*/
public ListISOsOptions id(long id) {
this.queryParameters.replaceValues("id", ImmutableSet.of(id + ""));
return this;
}
/**
* @param isoFilter possible values are "featured", "self", "self-executable","executable", and "community".
*/
public ListISOsOptions isoFilter(ISO.ISOFilter isoFilter) {
this.queryParameters.replaceValues("isofilter", ImmutableSet.of(isoFilter + ""));
return this;
}
/**
* @param isPublic true if the ISO is publicly available to all users, false otherwise.
*/
public ListISOsOptions isPublic(boolean isPublic) {
this.queryParameters.replaceValues("ispublic", ImmutableSet.of(isPublic + ""));
return this;
}
/**
* @param isReady true if this ISO is ready to be deployed
*/
public ListISOsOptions isReady(boolean isReady) {
this.queryParameters.replaceValues("isready", ImmutableSet.of(isReady + ""));
return this;
}
/**
* @param keyword List by keyword
*/
public ListISOsOptions keyword(String keyword) {
this.queryParameters.replaceValues("keyword", ImmutableSet.of(keyword + ""));
return this;
}
/**
* @param name list all isos by name
*/
public ListISOsOptions name(String name) {
this.queryParameters.replaceValues("name", ImmutableSet.of(name + ""));
return this;
}
/**
* @param zoneId the ID of the zone
*/
public ListISOsOptions zoneId(long zoneId) {
this.queryParameters.replaceValues("zoneid", ImmutableSet.of(zoneId + ""));
return this;
}
public static class Builder {
/**
* @param account the account of the ISO file. Must be used with the domainId parameter.
*/
public static ListISOsOptions accountInDomain(String account, long domainId) {
return (ListISOsOptions) new ListISOsOptions().accountInDomain(account, domainId);
}
/**
* @param bootable true if the ISO is bootable, false otherwise
*/
public static ListISOsOptions bootable(boolean bootable) {
return new ListISOsOptions().bootable(bootable);
}
/**
* @param domainId lists all available ISO files by ID of a domain. If used with the account parameter, lists all available ISO files for the account in the ID of a domain.
*/
public static ListISOsOptions domainId(long domainId) {
return (ListISOsOptions) new ListISOsOptions().domainId(domainId);
}
/**
* @param hypervisor the hypervisor for which to restrict the search
*/
public static ListISOsOptions hypervisor(String hypervisor) {
return new ListISOsOptions().hypervisor(hypervisor);
}
/**
* @param id list all isos by id
*/
public static ListISOsOptions id(long id) {
return new ListISOsOptions().id(id);
}
/**
* @param isoFilter possible values are "featured", "self", "self-executable","executable", and "community".
*/
public static ListISOsOptions isoFilter(ISO.ISOFilter isoFilter) {
return new ListISOsOptions().isoFilter(isoFilter);
}
/**
* @param isPublic true if the ISO is publicly available to all users, false otherwise.
*/
public static ListISOsOptions isPublic(boolean isPublic) {
return new ListISOsOptions().isPublic(isPublic);
}
/**
* @param isReady true if this ISO is ready to be deployed
*/
public static ListISOsOptions isReady(boolean isReady) {
return new ListISOsOptions().isReady(isReady);
}
/**
* @param keyword List by keyword
*/
public static ListISOsOptions keyword(String keyword) {
return new ListISOsOptions().keyword(keyword);
}
/**
* @param name list all isos by name
*/
public static ListISOsOptions name(String name) {
return new ListISOsOptions().name(name);
}
/**
* @param zoneId the ID of the zone
*/
public static ListISOsOptions zoneId(long zoneId) {
return new ListISOsOptions().zoneId(zoneId);
}
}
}

View File

@ -0,0 +1,127 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options for the ISO registerISO method.
*
* @see org.jclouds.cloudstack.features.ISOClient#registerISO
* @see org.jclouds.cloudstack.features.ISOAsyncClient#registerISO
* @author Richard Downer
*/
public class RegisterISOOptions extends AccountInDomainOptions {
public static final RegisterISOOptions NONE = new RegisterISOOptions();
/**
* @param bootable true if this ISO is bootable
*/
public RegisterISOOptions bootable(boolean bootable) {
this.queryParameters.replaceValues("bootable", ImmutableSet.of(bootable + ""));
return this;
}
/**
* @param isExtractable true if the iso or its derivatives are extractable; default is false
*/
public RegisterISOOptions isExtractable(boolean isExtractable) {
this.queryParameters.replaceValues("isextractable", ImmutableSet.of(isExtractable + ""));
return this;
}
/**
* @param isFeatured true if you want this ISO to be featured
*/
public RegisterISOOptions isFeatured(boolean isFeatured) {
this.queryParameters.replaceValues("isfeatured", ImmutableSet.of(isFeatured + ""));
return this;
}
/**
* @param isPublic true if you want to register the ISO to be publicly available to all users, false otherwise.
*/
public RegisterISOOptions isPublic(boolean isPublic) {
this.queryParameters.replaceValues("ispublic", ImmutableSet.of(isPublic + ""));
return this;
}
/**
* @param osTypeId the ID of the OS Type that best represents the OS of this ISO
*/
public RegisterISOOptions osTypeId(long osTypeId) {
this.queryParameters.replaceValues("ostypeid", ImmutableSet.of(osTypeId + ""));
return this;
}
public static class Builder {
/**
* @param account an optional account name. Must be used with domainId.
*/
public static RegisterISOOptions accountInDomain(String account, long domainId) {
return (RegisterISOOptions) new RegisterISOOptions().accountInDomain(account, domainId);
}
/**
* @param bootable true if this ISO is bootable
*/
public static RegisterISOOptions bootable(boolean bootable) {
return new RegisterISOOptions().bootable(bootable);
}
/**
* @param domainId an optional domainId. If the account parameter is used, domainId must also be used.
*/
public static RegisterISOOptions domainId(long domainId) {
return (RegisterISOOptions) new RegisterISOOptions().domainId(domainId);
}
/**
* @param isExtractable true if the iso or its derivatives are extractable; default is false
*/
public static RegisterISOOptions isExtractable(boolean isExtractable) {
return new RegisterISOOptions().isExtractable(isExtractable);
}
/**
* @param isFeatured true if you want this ISO to be featured
*/
public static RegisterISOOptions isFeatured(boolean isFeatured) {
return new RegisterISOOptions().isFeatured(isFeatured);
}
/**
* @param isPublic true if you want to register the ISO to be publicly available to all users, false otherwise.
*/
public static RegisterISOOptions isPublic(boolean isPublic) {
return new RegisterISOOptions().isPublic(isPublic);
}
/**
* @param osTypeId the ID of the OS Type that best represents the OS of this ISO
*/
public static RegisterISOOptions osTypeId(long osTypeId) {
return new RegisterISOOptions().osTypeId(osTypeId);
}
}
}

View File

@ -0,0 +1,128 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.collect.ImmutableSet;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options for the ISO updateISO method.
*
* @see org.jclouds.cloudstack.features.ISOClient#updateISO
* @see org.jclouds.cloudstack.features.ISOAsyncClient#updateISO
* @author Richard Downer
*/
public class UpdateISOOptions extends BaseHttpRequestOptions {
public static final UpdateISOOptions NONE = new UpdateISOOptions();
/**
* @param bootable true if image is bootable, false otherwise
*/
public UpdateISOOptions bootable(boolean bootable) {
this.queryParameters.replaceValues("bootable", ImmutableSet.of(bootable + ""));
return this;
}
/**
* @param displayText the display text of the image
*/
public UpdateISOOptions displayText(String displayText) {
this.queryParameters.replaceValues("displaytext", ImmutableSet.of(displayText + ""));
return this;
}
/**
* @param format the format for the image
*/
public UpdateISOOptions format(String format) {
this.queryParameters.replaceValues("format", ImmutableSet.of(format + ""));
return this;
}
/**
* @param name the name of the image file
*/
public UpdateISOOptions name(String name) {
this.queryParameters.replaceValues("name", ImmutableSet.of(name + ""));
return this;
}
/**
* @param osTypeId the ID of the OS type that best represents the OS of this image.
*/
public UpdateISOOptions osTypeId(long osTypeId) {
this.queryParameters.replaceValues("ostypeid", ImmutableSet.of(osTypeId + ""));
return this;
}
/**
* @param passwordEnabled true if the image supports the password reset feature; default is false
*/
public UpdateISOOptions passwordEnabled(boolean passwordEnabled) {
this.queryParameters.replaceValues("passwordenabled", ImmutableSet.of(passwordEnabled + ""));
return this;
}
public static class Builder {
/**
* @param bootable true if image is bootable, false otherwise
*/
public static UpdateISOOptions bootable(boolean bootable) {
return new UpdateISOOptions().bootable(bootable);
}
/**
* @param displayText the display text of the image
*/
public static UpdateISOOptions displayText(String displayText) {
return new UpdateISOOptions().displayText(displayText);
}
/**
* @param format the format for the image
*/
public static UpdateISOOptions format(String format) {
return new UpdateISOOptions().format(format);
}
/**
* @param name the name of the image file
*/
public static UpdateISOOptions name(String name) {
return new UpdateISOOptions().name(name);
}
/**
* @param osTypeId the ID of the OS type that best represents the OS of this image.
*/
public static UpdateISOOptions osTypeId(long osTypeId) {
return new UpdateISOOptions().osTypeId(osTypeId);
}
/**
* @param passwordEnabled true if the image supports the password reset feature; default is false
*/
public static UpdateISOOptions passwordEnabled(boolean passwordEnabled) {
return new UpdateISOOptions().passwordEnabled(passwordEnabled);
}
}
}

View File

@ -0,0 +1,115 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.options;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.PermissionOperation;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Options for the ISO updateISOPermissions method.
*
* @see org.jclouds.cloudstack.features.ISOClient#updateISOPermissions
* @see org.jclouds.cloudstack.features.ISOAsyncClient#updateISOPermissions
* @author Richard Downer
*/
public class UpdateISOPermissionsOptions extends BaseHttpRequestOptions {
public static final UpdateISOPermissionsOptions NONE = new UpdateISOPermissionsOptions();
/**
* @param accounts a comma delimited list of accounts. If specified, "op" parameter has to be passed in.
*/
public UpdateISOPermissionsOptions accounts(Iterable<String> accounts) {
this.queryParameters.replaceValues("accounts", ImmutableSet.of(Joiner.on(',').join(accounts)));
return this;
}
/**
* @param isExtractable true if the template/iso is extractable, false other wise. Can be set only by root admin
*/
public UpdateISOPermissionsOptions isExtractable(boolean isExtractable) {
this.queryParameters.replaceValues("isextractable", ImmutableSet.of(isExtractable + ""));
return this;
}
/**
* @param isFeatured true for featured template/iso, false otherwise
*/
public UpdateISOPermissionsOptions isFeatured(boolean isFeatured) {
this.queryParameters.replaceValues("isfeatured", ImmutableSet.of(isFeatured + ""));
return this;
}
/**
* @param isPublic true for public template/iso, false for private templates/isos
*/
public UpdateISOPermissionsOptions isPublic(boolean isPublic) {
this.queryParameters.replaceValues("ispublic", ImmutableSet.of(isPublic + ""));
return this;
}
/**
* @param operation permission operator (add, remove, reset)
*/
public UpdateISOPermissionsOptions operation(PermissionOperation operation) {
this.queryParameters.replaceValues("op", ImmutableSet.of(operation + ""));
return this;
}
public static class Builder {
/**
* @param accounts a comma delimited list of accounts. If specified, "op" parameter has to be passed in.
*/
public static UpdateISOPermissionsOptions accounts(Iterable<String> accounts) {
return new UpdateISOPermissionsOptions().accounts(accounts);
}
/**
* @param isExtractable true if the template/iso is extractable, false other wise. Can be set only by root admin
*/
public static UpdateISOPermissionsOptions isExtractable(boolean isExtractable) {
return new UpdateISOPermissionsOptions().isExtractable(isExtractable);
}
/**
* @param isFeatured true for featured template/iso, false otherwise
*/
public static UpdateISOPermissionsOptions isFeatured(boolean isFeatured) {
return new UpdateISOPermissionsOptions().isFeatured(isFeatured);
}
/**
* @param isPublic true for public template/iso, false for private templates/isos
*/
public static UpdateISOPermissionsOptions isPublic(boolean isPublic) {
return new UpdateISOPermissionsOptions().isPublic(isPublic);
}
/**
* @param operation permission operator (add, remove, reset)
*/
public static UpdateISOPermissionsOptions operation(PermissionOperation operation) {
return new UpdateISOPermissionsOptions().operation(operation);
}
}
}

View File

@ -0,0 +1,346 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.cloudstack.features;
import com.google.common.collect.ImmutableSet;
import com.google.inject.TypeLiteral;
import org.jclouds.cloudstack.domain.ExtractMode;
import org.jclouds.cloudstack.domain.ISO;
import org.jclouds.cloudstack.domain.PermissionOperation;
import org.jclouds.cloudstack.options.AccountInDomainOptions;
import org.jclouds.cloudstack.options.DeleteISOOptions;
import org.jclouds.cloudstack.options.ExtractISOOptions;
import org.jclouds.cloudstack.options.ListISOsOptions;
import org.jclouds.cloudstack.options.RegisterISOOptions;
import org.jclouds.cloudstack.options.UpdateISOOptions;
import org.jclouds.cloudstack.options.UpdateISOPermissionsOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.rest.functions.MapHttp4xxCodesToExceptions;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.testng.annotations.Test;
import java.lang.reflect.Method;
/**
* Tests the behaviour of ISOAsyncClient.
*
* @see ISOAsyncClient
* @author Richard Downer
*/
// NOTE:without testName, this will not call @Before* and fail w/NPE during
// surefire
@Test(groups = "unit", testName = "ISOAsyncClientTest")
public class ISOAsyncClientTest extends BaseCloudStackAsyncClientTest<ISOAsyncClient> {
public void testAttachISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("attachISO", long.class, long.class);
HttpRequest httpRequest = processor.createRequest(method, 3, 5);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=attachISO&id=3&virtualmachineid=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testDetachISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("detachISO", long.class);
HttpRequest httpRequest = processor.createRequest(method, 3);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=detachISO&virtualmachineid=3 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testGetISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("getISO", long.class);
HttpRequest httpRequest = processor.createRequest(method, 3);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listISOs&id=3 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testListISOs() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("listISOs", ListISOsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listISOs HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testListISOsOptions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("listISOs", ListISOsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, ListISOsOptions.Builder.accountInDomain("fred", 5).bootable(true).hypervisor("xen").id(3).isoFilter(ISO.ISOFilter.featured).isPublic(true).isReady(true).keyword("bob").name("bob's iso").zoneId(7));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listISOs&account=fred&domainid=5&bootable=true&hypervisor=xen&id=3&isofilter=featured&ispublic=true&isready=true&keyword=bob&name=bob%27s%20iso&zoneid=7 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testRegisterISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("registerISO", String.class, String.class, String.class, long.class, RegisterISOOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, "bob's iso", "bob's copy of linux", "http://example.com/", 9);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=registerISO&name=bob%27s%20iso&url=http%3A//example.com/&displaytext=bob%27s%20copy%20of%20linux&zoneid=9 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testRegisterISOOptions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("registerISO", String.class, String.class, String.class, long.class, RegisterISOOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, "bob's iso", "bob's copy of linux", "http://example.com/", 9, RegisterISOOptions.Builder.accountInDomain("fred", 5).bootable(true).isExtractable(true).isFeatured(true).isPublic(true).osTypeId(7));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=registerISO&name=bob%27s%20iso&url=http%3A//example.com/&displaytext=bob%27s%20copy%20of%20linux&zoneid=9&account=fred&domainid=5&bootable=true&isextractable=true&isfeatured=true&ispublic=true&ostypeid=7 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testUpdateISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("updateISO", long.class, UpdateISOOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=updateISO&id=3 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testUpdateISOOptions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("updateISO", long.class, UpdateISOOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3, UpdateISOOptions.Builder.bootable(true).displayText("robert").format("format").name("bob").osTypeId(9).passwordEnabled(true));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=updateISO&id=3&bootable=true&displaytext=robert&format=format&name=bob&ostypeid=9&passwordenabled=true HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testDeleteISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("deleteISO", long.class, DeleteISOOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=deleteISO&id=3 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testDeleteISOOptions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("deleteISO", long.class, DeleteISOOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3, DeleteISOOptions.Builder.zoneId(5));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=deleteISO&id=3&zoneid=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testCopyISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("copyISO", long.class, long.class, long.class);
HttpRequest httpRequest = processor.createRequest(method, 3, 5, 7);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=copyISO&id=3&destzoneid=7&sourcezoneid=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testUpdateISOPermissions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("updateISOPermissions", long.class, UpdateISOPermissionsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=updateISOPermissions&id=3 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testUpdateISOPermissionsOptions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("updateISOPermissions", long.class, UpdateISOPermissionsOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3, UpdateISOPermissionsOptions.Builder.accounts(ImmutableSet.<String>of("fred", "bob")).isExtractable(true).isFeatured(true).isPublic(true).operation(PermissionOperation.add));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=updateISOPermissions&id=3&accounts=fred,bob&isextractable=true&isfeatured=true&ispublic=true&op=add HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testListISOPermissions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("listISOPermissions", long.class, AccountInDomainOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listISOPermissions&id=3 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testListISOPermissionsOptions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("listISOPermissions", long.class, AccountInDomainOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3, AccountInDomainOptions.Builder.accountInDomain("fred", 5));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=listISOPermissions&id=3&account=fred&domainid=5 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testExtractISO() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("extractISO", long.class, ExtractMode.class, long.class, ExtractISOOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3, ExtractMode.HTTP_DOWNLOAD, 5);
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=extractISO&id=3&zoneid=5&mode=HTTP_DOWNLOAD HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
public void testExtractISOOptions() throws NoSuchMethodException {
Method method = ISOAsyncClient.class.getMethod("extractISO", long.class, ExtractMode.class, long.class, ExtractISOOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3, ExtractMode.HTTP_DOWNLOAD, 5, ExtractISOOptions.Builder.url("http://example.com/"));
assertRequestLineEquals(httpRequest,
"GET http://localhost:8080/client/api?response=json&command=extractISO&id=3&zoneid=5&mode=HTTP_DOWNLOAD&url=http%3A//example.com/ HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
assertPayloadEquals(httpRequest, null, null, false);
assertResponseParserClassEquals(method, httpRequest, UnwrapOnlyJsonValue.class);
assertSaxResponseParserClassEquals(method, null);
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
checkFilters(httpRequest);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<ISOAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<ISOAsyncClient>>() {
};
}
}

View File

@ -22,6 +22,7 @@ import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.jclouds.cloudstack.domain.ExtractMode;
import org.jclouds.cloudstack.domain.Template; import org.jclouds.cloudstack.domain.Template;
import org.jclouds.cloudstack.domain.TemplateFilter; import org.jclouds.cloudstack.domain.TemplateFilter;
import org.jclouds.cloudstack.domain.TemplateMetadata; import org.jclouds.cloudstack.domain.TemplateMetadata;
@ -48,8 +49,6 @@ import org.testng.annotations.Test;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import javax.annotation.concurrent.Immutable;
/** /**
* Tests behavior of {@code TemplateAsyncClient} * Tests behavior of {@code TemplateAsyncClient}
* *
@ -315,8 +314,8 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<Templ
} }
public void testExtractTemplate() throws NoSuchMethodException { public void testExtractTemplate() throws NoSuchMethodException {
Method method = TemplateAsyncClient.class.getMethod("extractTemplate", long.class, Template.ExtractMode.class, long.class, ExtractTemplateOptions[].class); Method method = TemplateAsyncClient.class.getMethod("extractTemplate", long.class, ExtractMode.class, long.class, ExtractTemplateOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3, Template.ExtractMode.HTTP_DOWNLOAD, 5); HttpRequest httpRequest = processor.createRequest(method, 3, ExtractMode.HTTP_DOWNLOAD, 5);
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=extractTemplate&id=3&zoneid=5&mode=HTTP_DOWNLOAD HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=extractTemplate&id=3&zoneid=5&mode=HTTP_DOWNLOAD HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");
@ -330,8 +329,8 @@ public class TemplateAsyncClientTest extends BaseCloudStackAsyncClientTest<Templ
} }
public void testExtractTemplateOptions() throws NoSuchMethodException { public void testExtractTemplateOptions() throws NoSuchMethodException {
Method method = TemplateAsyncClient.class.getMethod("extractTemplate", long.class, Template.ExtractMode.class, long.class, ExtractTemplateOptions[].class); Method method = TemplateAsyncClient.class.getMethod("extractTemplate", long.class, ExtractMode.class, long.class, ExtractTemplateOptions[].class);
HttpRequest httpRequest = processor.createRequest(method, 3, Template.ExtractMode.HTTP_DOWNLOAD, 5, ExtractTemplateOptions.Builder.url("http://example.com/")); HttpRequest httpRequest = processor.createRequest(method, 3, ExtractMode.HTTP_DOWNLOAD, 5, ExtractTemplateOptions.Builder.url("http://example.com/"));
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=extractTemplate&id=3&zoneid=5&mode=HTTP_DOWNLOAD&url=http%3A%2F%2Fexample.com%2F HTTP/1.1"); assertRequestLineEquals(httpRequest, "GET http://localhost:8080/client/api?response=json&command=extractTemplate&id=3&zoneid=5&mode=HTTP_DOWNLOAD&url=http%3A%2F%2Fexample.com%2F HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n");