Issue 290: added guest customization support

This commit is contained in:
Adrian Cole 2010-09-05 00:20:45 -07:00
parent e5bd9bbfb8
commit 36dec74379
22 changed files with 1438 additions and 266 deletions

View File

@ -0,0 +1,44 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.bluelock;
import static com.google.common.base.Preconditions.checkNotNull;
import org.jclouds.vcloud.VCloudGuestCustomizationLiveTest;
import org.testng.annotations.Test;
/**
*
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, sequential = true, testName = "vcloud.BlueLockVCloudDirectorGuestCustomizationLiveTest")
public class BlueLockVCloudDirectorGuestCustomizationLiveTest extends VCloudGuestCustomizationLiveTest {
@Override
protected void setupCredentials() {
provider = "bluelock-vclouddirector";
identity = checkNotNull(System.getProperty("bluelock-vclouddirector.identity"),
"bluelock-vclouddirector.identity");
credential = checkNotNull(System.getProperty("bluelock-vclouddirector.credential"),
"bluelock-vclouddirector.credential");
}
}

View File

@ -20,6 +20,7 @@
package org.jclouds.vcloud; package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudMediaType.DEPLOYVAPPPARAMS_XML; import static org.jclouds.vcloud.VCloudMediaType.DEPLOYVAPPPARAMS_XML;
import static org.jclouds.vcloud.VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML;
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
import static org.jclouds.vcloud.VCloudMediaType.UNDEPLOYVAPPPARAMS_XML; import static org.jclouds.vcloud.VCloudMediaType.UNDEPLOYVAPPPARAMS_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
@ -34,11 +35,13 @@ import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import org.jclouds.predicates.validators.DnsNameValidator; import org.jclouds.predicates.validators.DnsNameValidator;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.EndpointParam; import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.ExceptionParser;
@ -52,8 +55,10 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload; import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload; import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindGuestCustomizationSectionToXmlPayload;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload; import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload; import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
@ -79,8 +84,7 @@ import com.google.common.util.concurrent.ListenableFuture;
* Provides access to VCloud resources via their REST API. * Provides access to VCloud resources via their REST API.
* <p/> * <p/>
* *
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" * @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* />
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(SetVCloudTokenCookie.class) @RequestFilters(SetVCloudTokenCookie.class)
@ -122,9 +126,9 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
@XMLResponseParser(VAppTemplateHandler.class) @XMLResponseParser(VAppTemplateHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed( ListenableFuture<? extends VAppTemplate> findVAppTemplateInOrgCatalogNamed(
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName, @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName, @Nullable @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName); @EndpointParam(parser = OrgNameCatalogNameVAppTemplateNameToEndpoint.class) String itemName);
/** /**
* @see VCloudClient#instantiateVAppTemplateInVDC * @see VCloudClient#instantiateVAppTemplateInVDC
@ -136,9 +140,9 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
@XMLResponseParser(VAppHandler.class) @XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class) @MapBinder(BindInstantiateVAppTemplateParamsToXmlPayload.class)
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc, ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(@EndpointParam URI vdc,
@MapPayloadParam("template") URI template, @MapPayloadParam("template") URI template,
@MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName, @MapPayloadParam("name") @ParamValidators(DnsNameValidator.class) String appName,
InstantiateVAppTemplateOptions... options); InstantiateVAppTemplateOptions... options);
/** /**
* @see VCloudClient#cloneVAppInVDC * @see VCloudClient#cloneVAppInVDC
@ -150,8 +154,8 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
@XMLResponseParser(TaskHandler.class) @XMLResponseParser(TaskHandler.class)
@MapBinder(BindCloneVAppParamsToXmlPayload.class) @MapBinder(BindCloneVAppParamsToXmlPayload.class)
ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone, ListenableFuture<? extends Task> cloneVAppInVDC(@EndpointParam URI vdc, @MapPayloadParam("vApp") URI toClone,
@MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName, @MapPayloadParam("newName") @ParamValidators(DnsNameValidator.class) String newName,
CloneVAppOptions... options); CloneVAppOptions... options);
/** /**
* @see VCloudClient#findVAppInOrgVDCNamed * @see VCloudClient#findVAppInOrgVDCNamed
@ -161,9 +165,9 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
@XMLResponseParser(VAppHandler.class) @XMLResponseParser(VAppHandler.class)
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends VApp> findVAppInOrgVDCNamed( ListenableFuture<? extends VApp> findVAppInOrgVDCNamed(
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName, @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String orgName,
@Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName, @Nullable @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String catalogName,
@EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName); @EndpointParam(parser = OrgNameVDCNameResourceEntityNameToEndpoint.class) String vAppName);
/** /**
* @see VCloudClient#getVApp * @see VCloudClient#getVApp
@ -183,6 +187,18 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
@ExceptionParser(ReturnNullOnNotFoundOr404.class) @ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<? extends Vm> getVm(@EndpointParam URI vm); ListenableFuture<? extends Vm> getVm(@EndpointParam URI vm);
/**
* @see VCloudClient#updateGuestCustomizationOfVm
*/
@PUT
@Consumes(TASK_XML)
@Produces(GUESTCUSTOMIZATIONSECTION_XML)
@Path("/guestCustomizationSection")
@XMLResponseParser(TaskHandler.class)
ListenableFuture<? extends Task> updateGuestCustomizationOfVm(
@EndpointParam URI vm,
@BinderParam(BindGuestCustomizationSectionToXmlPayload.class) GuestCustomizationSection guestCustomizationSection);
/** /**
* @see VCloudClient#deployVAppOrVm * @see VCloudClient#deployVAppOrVm
*/ */

View File

@ -27,6 +27,7 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
@ -40,16 +41,14 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
* Provides access to VCloud resources via their REST API. * Provides access to VCloud resources via their REST API.
* <p/> * <p/>
* *
* @see <a * @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
* href="http://communities.vmware.com/community/developer/forums/vcloudapi"
* />
* @author Adrian Cole * @author Adrian Cole
*/ */
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
public interface VCloudClient extends CommonVCloudClient { public interface VCloudClient extends CommonVCloudClient {
/** /**
* The response to a login request includes a list of the organizations to * The response to a login request includes a list of the organizations to which the
* which the authenticated user has access. * authenticated user has access.
* *
* @return organizations indexed by name * @return organizations indexed by name
*/ */
@ -64,9 +63,19 @@ public interface VCloudClient extends CommonVCloudClient {
OvfEnvelope getOvfEnvelopeForVAppTemplate(URI vAppTemplate); OvfEnvelope getOvfEnvelopeForVAppTemplate(URI vAppTemplate);
/** /**
* returns the vapp template corresponding to a catalog item in the catalog * Modify the Guest Customization Section of a Virtual Machine
* associated with the specified name. Note that the org and catalog *
* parameters can be null to choose default. * @param vm
* uri to modify
* @param updated
* guestCustomizationSection
* @return task in progress
*/
Task updateGuestCustomizationOfVm(URI vm, GuestCustomizationSection guestCustomizationSection);
/**
* returns the vapp template corresponding to a catalog item in the catalog associated with the
* specified name. Note that the org and catalog parameters can be null to choose default.
* *
* @param orgName * @param orgName
* organization name, or null for the default * organization name, or null for the default
@ -76,11 +85,10 @@ public interface VCloudClient extends CommonVCloudClient {
* item you wish to lookup * item you wish to lookup
* *
* @throws NoSuchElementException * @throws NoSuchElementException
* if you specified an org, catalog, or catalog item name that * if you specified an org, catalog, or catalog item name that isn't present
* isn't present
*/ */
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName, VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
String itemName); String itemName);
VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName); VApp findVAppInOrgVDCNamed(@Nullable String orgName, @Nullable String catalogName, String vAppName);
@ -89,109 +97,97 @@ public interface VCloudClient extends CommonVCloudClient {
Vm getVm(URI vm); Vm getVm(URI vm);
/** /**
* To deploy a vApp, the client makes a request to its action/deploy URL. * To deploy a vApp, the client makes a request to its action/deploy URL. Deploying a vApp
* Deploying a vApp automatically deploys all of the virtual machines it * automatically deploys all of the virtual machines it contains. To deploy a virtual machine,
* contains. To deploy a virtual machine, the client makes a request to its * the client makes a request to its action/deploy URL.
* action/deploy URL.
* <p/> * <p/>
* Deploying a Vm implicitly deploys the parent vApp if that vApp is not * Deploying a Vm implicitly deploys the parent vApp if that vApp is not already deployed.
* already deployed.
*/ */
Task deployVAppOrVm(URI vAppOrVmId); Task deployVAppOrVm(URI vAppOrVmId);
/** /**
* like {@link #deployVAppOrVm(URI)}, except deploy transistions to power on * like {@link #deployVAppOrVm(URI)}, except deploy transistions to power on state
* state
* *
*/ */
Task deployAndPowerOnVAppOrVm(URI vAppOrVmId); Task deployAndPowerOnVAppOrVm(URI vAppOrVmId);
/** /**
* Undeploying a vApp powers off or suspends any running virtual machines it * Undeploying a vApp powers off or suspends any running virtual machines it contains, then frees
* contains, then frees the resources reserved for the vApp and sets the * the resources reserved for the vApp and sets the vApps deploy attribute to a value of false
* vApps deploy attribute to a value of false to indicate that it is not * to indicate that it is not deployed.
* deployed.
* <p/> * <p/>
* Undeploying a virtual machine powers off or suspends the virtual machine, * Undeploying a virtual machine powers off or suspends the virtual machine, then frees the
* then frees the resources reserved for it and sets the its deploy attribute * resources reserved for it and sets the its deploy attribute to a value of false to indicate
* to a value of false to indicate that it is not deployed. This operation * that it is not deployed. This operation has no effect on the containing vApp.
* has no effect on the containing vApp.
* <h4>NOTE</h4> * <h4>NOTE</h4>
* Using this method will simply power off the vms. In order to save their * Using this method will simply power off the vms. In order to save their state, use
* state, use {@link #undeployAndSaveStateOfVAppOrVm} * {@link #undeployAndSaveStateOfVAppOrVm}
* *
*/ */
Task undeployVAppOrVm(URI vAppOrVmId); Task undeployVAppOrVm(URI vAppOrVmId);
/** /**
* like {@link #undeployVAppOrVm(URI)}, where the undeployed virtual machines * like {@link #undeployVAppOrVm(URI)}, where the undeployed virtual machines are suspended and
* are suspended and their suspend state saved * their suspend state saved
* *
*/ */
Task undeployAndSaveStateOfVAppOrVm(URI vAppOrVmId); Task undeployAndSaveStateOfVAppOrVm(URI vAppOrVmId);
/** /**
* A powerOn request to a vApp URL powers on all of the virtual machines in * A powerOn request to a vApp URL powers on all of the virtual machines in the vApp, as
* the vApp, as specified in the vApps StartupSection field. * specified in the vApps StartupSection field.
* <p/> * <p/>
* A powerOn request to a virtual machine URL powers on the specified virtual * A powerOn request to a virtual machine URL powers on the specified virtual machine and forces
* machine and forces deployment of the parent vApp. * deployment of the parent vApp.
* <p/> * <p/>
* <h4>NOTE</h4> A powerOn request to a vApp or virtual machine that is * <h4>NOTE</h4> A powerOn request to a vApp or virtual machine that is undeployed forces
* undeployed forces deployment. * deployment.
*/ */
Task powerOnVAppOrVm(URI vAppOrVmId); Task powerOnVAppOrVm(URI vAppOrVmId);
/** /**
* A powerOff request to a vApp URL powers off all of the virtual machines in * A powerOff request to a vApp URL powers off all of the virtual machines in the vApp, as
* the vApp, as specified in its StartupSection field. * specified in its StartupSection field.
* <p/> * <p/>
* A powerOff request to a virtual machine URL powers off the specified * A powerOff request to a virtual machine URL powers off the specified virtual machine.
* virtual machine.
*/ */
Task powerOffVAppOrVm(URI vAppOrVmId); Task powerOffVAppOrVm(URI vAppOrVmId);
/** /**
* A shutdown request to a vApp URL shuts down all of the virtual machines in * A shutdown request to a vApp URL shuts down all of the virtual machines in the vApp, as
* the vApp, as specified in its StartupSection field. * specified in its StartupSection field.
* <p/> * <p/>
* A shutdown request to a virtual machine URL shuts down the specified * A shutdown request to a virtual machine URL shuts down the specified virtual machine.
* virtual machine.
* <p/> * <p/>
* <h4>NOTE</h4Because this request sends a signal to the guest OS, the * <h4>NOTE</h4Because this request sends a signal to the guest OS, the vCloud API cannot track
* vCloud API cannot track the progress or verify the result of the requested * the progress or verify the result of the requested operation. Hence, void is returned
* operation. Hence, void is returned
*/ */
void shutdownVAppOrVm(URI vAppOrVmId); void shutdownVAppOrVm(URI vAppOrVmId);
/** /**
* A reset request to a vApp URL resets all of the virtual machines in the * A reset request to a vApp URL resets all of the virtual machines in the vApp, as specified in
* vApp, as specified in its StartupSection field. * its StartupSection field.
* <p/> * <p/>
* A reset request to a virtual machine URL resets the specified virtual * A reset request to a virtual machine URL resets the specified virtual machine.
* machine.
*/ */
Task resetVAppOrVm(URI vAppOrVmId); Task resetVAppOrVm(URI vAppOrVmId);
/** /**
* A reboot request to a vApp URL reboots all of the virtual machines in the * A reboot request to a vApp URL reboots all of the virtual machines in the vApp, as specified
* vApp, as specified in its StartupSection field. * in its StartupSection field.
* <p/> * <p/>
* A reboot request to a virtual machine URL reboots the specified virtual * A reboot request to a virtual machine URL reboots the specified virtual machine.
* machine.
* <p/> * <p/>
* <h4>NOTE</h4> Because this request sends a signal to the guest OS, the * <h4>NOTE</h4> Because this request sends a signal to the guest OS, the vCloud API cannot track
* vCloud API cannot track the progress or verify the result of the requested * the progress or verify the result of the requested operation. Hence, void is returned
* operation. Hence, void is returned
*/ */
void rebootVAppOrVm(URI vAppOrVmId); void rebootVAppOrVm(URI vAppOrVmId);
/** /**
* A suspend request to a vApp URL suspends all of the virtual machines in * A suspend request to a vApp URL suspends all of the virtual machines in the vApp, as specified
* the vApp, as specified in its StartupSection field. * in its StartupSection field.
* <p/> * <p/>
* A suspend request to a virtual machine URL suspends the specified virtual * A suspend request to a virtual machine URL suspends the specified virtual machine.
* machine.
*/ */
Task suspendVAppOrVm(URI vAppOrVmId); Task suspendVAppOrVm(URI vAppOrVmId);

View File

@ -0,0 +1,115 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
import java.util.Properties;
import javax.annotation.Resource;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.logging.Logger;
import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.jamesmurty.utils.XMLBuilder;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindGuestCustomizationSectionToXmlPayload extends BindToStringPayload {
@Resource
protected Logger logger = Logger.NULL;
protected final String ns;
protected final String schema;
@Inject
public BindGuestCustomizationSectionToXmlPayload(BindToStringPayload stringBinder,
@Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
this.ns = ns;
this.schema = schema;
}
public void bindToRequest(HttpRequest request, Object payload) {
checkArgument(checkNotNull(payload, "GuestCustomizationSection") instanceof GuestCustomizationSection,
"this binder is only valid for GuestCustomizationSection!");
GuestCustomizationSection guest = GuestCustomizationSection.class.cast(payload);
XMLBuilder guestCustomizationSection;
try {
guestCustomizationSection = XMLBuilder.create("GuestCustomizationSection").a("xmlns", ns).a("xmlns:ovf",
"http://schemas.dmtf.org/ovf/envelope/1").a("type", guest.getType()).a("href",
guest.getHref().toASCIIString()).a("ovf:required", "false");
guestCustomizationSection.e("ovf:Info").t(guest.getInfo());
if (guest.isEnabled() != null)
guestCustomizationSection.e("Enabled").t(guest.isEnabled().toString());
if (guest.shouldChangeSid() != null)
guestCustomizationSection.e("ChangeSid").t(guest.shouldChangeSid().toString());
if (guest.getVirtualMachineId() != null)
guestCustomizationSection.e("VirtualMachineId").t(guest.getVirtualMachineId().toString());
if (guest.isJoinDomainEnabled() != null)
guestCustomizationSection.e("JoinDomainEnabled").t(guest.isJoinDomainEnabled().toString());
if (guest.shouldUseOrgSettings() != null)
guestCustomizationSection.e("UseOrgSettings").t(guest.shouldUseOrgSettings().toString());
if (guest.getDomainName() != null)
guestCustomizationSection.e("DomainName").t(guest.getDomainName().toString());
if (guest.getDomainUserName() != null)
guestCustomizationSection.e("DomainUserName").t(guest.getDomainUserName().toString());
if (guest.getDomainUserPassword() != null)
guestCustomizationSection.e("DomainUserPassword").t(guest.getDomainUserPassword().toString());
if (guest.isAdminPasswordEnabled() != null)
guestCustomizationSection.e("AdminPasswordEnabled").t(guest.isAdminPasswordEnabled().toString());
if (guest.isAdminPasswordAuto() != null)
guestCustomizationSection.e("AdminPasswordAuto").t(guest.isAdminPasswordAuto().toString());
// if (guest.getAdminPassword() != null)
// guestCustomizationSection.e("AdminPassword").t(guest.getAdminPassword().toString());
if (guest.isResetPasswordRequired() != null)
guestCustomizationSection.e("ResetPasswordRequired").t(guest.isResetPasswordRequired().toString());
if (guest.getCustomizationScript() != null)
guestCustomizationSection.e("CustomizationScript").t(guest.getCustomizationScript());
if (guest.getComputerName() != null)
guestCustomizationSection.e("ComputerName").t(guest.getComputerName().toString());
if (guest.getEdit() != null)
guestCustomizationSection.e("Link").a("rel", "edit").a("type", guest.getType()).a("href",
guest.getHref().toASCIIString());
Properties outputProperties = new Properties();
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
super.bindToRequest(request, guestCustomizationSection.asString(outputProperties));
request.getPayload().setContentType(guest.getType());
} catch (Exception e) {
Throwables.propagate(e);
}
}
}

View File

@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -45,11 +46,13 @@ import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.VAppTemplate; import org.jclouds.vcloud.domain.VAppTemplate;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.network.FenceMode; import org.jclouds.vcloud.domain.network.FenceMode;
import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.domain.network.NetworkConfig;
import org.jclouds.vcloud.endpoints.Network; import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -73,18 +76,20 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
protected final URI defaultNetwork; protected final URI defaultNetwork;
protected final FenceMode defaultFenceMode; protected final FenceMode defaultFenceMode;
protected final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate; protected final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate;
protected final VCloudClient client;
@Inject @Inject
public BindInstantiateVAppTemplateParamsToXmlPayload(DefaultNetworkNameInTemplate defaultNetworkNameInTemplate, public BindInstantiateVAppTemplateParamsToXmlPayload(DefaultNetworkNameInTemplate defaultNetworkNameInTemplate,
BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema, @Network URI network,
@Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode) { @Named(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) String fenceMode, VCloudClient client) {
this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate; this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate;
this.ns = ns; this.ns = ns;
this.schema = schema; this.schema = schema;
this.stringBinder = stringBinder; this.stringBinder = stringBinder;
this.defaultNetwork = network; this.defaultNetwork = network;
this.defaultFenceMode = FenceMode.fromValue(fenceMode); this.defaultFenceMode = FenceMode.fromValue(fenceMode);
this.client = client;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -98,11 +103,12 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
boolean deploy = true; boolean deploy = true;
boolean powerOn = true; boolean powerOn = true;
Boolean customizeOnInstantiate = null;
Set<? extends NetworkConfig> networkConfig = null; Set<? extends NetworkConfig> networkConfig = null;
NetworknetworkConfigDecorator networknetworkConfigDecorator = new NetworknetworkConfigDecorator(template, NetworkConfigDecorator networknetworkConfigDecorator = new NetworkConfigDecorator(template, defaultNetwork,
defaultNetwork, defaultFenceMode, defaultNetworkNameInTemplate); defaultFenceMode, defaultNetworkNameInTemplate);
InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest); InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
@ -110,16 +116,17 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
if (options.getNetworkConfig().size() > 0) if (options.getNetworkConfig().size() > 0)
networkConfig = Sets.newLinkedHashSet(Iterables.transform(options.getNetworkConfig(), networkConfig = Sets.newLinkedHashSet(Iterables.transform(options.getNetworkConfig(),
networknetworkConfigDecorator)); networknetworkConfigDecorator));
deploy = ifNullDefaultTo(options.shouldDeploy(), deploy); deploy = ifNullDefaultTo(options.shouldDeploy(), deploy);
powerOn = ifNullDefaultTo(options.shouldPowerOn(), powerOn); powerOn = ifNullDefaultTo(options.shouldPowerOn(), powerOn);
customizeOnInstantiate = options.shouldCustomizeOnInstantiate();
} }
if (networkConfig == null) if (networkConfig == null)
networkConfig = ImmutableSet.of(networknetworkConfigDecorator.apply(null)); networkConfig = ImmutableSet.of(networknetworkConfigDecorator.apply(null));
try { try {
stringBinder.bindToRequest(request, generateXml(name, deploy, powerOn, template, networkConfig)); stringBinder.bindToRequest(request, generateXml(name, deploy, powerOn, template, networkConfig,
customizeOnInstantiate));
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} catch (FactoryConfigurationError e) { } catch (FactoryConfigurationError e) {
@ -130,13 +137,25 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
} }
protected static final class NetworknetworkConfigDecorator implements Function<NetworkConfig, NetworkConfig> { @VisibleForTesting
Set<? extends Vm> ifCustomizationScriptIsSetGetVmsInTemplate(String customizationScript, final URI template) {
Set<? extends Vm> vms = Sets.newLinkedHashSet();
if (customizationScript != null) {
VAppTemplate vAppTemplate = client.getVAppTemplate(template);
checkArgument(vAppTemplate != null, "vAppTemplate %s not found!", template);
vms = vAppTemplate.getChildren();
checkArgument(vms.size() > 0, "no vms found in vAppTemplate %s", vAppTemplate);
}
return vms;
}
protected static final class NetworkConfigDecorator implements Function<NetworkConfig, NetworkConfig> {
private final URI template; private final URI template;
private final URI defaultNetwork; private final URI defaultNetwork;
private final FenceMode defaultFenceMode; private final FenceMode defaultFenceMode;
private final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate; private final DefaultNetworkNameInTemplate defaultNetworkNameInTemplate;
protected NetworknetworkConfigDecorator(URI template, URI defaultNetwork, FenceMode defaultFenceMode, protected NetworkConfigDecorator(URI template, URI defaultNetwork, FenceMode defaultFenceMode,
DefaultNetworkNameInTemplate defaultNetworkNameInTemplate) { DefaultNetworkNameInTemplate defaultNetworkNameInTemplate) {
this.template = checkNotNull(template, "template"); this.template = checkNotNull(template, "template");
this.defaultNetwork = checkNotNull(defaultNetwork, "defaultNetwork"); this.defaultNetwork = checkNotNull(defaultNetwork, "defaultNetwork");
@ -180,17 +199,15 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
networkName = Iterables.get(networks, 0).getName(); networkName = Iterables.get(networks, 0).getName();
return networkName; return networkName;
} }
} }
protected String generateXml(String name, boolean deploy, boolean powerOn, URI template, protected String generateXml(String name, boolean deploy, boolean powerOn, URI template,
Iterable<? extends NetworkConfig> networkConfig) throws ParserConfigurationException, Iterable<? extends NetworkConfig> networkConfig, @Nullable Boolean customizeOnInstantiate)
FactoryConfigurationError, TransformerException { throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + ""); XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + "");
XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams"); XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
addNetworkConfig(instantiationParamsBuilder, networkConfig); addNetworkConfig(instantiationParamsBuilder, networkConfig);
addCustomizationConfig(instantiationParamsBuilder, customizeOnInstantiate);
rootBuilder.e("Source").a("href", template.toASCIIString()); rootBuilder.e("Source").a("href", template.toASCIIString());
rootBuilder.e("AllEULAsAccepted").t("true"); rootBuilder.e("AllEULAsAccepted").t("true");
@ -199,6 +216,14 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder
return rootBuilder.asString(outputProperties); return rootBuilder.asString(outputProperties);
} }
protected void addCustomizationConfig(XMLBuilder instantiationParamsBuilder, Boolean customizeOnInstantiate) {
if (customizeOnInstantiate != null) {
// XMLBuilder customizationSectionBuilder = instantiationParamsBuilder.e("CustomizationSection");
// customizationSectionBuilder.e("ovf:Info").t("VApp template customization section");
// customizationSectionBuilder.e("CustomizeOnInstantiate").t(customizeOnInstantiate.toString());
}
}
protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder,
Iterable<? extends NetworkConfig> networkConfig) { Iterable<? extends NetworkConfig> networkConfig) {
XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection"); XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection");

View File

@ -24,7 +24,9 @@ import java.util.Set;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.internal.ComputeServiceContextImpl;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
@ -36,6 +38,8 @@ import org.jclouds.rest.internal.RestContextImpl;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.functions.ImagesInOrg; import org.jclouds.vcloud.compute.functions.ImagesInOrg;
import org.jclouds.vcloud.compute.functions.SizesInOrg; import org.jclouds.vcloud.compute.functions.SizesInOrg;
import org.jclouds.vcloud.compute.internal.VCloudTemplateBuilderImpl;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.compute.strategy.GetLoginCredentialsFromGuestConfiguration; import org.jclouds.vcloud.compute.strategy.GetLoginCredentialsFromGuestConfiguration;
import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy; import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy;
import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy;
@ -62,6 +66,8 @@ public class VCloudComputeServiceContextModule extends CommonVCloudComputeServic
@Override @Override
protected void configure() { protected void configure() {
super.configure(); super.configure();
bind(TemplateOptions.class).to(VCloudTemplateOptions.class);
bind(TemplateBuilder.class).to(VCloudTemplateBuilderImpl.class);
bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class); bind(RebootNodeStrategy.class).to(VCloudRebootNodeStrategy.class);
bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class); bind(GetNodeMetadataStrategy.class).to(VCloudGetNodeMetadataStrategy.class);
bind(new TypeLiteral<ComputeServiceContext>() { bind(new TypeLiteral<ComputeServiceContext>() {

View File

@ -19,70 +19,38 @@
package org.jclouds.vcloud.compute.functions; package org.jclouds.vcloud.compute.functions;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Maps.newHashMap;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import java.util.Map; import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.compute.internal.VCloudExpressComputeClientImpl;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
/** /**
* Configures the {@link VCloudComputeServiceContext}; requires
* {@link VCloudExpressComputeClientImpl} bound.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Singleton @Singleton
public class GetExtraFromVApp implements Function<VApp, Map<String, String>> { public class GetExtraFromVApp implements Function<VApp, Map<String, String>> {
private final GetExtraFromVm getExtraFromVm;
@Inject
GetExtraFromVApp(GetExtraFromVm getExtraFromVm) {
this.getExtraFromVm = getExtraFromVm;
}
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
public Map<String, String> apply(VApp vApp) { public Map<String, String> apply(VApp vApp) {
Map<String, String> extra = newHashMap(); // TODO make this work with composite vApps
try { return vApp.getChildren().size() == 0 ? ImmutableMap.<String, String> of() : getExtraFromVm.apply(Iterables.get(
// TODO make this work with composite vApps vApp.getChildren(), 0));
Vm vm = Iterables.get(vApp.getChildren(), 0);
extra.put("memory/mb", find(vm.getVirtualHardwareSection().getResourceAllocations(), resourceType(ResourceType.MEMORY))
.getVirtualQuantity()
+ "");
extra.put("processor/count", find(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.PROCESSOR)).getVirtualQuantity()
+ "");
for (ResourceAllocation disk : filter(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.DISK_DRIVE))) {
if (disk instanceof VCloudHardDisk) {
VCloudHardDisk vDisk = VCloudHardDisk.class.cast(disk);
extra.put(String.format("disk_drive/%s/mb", disk.getAddressOnParent()), vDisk.getCapacity() + "");
} else {
extra.put(String.format("disk_drive/%s/kb", disk.getAddressOnParent()), disk.getVirtualQuantity() + "");
}
}
for (ResourceAllocation net : filter(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.ETHERNET_ADAPTER))) {
if (net instanceof VCloudNetworkAdapter) {
VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net);
extra.put(String.format("network/%s/ip", net.getAddressOnParent()), vNet.getIpAddress());
}
}
} catch (Exception e) {
logger.error(e, "error getting extra data for vApp: %s", vApp);
}
return extra;
} }
} }

View File

@ -0,0 +1,81 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.functions;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Maps.newHashMap;
import static org.jclouds.vcloud.predicates.VCloudPredicates.resourceType;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.ovf.ResourceAllocation;
import org.jclouds.vcloud.domain.ovf.ResourceType;
import org.jclouds.vcloud.domain.ovf.VCloudHardDisk;
import org.jclouds.vcloud.domain.ovf.VCloudNetworkAdapter;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class GetExtraFromVm implements Function<Vm, Map<String, String>> {
@Resource
protected Logger logger = Logger.NULL;
public Map<String, String> apply(Vm vm) {
Map<String, String> extra = newHashMap();
try {
extra.put("memory/mb", find(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.MEMORY)).getVirtualQuantity()
+ "");
extra.put("processor/count", find(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.PROCESSOR)).getVirtualQuantity()
+ "");
for (ResourceAllocation disk : filter(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.DISK_DRIVE))) {
if (disk instanceof VCloudHardDisk) {
VCloudHardDisk vDisk = VCloudHardDisk.class.cast(disk);
extra.put(String.format("disk_drive/%s/mb", disk.getAddressOnParent()), vDisk.getCapacity() + "");
} else {
extra.put(String.format("disk_drive/%s/kb", disk.getAddressOnParent()), disk.getVirtualQuantity() + "");
}
}
for (ResourceAllocation net : filter(vm.getVirtualHardwareSection().getResourceAllocations(),
resourceType(ResourceType.ETHERNET_ADAPTER))) {
if (net instanceof VCloudNetworkAdapter) {
VCloudNetworkAdapter vNet = VCloudNetworkAdapter.class.cast(net);
extra.put(String.format("network/%s/ip", net.getAddressOnParent()), vNet.getIpAddress());
}
}
} catch (Exception e) {
logger.error(e, "error getting extra data for vm: %s", vm);
}
return extra;
}
}

View File

@ -0,0 +1,63 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.internal;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Size;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Location;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import com.google.common.base.Supplier;
/**
*
* @author Adrian Cole
*/
public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl {
@Inject
protected VCloudTemplateBuilderImpl(Supplier<Set<? extends Location>> locations,
Supplier<Set<? extends Image>> images, Supplier<Set<? extends Size>> sizes,
Supplier<Location> defaultLocation, Provider<TemplateOptions> optionsProvider,
@Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider) {
super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider);
}
@Override
protected void copyTemplateOptions(TemplateOptions from, TemplateOptions to) {
super.copyTemplateOptions(from, to);
if (from instanceof VCloudTemplateOptions) {
VCloudTemplateOptions eFrom = VCloudTemplateOptions.class.cast(from);
VCloudTemplateOptions eTo = VCloudTemplateOptions.class.cast(to);
if (eFrom.getCustomizationScript() != null)
eTo.customizationScript(eFrom.getCustomizationScript());
}
}
}

View File

@ -0,0 +1,243 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.options;
import java.util.Arrays;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.io.Payload;
import org.jclouds.util.Utils;
/**
* Contains options supported in the {@code ComputeService#runNode} operation on the "vcloud"
* provider. <h2>
* Usage</h2> The recommended way to instantiate a VCloudTemplateOptions object is to statically
* import VCloudTemplateOptions.* and invoke a static creation method followed by an instance
* mutator (if needed):
* <p/>
* <code>
* import static org.jclouds.compute.options.VCloudTemplateOptions.Builder.*;
* <p/>
* ComputeService client = // get connection
* templateBuilder.options(inboundPorts(22, 80, 8080, 443));
* Set<? extends NodeMetadata> set = client.runNodesWithTag(tag, 2, templateBuilder.build());
* <code>
*
* @author Adrian Cole
*/
public class VCloudTemplateOptions extends TemplateOptions {
private String customizationScript = null;
public static final VCloudTemplateOptions NONE = new VCloudTemplateOptions();
/**
* Specifies the customizationScript used to run instances with
*/
public VCloudTemplateOptions customizationScript(String customizationScript) {
Utils.checkNotEmpty(customizationScript, "customizationScript must be non-empty");
this.customizationScript = customizationScript;
return this;
}
public static class Builder {
/**
* @see VCloudTemplateOptions#customizationScript
*/
public static VCloudTemplateOptions customizationScript(String customizationScript) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.customizationScript(customizationScript));
}
// methods that only facilitate returning the correct object type
/**
* @see TemplateOptions#inboundPorts
*/
public static VCloudTemplateOptions inboundPorts(int... ports) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.inboundPorts(ports));
}
/**
* @see TemplateOptions#port
*/
public static VCloudTemplateOptions blockOnPort(int port, int seconds) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.blockOnPort(port, seconds));
}
/**
* @see TemplateOptions#runScript
*/
public static VCloudTemplateOptions runScript(Payload script) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.runScript(script));
}
/**
* @see TemplateOptions#installPrivateKey
*/
public static VCloudTemplateOptions installPrivateKey(Payload rsaKey) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.installPrivateKey(rsaKey));
}
/**
* @see TemplateOptions#authorizePublicKey
*/
public static VCloudTemplateOptions authorizePublicKey(Payload rsaKey) {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.authorizePublicKey(rsaKey));
}
/**
* @see TemplateOptions#withDetails
*/
public static VCloudTemplateOptions withDetails() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
return VCloudTemplateOptions.class.cast(options.withMetadata());
}
}
/**
* @return customizationScript on the vms
*/
public String getCustomizationScript() {
return customizationScript;
}
// methods that only facilitate returning the correct object type
/**
* @see TemplateOptions#blockOnPort
*/
@Override
public VCloudTemplateOptions blockOnPort(int port, int seconds) {
return VCloudTemplateOptions.class.cast(super.blockOnPort(port, seconds));
}
/**
*
* special thing is that we do assume if you are passing groups that you have everything you need
* already defined. for example, our option inboundPorts normally creates ingress rules
* accordingly but if we notice you've specified securityGroups, we do not mess with rules at all
*
* @see TemplateOptions#inboundPorts
*/
@Override
public VCloudTemplateOptions inboundPorts(int... ports) {
return VCloudTemplateOptions.class.cast(super.inboundPorts(ports));
}
/**
* @see TemplateOptions#authorizePublicKey(String)
*/
@Override
@Deprecated
public VCloudTemplateOptions authorizePublicKey(String publicKey) {
return VCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
}
/**
* @see TemplateOptions#authorizePublicKey(Payload)
*/
@Override
public VCloudTemplateOptions authorizePublicKey(Payload publicKey) {
return VCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey));
}
/**
* @see TemplateOptions#installPrivateKey(String)
*/
@Override
@Deprecated
public VCloudTemplateOptions installPrivateKey(String privateKey) {
return VCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
}
/**
* @see TemplateOptions#installPrivateKey(Payload)
*/
@Override
public VCloudTemplateOptions installPrivateKey(Payload privateKey) {
return VCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey));
}
/**
* @see TemplateOptions#runScript(Payload)
*/
@Override
public VCloudTemplateOptions runScript(Payload script) {
return VCloudTemplateOptions.class.cast(super.runScript(script));
}
/**
* @see TemplateOptions#runScript(byte[])
*/
@Override
@Deprecated
public VCloudTemplateOptions runScript(byte[] script) {
return VCloudTemplateOptions.class.cast(super.runScript(script));
}
/**
* @see TemplateOptions#withMetadata
*/
@Override
public VCloudTemplateOptions withMetadata() {
return VCloudTemplateOptions.class.cast(super.withMetadata());
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((customizationScript == null) ? 0 : customizationScript.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VCloudTemplateOptions other = (VCloudTemplateOptions) obj;
if (customizationScript == null) {
if (other.customizationScript != null)
return false;
} else if (!customizationScript.equals(other.customizationScript))
return false;
return true;
}
@Override
public String toString() {
return "[customizationScript=" + customizationScript + ", inboundPorts=" + Arrays.toString(inboundPorts)
+ ", privateKey=" + (privateKey != null) + ", publicKey=" + (publicKey != null) + ", runScript="
+ (script != null) + ", port:seconds=" + port + ":" + seconds + ", metadata/details: " + includeMetadata
+ "]";
}
}

View File

@ -35,11 +35,15 @@ import org.jclouds.compute.strategy.AddNodeWithTagStrategy;
import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -66,6 +70,17 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
public NodeMetadata execute(String tag, String name, Template template) { public NodeMetadata execute(String tag, String name, Template template) {
InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue()) InstantiateVAppTemplateOptions options = processorCount(Double.valueOf(template.getSize().getCores()).intValue())
.memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l); .memory(template.getSize().getRam()).disk(template.getSize().getDisk() * 1024 * 1024l);
String customizationScript = null;
if (template.getOptions() instanceof VCloudTemplateOptions) {
customizationScript = VCloudTemplateOptions.class.cast(template.getOptions()).getCustomizationScript();
if (customizationScript != null) {
options.customizeOnInstantiate(false);
options.deploy(false);
options.powerOn(false);
}
}
if (!template.getOptions().shouldBlockUntilRunning()) if (!template.getOptions().shouldBlockUntilRunning())
options.block(false); options.block(false);
@ -78,6 +93,35 @@ public class VCloudAddNodeWithTagStrategy implements AddNodeWithTagStrategy {
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName()); logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
Task task = vAppResponse.getTasks().get(0); Task task = vAppResponse.getTasks().get(0);
if (customizationScript == null) {
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task);
} else {
if (!successTester.apply(task.getHref())) {
throw new RuntimeException(String
.format("failed to %s %s: %s", "instantiate", vAppResponse.getName(), task));
}
Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0);
GuestCustomizationSection guestConfiguration = vm.getGuestCustomizationSection();
// guestConfiguration
// .setCustomizationScript(guestConfiguration.getCustomizationScript() != null ?
// guestConfiguration
// .getCustomizationScript()
// + "\n" + customizationScript : customizationScript);
guestConfiguration.setCustomizationScript(customizationScript);
task = client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration);
if (!successTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "updateGuestCustomizationOfVm", vm
.getName(), task));
}
task = client.deployAndPowerOnVAppOrVm(vAppResponse.getHref());
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task);
}
}
private NodeMetadata blockOnDeployAndPowerOnIfConfigured(InstantiateVAppTemplateOptions options, VApp vAppResponse,
Task task) {
if (options.shouldBlock()) { if (options.shouldBlock()) {
if (!successTester.apply(task.getHref())) { if (!successTester.apply(task.getHref())) {
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on", vAppResponse throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on", vAppResponse

View File

@ -21,30 +21,39 @@ package org.jclouds.vcloud.domain;
import java.net.URI; import java.net.URI;
import org.jclouds.vcloud.VCloudMediaType;
/** /**
* The GuestCustomization of a Vm contains customization parameters for the guest * The GuestCustomization of a Vm contains customization parameters for the guest operating system
* operating system of the virtual machine. * of the virtual machine.
*/ */
public class GuestCustomizationSection { public class GuestCustomizationSection {
protected final String type; protected final String type;
protected final URI href; protected final URI href;
protected final String info; protected String info;
protected final Boolean enabled; protected Boolean enabled;
protected final Boolean changeSid; protected Boolean changeSid;
protected final String virtualMachineId; protected String virtualMachineId;
protected final Boolean joinDomainEnabled; protected Boolean joinDomainEnabled;
protected final Boolean useOrgSettings; protected Boolean useOrgSettings;
protected final String domainName; protected String domainName;
protected final String domainUserName; protected String domainUserName;
protected final String domainUserPassword; protected String domainUserPassword;
protected final Boolean adminPasswordEnabled; protected Boolean adminPasswordEnabled;
protected final Boolean adminPasswordAuto; protected Boolean adminPasswordAuto;
protected final String adminPassword; protected String adminPassword;
protected final Boolean resetPasswordRequired; protected Boolean resetPasswordRequired;
protected final String customizationScript; protected String customizationScript;
protected final String computerName; protected String computerName;
protected final ReferenceType edit; protected final ReferenceType edit;
public GuestCustomizationSection(URI href) {
this.href = href;
this.type = VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML;
this.info = "Specifies Guest OS Customization Settings";
this.edit = null;
}
public GuestCustomizationSection(String type, URI href, String info, Boolean enabled, Boolean changeSid, public GuestCustomizationSection(String type, URI href, String info, Boolean enabled, Boolean changeSid,
String virtualMachineId, Boolean joinDomainEnabled, Boolean useOrgSettings, String domainName, String virtualMachineId, Boolean joinDomainEnabled, Boolean useOrgSettings, String domainName,
String domainUserName, String domainUserPassword, Boolean adminPasswordEnabled, Boolean adminPasswordAuto, String domainUserName, String domainUserPassword, Boolean adminPasswordEnabled, Boolean adminPasswordAuto,
@ -223,7 +232,7 @@ public class GuestCustomizationSection {
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((adminPassword == null) ? 0 : adminPassword.hashCode()); result = prime * result + ((adminPassword == null) ? 0 : adminPassword.hashCode());
result = prime * result + ((adminPasswordAuto == null) ? 0 : adminPasswordAuto.hashCode()); result = prime * result + ((adminPasswordAuto == null) ? 0 : adminPasswordAuto.hashCode());
@ -347,4 +356,88 @@ public class GuestCustomizationSection {
return false; return false;
return true; return true;
} }
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Boolean getChangeSid() {
return changeSid;
}
public void setChangeSid(Boolean changeSid) {
this.changeSid = changeSid;
}
public Boolean getJoinDomainEnabled() {
return joinDomainEnabled;
}
public void setJoinDomainEnabled(Boolean joinDomainEnabled) {
this.joinDomainEnabled = joinDomainEnabled;
}
public Boolean shouldUseOrgSettings() {
return useOrgSettings;
}
public void setUseOrgSettings(Boolean useOrgSettings) {
this.useOrgSettings = useOrgSettings;
}
public Boolean getAdminPasswordEnabled() {
return adminPasswordEnabled;
}
public void setAdminPasswordEnabled(Boolean adminPasswordEnabled) {
this.adminPasswordEnabled = adminPasswordEnabled;
}
public Boolean getAdminPasswordAuto() {
return adminPasswordAuto;
}
public void setAdminPasswordAuto(Boolean adminPasswordAuto) {
this.adminPasswordAuto = adminPasswordAuto;
}
public Boolean getResetPasswordRequired() {
return resetPasswordRequired;
}
public void setResetPasswordRequired(Boolean resetPasswordRequired) {
this.resetPasswordRequired = resetPasswordRequired;
}
public void setInfo(String info) {
this.info = info;
}
public void setVirtualMachineId(String virtualMachineId) {
this.virtualMachineId = virtualMachineId;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
public void setDomainUserName(String domainUserName) {
this.domainUserName = domainUserName;
}
public void setDomainUserPassword(String domainUserPassword) {
this.domainUserPassword = domainUserPassword;
}
public void setAdminPassword(String adminPassword) {
this.adminPassword = adminPassword;
}
public void setCustomizationScript(String customizationScript) {
this.customizationScript = customizationScript;
}
public void setComputerName(String computerName) {
this.computerName = computerName;
}
} }

View File

@ -26,8 +26,6 @@ import java.util.Set;
import org.jclouds.vcloud.domain.network.NetworkConfig; import org.jclouds.vcloud.domain.network.NetworkConfig;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
/** /**
@ -38,6 +36,7 @@ import com.google.common.collect.Sets;
public class InstantiateVAppTemplateOptions { public class InstantiateVAppTemplateOptions {
private Set<NetworkConfig> networkConfig = Sets.newLinkedHashSet(); private Set<NetworkConfig> networkConfig = Sets.newLinkedHashSet();
private Boolean customizeOnInstantiate;
private String cpuCount; private String cpuCount;
private String memorySizeMegabytes; private String memorySizeMegabytes;
private String diskSizeKilobytes; private String diskSizeKilobytes;
@ -82,6 +81,15 @@ public class InstantiateVAppTemplateOptions {
return this; return this;
} }
/**
* If true, then customization is executed for all children that include a
* GuestCustomizationSection.
*/
public InstantiateVAppTemplateOptions customizeOnInstantiate(boolean customizeOnInstantiate) {
this.customizeOnInstantiate = customizeOnInstantiate;
return this;
}
public InstantiateVAppTemplateOptions processorCount(int cpuCount) { public InstantiateVAppTemplateOptions processorCount(int cpuCount) {
checkArgument(cpuCount >= 1, "cpuCount must be positive"); checkArgument(cpuCount >= 1, "cpuCount must be positive");
this.cpuCount = cpuCount + ""; this.cpuCount = cpuCount + "";
@ -126,6 +134,10 @@ public class InstantiateVAppTemplateOptions {
return cpuCount; return cpuCount;
} }
public Boolean shouldCustomizeOnInstantiate() {
return customizeOnInstantiate;
}
public String getMemorySizeMegabytes() { public String getMemorySizeMegabytes() {
return memorySizeMegabytes; return memorySizeMegabytes;
} }
@ -168,6 +180,14 @@ public class InstantiateVAppTemplateOptions {
return options.processorCount(cpuCount); return options.processorCount(cpuCount);
} }
/**
* @see InstantiateVAppTemplateOptions#customizeOnInstantiate
*/
public static InstantiateVAppTemplateOptions customizeOnInstantiate(Boolean customizeOnInstantiate) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.customizeOnInstantiate(customizeOnInstantiate);
}
/** /**
* @see InstantiateVAppTemplateOptions#memory(int) * @see InstantiateVAppTemplateOptions#memory(int)
*/ */
@ -197,7 +217,9 @@ public class InstantiateVAppTemplateOptions {
@Override @Override
public String toString() { public String toString() {
return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes=" + memorySizeMegabytes return "InstantiateVAppTemplateOptions [cpuCount=" + cpuCount + ", memorySizeMegabytes=" + memorySizeMegabytes
+ ", diskSizeKilobytes=" + diskSizeKilobytes + ", networkConfig=" + networkConfig + "]"; + ", diskSizeKilobytes=" + diskSizeKilobytes + ", networkConfig=" + networkConfig
+ ", customizeOnInstantiate=" + customizeOnInstantiate + ", deploy=" + (deploy) + ", powerOn="
+ (powerOn) + "]";
} }
@Override @Override
@ -206,10 +228,11 @@ public class InstantiateVAppTemplateOptions {
int result = 1; int result = 1;
result = prime * result + (block ? 1231 : 1237); result = prime * result + (block ? 1231 : 1237);
result = prime * result + ((cpuCount == null) ? 0 : cpuCount.hashCode()); result = prime * result + ((cpuCount == null) ? 0 : cpuCount.hashCode());
result = prime * result + ((customizeOnInstantiate == null) ? 0 : customizeOnInstantiate.hashCode());
result = prime * result + (deploy ? 1231 : 1237); result = prime * result + (deploy ? 1231 : 1237);
result = prime * result + ((diskSizeKilobytes == null) ? 0 : diskSizeKilobytes.hashCode()); result = prime * result + ((diskSizeKilobytes == null) ? 0 : diskSizeKilobytes.hashCode());
result = prime * result + ((networkConfig == null) ? 0 : networkConfig.hashCode());
result = prime * result + ((memorySizeMegabytes == null) ? 0 : memorySizeMegabytes.hashCode()); result = prime * result + ((memorySizeMegabytes == null) ? 0 : memorySizeMegabytes.hashCode());
result = prime * result + ((networkConfig == null) ? 0 : networkConfig.hashCode());
result = prime * result + (powerOn ? 1231 : 1237); result = prime * result + (powerOn ? 1231 : 1237);
return result; return result;
} }
@ -230,6 +253,11 @@ public class InstantiateVAppTemplateOptions {
return false; return false;
} else if (!cpuCount.equals(other.cpuCount)) } else if (!cpuCount.equals(other.cpuCount))
return false; return false;
if (customizeOnInstantiate == null) {
if (other.customizeOnInstantiate != null)
return false;
} else if (!customizeOnInstantiate.equals(other.customizeOnInstantiate))
return false;
if (deploy != other.deploy) if (deploy != other.deploy)
return false; return false;
if (diskSizeKilobytes == null) { if (diskSizeKilobytes == null) {
@ -237,16 +265,16 @@ public class InstantiateVAppTemplateOptions {
return false; return false;
} else if (!diskSizeKilobytes.equals(other.diskSizeKilobytes)) } else if (!diskSizeKilobytes.equals(other.diskSizeKilobytes))
return false; return false;
if (networkConfig == null) {
if (other.networkConfig != null)
return false;
} else if (!networkConfig.equals(other.networkConfig))
return false;
if (memorySizeMegabytes == null) { if (memorySizeMegabytes == null) {
if (other.memorySizeMegabytes != null) if (other.memorySizeMegabytes != null)
return false; return false;
} else if (!memorySizeMegabytes.equals(other.memorySizeMegabytes)) } else if (!memorySizeMegabytes.equals(other.memorySizeMegabytes))
return false; return false;
if (networkConfig == null) {
if (other.networkConfig != null)
return false;
} else if (!networkConfig.equals(other.networkConfig))
return false;
if (powerOn != other.powerOn) if (powerOn != other.powerOn)
return false; return false;
return true; return true;

View File

@ -118,6 +118,9 @@ public class GuestCustomizationSectionHandler extends ParseSax.HandlerWithResult
this.resetPasswordRequired = Boolean.parseBoolean(currentOrNull()); this.resetPasswordRequired = Boolean.parseBoolean(currentOrNull());
} else if (qName.endsWith("CustomizationScript")) { } else if (qName.endsWith("CustomizationScript")) {
this.customizationScript = currentOrNull(); this.customizationScript = currentOrNull();
if (this.customizationScript != null)
customizationScript = customizationScript.replace("&lt;", "<").replace(">", "&gt;").replace("&quot;", "\"")
.replace("&apos;", "'").replace("&#13;", "\r\n").replace("&#13;", "\n").replace("&amp;", "&");
} else if (qName.endsWith("ComputerName")) { } else if (qName.endsWith("ComputerName")) {
this.computerName = currentOrNull(); this.computerName = currentOrNull();
} else if (qName.endsWith("Name")) { } else if (qName.endsWith("Name")) {

View File

@ -51,6 +51,7 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.config.VCloudRestClientModule; import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.domain.GuestCustomizationSection;
import org.jclouds.vcloud.domain.Org; import org.jclouds.vcloud.domain.Org;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
@ -97,23 +98,45 @@ import domain.VCloudVersionsAsyncClient;
*/ */
@Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest") @Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest")
public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> { public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testUpdateGuestConfiguration() throws SecurityException, NoSuchMethodException, IOException {
public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException, Method method = VCloudAsyncClient.class.getMethod("updateGuestCustomizationOfVm", URI.class,
IOException { GuestCustomizationSection.class);
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, GuestCustomizationSection guest = new GuestCustomizationSection(URI
String.class, InstantiateVAppTemplateOptions[].class); .create("http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection"));
HttpRequest request = processor.createRequest(method, URI guest.setCustomizationScript("cat > /tmp/foo.txt<<EOF\nI love candy\nEOF");
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI HttpRequest request = processor.createRequest(method,
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp", URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"), guest);
addNetworkConfig(new NetworkConfig("aloha", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED)));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); "PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/guestCustomizationSection.xml")), "application/vnd.vmware.vcloud.guestCustomizationSection+xml",
false);
assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(request);
}
public void testInstantiateVAppTemplateInVDCURIOptions() throws SecurityException, NoSuchMethodException,
IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class);
HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), "my-vapp",
addNetworkConfig(new NetworkConfig("aloha", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED)));
assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream( assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream(
"/instantiationparams-network.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", "/instantiationparams-network.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
false); false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class); assertSaxResponseParserClassEquals(method, VAppHandler.class);
@ -124,28 +147,28 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
@Test(expectedExceptions = IllegalArgumentException.class) @Test(expectedExceptions = IllegalArgumentException.class)
public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException, public void testInstantiateVAppTemplateInOrgOptionsIllegalName() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class, Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
String.class, InstantiateVAppTemplateOptions[].class); String.class, InstantiateVAppTemplateOptions[].class);
processor processor.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.createRequest(method, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "CentOS 01", processorCount(1).memory(512)
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "CentOS 01", processorCount(1).memory( .disk(1024).addNetworkConfig(
512).disk(1024).addNetworkConfig( new NetworkConfig(null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"),
new NetworkConfig(null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), null))); null)));
} }
public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException { public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class,
CloneVAppOptions[].class); CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-vapp"); .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-vapp");
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")), assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp-default.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false); "application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -156,17 +179,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException { public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class, Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class,
CloneVAppOptions[].class); CloneVAppOptions[].class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "new-linux-server", new CloneVAppOptions() .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "new-linux-server",
.deploy().powerOn().withDescription("The description of the new vApp")); new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp"));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml")), assertPayloadEquals(request, Utils.toStringAndClose(getClass().getResourceAsStream("/cloneVApp.xml")),
"application/vnd.vmware.vcloud.cloneVAppParams+xml", false); "application/vnd.vmware.vcloud.cloneVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -193,7 +216,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testOrg() throws SecurityException, NoSuchMethodException, IOException { public void testOrg() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOrg", URI.class); Method method = VCloudAsyncClient.class.getMethod("getOrg", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/org/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/org/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n");
@ -224,7 +247,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalog", URI.class); Method method = VCloudAsyncClient.class.getMethod("getCatalog", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
@ -255,7 +278,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getNetwork", URI.class); Method method = VCloudAsyncClient.class.getMethod("getNetwork", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/network/2")); .create("https://vcenterprise.bluelock.com/api/v1.0/network/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/network/2 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/network/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
@ -271,7 +294,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class); Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2")); .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
@ -286,7 +309,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException { public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, String.class, Method method = VCloudAsyncClient.class.getMethod("findCatalogItemInOrgCatalogNamed", String.class, String.class,
String.class); String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "item"); HttpRequest request = processor.createRequest(method, "org", "catalog", "item");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1 HTTP/1.1");
@ -302,7 +325,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class, Method method = VCloudAsyncClient.class.getMethod("findVAppTemplateInOrgCatalogNamed", String.class,
String.class, String.class); String.class, String.class);
HttpRequest request = processor.createRequest(method, "org", "catalog", "template"); HttpRequest request = processor.createRequest(method, "org", "catalog", "template");
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1");
@ -319,7 +342,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException { public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", URI.class); Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")); .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
@ -335,7 +358,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetOvfEnvelopeForVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { public void testGetOvfEnvelopeForVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOvfEnvelopeForVAppTemplate", URI.class); Method method = VCloudAsyncClient.class.getMethod("getOvfEnvelopeForVAppTemplate", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")); .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2/ovf HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2/ovf HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: text/xml\n"); assertNonPayloadHeadersEqual(request, "Accept: text/xml\n");
@ -408,7 +431,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class); Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
@ -424,7 +447,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException { public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTasksList", URI.class); Method method = VCloudAsyncClient.class.getMethod("getTasksList", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
@ -455,12 +478,12 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testDeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { public void testDeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deployVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("deployVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1"); assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>", assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false); "application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -472,12 +495,12 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testDeployAndPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { public void testDeployAndPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deployAndPowerOnVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("deployAndPowerOnVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1"); assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>", assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>",
"application/vnd.vmware.vcloud.deployVAppParams+xml", false); "application/vnd.vmware.vcloud.deployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -489,7 +512,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException { public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVApp", URI.class); Method method = VCloudAsyncClient.class.getMethod("getVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
@ -505,7 +528,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetVm() throws SecurityException, NoSuchMethodException, IOException { public void testGetVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("getVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vm/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vm/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vm/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vm/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vm+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vm+xml\n");
@ -521,10 +544,10 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testRebootVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { public void testRebootVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("rebootVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("rebootVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1");
assertNonPayloadHeadersEqual(request, ""); assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
@ -538,13 +561,13 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testUndeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { public void testUndeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("undeployVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("undeployVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>", assertPayloadEquals(request, "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false); "application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -554,17 +577,17 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
} }
public void testUndeployAndSaveStateOfVAppOrVmSaveState() throws SecurityException, NoSuchMethodException, public void testUndeployAndSaveStateOfVAppOrVmSaveState() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = VCloudAsyncClient.class.getMethod("undeployAndSaveStateOfVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("undeployAndSaveStateOfVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, assertPayloadEquals(request,
"<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>", "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>",
"application/vnd.vmware.vcloud.undeployVAppParams+xml", false); "application/vnd.vmware.vcloud.undeployVAppParams+xml", false);
assertResponseParserClassEquals(method, request, ParseSax.class); assertResponseParserClassEquals(method, request, ParseSax.class);
assertSaxResponseParserClassEquals(method, TaskHandler.class); assertSaxResponseParserClassEquals(method, TaskHandler.class);
@ -576,7 +599,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("deleteVApp", URI.class); Method method = VCloudAsyncClient.class.getMethod("deleteVApp", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, "DELETE https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); assertRequestLineEquals(request, "DELETE https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, ""); assertNonPayloadHeadersEqual(request, "");
@ -592,10 +615,10 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { public void testPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOnVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("powerOnVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
@ -609,10 +632,10 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testPowerOffVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { public void testPowerOffVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("powerOffVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("powerOffVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
@ -626,10 +649,10 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testResetVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { public void testResetVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("resetVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("resetVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
@ -643,10 +666,10 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testSuspendVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { public void testSuspendVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("suspendVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("suspendVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
@ -660,10 +683,10 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testShutdownVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { public void testShutdownVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("shutdownVAppOrVm", URI.class); Method method = VCloudAsyncClient.class.getMethod("shutdownVAppOrVm", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
assertRequestLineEquals(request, assertRequestLineEquals(request,
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1"); "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1");
assertNonPayloadHeadersEqual(request, ""); assertNonPayloadHeadersEqual(request, "");
assertPayloadEquals(request, null, null, false); assertPayloadEquals(request, null, null, false);
@ -677,7 +700,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getTask", URI.class); Method method = VCloudAsyncClient.class.getMethod("getTask", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/task/1 HTTP/1.1"); assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/task/1 HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
@ -693,7 +716,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("cancelTask", URI.class); Method method = VCloudAsyncClient.class.getMethod("cancelTask", URI.class);
HttpRequest request = processor.createRequest(method, URI HttpRequest request = processor.createRequest(method, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/task/1")); .create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/task/1/action/cancel HTTP/1.1"); assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/task/1/action/cancel HTTP/1.1");
assertNonPayloadHeadersEqual(request, ""); assertNonPayloadHeadersEqual(request, "");
@ -735,7 +758,7 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public static class VCloudRestClientModuleExtension extends VCloudRestClientModule { public static class VCloudRestClientModuleExtension extends VCloudRestClientModule {
@Override @Override
protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService, protected URI provideAuthenticationURI(VCloudVersionsAsyncClient versionService,
@Named(PROPERTY_API_VERSION) String version) { @Named(PROPERTY_API_VERSION) String version) {
return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login"); return URI.create("https://vcenterprise.bluelock.com/api/v1.0/login");
} }
@ -778,13 +801,13 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
@Override @Override
protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds, protected Supplier<VCloudSession> provideVCloudTokenCache(@Named(PROPERTY_SESSION_INTERVAL) long seconds,
final VCloudLoginAsyncClient login) { final VCloudLoginAsyncClient login) {
return Suppliers.<VCloudSession> ofInstance(new VCloudSession() { return Suppliers.<VCloudSession> ofInstance(new VCloudSession() {
@Override @Override
public Map<String, ReferenceType> getOrgs() { public Map<String, ReferenceType> getOrgs() {
return ImmutableMap.<String, ReferenceType> of("org", new ReferenceTypeImpl("org", return ImmutableMap.<String, ReferenceType> of("org", new ReferenceTypeImpl("org",
VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"))); VCloudMediaType.ORG_XML, URI.create("https://vcenterprise.bluelock.com/api/v1.0/org/1")));
} }
@Override @Override
@ -805,19 +828,44 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
} }
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache( protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) { @Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
return Suppliers.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap return Suppliers
.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of("org", .<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap
.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of(
"org",
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of("vdc", new VDCImpl("vdc", null, URI ImmutableMap
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), null, null, "description", null, .<String, org.jclouds.vcloud.domain.VDC> of(
null, null, null, null, ImmutableMap.<String, ReferenceType> of("vapp", new ReferenceTypeImpl( "vdc",
"vapp", "application/vnd.vmware.vcloud.vApp+xml", URI new VDCImpl(
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")), "network", "vdc",
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI null,
.create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))), null, 0, 0, 0, URI
false)))); .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
null,
null,
"description",
null,
null,
null,
null,
null,
ImmutableMap
.<String, ReferenceType> of(
"vapp",
new ReferenceTypeImpl(
"vapp",
"application/vnd.vmware.vcloud.vApp+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/188849-1")),
"network",
new ReferenceTypeImpl(
"network",
"application/vnd.vmware.vcloud.vAppTemplate+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))),
null, 0, 0, 0, false))));
} }
@ -831,15 +879,18 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
@Override @Override
public Map<String, Org> get() { public Map<String, Org> get() {
return ImmutableMap.<String, Org> of("org", new OrgImpl("org", null, URI return ImmutableMap.<String, Org> of("org", new OrgImpl("org", null, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org", "description", ImmutableMap .create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org", "description", ImmutableMap
.<String, ReferenceType> of("catalog", new ReferenceTypeImpl("catalog", VCloudMediaType.CATALOG_XML, .<String, ReferenceType> of("catalog", new ReferenceTypeImpl("catalog",
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap VCloudMediaType.CATALOG_XML, URI
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML, URI .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap .<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML, URI
.<String, ReferenceType> of("network", new ReferenceTypeImpl("network", VCloudMediaType.NETWORK_XML, .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap
URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1"))), new ReferenceTypeImpl( .<String, ReferenceType> of("network", new ReferenceTypeImpl("network",
"tasksList", VCloudMediaType.TASKSLIST_XML, URI VCloudMediaType.NETWORK_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")), ImmutableList.<Task> of())); .create("https://vcenterprise.bluelock.com/api/v1.0/network/1"))),
new ReferenceTypeImpl("tasksList", VCloudMediaType.TASKSLIST_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1")), ImmutableList
.<Task> of()));
} }
} }
@ -855,13 +906,14 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of("org", return ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> of("org",
ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of("catalog", new CatalogImpl("catalog", "type", ImmutableMap.<String, org.jclouds.vcloud.domain.Catalog> of("catalog", new CatalogImpl("catalog", "type",
URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description", ImmutableMap URI.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), null, "description",
.<String, ReferenceType> of("item", new ReferenceTypeImpl("item", ImmutableMap.<String, ReferenceType> of("item", new ReferenceTypeImpl("item",
"application/vnd.vmware.vcloud.catalogItem+xml", URI "application/vnd.vmware.vcloud.catalogItem+xml", URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")), "template", .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")),
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI "template", new ReferenceTypeImpl("template",
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))), "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
ImmutableList.<Task> of(), true))); .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))),
ImmutableList.<Task> of(), true)));
} }
} }
@ -873,14 +925,26 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
@Override @Override
public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() { public Map<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> get() {
return ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of( return ImmutableMap
"org", ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of( .<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
"catalog", ImmutableMap.<String, org.jclouds.vcloud.domain.CatalogItem> of("template", "org",
new CatalogItemImpl("template", URI ImmutableMap
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"), "description", .<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", "catalog",
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")), ImmutableMap
ImmutableMap.<String, String> of())))); .<String, org.jclouds.vcloud.domain.CatalogItem> of(
"template",
new CatalogItemImpl(
"template",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"),
"description",
new ReferenceTypeImpl(
"template",
"application/vnd.vmware.vcloud.vAppTemplate+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2")),
ImmutableMap.<String, String> of()))));
} }
} }

View File

@ -0,0 +1,143 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.get;
import static org.testng.Assert.assertEquals;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.jclouds.Constants;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Module;
/**
*
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = true, sequential = true, testName = "vcloud.VCloudGuestCustomizationLiveTest")
public class VCloudGuestCustomizationLiveTest {
protected String identity;
protected String provider;
protected String credential;
protected ComputeServiceContext context;
protected ComputeService client;
protected RetryablePredicate<IPSocket> socketTester;
protected Factory sshFactory;
protected void setupCredentials() {
provider = "vcloud";
identity = checkNotNull(System.getProperty("vcloud.identity"), "vcloud.identity");
credential = checkNotNull(System.getProperty("vcloud.credential"), "vcloud.credential");
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
setupCredentials();
Properties props = new Properties();
props.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
props.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
context = new ComputeServiceContextFactory().createContext(provider, identity, credential, ImmutableSet
.<Module> of(new Log4JLoggingModule()), props);
client = context.getComputeService();
Injector injector = createSshClientInjector();
sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 60, 1, TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger
}
protected Injector createSshClientInjector() {
return Guice.createInjector(getSshModule());
}
protected JschSshClientModule getSshModule() {
return new JschSshClientModule();
}
@Test
public void testExtendedOptionsWithCustomizationScript() throws Exception {
String tag = "customize";
TemplateOptions options = client.templateOptions();
options.as(VCloudTemplateOptions.class).customizationScript("cat > /root/foo.txt<<EOF\nI love candy\nEOF\n");
String nodeId = null;
try {
Set<? extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
NodeMetadata node = Iterables.get(nodes, 0);
nodeId = node.getId();
IPSocket socket = new IPSocket(get(node.getPublicAddresses(), 0), 22);
socketTester.apply(socket);
SshClient ssh = sshFactory.create(socket, node.getCredentials().identity, node.getCredentials().credential);
try {
ssh.connect();
System.out
.println(ssh
.exec("vmtoolsd --cmd=\"info-get guestinfo.ovfenv\" |grep vCloud_CustomizationInfo|sed 's/.*value=\"\\(.*\\)\".*/\\1/g'|base64 -d"));
ExecResponse hello = ssh.exec("cat /root/foo.txt");
assertEquals(hello.getOutput().trim(), "I love candy");
} finally {
if (ssh != null)
ssh.disconnect();
}
} finally {
if (nodeId != null)
client.destroyNode(nodeId);
}
}
}

View File

@ -25,6 +25,7 @@ import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay; import static org.easymock.classextension.EasyMock.replay;
import static org.easymock.classextension.EasyMock.verify; import static org.easymock.classextension.EasyMock.verify;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.customizeOnInstantiate;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -196,6 +197,46 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
binder.bindToRequest(request, map); binder.bindToRequest(request, map);
verify(request); verify(request);
}
public void testWithCustomization() throws IOException {
URI templateUri = URI.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3");
VAppTemplate template = createMock(VAppTemplate.class);
VCloudNetworkSection net = createMock(VCloudNetworkSection.class);
InstantiateVAppTemplateOptions options = customizeOnInstantiate(true);
String expected = Utils
.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-customization.xml"));
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(new Object[] { options }).atLeastOnce();
request.setPayload(expected);
expect(template.getNetworkSection()).andReturn(net).atLeastOnce();
expect(net.getNetworks())
.andReturn(
ImmutableSet
.<org.jclouds.vcloud.domain.ovf.network.Network> of(new org.jclouds.vcloud.domain.ovf.network.Network(
"vAppNet-vApp Internal", null)));
replay(request);
replay(template);
replay(net);
BindInstantiateVAppTemplateParamsToXmlPayload binder = createInjector(templateUri, template).getInstance(
BindInstantiateVAppTemplateParamsToXmlPayload.class);
Map<String, String> map = Maps.newHashMap();
map.put("name", "my-vapp");
map.put("template", "https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3");
binder.bindToRequest(request, map);
verify(request);
verify(template);
verify(net);
} }
} }

View File

@ -76,5 +76,4 @@ public class VCloudComputeServiceLiveTest extends BaseComputeServiceLiveTest {
System.out.println(allData.getExtra()); System.out.println(allData.getExtra());
} }
} }
} }

View File

@ -0,0 +1,182 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.compute.options;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.authorizePublicKey;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.blockOnPort;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.customizationScript;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.inboundPorts;
import static org.jclouds.vcloud.compute.options.VCloudTemplateOptions.Builder.installPrivateKey;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.io.Payloads;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
/**
* Tests possible uses of VCloudTemplateOptions and VCloudTemplateOptions.Builder.*
*
* @author Adrian Cole
*/
public class VCloudTemplateOptionsTest {
public void testAs() {
TemplateOptions options = new VCloudTemplateOptions();
assertEquals(options.as(VCloudTemplateOptions.class), options);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testcustomizationScriptBadFormat() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
options.customizationScript("");
}
@Test
public void testcustomizationScript() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
options.customizationScript("mykeypair");
assertEquals(options.getCustomizationScript(), "mykeypair");
}
@Test
public void testNullcustomizationScript() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
assertEquals(options.getCustomizationScript(), null);
}
@Test
public void testcustomizationScriptStatic() {
VCloudTemplateOptions options = customizationScript("mykeypair");
assertEquals(options.getCustomizationScript(), "mykeypair");
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testcustomizationScriptNPE() {
customizationScript(null);
}
@Test
public void testinstallPrivateKey() throws IOException {
VCloudTemplateOptions options = new VCloudTemplateOptions();
options.installPrivateKey(Payloads.newPayload("-----BEGIN RSA PRIVATE KEY-----"));
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
}
@Test
public void testNullinstallPrivateKey() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
assertEquals(options.getPrivateKey(), null);
}
@Test
public void testinstallPrivateKeyStatic() throws IOException {
VCloudTemplateOptions options = installPrivateKey(Payloads.newPayload("-----BEGIN RSA PRIVATE KEY-----"));
assertEquals(Utils.toStringAndClose(options.getPrivateKey().getInput()), "-----BEGIN RSA PRIVATE KEY-----");
}
@Test(expectedExceptions = NullPointerException.class)
public void testinstallPrivateKeyNPE() {
installPrivateKey(null);
}
@Test
public void testauthorizePublicKey() throws IOException {
VCloudTemplateOptions options = new VCloudTemplateOptions();
options.authorizePublicKey(Payloads.newPayload("ssh-rsa"));
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
}
@Test
public void testNullauthorizePublicKey() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
assertEquals(options.getPublicKey(), null);
}
@Test
public void testauthorizePublicKeyStatic() throws IOException {
VCloudTemplateOptions options = authorizePublicKey(Payloads.newPayload("ssh-rsa"));
assertEquals(Utils.toStringAndClose(options.getPublicKey().getInput()), "ssh-rsa");
}
@Test(expectedExceptions = NullPointerException.class)
public void testauthorizePublicKeyNPE() {
authorizePublicKey(null);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testblockOnPortBadFormat() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
options.blockOnPort(-1, -1);
}
@Test
public void testblockOnPort() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
options.blockOnPort(22, 30);
assertEquals(options.getPort(), 22);
assertEquals(options.getSeconds(), 30);
}
@Test
public void testNullblockOnPort() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
assertEquals(options.getPort(), -1);
assertEquals(options.getSeconds(), -1);
}
@Test
public void testblockOnPortStatic() {
VCloudTemplateOptions options = blockOnPort(22, 30);
assertEquals(options.getPort(), 22);
assertEquals(options.getSeconds(), 30);
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testinboundPortsBadFormat() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
options.inboundPorts(-1, -1);
}
@Test
public void testinboundPorts() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
options.inboundPorts(22, 30);
assertEquals(options.getInboundPorts()[0], 22);
assertEquals(options.getInboundPorts()[1], 30);
}
@Test
public void testDefaultOpen22() {
VCloudTemplateOptions options = new VCloudTemplateOptions();
assertEquals(options.getInboundPorts()[0], 22);
}
@Test
public void testinboundPortsStatic() {
VCloudTemplateOptions options = inboundPorts(22, 30);
assertEquals(options.getInboundPorts()[0], 22);
assertEquals(options.getInboundPorts()[1], 30);
}
}

View File

@ -20,6 +20,7 @@
package org.jclouds.vcloud.options; package org.jclouds.vcloud.options;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.customizeOnInstantiate;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.disk; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.disk;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.memory; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.memory;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
@ -77,6 +78,19 @@ public class InstantiateVAppTemplateOptionsTest {
assertEquals(options.getCpuCount(), "3"); assertEquals(options.getCpuCount(), "3");
} }
@Test
public void testCustomizeOnInstantiate() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.customizeOnInstantiate(true);
assertEquals(options.shouldCustomizeOnInstantiate(), new Boolean(true));
}
@Test
public void testCustomizeOnInstantiateStatic() {
InstantiateVAppTemplateOptions options = customizeOnInstantiate(true);
assertEquals(options.shouldCustomizeOnInstantiate(), new Boolean(true));
}
@Test @Test
public void testRam() { public void testRam() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions(); InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();

View File

@ -0,0 +1,3 @@
<GuestCustomizationSection xmlns="http://www.vmware.com/vcloud/v1" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" href="http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection" ovf:required="false" type="application/vnd.vmware.vcloud.guestCustomizationSection+xml"><ovf:Info>Specifies Guest OS Customization Settings</ovf:Info><CustomizationScript>cat &gt; /tmp/foo.txt&lt;&lt;EOF
I love candy
EOF</CustomizationScript></GuestCustomizationSection>

View File

@ -0,0 +1 @@
<InstantiateVAppTemplateParams xmlns="http://www.vmware.com/vcloud/v1" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" deploy="true" name="my-vapp" powerOn="true"><InstantiationParams><NetworkConfigSection><ovf:Info>Configuration parameters for logical networks</ovf:Info><NetworkConfig networkName="vAppNet-vApp Internal"><Configuration><ParentNetwork href="https://vcenterprise.bluelock.com/api/v1.0/network/1990"/><FenceMode>bridged</FenceMode></Configuration></NetworkConfig></NetworkConfigSection></InstantiationParams><Source href="https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"/><AllEULAsAccepted>true</AllEULAsAccepted></InstantiateVAppTemplateParams>