mirror of https://github.com/apache/jclouds.git
Issue 571:added cpu/mem update methods and tested lightly
This commit is contained in:
parent
9f1f61d3b4
commit
352a5e1cc1
|
@ -21,6 +21,7 @@ package org.jclouds.vcloud;
|
|||
import static org.jclouds.vcloud.VCloudMediaType.DEPLOYVAPPPARAMS_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.GUESTCUSTOMIZATIONSECTION_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.NETWORKCONNECTIONSECTION_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.RASDITEM_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.TASK_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.UNDEPLOYVAPPPARAMS_XML;
|
||||
import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML;
|
||||
|
@ -56,11 +57,13 @@ import org.jclouds.rest.annotations.RequestFilters;
|
|||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404;
|
||||
import org.jclouds.vcloud.binders.BindCPUCountToXmlPayload;
|
||||
import org.jclouds.vcloud.binders.BindCaptureVAppParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.binders.BindCloneVAppParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.binders.BindDeployVAppParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.binders.BindGuestCustomizationSectionToXmlPayload;
|
||||
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.binders.BindMemoryToXmlPayload;
|
||||
import org.jclouds.vcloud.binders.BindNetworkConnectionSectionToXmlPayload;
|
||||
import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload;
|
||||
import org.jclouds.vcloud.domain.GuestCustomizationSection;
|
||||
|
@ -89,7 +92,9 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
* Provides access to VCloud resources via their REST API.
|
||||
* <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
|
||||
*/
|
||||
@RequestFilters(SetVCloudTokenCookie.class)
|
||||
|
@ -216,6 +221,28 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient {
|
|||
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||
ListenableFuture<? extends Vm> getVm(@EndpointParam URI vm);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#updateCPUCountOfVm
|
||||
*/
|
||||
@PUT
|
||||
@Consumes(TASK_XML)
|
||||
@Produces(RASDITEM_XML)
|
||||
@Path("/virtualHardwareSection/cpu")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
ListenableFuture<? extends Task> updateCPUCountOfVm(@EndpointParam URI vm,
|
||||
@BinderParam(BindCPUCountToXmlPayload.class) int cpuCount);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#updateMemoryMBOfVm
|
||||
*/
|
||||
@PUT
|
||||
@Consumes(TASK_XML)
|
||||
@Produces(RASDITEM_XML)
|
||||
@Path("/virtualHardwareSection/memory")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
ListenableFuture<? extends Task> updateMemoryMBOfVm(@EndpointParam URI vm,
|
||||
@BinderParam(BindMemoryToXmlPayload.class) int memoryInMB);
|
||||
|
||||
/**
|
||||
* @see VCloudClient#updateGuestCustomizationOfVm
|
||||
*/
|
||||
|
|
|
@ -43,7 +43,9 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
|
|||
* Provides access to VCloud resources via their REST API.
|
||||
* <p/>
|
||||
*
|
||||
* @see <a href="http://communities.vmware.com/community/developer/forums/vcloudapi" />
|
||||
* @see <a
|
||||
* href="http://communities.vmware.com/community/developer/forums/vcloudapi"
|
||||
* />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
|
||||
|
@ -58,8 +60,8 @@ public interface VCloudClient extends CommonVCloudClient {
|
|||
InputStream getThumbnailOfVm(URI vm);
|
||||
|
||||
/**
|
||||
* The response to a login request includes a list of the organizations to which the
|
||||
* authenticated user has access.
|
||||
* The response to a login request includes a list of the organizations to
|
||||
* which the authenticated user has access.
|
||||
*
|
||||
* @return organizations indexed by name
|
||||
*/
|
||||
|
@ -70,8 +72,8 @@ public interface VCloudClient extends CommonVCloudClient {
|
|||
Task cloneVAppInVDC(URI vDC, URI toClone, String newName, CloneVAppOptions... options);
|
||||
|
||||
/**
|
||||
* The captureVApp request creates a vApp template from an instantiated vApp. <h4>Note</h4>
|
||||
* Before it can be captured, a vApp must be undeployed
|
||||
* The captureVApp request creates a vApp template from an instantiated vApp.
|
||||
* <h4>Note</h4> Before it can be captured, a vApp must be undeployed
|
||||
*
|
||||
* @param vDC
|
||||
* @param toClone
|
||||
|
@ -108,8 +110,9 @@ public interface VCloudClient extends CommonVCloudClient {
|
|||
Task updateNetworkConnectionOfVm(URI vm, NetworkConnectionSection 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.
|
||||
* 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
|
||||
* organization name, or null for the default
|
||||
|
@ -119,7 +122,8 @@ public interface VCloudClient extends CommonVCloudClient {
|
|||
* item you wish to lookup
|
||||
*
|
||||
* @throws NoSuchElementException
|
||||
* if you specified an org, catalog, or catalog item name that isn't present
|
||||
* if you specified an org, catalog, or catalog item name that
|
||||
* isn't present
|
||||
*/
|
||||
VAppTemplate findVAppTemplateInOrgCatalogNamed(@Nullable String orgName, @Nullable String catalogName,
|
||||
String itemName);
|
||||
|
@ -131,97 +135,129 @@ public interface VCloudClient extends CommonVCloudClient {
|
|||
Vm getVm(URI vm);
|
||||
|
||||
/**
|
||||
* To deploy a vApp, the client makes a request to its action/deploy URL. Deploying a vApp
|
||||
* automatically deploys all of the virtual machines it contains. To deploy a virtual machine,
|
||||
* the client makes a request to its action/deploy URL.
|
||||
* update the cpuCount of an existing VM
|
||||
*
|
||||
* @param vm
|
||||
* to update
|
||||
* @param cpuCount
|
||||
* count to change the primary cpu to
|
||||
*/
|
||||
Task updateCPUCountOfVm(URI vm, int cpuCount);
|
||||
|
||||
/**
|
||||
* update the memoryInMB of an existing VM
|
||||
*
|
||||
* @param vm
|
||||
* to update
|
||||
* @param memoryInMB
|
||||
* memory in MB to assign to the VM
|
||||
*/
|
||||
Task updateMemoryMBOfVm(URI vm, int memoryInMB);
|
||||
|
||||
/**
|
||||
* To deploy a vApp, the client makes a request to its action/deploy URL.
|
||||
* Deploying a vApp automatically deploys all of the virtual machines it
|
||||
* contains. To deploy a virtual machine, the client makes a request to its
|
||||
* action/deploy URL.
|
||||
* <p/>
|
||||
* Deploying a Vm implicitly deploys the parent vApp if that vApp is not already deployed.
|
||||
* Deploying a Vm implicitly deploys the parent vApp if that vApp is not
|
||||
* already deployed.
|
||||
*/
|
||||
Task deployVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
/**
|
||||
* like {@link #deployVAppOrVm(URI)}, except deploy transistions to power on state
|
||||
* like {@link #deployVAppOrVm(URI)}, except deploy transistions to power on
|
||||
* state
|
||||
*
|
||||
*/
|
||||
Task deployAndPowerOnVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
/**
|
||||
* Undeploying a vApp powers off or suspends any running virtual machines it contains, then frees
|
||||
* the resources reserved for the vApp and sets the vApp’s deploy attribute to a value of false
|
||||
* to indicate that it is not deployed.
|
||||
* Undeploying a vApp powers off or suspends any running virtual machines it
|
||||
* contains, then frees the resources reserved for the vApp and sets the
|
||||
* vApp’s deploy attribute to a value of false to indicate that it is not
|
||||
* deployed.
|
||||
* <p/>
|
||||
* Undeploying a virtual machine powers off or suspends the virtual machine, then frees the
|
||||
* resources reserved for it and sets the its deploy attribute to a value of false to indicate
|
||||
* that it is not deployed. This operation has no effect on the containing vApp.
|
||||
* Undeploying a virtual machine powers off or suspends the virtual machine,
|
||||
* then frees the resources reserved for it and sets the its deploy attribute
|
||||
* to a value of false to indicate that it is not deployed. This operation
|
||||
* has no effect on the containing vApp.
|
||||
* <h4>NOTE</h4>
|
||||
* Using this method will simply power off the vms. In order to save their state, use
|
||||
* {@link #undeployAndSaveStateOfVAppOrVm}
|
||||
* Using this method will simply power off the vms. In order to save their
|
||||
* state, use {@link #undeployAndSaveStateOfVAppOrVm}
|
||||
*
|
||||
*/
|
||||
Task undeployVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
/**
|
||||
* like {@link #undeployVAppOrVm(URI)}, where the undeployed virtual machines are suspended and
|
||||
* their suspend state saved
|
||||
* like {@link #undeployVAppOrVm(URI)}, where the undeployed virtual machines
|
||||
* are suspended and their suspend state saved
|
||||
*
|
||||
*/
|
||||
Task undeployAndSaveStateOfVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
/**
|
||||
* A powerOn request to a vApp URL powers on all of the virtual machines in the vApp, as
|
||||
* specified in the vApp’s StartupSection field.
|
||||
* A powerOn request to a vApp URL powers on all of the virtual machines in
|
||||
* the vApp, as specified in the vApp’s StartupSection field.
|
||||
* <p/>
|
||||
* A powerOn request to a virtual machine URL powers on the specified virtual machine and forces
|
||||
* deployment of the parent vApp.
|
||||
* A powerOn request to a virtual machine URL powers on the specified virtual
|
||||
* machine and forces deployment of the parent vApp.
|
||||
* <p/>
|
||||
* <h4>NOTE</h4> A powerOn request to a vApp or virtual machine that is undeployed forces
|
||||
* deployment.
|
||||
* <h4>NOTE</h4> A powerOn request to a vApp or virtual machine that is
|
||||
* undeployed forces deployment.
|
||||
*/
|
||||
Task powerOnVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
/**
|
||||
* A powerOff request to a vApp URL powers off all of the virtual machines in the vApp, as
|
||||
* specified in its StartupSection field.
|
||||
* A powerOff request to a vApp URL powers off all of the virtual machines in
|
||||
* the vApp, as specified in its StartupSection field.
|
||||
* <p/>
|
||||
* A powerOff request to a virtual machine URL powers off the specified virtual machine.
|
||||
* A powerOff request to a virtual machine URL powers off the specified
|
||||
* virtual machine.
|
||||
*/
|
||||
Task powerOffVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
/**
|
||||
* A shutdown request to a vApp URL shuts down all of the virtual machines in the vApp, as
|
||||
* specified in its StartupSection field.
|
||||
* A shutdown request to a vApp URL shuts down all of the virtual machines in
|
||||
* the vApp, as specified in its StartupSection field.
|
||||
* <p/>
|
||||
* A shutdown request to a virtual machine URL shuts down the specified virtual machine.
|
||||
* A shutdown request to a virtual machine URL shuts down the specified
|
||||
* virtual machine.
|
||||
* <p/>
|
||||
* <h4>NOTE</h4Because this request sends a signal to the guest OS, the vCloud API cannot track
|
||||
* the progress or verify the result of the requested operation. Hence, void is returned
|
||||
* <h4>NOTE</h4Because this request sends a signal to the guest OS, the
|
||||
* vCloud API cannot track the progress or verify the result of the requested
|
||||
* operation. Hence, void is returned
|
||||
*/
|
||||
void shutdownVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
/**
|
||||
* A reset request to a vApp URL resets all of the virtual machines in the vApp, as specified in
|
||||
* its StartupSection field.
|
||||
* A reset request to a vApp URL resets all of the virtual machines in the
|
||||
* vApp, as specified in its StartupSection field.
|
||||
* <p/>
|
||||
* A reset request to a virtual machine URL resets the specified virtual machine.
|
||||
* A reset request to a virtual machine URL resets the specified virtual
|
||||
* machine.
|
||||
*/
|
||||
Task resetVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
/**
|
||||
* A reboot request to a vApp URL reboots all of the virtual machines in the vApp, as specified
|
||||
* in its StartupSection field.
|
||||
* A reboot request to a vApp URL reboots all of the virtual machines in the
|
||||
* vApp, as specified in its StartupSection field.
|
||||
* <p/>
|
||||
* A reboot request to a virtual machine URL reboots the specified virtual machine.
|
||||
* A reboot request to a virtual machine URL reboots the specified virtual
|
||||
* machine.
|
||||
* <p/>
|
||||
* <h4>NOTE</h4> Because this request sends a signal to the guest OS, the vCloud API cannot track
|
||||
* the progress or verify the result of the requested operation. Hence, void is returned
|
||||
* <h4>NOTE</h4> Because this request sends a signal to the guest OS, the
|
||||
* vCloud API cannot track the progress or verify the result of the requested
|
||||
* operation. Hence, void is returned
|
||||
*/
|
||||
void rebootVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
/**
|
||||
* A suspend request to a vApp URL suspends all of the virtual machines in the vApp, as specified
|
||||
* in its StartupSection field.
|
||||
* A suspend request to a vApp URL suspends all of the virtual machines in
|
||||
* the vApp, as specified in its StartupSection field.
|
||||
* <p/>
|
||||
* A suspend request to a virtual machine URL suspends the specified virtual machine.
|
||||
* A suspend request to a virtual machine URL suspends the specified virtual
|
||||
* machine.
|
||||
*/
|
||||
Task suspendVAppOrVm(URI vAppOrVmId);
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 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.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindCPUCountToXmlPayload extends BindToStringPayload {
|
||||
protected final String ns;
|
||||
protected final String schema;
|
||||
|
||||
@Inject
|
||||
public BindCPUCountToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
|
||||
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
|
||||
this.ns = ns;
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
private static final String RESOURCE_ALLOCATION_NS = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
|
||||
checkArgument(checkNotNull(payload, "cpuCount") instanceof Integer, "this binder is only valid for Integers!");
|
||||
Integer cpuCount = Integer.class.cast(payload);
|
||||
XMLBuilder cpuItem;
|
||||
try {
|
||||
cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS);
|
||||
cpuItem.e("rasd:AllocationUnits").t("hertz * 10^6");
|
||||
cpuItem.e("rasd:Description").t("Number of Virtual CPUs");
|
||||
cpuItem.e("rasd:ElementName").t(cpuCount.toString() + " virtual CPU(s)");
|
||||
cpuItem.e("rasd:InstanceID").t("4");
|
||||
cpuItem.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value());
|
||||
cpuItem.e("rasd:VirtualQuantity").t(cpuCount.toString());
|
||||
cpuItem.e("rasd:Weight").t("0");
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
request = super.bindToRequest(request, cpuItem.asString(outputProperties));
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 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.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.inject.Inject;
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindMemoryToXmlPayload extends BindToStringPayload {
|
||||
protected final String ns;
|
||||
protected final String schema;
|
||||
|
||||
@Inject
|
||||
public BindMemoryToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
|
||||
@Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
|
||||
this.ns = ns;
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
private static final String RESOURCE_ALLOCATION_NS = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
|
||||
checkArgument(checkNotNull(payload, "memoryInMB") instanceof Integer, "this binder is only valid for Integers!");
|
||||
Integer memoryInMB = Integer.class.cast(payload);
|
||||
XMLBuilder cpuItem;
|
||||
try {
|
||||
cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS);
|
||||
cpuItem.e("rasd:AllocationUnits").t("byte * 2^20");
|
||||
cpuItem.e("rasd:Description").t("Memory Size");
|
||||
cpuItem.e("rasd:ElementName").t(memoryInMB.toString() + " MB of memory");
|
||||
cpuItem.e("rasd:InstanceID").t("5");
|
||||
cpuItem.e("rasd:Reservation").t("0");
|
||||
cpuItem.e("rasd:ResourceType").t(ResourceType.MEMORY.value());
|
||||
cpuItem.e("rasd:VirtualQuantity").t(memoryInMB.toString());
|
||||
cpuItem.e("rasd:Weight").t("0");
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
request = super.bindToRequest(request, cpuItem.asString(outputProperties));
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
}
|
|
@ -18,15 +18,13 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.compute.strategy;
|
||||
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||
|
||||
import org.jclouds.compute.domain.NodeMetadata;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
|
@ -74,21 +72,19 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
|||
|
||||
@Override
|
||||
public NodeMetadata createNodeWithGroupEncodedIntoName(String tag, String name, Template template) {
|
||||
InstantiateVAppTemplateOptions options = processorCount((int) getCores(template.getHardware())).memory(
|
||||
template.getHardware().getRam()).disk(
|
||||
(long) ((template.getHardware().getVolumes().get(0).getSize()) * 1024 * 1024l));
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
|
||||
// TODO make disk size specifiable
|
||||
// disk((long) ((template.getHardware().getVolumes().get(0).getSize()) *
|
||||
// 1024 * 1024l));
|
||||
|
||||
String customizationScript = VCloudTemplateOptions.class.cast(template.getOptions()).getCustomizationScript();
|
||||
IpAddressAllocationMode ipAddressAllocationMode = VCloudTemplateOptions.class.cast(template.getOptions())
|
||||
.getIpAddressAllocationMode();
|
||||
|
||||
String customizationScript = null;
|
||||
IpAddressAllocationMode ipAddressAllocationMode = null;
|
||||
if (template.getOptions() instanceof VCloudTemplateOptions) {
|
||||
customizationScript = VCloudTemplateOptions.class.cast(template.getOptions()).getCustomizationScript();
|
||||
ipAddressAllocationMode = VCloudTemplateOptions.class.cast(template.getOptions()).getIpAddressAllocationMode();
|
||||
if (customizationScript != null || ipAddressAllocationMode != null) {
|
||||
options.customizeOnInstantiate(false);
|
||||
options.deploy(false);
|
||||
options.powerOn(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (!template.getOptions().shouldBlockUntilRunning())
|
||||
options.block(false);
|
||||
|
@ -99,44 +95,53 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
|||
logger.debug(">> instantiating vApp vDC(%s) template(%s) name(%s) options(%s) ", VDC, templateId, name, options);
|
||||
|
||||
VApp vAppResponse = client.instantiateVAppTemplateInVDC(VDC, templateId, name, options);
|
||||
waitForTask(vAppResponse.getTasks().get(0), vAppResponse);
|
||||
logger.debug("<< instantiated VApp(%s)", vAppResponse.getName());
|
||||
|
||||
Task task = vAppResponse.getTasks().get(0);
|
||||
|
||||
if (customizationScript == null && ipAddressAllocationMode == 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));
|
||||
}
|
||||
// note customization is a serial concern at the moment
|
||||
Vm vm = Iterables.get(client.getVApp(vAppResponse.getHref()).getChildren(), 0);
|
||||
if (customizationScript != null)
|
||||
updateVmWithCustomizationScript(vm, customizationScript);
|
||||
if (ipAddressAllocationMode != null)
|
||||
updateVmWithIpAddressAllocationMode(vm, ipAddressAllocationMode);
|
||||
task = client.deployAndPowerOnVAppOrVm(vAppResponse.getHref());
|
||||
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse, task);
|
||||
if (customizationScript != null) {
|
||||
logger.trace(">> updating customization vm(%s) ", vm.getName());
|
||||
waitForTask(updateVmWithCustomizationScript(vm, customizationScript), vAppResponse);
|
||||
logger.trace("<< updated customization vm(%s) ", vm.getName());
|
||||
}
|
||||
if (ipAddressAllocationMode != null) {
|
||||
logger.trace(">> updating ipAddressAllocationMode(%s) vm(%s) ", ipAddressAllocationMode, vm.getName());
|
||||
waitForTask(updateVmWithIpAddressAllocationMode(vm, ipAddressAllocationMode), vAppResponse);
|
||||
logger.trace("<< updated ipAddressAllocationMode vm(%s) ", vm.getName());
|
||||
}
|
||||
int cpuCount = new Double(getCores(template.getHardware())).intValue();
|
||||
logger.trace(">> updating cpuCount(%d) vm(%s) ", cpuCount, vm.getName());
|
||||
waitForTask(updateCPUCountOfVm(vm, cpuCount), vAppResponse);
|
||||
logger.trace("<< updated cpuCount vm(%s) ", vm.getName());
|
||||
int memoryMB = template.getHardware().getRam();
|
||||
logger.trace(">> updating memoryMB(%d) vm(%s) ", memoryMB, vm.getName());
|
||||
waitForTask(updateMemoryMBOfVm(vm, memoryMB), vAppResponse);
|
||||
logger.trace("<< updated memoryMB vm(%s) ", vm.getName());
|
||||
logger.trace(">> deploying and powering on vApp(%s) ", vAppResponse.getName());
|
||||
return blockOnDeployAndPowerOnIfConfigured(options, vAppResponse,
|
||||
client.deployAndPowerOnVAppOrVm(vAppResponse.getHref()));
|
||||
|
||||
}
|
||||
|
||||
public void updateVmWithCustomizationScript(Vm vm, String customizationScript) {
|
||||
Task task;
|
||||
public void waitForTask(Task task, VApp vAppResponse) {
|
||||
if (!successTester.apply(task.getHref())) {
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", task.getName(), vAppResponse.getName(), task));
|
||||
}
|
||||
}
|
||||
|
||||
public Task updateVmWithCustomizationScript(Vm vm, String customizationScript) {
|
||||
GuestCustomizationSection guestConfiguration = vm.getGuestCustomizationSection();
|
||||
// TODO: determine if the server version is beyond 1.0.0, and if so append to, but
|
||||
// not overwrite the customization script. In version 1.0.0, the api returns a script that
|
||||
// TODO: determine if the server version is beyond 1.0.0, and if so append
|
||||
// to, but
|
||||
// not overwrite the customization script. In version 1.0.0, the api
|
||||
// returns a script that
|
||||
// loses newlines.
|
||||
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));
|
||||
}
|
||||
return client.updateGuestCustomizationOfVm(vm.getHref(), guestConfiguration);
|
||||
}
|
||||
|
||||
public void updateVmWithIpAddressAllocationMode(Vm vm, final IpAddressAllocationMode ipAddressAllocationMode) {
|
||||
Task task;
|
||||
public Task updateVmWithIpAddressAllocationMode(Vm vm, final IpAddressAllocationMode ipAddressAllocationMode) {
|
||||
NetworkConnectionSection net = vm.getNetworkConnectionSection();
|
||||
Builder builder = net.toBuilder();
|
||||
builder.connections(Iterables.transform(net.getConnections(),
|
||||
|
@ -148,20 +153,21 @@ public class InstantiateVAppTemplateWithGroupEncodedIntoNameThenCustomizeDeployA
|
|||
}
|
||||
|
||||
}));
|
||||
task = client.updateNetworkConnectionOfVm(vm.getHref(), builder.build());
|
||||
if (!successTester.apply(task.getHref())) {
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "updateNetworkConnectionOfVm", vm.getName(),
|
||||
task));
|
||||
return client.updateNetworkConnectionOfVm(vm.getHref(), builder.build());
|
||||
}
|
||||
|
||||
public Task updateCPUCountOfVm(Vm vm, int cpuCount) {
|
||||
return client.updateCPUCountOfVm(vm.getHref(), cpuCount);
|
||||
}
|
||||
|
||||
public Task updateMemoryMBOfVm(Vm vm, int memoryInMB) {
|
||||
return client.updateMemoryMBOfVm(vm.getHref(), memoryInMB);
|
||||
}
|
||||
|
||||
private NodeMetadata blockOnDeployAndPowerOnIfConfigured(InstantiateVAppTemplateOptions options, VApp vAppResponse,
|
||||
Task task) {
|
||||
if (options.shouldBlock()) {
|
||||
if (!successTester.apply(task.getHref())) {
|
||||
throw new RuntimeException(String.format("failed to %s %s: %s", "deploy and power on",
|
||||
vAppResponse.getName(), task));
|
||||
}
|
||||
waitForTask(task, vAppResponse);
|
||||
logger.debug("<< ready vApp(%s)", vAppResponse.getName());
|
||||
}
|
||||
return getNode.getNode(vAppResponse.getHref().toASCIIString());
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 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.options;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.vcloud.domain.network.NetworkConfig;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class InstantiateVAppTemplateOptions {
|
||||
private Set<NetworkConfig> networkConfig = Sets.newLinkedHashSet();
|
||||
|
||||
private Boolean customizeOnInstantiate;
|
||||
|
||||
private boolean block = true;
|
||||
private boolean deploy = true;
|
||||
private boolean powerOn = true;
|
||||
|
||||
public boolean shouldBlock() {
|
||||
return block;
|
||||
}
|
||||
|
||||
public boolean shouldDeploy() {
|
||||
return deploy;
|
||||
}
|
||||
|
||||
public boolean shouldPowerOn() {
|
||||
return powerOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* deploy the vapp after it is instantiated?
|
||||
*/
|
||||
public InstantiateVAppTemplateOptions deploy(boolean deploy) {
|
||||
this.deploy = deploy;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* powerOn the vapp after it is instantiated?
|
||||
*/
|
||||
public InstantiateVAppTemplateOptions powerOn(boolean powerOn) {
|
||||
this.powerOn = powerOn;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* block until instantiate or deployment operations complete?
|
||||
*/
|
||||
public InstantiateVAppTemplateOptions block(boolean block) {
|
||||
this.block = block;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@networkConfig VAppTemplate}s have internal networks that can be
|
||||
* connected in order to access the internet or other external networks.
|
||||
*
|
||||
* <h4>default behaviour if you don't use this option</h4> By default, we
|
||||
* connect the first internal {@networkConfig
|
||||
* org.jclouds.vcloud.domain.VAppTemplate#getNetworkSection network in the
|
||||
* vapp template}to a default chosen from the org or specified via
|
||||
* {@networkConfig
|
||||
* org.jclouds.vcloud.reference.VCloudConstants#
|
||||
* PROPERTY_VCLOUD_DEFAULT_NETWORK} using the {@networkConfig
|
||||
* org.jclouds.vcloud.domain.FenceMode#BRIDGED} or an
|
||||
* override set by the property {@networkConfig
|
||||
* org.jclouds.vcloud.reference.VCloudConstants#
|
||||
* PROPERTY_VCLOUD_DEFAULT_FENCEMODE}.
|
||||
*/
|
||||
public InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) {
|
||||
this.networkConfig.add(checkNotNull(networkConfig, "networkConfig"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Set<NetworkConfig> getNetworkConfig() {
|
||||
return networkConfig;
|
||||
}
|
||||
|
||||
public Boolean shouldCustomizeOnInstantiate() {
|
||||
return customizeOnInstantiate;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#block
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions block(boolean block) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.block(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#deploy
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions deploy(boolean deploy) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.deploy(deploy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#powerOn
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions powerOn(boolean powerOn) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.powerOn(powerOn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#customizeOnInstantiate
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions customizeOnInstantiate(Boolean customizeOnInstantiate) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.customizeOnInstantiate(customizeOnInstantiate);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see InstantiateVAppTemplateOptions#addNetworkConfig
|
||||
*/
|
||||
public static InstantiateVAppTemplateOptions addNetworkConfig(NetworkConfig networkConfig) {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
return options.addNetworkConfig(networkConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[networkConfig=" + networkConfig + ", customizeOnInstantiate=" + customizeOnInstantiate + ", deploy="
|
||||
+ (deploy) + ", powerOn=" + (powerOn) + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (block ? 1231 : 1237);
|
||||
result = prime * result + ((customizeOnInstantiate == null) ? 0 : customizeOnInstantiate.hashCode());
|
||||
result = prime * result + (deploy ? 1231 : 1237);
|
||||
result = prime * result + ((networkConfig == null) ? 0 : networkConfig.hashCode());
|
||||
result = prime * result + (powerOn ? 1231 : 1237);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
InstantiateVAppTemplateOptions other = (InstantiateVAppTemplateOptions) obj;
|
||||
if (block != other.block)
|
||||
return false;
|
||||
if (customizeOnInstantiate == null) {
|
||||
if (other.customizeOnInstantiate != null)
|
||||
return false;
|
||||
} else if (!customizeOnInstantiate.equals(other.customizeOnInstantiate))
|
||||
return false;
|
||||
if (deploy != other.deploy)
|
||||
return false;
|
||||
if (networkConfig == null) {
|
||||
if (other.networkConfig != null)
|
||||
return false;
|
||||
} else if (!networkConfig.equals(other.networkConfig))
|
||||
return false;
|
||||
if (powerOn != other.powerOn)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,7 +22,6 @@ import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
|||
import static org.jclouds.Constants.PROPERTY_IDENTITY;
|
||||
import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -92,13 +91,13 @@ import com.google.inject.Injector;
|
|||
import com.google.inject.Module;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code VCloudAsyncClient}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||
// NOTE:without testName, this will not call @Before* and fail w/NPE during
|
||||
// surefire
|
||||
@Test(groups = "unit", testName = "VCloudAsyncClientTest")
|
||||
public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
||||
|
||||
|
@ -121,8 +120,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
public void testUpdateGuestConfiguration() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("updateGuestCustomizationOfVm", URI.class,
|
||||
GuestCustomizationSection.class);
|
||||
GuestCustomizationSection guest = new GuestCustomizationSection(URI
|
||||
.create("http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection"));
|
||||
GuestCustomizationSection guest = new GuestCustomizationSection(
|
||||
URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12/guestCustomizationSection"));
|
||||
guest.setCustomizationScript("cat > /tmp/foo.txt<<EOF\nI love candy\nEOF");
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"), guest);
|
||||
|
@ -130,8 +129,45 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
assertRequestLineEquals(request,
|
||||
"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, Strings2.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/guestCustomizationSection.xml")), "application/vnd.vmware.vcloud.guestCustomizationSection+xml", false);
|
||||
assertPayloadEquals(request,
|
||||
Strings2.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 testUpdateCPUCountOfVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("updateCPUCountOfVm", URI.class, int.class);
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"), 2);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/virtualHardwareSection/cpu HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/cpuItem.xml")),
|
||||
"application/vnd.vmware.vcloud.rasdItem+xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TaskHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testUpdateMemoryMBOfVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("updateMemoryMBOfVm", URI.class, int.class);
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("http://vcloud.example.com/api/v1.0/vApp/vm-12"), 512);
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"PUT http://vcloud.example.com/api/v1.0/vApp/vm-12/virtualHardwareSection/memory HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/memoryItem.xml")),
|
||||
"application/vnd.vmware.vcloud.rasdItem+xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TaskHandler.class);
|
||||
|
@ -144,18 +180,20 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
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",
|
||||
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");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/instantiationparams-network.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml",
|
||||
false);
|
||||
assertPayloadEquals(request,
|
||||
Strings2.toStringAndClose(getClass().getResourceAsStream("/instantiationparams-network.xml")),
|
||||
"application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, VAppHandler.class);
|
||||
|
@ -169,19 +207,21 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("instantiateVAppTemplateInVDC", URI.class, URI.class,
|
||||
String.class, InstantiateVAppTemplateOptions[].class);
|
||||
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"), "CentOS 01", processorCount(1).memory(512)
|
||||
.disk(1024).addNetworkConfig(
|
||||
new NetworkConfig(null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"),
|
||||
null)));
|
||||
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"),
|
||||
"CentOS 01",
|
||||
addNetworkConfig(new NetworkConfig(null, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), null)));
|
||||
}
|
||||
|
||||
public void testCloneVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class,
|
||||
CloneVAppOptions[].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/vapp/4181"), "my-vapp");
|
||||
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/vapp/4181"), "my-vapp");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1");
|
||||
|
@ -199,9 +239,9 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
public void testCloneVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("cloneVAppInVDC", URI.class, URI.class, String.class,
|
||||
CloneVAppOptions[].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/vapp/201"), "new-linux-server",
|
||||
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/vapp/201"), "new-linux-server",
|
||||
new CloneVAppOptions().deploy().powerOn().withDescription("The description of the new vApp"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
|
@ -220,14 +260,15 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
public void testCaptureVAppInVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("captureVAppInVDC", URI.class, URI.class, String.class,
|
||||
CaptureVAppOptions[].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/vapp/4181"), "my-template");
|
||||
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/vapp/4181"), "my-template");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp-default.xml")),
|
||||
assertPayloadEquals(request,
|
||||
Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp-default.xml")),
|
||||
"application/vnd.vmware.vcloud.captureVAppParams+xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
|
@ -240,10 +281,10 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
public void testCaptureVAppInVDCOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("captureVAppInVDC", URI.class, URI.class, String.class,
|
||||
CaptureVAppOptions[].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/vapp/201"), "my-template", new CaptureVAppOptions()
|
||||
.withDescription("The description of the new vApp Template"));
|
||||
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/vapp/201"), "my-template",
|
||||
new CaptureVAppOptions().withDescription("The description of the new vApp Template"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1");
|
||||
|
@ -275,8 +316,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testOrg() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getOrg", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n");
|
||||
|
@ -306,8 +347,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getCatalog", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
|
||||
|
@ -337,8 +378,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getNetwork", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/network/2"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n");
|
||||
|
@ -369,8 +410,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getCatalogItem", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n");
|
||||
|
@ -417,8 +458,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getVAppTemplate", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n");
|
||||
|
@ -433,8 +474,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testGetOvfEnvelopeForVAppTemplate() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getOvfEnvelopeForVAppTemplate", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: text/xml\n");
|
||||
|
@ -506,8 +547,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getVDC", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n");
|
||||
|
@ -522,8 +563,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getTasksList", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n");
|
||||
|
@ -553,8 +594,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testDeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("deployVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
|
@ -570,8 +611,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testDeployAndPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("deployAndPowerOnVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
|
@ -587,8 +628,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getVApp", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
|
||||
|
@ -603,8 +644,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testGetVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vm/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vm+xml\n");
|
||||
|
@ -619,8 +660,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testRebootVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("rebootVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1");
|
||||
|
@ -636,8 +677,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testUndeployVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("undeployVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
|
||||
|
@ -655,8 +696,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
public void testUndeployAndSaveStateOfVAppOrVmSaveState() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("undeployAndSaveStateOfVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1");
|
||||
|
@ -674,8 +715,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("deleteVApp", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -690,8 +731,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testPowerOnVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("powerOnVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1");
|
||||
|
@ -707,8 +748,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testPowerOffVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("powerOffVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1");
|
||||
|
@ -724,8 +765,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testResetVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("resetVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1");
|
||||
|
@ -741,8 +782,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testSuspendVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("suspendVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1");
|
||||
|
@ -758,8 +799,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testShutdownVAppOrVm() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("shutdownVAppOrVm", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1");
|
||||
|
@ -775,8 +816,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("getTask", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
|
@ -791,8 +832,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudAsyncClient.class.getMethod("cancelTask", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/task/1"));
|
||||
HttpRequest request = processor.createRequest(method,
|
||||
URI.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");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
|
@ -912,43 +953,21 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
protected Supplier<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> provideOrgVDCSupplierCache(
|
||||
@Named(PROPERTY_SESSION_INTERVAL) long seconds, final OrgVDCSupplier supplier) {
|
||||
|
||||
return Suppliers
|
||||
.<Map<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>>> ofInstance(ImmutableMap
|
||||
.<String, Map<String, ? extends org.jclouds.vcloud.domain.VDC>> of(
|
||||
"org",
|
||||
return Suppliers.<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(
|
||||
ImmutableMap.<String, org.jclouds.vcloud.domain.VDC> of(
|
||||
"vdc",
|
||||
new VDCImpl(
|
||||
"vdc",
|
||||
null,
|
||||
URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
|
||||
VDCStatus.READY,
|
||||
null,
|
||||
"description",
|
||||
ImmutableSet.<Task> of(),
|
||||
AllocationModel.ALLOCATION_POOL,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
ImmutableMap
|
||||
.<String, ReferenceType> of(
|
||||
new VDCImpl("vdc", null, URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"),
|
||||
VDCStatus.READY, null, "description", ImmutableSet.<Task> of(),
|
||||
AllocationModel.ALLOCATION_POOL, null, null, null, ImmutableMap.<String, ReferenceType> of(
|
||||
"vapp",
|
||||
new ReferenceTypeImpl(
|
||||
"vapp",
|
||||
"application/vnd.vmware.vcloud.vApp+xml",
|
||||
URI
|
||||
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"))),
|
||||
ImmutableMap.<String, ReferenceType> of(), 0, 0, 0,
|
||||
false))));
|
||||
new ReferenceTypeImpl("network", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vdcItem/2"))), ImmutableMap
|
||||
.<String, ReferenceType> of(), 0, 0, 0, false))));
|
||||
|
||||
}
|
||||
|
||||
|
@ -961,15 +980,18 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
@Override
|
||||
public Map<String, Org> get() {
|
||||
return ImmutableMap.<String, Org> of("org", new OrgImpl("org", null, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/org/1"), "org", "description", ImmutableMap
|
||||
.<String, ReferenceType> of("catalog", new ReferenceTypeImpl("catalog",
|
||||
VCloudMediaType.CATALOG_XML, 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.<String, ReferenceType> of(
|
||||
"catalog",
|
||||
new ReferenceTypeImpl("catalog", VCloudMediaType.CATALOG_XML, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))), ImmutableMap
|
||||
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML, URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap
|
||||
.<String, ReferenceType> of("network", new ReferenceTypeImpl("network",
|
||||
VCloudMediaType.NETWORK_XML, URI
|
||||
.<String, ReferenceType> of("vdc", new ReferenceTypeImpl("vdc", VCloudMediaType.VDC_XML,
|
||||
URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))), ImmutableMap
|
||||
.<String, ReferenceType> of(
|
||||
"network",
|
||||
new ReferenceTypeImpl("network", VCloudMediaType.NETWORK_XML, URI
|
||||
.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
|
||||
|
@ -988,13 +1010,16 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
public Map<String, Map<String, ? extends org.jclouds.vcloud.domain.Catalog>> get() {
|
||||
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.<String, ReferenceType> of("item", new ReferenceTypeImpl("item",
|
||||
"application/vnd.vmware.vcloud.catalogItem+xml", URI
|
||||
ImmutableMap.<String, ReferenceType> of(
|
||||
"item",
|
||||
new ReferenceTypeImpl("item", "application/vnd.vmware.vcloud.catalogItem+xml", URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1")),
|
||||
"template", new ReferenceTypeImpl("template",
|
||||
"application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
||||
"template",
|
||||
new ReferenceTypeImpl("template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI
|
||||
.create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))),
|
||||
ImmutableList.<Task> of(), true)));
|
||||
}
|
||||
|
@ -1008,25 +1033,14 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
|
|||
|
||||
@Override
|
||||
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(
|
||||
"org",
|
||||
ImmutableMap
|
||||
.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(
|
||||
"catalog",
|
||||
ImmutableMap
|
||||
.<String, org.jclouds.vcloud.domain.CatalogItem> of(
|
||||
return ImmutableMap.<String, Map<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>>> of(
|
||||
"org", ImmutableMap.<String, Map<String, ? extends org.jclouds.vcloud.domain.CatalogItem>> of(
|
||||
"catalog", ImmutableMap.<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")),
|
||||
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()))));
|
||||
|
||||
}
|
||||
|
|
|
@ -152,7 +152,6 @@ public class BindInstantiateVAppTemplateParamsToXmlPayloadTest {
|
|||
VAppTemplate template = null;
|
||||
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
options.processorCount(1).memory(512).disk(1024);
|
||||
|
||||
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/instantiationparams.xml"));
|
||||
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2011 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.options;
|
||||
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig;
|
||||
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.customizeOnInstantiate;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.functions.config.SaxParserModule;
|
||||
import org.jclouds.vcloud.domain.network.FenceMode;
|
||||
import org.jclouds.vcloud.domain.network.NetworkConfig;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code InstantiateVAppTemplateOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class InstantiateVAppTemplateOptionsTest {
|
||||
|
||||
Injector injector = Guice.createInjector(new SaxParserModule());
|
||||
|
||||
@Test
|
||||
public void testAddNetworkConfig() {
|
||||
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
|
||||
options.addNetworkConfig(new NetworkConfig("default", URI.create("http://localhost"), FenceMode.BRIDGED));
|
||||
assertEquals(Iterables.get(options.getNetworkConfig(), 0).getNetworkName(), "default");
|
||||
assertEquals(Iterables.get(options.getNetworkConfig(), 0).getParentNetwork(), URI.create("http://localhost"));
|
||||
assertEquals(Iterables.get(options.getNetworkConfig(), 0).getFenceMode(), FenceMode.BRIDGED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddNetworkConfigStatic() {
|
||||
InstantiateVAppTemplateOptions options = addNetworkConfig(new NetworkConfig("default",
|
||||
URI.create("http://localhost"), FenceMode.BRIDGED));
|
||||
assertEquals(Iterables.get(options.getNetworkConfig(), 0).getNetworkName(), "default");
|
||||
assertEquals(Iterables.get(options.getNetworkConfig(), 0).getParentNetwork(), URI.create("http://localhost"));
|
||||
assertEquals(Iterables.get(options.getNetworkConfig(), 0).getFenceMode(), FenceMode.BRIDGED);
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
<Item xmlns="http://www.vmware.com/vcloud/v1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"><rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits><rasd:Description>Number of Virtual CPUs</rasd:Description><rasd:ElementName>2 virtual CPU(s)</rasd:ElementName><rasd:InstanceID>4</rasd:InstanceID><rasd:ResourceType>3</rasd:ResourceType><rasd:VirtualQuantity>2</rasd:VirtualQuantity><rasd:Weight>0</rasd:Weight></Item>
|
|
@ -0,0 +1 @@
|
|||
<Item xmlns="http://www.vmware.com/vcloud/v1" xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"><rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits><rasd:Description>Memory Size</rasd:Description><rasd:ElementName>512 MB of memory</rasd:ElementName><rasd:InstanceID>5</rasd:InstanceID><rasd:Reservation>0</rasd:Reservation><rasd:ResourceType>4</rasd:ResourceType><rasd:VirtualQuantity>512</rasd:VirtualQuantity><rasd:Weight>0</rasd:Weight></Item>
|
|
@ -202,4 +202,13 @@ public interface VCloudMediaType {
|
|||
*/
|
||||
public final static MediaType NETWORK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.network+xml");
|
||||
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.rasdItem+xml"
|
||||
*/
|
||||
public final static String RASDITEM_XML = "application/vnd.vmware.vcloud.rasdItem+xml";
|
||||
/**
|
||||
* "application/vnd.vmware.vcloud.rasdItem+xml"
|
||||
*/
|
||||
public final static MediaType RASDITEM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.rasdItem+xml");
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue