mirror of https://github.com/apache/jclouds.git
Issue 435 added more test cases to savvis and cleaned up VMSpec binding
This commit is contained in:
parent
b9f6484940
commit
37587fdfeb
|
@ -53,11 +53,11 @@
|
|||
<properties>
|
||||
<!-- when instances are hung, open a ticket and add here -->
|
||||
<jclouds.compute.blacklist-nodes>node-924</jclouds.compute.blacklist-nodes>
|
||||
<test.savvis-symphonyvpdc.endpoint>https://api.symphonyvpdc.savvis.net/rest/api</test.savvis-symphonyvpdc.endpoint>
|
||||
<test.savvis-symphonyvpdc.apiversion>0.8</test.savvis-symphonyvpdc.apiversion>
|
||||
<test.savvis-symphonyvpdc.endpoint>https://api.symphonyvpdc.savvis.net/vpdc</test.savvis-symphonyvpdc.endpoint>
|
||||
<test.savvis-symphonyvpdc.apiversion>1.0</test.savvis-symphonyvpdc.apiversion>
|
||||
<test.savvis-symphonyvpdc.identity>FIXME</test.savvis-symphonyvpdc.identity>
|
||||
<test.savvis-symphonyvpdc.credential>FIXME</test.savvis-symphonyvpdc.credential>
|
||||
<test.savvis-symphonyvpdc.vpdc-email>FIXME</test.savvis-symphonyvpdc.vpdc-email>
|
||||
<test.savvis-symphonyvpdc.vdc-email>FIXME</test.savvis-symphonyvpdc.vdc-email>
|
||||
<test.savvis-symphonyvpdc.loginUser>FIXME</test.savvis-symphonyvpdc.loginUser>
|
||||
<test.savvis-symphonyvpdc.loginPassword>FIXME</test.savvis-symphonyvpdc.loginPassword>
|
||||
</properties>
|
||||
|
@ -144,7 +144,7 @@
|
|||
<value>${test.savvis-symphonyvpdc.credential}</value>
|
||||
</property>
|
||||
<property>
|
||||
<name>savvis-symphonyvpdc.vpdc-email</name>
|
||||
<name>test.savvis-symphonyvpdc.vdc-email</name>
|
||||
<value>${test.savvis-symphonyvpdc.vdc-email}</value>
|
||||
</property>
|
||||
<property>
|
||||
|
|
|
@ -0,0 +1,210 @@
|
|||
/**
|
||||
*
|
||||
* 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.savvis.vpdc.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
|
||||
import org.jclouds.compute.domain.CIMOperatingSystem;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.savvis.vpdc.domain.VMSpec;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public abstract class BaseBindVMSpecToXmlPayload<T> extends BindToStringPayload implements MapBinder {
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
|
||||
throw new IllegalStateException("BindVMSpecToXmlPayload needs parameters");
|
||||
}
|
||||
|
||||
protected abstract T findSpecInArgsOrNull(GeneratedHttpRequest<?> gRequest);
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
|
||||
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
|
||||
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
|
||||
|
||||
request = super.bindToRequest(request, generateXml(findSpecInArgsOrNull(gRequest)));
|
||||
request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_XML);
|
||||
return request;
|
||||
}
|
||||
|
||||
public String generateXml(T spec) {
|
||||
try {
|
||||
XMLBuilder rootBuilder = buildRoot();
|
||||
bindSpec(spec, rootBuilder);
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
return rootBuilder.asString(outputProperties);
|
||||
} catch (Exception e) {
|
||||
Throwables.propagate(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void bindSpec(T spec, XMLBuilder rootBuilder) throws ParserConfigurationException,
|
||||
FactoryConfigurationError;
|
||||
|
||||
protected void checkSpec(VMSpec spec) {
|
||||
checkNotNull(spec, "VMSpec");
|
||||
checkNotNull(spec.getName(), "name");
|
||||
checkNotNull(spec.getNetworkTierName(), "networkTierName");
|
||||
}
|
||||
|
||||
protected void addOperatingSystemAndVirtualHardware(VMSpec spec, XMLBuilder vAppBuilder) {
|
||||
addOperatingSystemSection(vAppBuilder, spec.getOperatingSystem());
|
||||
// TODO: Savvis returns network names with a - instead of space on getNetworkInVDC
|
||||
// call,
|
||||
// fix this once savvis api starts returning correctly
|
||||
addVirtualHardwareSection(vAppBuilder, spec.getName(), spec.getNetworkTierName().replace("-", " "), spec);
|
||||
}
|
||||
|
||||
void addVirtualHardwareSection(XMLBuilder rootBuilder, String name, String networkName, VMSpec spec) {
|
||||
XMLBuilder virtualHardwareSectionBuilder = rootBuilder.e("ovf:VirtualHardwareSection");
|
||||
virtualHardwareSectionBuilder.e("ovf:Info").t("Virtual Hardware");
|
||||
addSystem(virtualHardwareSectionBuilder, name);
|
||||
addItems(virtualHardwareSectionBuilder, spec, networkName);
|
||||
}
|
||||
|
||||
void addItems(XMLBuilder virtualHardwareSectionBuilder, VMSpec spec, String networkName) {
|
||||
// todo make this work with fractional, which I think means setting speed to half
|
||||
addCPU(virtualHardwareSectionBuilder, (int) spec.getProcessorCount());
|
||||
addMemory(virtualHardwareSectionBuilder, spec.getMemoryInGig());
|
||||
addNetwork(virtualHardwareSectionBuilder, networkName);
|
||||
addDisks(virtualHardwareSectionBuilder, spec);
|
||||
}
|
||||
|
||||
private void addSystem(XMLBuilder virtualHardwareSectionBuilder, String name) {
|
||||
XMLBuilder systemBuilder = virtualHardwareSectionBuilder.e("ovf:System");
|
||||
systemBuilder.e("vssd:Description").t("Virtual Hardware Family");
|
||||
systemBuilder.e("vssd:ElementName").t(name);
|
||||
systemBuilder.e("vssd:InstanceID").t("1");
|
||||
systemBuilder.e("vssd:VirtualSystemIdentifier").t(name);
|
||||
}
|
||||
|
||||
private void addOperatingSystemSection(XMLBuilder rootBuilder, CIMOperatingSystem operatingSystem) {
|
||||
XMLBuilder sectionBuilder = rootBuilder.e("ovf:OperatingSystemSection").a("ovf:id",
|
||||
operatingSystem.getOsType().getCode() + "");
|
||||
sectionBuilder.e("ovf:Info").t("Specifies the operating system installed");
|
||||
sectionBuilder.e("ovf:Description").t(operatingSystem.getDescription());
|
||||
}
|
||||
|
||||
private void addCPU(XMLBuilder sectionBuilder, int processorCount) {
|
||||
XMLBuilder cpuBuilder = sectionBuilder.e("ovf:Item");
|
||||
cpuBuilder.e("rasd:AllocationUnits").t("3 GHz");
|
||||
cpuBuilder.e("rasd:Description").t("Number of Virtual CPUs");
|
||||
cpuBuilder.e("rasd:ElementName").t(processorCount + " CPU");
|
||||
cpuBuilder.e("rasd:InstanceID").t("1");
|
||||
cpuBuilder.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value());
|
||||
cpuBuilder.e("rasd:VirtualQuantity").t(processorCount + "");
|
||||
}
|
||||
|
||||
private void addMemory(XMLBuilder sectionBuilder, int memoryInGig) {
|
||||
XMLBuilder memoryBuilder = sectionBuilder.e("ovf:Item");
|
||||
memoryBuilder.e("rasd:AllocationUnits").t("Gigabytes");
|
||||
memoryBuilder.e("rasd:Description").t("Memory Size");
|
||||
memoryBuilder.e("rasd:ElementName").t("Memory");
|
||||
memoryBuilder.e("rasd:InstanceID").t("2");
|
||||
memoryBuilder.e("rasd:ResourceType").t(ResourceType.MEMORY.value());
|
||||
memoryBuilder.e("rasd:VirtualQuantity").t(memoryInGig + "");
|
||||
}
|
||||
|
||||
private void addNetwork(XMLBuilder sectionBuilder, String networkName) {
|
||||
XMLBuilder networkBuilder = sectionBuilder.e("ovf:Item");
|
||||
networkBuilder.e("rasd:Caption").t("false");
|
||||
networkBuilder.e("rasd:Connection").t(networkName);
|
||||
networkBuilder.e("rasd:ElementName").t("Network");
|
||||
networkBuilder.e("rasd:InstanceID").t("3");
|
||||
networkBuilder.e("rasd:ResourceType").t(ResourceType.ETHERNET_ADAPTER.value());
|
||||
networkBuilder.e("rasd:VirtualQuantity").t("1");
|
||||
}
|
||||
|
||||
private void addDisks(XMLBuilder sectionBuilder, VMSpec spec) {
|
||||
XMLBuilder bootDiskBuilder = sectionBuilder.e("ovf:Item");
|
||||
bootDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes");
|
||||
bootDiskBuilder.e("rasd:Caption").t("");
|
||||
bootDiskBuilder.e("rasd:Description").t("Hard Disk");
|
||||
bootDiskBuilder.e("rasd:ElementName").t(spec.getBootDeviceName());
|
||||
bootDiskBuilder.e("rasd:HostResource").t("boot");
|
||||
bootDiskBuilder.e("rasd:InstanceID").t("4");
|
||||
bootDiskBuilder.e("rasd:ResourceType").t(ResourceType.BASE_PARTITIONABLE_UNIT.value());
|
||||
bootDiskBuilder.e("rasd:VirtualQuantity").t(spec.getBootDiskSize() + "");
|
||||
|
||||
int instanceId = 5;
|
||||
for (Entry<String, Integer> dataDisk : spec.getDataDiskDeviceNameToSizeInGig().entrySet()) {
|
||||
XMLBuilder dataDiskBuilder = sectionBuilder.e("ovf:Item");
|
||||
dataDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes");
|
||||
dataDiskBuilder.e("rasd:Caption").t("");
|
||||
dataDiskBuilder.e("rasd:Description").t("Hard Disk");
|
||||
dataDiskBuilder.e("rasd:ElementName").t(dataDisk.getKey());
|
||||
dataDiskBuilder.e("rasd:HostResource").t("data");
|
||||
dataDiskBuilder.e("rasd:InstanceID").t("" + instanceId++);
|
||||
dataDiskBuilder.e("rasd:ResourceType").t(ResourceType.PARTITIONABLE_UNIT.value());
|
||||
dataDiskBuilder.e("rasd:VirtualQuantity").t(dataDisk.getValue() + "");
|
||||
}
|
||||
}
|
||||
|
||||
protected XMLBuilder buildRoot() throws ParserConfigurationException, FactoryConfigurationError {
|
||||
XMLBuilder rootBuilder = XMLBuilder.create("vApp:VApp").a("xmlns:vApp", "http://www.vmware.com/vcloud/v0.8").a(
|
||||
"xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1").a("xmlns:vssd",
|
||||
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData").a("xmlns:common",
|
||||
"http://schemas.dmtf.org/wbem/wscim/1/common").a("xmlns:rasd",
|
||||
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData");
|
||||
return rootBuilder;
|
||||
}
|
||||
|
||||
protected XMLBuilder buildChildren(XMLBuilder rootBuilder) throws ParserConfigurationException,
|
||||
FactoryConfigurationError {
|
||||
XMLBuilder vAppChildrenBuilder = rootBuilder.e("vApp:Children");
|
||||
return vAppChildrenBuilder;
|
||||
}
|
||||
|
||||
protected XMLBuilder buildRootForName(XMLBuilder rootBuilder, String name) throws ParserConfigurationException,
|
||||
FactoryConfigurationError {
|
||||
XMLBuilder vAppBuilder = rootBuilder.e("vApp:VApp").a("name", name).a("type",
|
||||
"application/vnd.vmware.vcloud.vApp+xml");
|
||||
return vAppBuilder;
|
||||
}
|
||||
|
||||
protected String ifNullDefaultTo(String value, String defaultValue) {
|
||||
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
|
||||
}
|
||||
|
||||
}
|
|
@ -18,26 +18,10 @@
|
|||
*/
|
||||
package org.jclouds.savvis.vpdc.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
|
||||
import org.jclouds.compute.domain.CIMOperatingSystem;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringPayload;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.savvis.vpdc.domain.VMSpec;
|
||||
|
||||
|
@ -49,173 +33,23 @@ import com.jamesmurty.utils.XMLBuilder;
|
|||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindVMSpecToXmlPayload extends BindToStringPayload implements MapBinder {
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object toBind) {
|
||||
throw new IllegalStateException("BindVMSpecToXmlPayload needs parameters");
|
||||
public class BindVMSpecToXmlPayload extends BaseBindVMSpecToXmlPayload<VMSpec> {
|
||||
|
||||
}
|
||||
|
||||
protected List<VMSpec> findSpecInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
|
||||
protected VMSpec findSpecInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
|
||||
for (Object arg : gRequest.getArgs()) {
|
||||
if (arg instanceof VMSpec) {
|
||||
List<VMSpec> vmSpecs = new ArrayList<VMSpec>();
|
||||
vmSpecs.add((VMSpec) arg);
|
||||
return vmSpecs;
|
||||
} else if (arg instanceof ArrayList) {
|
||||
List<VMSpec> configurations = (List<VMSpec>) arg;
|
||||
return (configurations.size() > 0) ? configurations : null;
|
||||
return VMSpec.class.cast(arg);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
throw new IllegalArgumentException("Iterbable<VMSpec> must be included in the argument list");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
|
||||
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
|
||||
"this binder is only valid for GeneratedHttpRequests!");
|
||||
GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;
|
||||
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
|
||||
|
||||
request = super.bindToRequest(request,
|
||||
generateXml(findSpecInArgsOrNull(gRequest)));
|
||||
request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_XML);
|
||||
return request;
|
||||
}
|
||||
|
||||
public String generateXml(List<VMSpec> specs) {
|
||||
try {
|
||||
XMLBuilder rootBuilder = buildRoot();
|
||||
XMLBuilder vAppChildrenBuilder = buildChildren(rootBuilder);
|
||||
for (VMSpec spec : specs) {
|
||||
checkNotNull(spec, "VMSpec");
|
||||
checkNotNull(spec.getName(), "name");
|
||||
checkNotNull(spec.getNetwork(), "network");
|
||||
checkNotNull(spec.getNetwork().getName(), "networkName");
|
||||
XMLBuilder vAppBuilder = buildRootForName(vAppChildrenBuilder, spec.getName());
|
||||
addOperatingSystemSection(vAppBuilder, spec.getOperatingSystem());
|
||||
// TODO: Savvis returns network names with a - instead of space on getNetworkInVDC call,
|
||||
// fix this once savvis api starts returning correctly
|
||||
addVirtualHardwareSection(vAppBuilder, spec.getName(), spec.getNetwork().getName().replace("-", " "), spec);
|
||||
}
|
||||
Properties outputProperties = new Properties();
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
return rootBuilder.asString(outputProperties);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void addVirtualHardwareSection(XMLBuilder rootBuilder, String name, String networkName, VMSpec spec) {
|
||||
XMLBuilder virtualHardwareSectionBuilder = rootBuilder.e("ovf:VirtualHardwareSection");
|
||||
virtualHardwareSectionBuilder.e("ovf:Info").t("Virtual Hardware");
|
||||
addSystem(virtualHardwareSectionBuilder, name);
|
||||
addItems(virtualHardwareSectionBuilder, spec, networkName);
|
||||
}
|
||||
|
||||
void addItems(XMLBuilder virtualHardwareSectionBuilder, VMSpec spec, String networkName) {
|
||||
//todo make this work with fractional, which I think means setting speed to half
|
||||
addCPU(virtualHardwareSectionBuilder, (int)spec.getProcessorCount());
|
||||
addMemory(virtualHardwareSectionBuilder, spec.getMemoryInGig());
|
||||
addNetwork(virtualHardwareSectionBuilder, networkName);
|
||||
addDisks(virtualHardwareSectionBuilder, spec);
|
||||
}
|
||||
|
||||
private void addSystem(XMLBuilder virtualHardwareSectionBuilder, String name) {
|
||||
XMLBuilder systemBuilder = virtualHardwareSectionBuilder.e("ovf:System");
|
||||
systemBuilder.e("vssd:Description").t("Virtual Hardware Family");
|
||||
systemBuilder.e("vssd:ElementName").t(name);
|
||||
systemBuilder.e("vssd:InstanceID").t("1");
|
||||
systemBuilder.e("vssd:VirtualSystemIdentifier").t(name);
|
||||
}
|
||||
|
||||
private void addOperatingSystemSection(XMLBuilder rootBuilder, CIMOperatingSystem operatingSystem) {
|
||||
XMLBuilder sectionBuilder = rootBuilder.e("ovf:OperatingSystemSection").a("ovf:id",
|
||||
operatingSystem.getOsType().getCode() + "");
|
||||
sectionBuilder.e("ovf:Info").t("Specifies the operating system installed");
|
||||
sectionBuilder.e("ovf:Description").t(operatingSystem.getDescription());
|
||||
}
|
||||
|
||||
private void addCPU(XMLBuilder sectionBuilder, int processorCount) {
|
||||
XMLBuilder cpuBuilder = sectionBuilder.e("ovf:Item");
|
||||
cpuBuilder.e("rasd:AllocationUnits").t("3 GHz");
|
||||
cpuBuilder.e("rasd:Description").t("Number of Virtual CPUs");
|
||||
cpuBuilder.e("rasd:ElementName").t(processorCount + " CPU");
|
||||
cpuBuilder.e("rasd:InstanceID").t("1");
|
||||
cpuBuilder.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value());
|
||||
cpuBuilder.e("rasd:VirtualQuantity").t(processorCount + "");
|
||||
}
|
||||
|
||||
private void addMemory(XMLBuilder sectionBuilder, int memoryInGig) {
|
||||
XMLBuilder memoryBuilder = sectionBuilder.e("ovf:Item");
|
||||
memoryBuilder.e("rasd:AllocationUnits").t("Gigabytes");
|
||||
memoryBuilder.e("rasd:Description").t("Memory Size");
|
||||
memoryBuilder.e("rasd:ElementName").t("Memory");
|
||||
memoryBuilder.e("rasd:InstanceID").t("2");
|
||||
memoryBuilder.e("rasd:ResourceType").t(ResourceType.MEMORY.value());
|
||||
memoryBuilder.e("rasd:VirtualQuantity").t(memoryInGig + "");
|
||||
}
|
||||
|
||||
private void addNetwork(XMLBuilder sectionBuilder, String networkName) {
|
||||
XMLBuilder networkBuilder = sectionBuilder.e("ovf:Item");
|
||||
networkBuilder.e("rasd:Caption").t("false");
|
||||
networkBuilder.e("rasd:Connection").t(networkName);
|
||||
networkBuilder.e("rasd:ElementName").t("Network");
|
||||
networkBuilder.e("rasd:InstanceID").t("3");
|
||||
networkBuilder.e("rasd:ResourceType").t(ResourceType.ETHERNET_ADAPTER.value());
|
||||
networkBuilder.e("rasd:VirtualQuantity").t("1");
|
||||
}
|
||||
|
||||
private void addDisks(XMLBuilder sectionBuilder, VMSpec spec) {
|
||||
XMLBuilder bootDiskBuilder = sectionBuilder.e("ovf:Item");
|
||||
bootDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes");
|
||||
bootDiskBuilder.e("rasd:Caption").t("");
|
||||
bootDiskBuilder.e("rasd:Description").t("Hard Disk");
|
||||
bootDiskBuilder.e("rasd:ElementName").t(spec.getBootDeviceName());
|
||||
bootDiskBuilder.e("rasd:HostResource").t("boot");
|
||||
bootDiskBuilder.e("rasd:InstanceID").t("4");
|
||||
bootDiskBuilder.e("rasd:ResourceType").t(ResourceType.BASE_PARTITIONABLE_UNIT.value());
|
||||
bootDiskBuilder.e("rasd:VirtualQuantity").t(spec.getBootDiskSize() + "");
|
||||
|
||||
int instanceId = 5;
|
||||
for (Entry<String, Integer> dataDisk : spec.getDataDiskDeviceNameToSizeInGig().entrySet()) {
|
||||
XMLBuilder dataDiskBuilder = sectionBuilder.e("ovf:Item");
|
||||
dataDiskBuilder.e("rasd:AllocationUnits").t("Gigabytes");
|
||||
dataDiskBuilder.e("rasd:Caption").t("");
|
||||
dataDiskBuilder.e("rasd:Description").t("Hard Disk");
|
||||
dataDiskBuilder.e("rasd:ElementName").t(dataDisk.getKey());
|
||||
dataDiskBuilder.e("rasd:HostResource").t("data");
|
||||
dataDiskBuilder.e("rasd:InstanceID").t("" + instanceId++);
|
||||
dataDiskBuilder.e("rasd:ResourceType").t(ResourceType.PARTITIONABLE_UNIT.value());
|
||||
dataDiskBuilder.e("rasd:VirtualQuantity").t(dataDisk.getValue() + "");
|
||||
}
|
||||
}
|
||||
|
||||
protected XMLBuilder buildRoot() throws ParserConfigurationException, FactoryConfigurationError {
|
||||
XMLBuilder rootBuilder = XMLBuilder.create("vApp:VApp")
|
||||
.a("xmlns:vApp", "http://www.vmware.com/vcloud/v0.8")
|
||||
.a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1")
|
||||
.a("xmlns:vssd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData")
|
||||
.a("xmlns:common", "http://schemas.dmtf.org/wbem/wscim/1/common")
|
||||
.a("xmlns:rasd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData")
|
||||
.a("name", "");
|
||||
return rootBuilder;
|
||||
}
|
||||
|
||||
protected XMLBuilder buildChildren(XMLBuilder rootBuilder) throws ParserConfigurationException, FactoryConfigurationError {
|
||||
XMLBuilder vAppChildrenBuilder = rootBuilder.e("vApp:Children");
|
||||
return vAppChildrenBuilder;
|
||||
}
|
||||
|
||||
protected XMLBuilder buildRootForName(XMLBuilder rootBuilder, String name) throws ParserConfigurationException, FactoryConfigurationError {
|
||||
XMLBuilder vAppBuilder = rootBuilder.e("vApp:VApp")
|
||||
.a("name", name)
|
||||
.a("type", "application/vnd.vmware.vcloud.vApp+xml");
|
||||
return vAppBuilder;
|
||||
}
|
||||
|
||||
protected String ifNullDefaultTo(String value, String defaultValue) {
|
||||
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
|
||||
protected void bindSpec(VMSpec spec, XMLBuilder rootBuilder) throws ParserConfigurationException,
|
||||
FactoryConfigurationError {
|
||||
checkSpec(spec);
|
||||
rootBuilder.a("name", spec.getName()).a("type", "application/vnd.vmware.vcloud.vApp+xml").a("href", "");
|
||||
addOperatingSystemAndVirtualHardware(spec, rootBuilder);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
*
|
||||
* 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.savvis.vpdc.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.savvis.vpdc.domain.VMSpec;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindVMSpecsToXmlPayload extends BaseBindVMSpecToXmlPayload<Iterable<VMSpec>> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Iterable<VMSpec> findSpecInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
|
||||
for (Object arg : gRequest.getArgs()) {
|
||||
if (arg instanceof Iterable<?>) {
|
||||
Iterable<VMSpec> specs = (Iterable<VMSpec>) arg;
|
||||
checkArgument(Iterables.size(specs) > 0,
|
||||
"At least one VMSpec must be included in the argument list");
|
||||
return specs;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Iterbable<VMSpec> must be included in the argument list");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindSpec(Iterable<VMSpec> specs, XMLBuilder rootBuilder) throws ParserConfigurationException, FactoryConfigurationError {
|
||||
rootBuilder.a("name", "");
|
||||
XMLBuilder specBuilder = buildChildren(rootBuilder);
|
||||
for (VMSpec spec : specs) {
|
||||
checkSpec(spec);
|
||||
XMLBuilder vAppBuilder = buildRootForName(specBuilder, spec.getName());
|
||||
addOperatingSystemAndVirtualHardware(spec, vAppBuilder);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -85,6 +85,8 @@ public class VPDCComputeServiceAdapter implements ComputeServiceAdapter<VM, VMSp
|
|||
String billingSiteId = template.getLocation().getParent().getParent().getId();
|
||||
|
||||
VMSpec.Builder specBuilder = VMSpec.builder();
|
||||
specBuilder.name(name);
|
||||
specBuilder.networkTierName(networkTierName);
|
||||
specBuilder.operatingSystem(CIMOperatingSystem.class.cast(template.getImage().getOperatingSystem()));
|
||||
specBuilder.processorCount(template.getHardware().getProcessors().size());
|
||||
specBuilder.memoryInGig(template.getHardware().getRam() / 1024);
|
||||
|
@ -96,7 +98,7 @@ public class VPDCComputeServiceAdapter implements ComputeServiceAdapter<VM, VMSp
|
|||
specBuilder.addDataDrive(volume.getDevice(), volume.getSize().intValue());
|
||||
}
|
||||
|
||||
Task task = client.getVMClient().addVMIntoVDC(billingSiteId, vpdcId, networkTierName, name, specBuilder.build());
|
||||
Task task = client.getVMClient().addVMIntoVDC(billingSiteId, vpdcId, specBuilder.build());
|
||||
// make sure there's no error
|
||||
if (task.getError() != null)
|
||||
throw new RuntimeException("cloud not add vm: " + task.getError().toString());
|
||||
|
|
|
@ -40,8 +40,8 @@ public class VMSpec {
|
|||
}
|
||||
|
||||
public static class Builder {
|
||||
private String name;
|
||||
private Network network;
|
||||
private String name;
|
||||
private String networkTierName;
|
||||
private CIMOperatingSystem operatingSystem;
|
||||
private int processorCount = 1;
|
||||
private int memoryInGig = 1;
|
||||
|
@ -51,13 +51,13 @@ public class VMSpec {
|
|||
private Map<String, Integer> dataDriveDeviceNameToSizeInGig = Maps.newLinkedHashMap();
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = checkNotNull(name, "name");
|
||||
return this;
|
||||
}
|
||||
this.name = checkNotNull(name, "name");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder network(Network network) {
|
||||
this.network = checkNotNull(network, "network");
|
||||
return this;
|
||||
public Builder networkTierName(String networkTierName) {
|
||||
this.networkTierName = checkNotNull(networkTierName, "networkTierName");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder operatingSystem(CIMOperatingSystem operatingSystem) {
|
||||
|
@ -96,19 +96,19 @@ public class VMSpec {
|
|||
|
||||
public Builder addDataDrives(Map<String, Integer> dataDriveDeviceNameToSizeInGig) {
|
||||
this.dataDriveDeviceNameToSizeInGig = ImmutableMap.copyOf(checkNotNull(dataDriveDeviceNameToSizeInGig,
|
||||
"dataDriveDeviceNameToSizeInGig"));
|
||||
"dataDriveDeviceNameToSizeInGig"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public VMSpec build() {
|
||||
return new VMSpec(name, network, operatingSystem, processorCount, memoryInGig, bootDeviceName, bootDriveSize,
|
||||
dataDriveDeviceNameToSizeInGig);
|
||||
return new VMSpec(name, networkTierName, operatingSystem, processorCount, memoryInGig, bootDeviceName,
|
||||
bootDriveSize, dataDriveDeviceNameToSizeInGig);
|
||||
}
|
||||
|
||||
public static Builder fromVMSpec(VMSpec in) {
|
||||
return new Builder().operatingSystem(in.getOperatingSystem()).memoryInGig(in.getMemoryInGig())
|
||||
.bootDeviceName(in.getBootDeviceName()).bootDiskSize(in.getBootDiskSize())
|
||||
.addDataDrives(in.getDataDiskDeviceNameToSizeInGig()).processorCount(in.getProcessorCount());
|
||||
return new Builder().operatingSystem(in.getOperatingSystem()).memoryInGig(in.getMemoryInGig()).bootDeviceName(
|
||||
in.getBootDeviceName()).bootDiskSize(in.getBootDiskSize()).addDataDrives(
|
||||
in.getDataDiskDeviceNameToSizeInGig()).processorCount(in.getProcessorCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public class VMSpec {
|
|||
}
|
||||
|
||||
private final String name;
|
||||
private final Network network;
|
||||
private final String networkTierName;
|
||||
private final CIMOperatingSystem operatingSystem;
|
||||
private final int processorCount;
|
||||
private final int memoryInGig;
|
||||
|
@ -127,10 +127,11 @@ public class VMSpec {
|
|||
private final int bootDriveSize;
|
||||
private final Map<String, Integer> dataDriveDeviceNameToSizeInGig;
|
||||
|
||||
protected VMSpec(String name, Network network, CIMOperatingSystem operatingSystem, int processorCount, int memoryInGig, String bootDeviceName,
|
||||
int bootDriveSize, Map<String, Integer> dataDriveDeviceNameToSizeInGig) {
|
||||
this.name = name;
|
||||
this.network = network;
|
||||
protected VMSpec(String name, String networkTierName, CIMOperatingSystem operatingSystem, int processorCount,
|
||||
int memoryInGig, String bootDeviceName, int bootDriveSize,
|
||||
Map<String, Integer> dataDriveDeviceNameToSizeInGig) {
|
||||
this.name = name;
|
||||
this.networkTierName = networkTierName;
|
||||
this.operatingSystem = checkNotNull(operatingSystem, "operatingSystem not specified");
|
||||
checkProcessorCount(processorCount);
|
||||
this.processorCount = processorCount;
|
||||
|
@ -140,16 +141,16 @@ public class VMSpec {
|
|||
checkArgument(bootDriveSize > 0, "bootDriveSize must be positive");
|
||||
this.bootDriveSize = bootDriveSize;
|
||||
this.dataDriveDeviceNameToSizeInGig = ImmutableMap.copyOf(checkNotNull(dataDriveDeviceNameToSizeInGig,
|
||||
"dataDriveDeviceNameToSizeInGig"));
|
||||
"dataDriveDeviceNameToSizeInGig"));
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public Network getNetwork() {
|
||||
return network;
|
||||
}
|
||||
public String getNetworkTierName() {
|
||||
return networkTierName;
|
||||
}
|
||||
|
||||
public CIMOperatingSystem getOperatingSystem() {
|
||||
return operatingSystem;
|
||||
|
@ -228,9 +229,10 @@ public class VMSpec {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name= " + name + ", operatingSystem=" + operatingSystem + ", processorCount=" + processorCount + ", memoryInGig="
|
||||
+ memoryInGig + ", network=" + network.getName() + ", bootDeviceName=" + bootDeviceName + ", bootDriveSize=" + bootDriveSize
|
||||
+ ", dataDriveDeviceNameToSizeInGig=" + dataDriveDeviceNameToSizeInGig + "]";
|
||||
return "[name= " + name + ", operatingSystem=" + operatingSystem + ", processorCount=" + processorCount
|
||||
+ ", memoryInGig=" + memoryInGig + ", networkTierName=" + networkTierName + ", bootDeviceName="
|
||||
+ bootDeviceName + ", bootDriveSize=" + bootDriveSize + ", dataDriveDeviceNameToSizeInGig="
|
||||
+ dataDriveDeviceNameToSizeInGig + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.savvis.vpdc.features;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -40,6 +39,7 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
|||
import org.jclouds.savvis.vpdc.binders.BindCaptureVAppTemplateToXmlPayload;
|
||||
import org.jclouds.savvis.vpdc.binders.BindCloneVMToXmlPayload;
|
||||
import org.jclouds.savvis.vpdc.binders.BindVMSpecToXmlPayload;
|
||||
import org.jclouds.savvis.vpdc.binders.BindVMSpecsToXmlPayload;
|
||||
import org.jclouds.savvis.vpdc.domain.Task;
|
||||
import org.jclouds.savvis.vpdc.domain.VMSpec;
|
||||
import org.jclouds.savvis.vpdc.filters.SetVCloudTokenCookie;
|
||||
|
@ -68,8 +68,7 @@ public interface VMAsyncClient {
|
|||
@MapBinder(BindVMSpecToXmlPayload.class)
|
||||
ListenableFuture<Task> addVMIntoVDC(
|
||||
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
|
||||
@PathParam("vpdcId") String vpdcId, @PayloadParam("networkName") String networkTierName,
|
||||
@PayloadParam("name") String vAppName, VMSpec spec);
|
||||
@PathParam("vpdcId") String vpdcId, VMSpec spec);
|
||||
|
||||
/**
|
||||
* @see VMClient#addVMIntoVDC
|
||||
|
@ -78,8 +77,18 @@ public interface VMAsyncClient {
|
|||
@XMLResponseParser(TaskHandler.class)
|
||||
@Path("vApp/")
|
||||
@MapBinder(BindVMSpecToXmlPayload.class)
|
||||
ListenableFuture<Task> addVMIntoVDC(@EndpointParam URI vpdc, @PayloadParam("networkName") String networkTierName,
|
||||
@PayloadParam("name") String vAppName, VMSpec spec);
|
||||
ListenableFuture<Task> addVMIntoVDC(@EndpointParam URI vpdc, VMSpec spec);
|
||||
|
||||
/**
|
||||
* @see VMClient#addMultipleVMsIntoVDC
|
||||
*/
|
||||
@GET
|
||||
@XMLResponseParser(TasksListHandler.class)
|
||||
@Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/vApp/")
|
||||
@MapBinder(BindVMSpecsToXmlPayload.class)
|
||||
ListenableFuture<Set<Task>> addMultipleVMsIntoVDC(
|
||||
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
|
||||
@PathParam("vpdcId") String vpdcId, Iterable<VMSpec> vmSpecs);
|
||||
|
||||
/**
|
||||
* @see VMClient#addMultipleVMsIntoVDC
|
||||
|
@ -87,8 +96,8 @@ public interface VMAsyncClient {
|
|||
@GET
|
||||
@XMLResponseParser(TasksListHandler.class)
|
||||
@Path("vApp/")
|
||||
@MapBinder(BindVMSpecToXmlPayload.class)
|
||||
ListenableFuture<Set<Task>> addMultipleVMsIntoVDC(@EndpointParam URI vpdc, List<VMSpec> vmSpecs);
|
||||
@MapBinder(BindVMSpecsToXmlPayload.class)
|
||||
ListenableFuture<Set<Task>> addMultipleVMsIntoVDC(@EndpointParam URI vpdc, Iterable<VMSpec> vmSpecs);
|
||||
|
||||
/**
|
||||
* @see VMClient#captureVApp
|
||||
|
@ -97,8 +106,9 @@ public interface VMAsyncClient {
|
|||
@XMLResponseParser(TaskHandler.class)
|
||||
@Path("v{jclouds.api-version}/org/{billingSiteId}/vdc/{vpdcId}/action/captureVApp")
|
||||
@MapBinder(BindCaptureVAppTemplateToXmlPayload.class)
|
||||
ListenableFuture<Task> captureVApp(@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
|
||||
@PathParam("vpdcId") String vpdcId, URI vAppUri);
|
||||
ListenableFuture<Task> captureVApp(
|
||||
@PathParam("billingSiteId") @Nullable @ParamParser(DefaultOrgIfNull.class) String billingSiteId,
|
||||
@PathParam("vpdcId") String vpdcId, URI vAppUri);
|
||||
|
||||
/**
|
||||
* @see VMClient#cloneVApp
|
||||
|
@ -108,7 +118,7 @@ public interface VMAsyncClient {
|
|||
@Path("action/cloneVApp")
|
||||
@MapBinder(BindCloneVMToXmlPayload.class)
|
||||
ListenableFuture<Task> cloneVApp(@EndpointParam URI vAppUri, @PayloadParam("name") String newVAppName,
|
||||
@PayloadParam("networkTierName") String networkTierName);
|
||||
@PayloadParam("networkTierName") String networkTierName);
|
||||
|
||||
/**
|
||||
* @see VMClient#removeVMFromVDC
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
package org.jclouds.savvis.vpdc.features;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -44,14 +43,12 @@ public interface VMClient {
|
|||
* billing site Id, or null for default
|
||||
* @param vpdcId
|
||||
* vpdc Id
|
||||
* @param networkTierName
|
||||
* network tier name
|
||||
* @param spec
|
||||
* how to
|
||||
*
|
||||
* @return VM in progress
|
||||
*/
|
||||
Task addVMIntoVDC(String billingSiteId, String vpdcId, String networkTierName, String name, VMSpec spec);
|
||||
Task addVMIntoVDC(String billingSiteId, String vpdcId, VMSpec spec);
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -59,9 +56,23 @@ public interface VMClient {
|
|||
* href of the vpdc
|
||||
* @see #addVMIntoVDC
|
||||
*/
|
||||
Task addVMIntoVDC(URI vpdc, String networkTierName, String name, VMSpec spec);
|
||||
Task addVMIntoVDC(URI vpdc, VMSpec spec);
|
||||
|
||||
/**
|
||||
* Add/Deploy new VMs into VDC
|
||||
*
|
||||
* @param billingSiteId
|
||||
* billing site Id, or null for default
|
||||
* @param vpdcId
|
||||
* vpdc Id
|
||||
* @param vmSpecs
|
||||
* vm configurations
|
||||
* @return VM's in progress
|
||||
*/
|
||||
Set<Task> addMultipleVMsIntoVDC(String billingSiteId, String vpdcId, Iterable<VMSpec> vmSpecs);
|
||||
|
||||
/**
|
||||
* Add/Deploy new VMs into VDC
|
||||
*
|
||||
* @param vpdc
|
||||
* href of the vpdc
|
||||
|
@ -69,29 +80,28 @@ public interface VMClient {
|
|||
* vm configurations
|
||||
* @return VM's in progress
|
||||
*/
|
||||
Set<Task> addMultipleVMsIntoVDC(URI vpdc, List<VMSpec> vmSpecs);
|
||||
Set<Task> addMultipleVMsIntoVDC(URI vpdc, Iterable<VMSpec> vmSpecs);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param billingSiteId
|
||||
* @param billingSiteId
|
||||
* billing site Id, or null for default
|
||||
* @param vpdcId
|
||||
* vpdc Id
|
||||
* @param vAppUri
|
||||
* href of the vApp
|
||||
* @return
|
||||
* Task with vAppTemplate href
|
||||
* href of the vApp
|
||||
* @return Task with vAppTemplate href
|
||||
*/
|
||||
Task captureVApp(String billingSiteId, String vpdcId, URI vAppUri);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param vAppUri
|
||||
* href of the vApp
|
||||
* href of the vApp
|
||||
* @param newVAppName
|
||||
* name for the new vApp
|
||||
* name for the new vApp
|
||||
* @param networkTierName
|
||||
* network tier name for vApp
|
||||
* network tier name for vApp
|
||||
* @return
|
||||
*/
|
||||
Task cloneVApp(URI vAppUri, String newVAppName, String networkTierName);
|
||||
|
@ -131,7 +141,7 @@ public interface VMClient {
|
|||
* Power off a VM
|
||||
*
|
||||
* @param vm
|
||||
* href of the vm
|
||||
* href of the vm
|
||||
* @return
|
||||
*/
|
||||
Task powerOffVM(URI vm);
|
||||
|
@ -140,7 +150,7 @@ public interface VMClient {
|
|||
* Power on a VM
|
||||
*
|
||||
* @param vm
|
||||
* href of the vm
|
||||
* href of the vm
|
||||
* @return
|
||||
*/
|
||||
Task powerOnVM(URI vm);
|
||||
|
|
|
@ -21,36 +21,34 @@ package org.jclouds.savvis.vpdc.binders;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.cim.OSType;
|
||||
import org.jclouds.compute.domain.CIMOperatingSystem;
|
||||
import org.jclouds.savvis.vpdc.domain.Network;
|
||||
import org.jclouds.savvis.vpdc.domain.VMSpec;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BindVMSpecToXmlPayload}
|
||||
* Tests behavior of {@code BindVMSpecsToXmlPayload}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class BindVMSpecToXmlPayloadTest {
|
||||
public class BindVMSpecsToXmlPayloadTest {
|
||||
|
||||
public void test() throws IOException {
|
||||
CIMOperatingSystem os = Iterables.find(new Gson().<Set<CIMOperatingSystem>> fromJson(
|
||||
Strings2.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/savvis-symphonyvpdc/predefined_operatingsystems.json")),
|
||||
new TypeLiteral<Set<CIMOperatingSystem>>() {
|
||||
}.getType()), new Predicate<CIMOperatingSystem>() {
|
||||
CIMOperatingSystem os = Iterables.find(new Gson().<Set<CIMOperatingSystem>> fromJson(Strings2
|
||||
.toStringAndClose(getClass()
|
||||
.getResourceAsStream("/savvis-symphonyvpdc/predefined_operatingsystems.json")),
|
||||
new TypeLiteral<Set<CIMOperatingSystem>>() {
|
||||
}.getType()), new Predicate<CIMOperatingSystem>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(CIMOperatingSystem arg0) {
|
||||
|
@ -59,14 +57,10 @@ public class BindVMSpecToXmlPayloadTest {
|
|||
|
||||
});
|
||||
|
||||
Network network = Network.builder().name("VM Tier01").build();
|
||||
|
||||
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-multiple-default.xml"));
|
||||
|
||||
VMSpec spec = VMSpec.builder().name("Test VM").operatingSystem(os).network(network).build();
|
||||
List<VMSpec> specs = new ArrayList<VMSpec>();
|
||||
specs.add(spec);
|
||||
VMSpec spec = VMSpec.builder().name("Test VM").operatingSystem(os).networkTierName("VM Tier01").build();
|
||||
|
||||
assertEquals(new BindVMSpecToXmlPayload().generateXml(specs), expected);
|
||||
assertEquals(new BindVMSpecsToXmlPayload().generateXml(ImmutableSet.of(spec)), expected);
|
||||
}
|
||||
}
|
|
@ -49,7 +49,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
Method method = BrowsingAsyncClient.class.getMethod("getOrg", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "11");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11 HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -64,7 +64,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
Method method = BrowsingAsyncClient.class.getMethod("getOrg", String.class);
|
||||
HttpRequest request = processor.createRequest(method, (String) null);
|
||||
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1 HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
Method method = BrowsingAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, "11", "22");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22 HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -94,7 +94,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
Method method = BrowsingAsyncClient.class.getMethod("getVDCInOrg", String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, (String) null, "22");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1/vdc/22 HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/1/vdc/22 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -110,7 +110,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
HttpRequest request = processor.createRequest(method, "11", "22", "VM-Tier01");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/network/VM-Tier01 HTTP/1.1");
|
||||
"GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/network/VM-Tier01 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -126,7 +126,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1/vdc/22/network/VM-Tier01 HTTP/1.1");
|
||||
"GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/1/vdc/22/network/VM-Tier01 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -143,7 +143,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
HttpRequest request = processor.createRequest(method, "11", "22", "33");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33 HTTP/1.1");
|
||||
"GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -157,10 +157,10 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
public void testVM() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = BrowsingAsyncClient.class.getMethod("getVM", URI.class, GetVMOptions[].class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33"));
|
||||
.create("https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33 HTTP/1.1");
|
||||
"GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -178,7 +178,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
.withPowerState());
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/VM-Tier01/withpowerstate HTTP/1.1");
|
||||
"GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/VM-Tier01/withpowerstate HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -195,7 +195,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
HttpRequest request = processor.createRequest(method, (String) null, "22", "VM-Tier01");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/1/vdc/22/vApp/VM-Tier01 HTTP/1.1");
|
||||
"GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/1/vdc/22/vApp/VM-Tier01 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -210,7 +210,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
Method method = BrowsingAsyncClient.class.getMethod("getTask", String.class);
|
||||
HttpRequest request = processor.createRequest(method, "1");
|
||||
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/task/1 HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/task/1 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -226,7 +226,7 @@ public class BrowsingAsyncClientTest extends BaseVPDCAsyncClientTest<BrowsingAsy
|
|||
HttpRequest request = processor.createRequest(method, "11", "22");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/FirewallService HTTP/1.1");
|
||||
"GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/FirewallService HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
|
|
@ -40,38 +40,44 @@ import com.google.inject.TypeLiteral;
|
|||
@Test(groups = "unit")
|
||||
public class FirewallAsyncClientTest extends BaseVPDCAsyncClientTest<FirewallAsyncClient> {
|
||||
|
||||
public void testAddFirewallRule() throws NoSuchMethodException, IOException{
|
||||
Method method = FirewallAsyncClient.class.getMethod("addFirewallRule", String.class, String.class, FirewallRule.class);
|
||||
HttpRequest request = processor.createRequest(method, "11", "22", FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("internet")
|
||||
.destination("VM Tier01").port("22").protocol("Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build());
|
||||
public void testAddFirewallRule() throws NoSuchMethodException, IOException {
|
||||
Method method = FirewallAsyncClient.class.getMethod("addFirewallRule", String.class, String.class,
|
||||
FirewallRule.class);
|
||||
HttpRequest request = processor.createRequest(method, "11", "22", FirewallRule.builder().firewallType(
|
||||
"SERVER_TIER_FIREWALL").isEnabled(true).source("internet").destination("VM Tier01").port("22").protocol(
|
||||
"Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build());
|
||||
|
||||
assertRequestLineEquals(request, "PUT https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/FirewallService/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/firewallService-default.xml")),
|
||||
"application/xml", false);
|
||||
assertRequestLineEquals(request,
|
||||
"PUT https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/FirewallService/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/firewallService-default.xml")), "application/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TaskHandler.class);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TaskHandler.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testDeleteFirewallRule() throws NoSuchMethodException, IOException{
|
||||
Method method = FirewallAsyncClient.class.getMethod("deleteFirewallRule", String.class, String.class, FirewallRule.class);
|
||||
HttpRequest request = processor.createRequest(method, "11", "22", FirewallRule.builder().firewallType("SERVER_TIER_FIREWALL").isEnabled(true).source("internet")
|
||||
.destination("VM Tier01").port("22").protocol("Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build());
|
||||
public void testDeleteFirewallRule() throws NoSuchMethodException, IOException {
|
||||
Method method = FirewallAsyncClient.class.getMethod("deleteFirewallRule", String.class, String.class,
|
||||
FirewallRule.class);
|
||||
HttpRequest request = processor.createRequest(method, "11", "22", FirewallRule.builder().firewallType(
|
||||
"SERVER_TIER_FIREWALL").isEnabled(true).source("internet").destination("VM Tier01").port("22").protocol(
|
||||
"Tcp").policy("allow").description("Server Tier Firewall Rule").isLogged(false).build());
|
||||
|
||||
assertRequestLineEquals(request, "DELETE https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/FirewallService/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/firewallService-default.xml")),
|
||||
"application/xml", false);
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/FirewallService/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/firewallService-default.xml")), "application/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TaskHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TaskHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<FirewallAsyncClient>> createTypeLiteral() {
|
||||
|
|
|
@ -51,7 +51,7 @@ public class ServiceManagementAsyncClientTest extends BaseVPDCAsyncClientTest<Se
|
|||
HttpRequest request = processor.createRequest(method, "11", "22", "33");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33/action/powerOn HTTP/1.1");
|
||||
"POST https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33/action/powerOn HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -65,10 +65,10 @@ public class ServiceManagementAsyncClientTest extends BaseVPDCAsyncClientTest<Se
|
|||
public void testPowerOnVM() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ServiceManagementAsyncClient.class.getMethod("powerOnVM", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33"));
|
||||
.create("https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33/action/powerOn HTTP/1.1");
|
||||
"POST https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33/action/powerOn HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -85,7 +85,7 @@ public class ServiceManagementAsyncClientTest extends BaseVPDCAsyncClientTest<Se
|
|||
HttpRequest request = processor.createRequest(method, "11", "22", "33");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33/action/powerOff HTTP/1.1");
|
||||
"POST https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33/action/powerOff HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -99,10 +99,10 @@ public class ServiceManagementAsyncClientTest extends BaseVPDCAsyncClientTest<Se
|
|||
public void testPowerOffVM() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = ServiceManagementAsyncClient.class.getMethod("powerOffVM", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33"));
|
||||
.create("https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33/action/powerOff HTTP/1.1");
|
||||
"POST https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33/action/powerOff HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
|
|
@ -32,10 +32,12 @@ import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.savvis.vpdc.domain.VMSpec;
|
||||
import org.jclouds.savvis.vpdc.xml.TaskHandler;
|
||||
import org.jclouds.savvis.vpdc.xml.TasksListHandler;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.TypeLiteral;
|
||||
|
@ -49,8 +51,7 @@ import com.google.inject.TypeLiteral;
|
|||
public class VMAsyncClientTest extends BaseVPDCAsyncClientTest<VMAsyncClient> {
|
||||
|
||||
public void testAddVMIntoVDCURI() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VMAsyncClient.class
|
||||
.getMethod("addVMIntoVDC", URI.class, String.class, String.class, VMSpec.class);
|
||||
Method method = VMAsyncClient.class.getMethod("addVMIntoVDC", URI.class, VMSpec.class);
|
||||
|
||||
CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral<Set<CIMOperatingSystem>>() {
|
||||
})), new Predicate<CIMOperatingSystem>() {
|
||||
|
@ -63,8 +64,8 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest<VMAsyncClient> {
|
|||
});
|
||||
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22"), "VM Tier01", "DemoHost-1",
|
||||
VMSpec.builder().operatingSystem(os).build());
|
||||
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22"), VMSpec.builder().name(
|
||||
"DemoHost-1").networkTierName("VM Tier01").operatingSystem(os).build());
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/ HTTP/1.1");
|
||||
|
@ -80,8 +81,7 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest<VMAsyncClient> {
|
|||
}
|
||||
|
||||
public void testAddVMIntoVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VMAsyncClient.class.getMethod("addVMIntoVDC", String.class, String.class, String.class,
|
||||
String.class, VMSpec.class);
|
||||
Method method = VMAsyncClient.class.getMethod("addVMIntoVDC", String.class, String.class, VMSpec.class);
|
||||
|
||||
CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral<Set<CIMOperatingSystem>>() {
|
||||
})), new Predicate<CIMOperatingSystem>() {
|
||||
|
@ -93,11 +93,10 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest<VMAsyncClient> {
|
|||
|
||||
});
|
||||
|
||||
HttpRequest request = processor.createRequest(method, "11", "22", "VM Tier01", "DemoHost-1", VMSpec.builder()
|
||||
.operatingSystem(os).build());
|
||||
HttpRequest request = processor.createRequest(method, "11", "22", VMSpec.builder().operatingSystem(os).name(
|
||||
"DemoHost-1").networkTierName("VM Tier01").build());
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/ HTTP/1.1");
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-default.xml")),
|
||||
"application/xml", false);
|
||||
|
@ -109,12 +108,71 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest<VMAsyncClient> {
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testAddMultipleVMsIntoVDCURI() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VMAsyncClient.class.getMethod("addMultipleVMsIntoVDC", URI.class, Iterable.class);
|
||||
|
||||
CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral<Set<CIMOperatingSystem>>() {
|
||||
})), new Predicate<CIMOperatingSystem>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(CIMOperatingSystem arg0) {
|
||||
return arg0.getOsType() == OSType.RHEL_64;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22"), ImmutableSet.of(VMSpec
|
||||
.builder().name("Test VM").networkTierName("VM Tier01").operatingSystem(os).build()));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"GET https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-multiple-default.xml")),
|
||||
"application/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TasksListHandler.class);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testAddMultipleVMsIntoVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VMAsyncClient.class
|
||||
.getMethod("addMultipleVMsIntoVDC", String.class, String.class, Iterable.class);
|
||||
|
||||
CIMOperatingSystem os = Iterables.find(injector.getInstance(Key.get(new TypeLiteral<Set<CIMOperatingSystem>>() {
|
||||
})), new Predicate<CIMOperatingSystem>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(CIMOperatingSystem arg0) {
|
||||
return arg0.getOsType() == OSType.RHEL_64;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
HttpRequest request = processor.createRequest(method, "11", "22", ImmutableSet.of(VMSpec.builder()
|
||||
.operatingSystem(os).name("Test VM").networkTierName("VM Tier01").build()));
|
||||
|
||||
assertRequestLineEquals(request, "GET https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/vm-multiple-default.xml")),
|
||||
"application/xml", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TasksListHandler.class);
|
||||
assertExceptionParserClassEquals(method, MapHttp4xxCodesToExceptions.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
public void testRemoveVMFromVDC() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VMAsyncClient.class.getMethod("removeVMFromVDC", String.class, String.class, String.class);
|
||||
HttpRequest request = processor.createRequest(method, "11", "22", "33");
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"DELETE https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33 HTTP/1.1");
|
||||
"DELETE https://api.symphonyvpdc.savvis.net/vpdc/v1.0/org/11/vdc/22/vApp/33 HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
|
@ -160,21 +218,21 @@ public class VMAsyncClientTest extends BaseVPDCAsyncClientTest<VMAsyncClient> {
|
|||
}
|
||||
|
||||
public void testPowerOnVM() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VMAsyncClient.class.getMethod("powerOnVM", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33"));
|
||||
Method method = VMAsyncClient.class.getMethod("powerOnVM", URI.class);
|
||||
HttpRequest request = processor.createRequest(method, URI
|
||||
.create("https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33"));
|
||||
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33/action/powerOn HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
assertRequestLineEquals(request,
|
||||
"POST https://api.symphonyvpdc.savvis.net/rest/api/v0.8/org/11/vdc/22/vApp/33/action/powerOn HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "");
|
||||
assertPayloadEquals(request, null, null, false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TaskHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
assertResponseParserClassEquals(method, request, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, TaskHandler.class);
|
||||
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeLiteral<RestAnnotationProcessor<VMAsyncClient>> createTypeLiteral() {
|
||||
|
|
|
@ -22,8 +22,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -39,8 +37,8 @@ import org.jclouds.savvis.vpdc.domain.Resource;
|
|||
import org.jclouds.savvis.vpdc.domain.Task;
|
||||
import org.jclouds.savvis.vpdc.domain.VDC;
|
||||
import org.jclouds.savvis.vpdc.domain.VM;
|
||||
import org.jclouds.savvis.vpdc.domain.VM.Status;
|
||||
import org.jclouds.savvis.vpdc.domain.VMSpec;
|
||||
import org.jclouds.savvis.vpdc.domain.VM.Status;
|
||||
import org.jclouds.savvis.vpdc.options.GetVMOptions;
|
||||
import org.jclouds.savvis.vpdc.reference.VCloudMediaType;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
|
@ -50,7 +48,9 @@ import org.testng.annotations.BeforeGroups;
|
|||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.ImmutableSet.Builder;
|
||||
import com.google.common.net.HostSpecifier;
|
||||
|
||||
@Test(groups = "live")
|
||||
|
@ -118,8 +118,8 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
|
||||
// TODO: determine the sizes available in the VDC, for example there's
|
||||
// a minimum size of boot disk, and also a preset combination of cpu count vs ram
|
||||
Task task = client.addVMIntoVDC(billingSiteId, vpdcId, networkTierName, name, VMSpec.builder()
|
||||
.operatingSystem(os).memoryInGig(2).addDataDrive("/data01", 25).build());
|
||||
Task task = client.addVMIntoVDC(billingSiteId, vpdcId, VMSpec.builder().name(name).networkTierName(
|
||||
networkTierName).operatingSystem(os).memoryInGig(2).addDataDrive("/data01", 25).build());
|
||||
|
||||
// make sure there's no error
|
||||
assert task.getId() != null && task.getError() == null : task;
|
||||
|
@ -139,9 +139,9 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
// the jclouds-wire.log
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
}
|
||||
|
||||
}).getId();
|
||||
|
@ -149,7 +149,8 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
String networkTierName = Iterables.get(
|
||||
restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId).getAvailableNetworks(), 0)
|
||||
.getId();
|
||||
Network networkTier = restContext.getApi().getBrowsingClient().getNetworkInVDC(billingSiteId, vpdcId, networkTierName);
|
||||
Network networkTier = restContext.getApi().getBrowsingClient().getNetworkInVDC(billingSiteId, vpdcId,
|
||||
networkTierName);
|
||||
|
||||
String name = prefix;
|
||||
|
||||
|
@ -166,30 +167,32 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
});
|
||||
|
||||
// TODO: Savvis returns network names with a - instead of space on getNetworkInVDC call,
|
||||
// fix this once savvis api starts returning correctly
|
||||
System.out.printf("vpdcId %s, vpdcName %s, networkName %s, name %s, os %s%n", vpdcId, vpdc.getName(), networkTier.getName().replace("-", " "), name, os);
|
||||
// fix this once savvis api starts returning correctly
|
||||
System.out.printf("vpdcId %s, vpdcName %s, networkName %s, name %s, os %s%n", vpdcId, vpdc.getName(), networkTier
|
||||
.getName().replace("-", " "), name, os);
|
||||
|
||||
List<VMSpec> vmSpecs = new ArrayList<VMSpec>();
|
||||
Builder<VMSpec> vmSpecs = ImmutableSet.<VMSpec> builder();
|
||||
int noOfVms = 2;
|
||||
for (int i = 0; i < noOfVms; i++) {
|
||||
// TODO: determine the sizes available in the VDC, for example there's
|
||||
// a minimum size of boot disk, and also a preset combination of cpu count vs ram
|
||||
VMSpec vmSpec = VMSpec.builder().name(name + i).operatingSystem(os).memoryInGig(2).network(networkTier).addDataDrive("/data01", 25).build();
|
||||
vmSpecs.add(vmSpec);
|
||||
// TODO: determine the sizes available in the VDC, for example there's
|
||||
// a minimum size of boot disk, and also a preset combination of cpu count vs ram
|
||||
VMSpec vmSpec = VMSpec.builder().name(name + i).operatingSystem(os).memoryInGig(2).networkTierName(
|
||||
networkTierName).addDataDrive("/data01", 25).build();
|
||||
vmSpecs.add(vmSpec);
|
||||
}
|
||||
|
||||
Set<Task> tasks = client.addMultipleVMsIntoVDC(vpdc.getHref(), vmSpecs);
|
||||
Set<Task> tasks = client.addMultipleVMsIntoVDC(vpdc.getHref(), vmSpecs.build());
|
||||
|
||||
for (Task task : tasks) {
|
||||
// make sure there's no error
|
||||
assert task.getId() != null && task.getError() == null : task;
|
||||
// make sure there's no error
|
||||
assert task.getId() != null && task.getError() == null : task;
|
||||
|
||||
assert this.taskTester.apply(task.getId());
|
||||
assert this.taskTester.apply(task.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void testCaptureVAppTemplate() throws Exception {
|
||||
billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default
|
||||
billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default
|
||||
vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(),
|
||||
new Predicate<Resource>() {
|
||||
|
||||
|
@ -198,36 +201,36 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
// the jclouds-wire.log
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
}
|
||||
|
||||
}).getId();
|
||||
|
||||
VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId);
|
||||
VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId);
|
||||
|
||||
for (Resource vApp : Iterables.filter(vpdc.getResourceEntities(), new Predicate<Resource>() {
|
||||
for (Resource vApp : Iterables.filter(vpdc.getResourceEntities(), new Predicate<Resource>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
return VCloudMediaType.VAPP_XML.equals(arg0.getType());
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
return VCloudMediaType.VAPP_XML.equals(arg0.getType());
|
||||
}
|
||||
|
||||
})) {
|
||||
})) {
|
||||
|
||||
System.out.printf("Capturing VAppTemplate for vApp - %s%n", vApp.getName());
|
||||
Task task = client.captureVApp(billingSiteId, vpdcId, vApp.getHref());
|
||||
System.out.printf("Capturing VAppTemplate for vApp - %s%n", vApp.getName());
|
||||
Task task = client.captureVApp(billingSiteId, vpdcId, vApp.getHref());
|
||||
|
||||
// make sure there's no error
|
||||
assert task.getId() != null && task.getError() == null : task;
|
||||
// make sure there's no error
|
||||
assert task.getId() != null && task.getError() == null : task;
|
||||
|
||||
assert this.taskTester.apply(task.getId());
|
||||
}
|
||||
assert this.taskTester.apply(task.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void testCloneVApp() throws Exception {
|
||||
billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default
|
||||
billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default
|
||||
vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(),
|
||||
new Predicate<Resource>() {
|
||||
|
||||
|
@ -236,35 +239,35 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
// the jclouds-wire.log
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
}
|
||||
|
||||
}).getId();
|
||||
|
||||
VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId);
|
||||
VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId);
|
||||
|
||||
String networkTierName = Iterables.get(vpdc.getAvailableNetworks(), 0).getId();
|
||||
String networkTierName = Iterables.get(vpdc.getAvailableNetworks(), 0).getId();
|
||||
|
||||
for (Resource vApp : Iterables.filter(vpdc.getResourceEntities(), new Predicate<Resource>() {
|
||||
for (Resource vApp : Iterables.filter(vpdc.getResourceEntities(), new Predicate<Resource>() {
|
||||
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
return VCloudMediaType.VAPP_XML.equals(arg0.getType());
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
return VCloudMediaType.VAPP_XML.equals(arg0.getType());
|
||||
}
|
||||
|
||||
})) {
|
||||
})) {
|
||||
|
||||
System.out.printf("Cloning VApp - %s%n", vApp.getName());
|
||||
System.out.printf("Cloning VApp - %s%n", vApp.getName());
|
||||
|
||||
Task task = client.cloneVApp(vApp.getHref(), "clonedvm", networkTierName);
|
||||
Task task = client.cloneVApp(vApp.getHref(), "clonedvm", networkTierName);
|
||||
|
||||
// make sure there's no error
|
||||
assert task.getId() != null && task.getError() == null : task;
|
||||
// make sure there's no error
|
||||
assert task.getId() != null && task.getError() == null : task;
|
||||
|
||||
assert this.taskTester.apply(task.getId());
|
||||
}
|
||||
assert this.taskTester.apply(task.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private void conditionallyCheckSSH() {
|
||||
|
@ -296,37 +299,37 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
|
||||
@Test(enabled = false)
|
||||
public void testPowerOffVM() throws Exception {
|
||||
billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default
|
||||
vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(),
|
||||
new Predicate<Resource>() {
|
||||
billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default
|
||||
vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(),
|
||||
new Predicate<Resource>() {
|
||||
|
||||
// try to find the first VDC owned by the current user
|
||||
// check here for what the email property might be, or in
|
||||
// the jclouds-wire.log
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
}
|
||||
// try to find the first VDC owned by the current user
|
||||
// check here for what the email property might be, or in
|
||||
// the jclouds-wire.log
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
}
|
||||
|
||||
}).getId();
|
||||
}).getId();
|
||||
|
||||
VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId);
|
||||
URI vmURI = Iterables.find(vpdc.getResourceEntities(), new Predicate<Resource>() {
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
if(VCloudMediaType.VAPP_XML.equals(arg0.getType())){
|
||||
VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null);
|
||||
System.out.printf("powering off vm - %s%n", response1.getName());
|
||||
if(response1.getStatus().equals(Status.ON)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
if (VCloudMediaType.VAPP_XML.equals(arg0.getType())) {
|
||||
VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null);
|
||||
System.out.printf("powering off vm - %s%n", response1.getName());
|
||||
if (response1.getStatus().equals(Status.ON)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}).getHref();
|
||||
}).getHref();
|
||||
|
||||
Task task = client.powerOffVM(vmURI);
|
||||
|
||||
|
@ -338,37 +341,37 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
|
|||
|
||||
@Test(enabled = false)
|
||||
public void testPowerOnVM() throws Exception {
|
||||
billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default
|
||||
vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(),
|
||||
new Predicate<Resource>() {
|
||||
billingSiteId = restContext.getApi().getBrowsingClient().getOrg(null).getId();// default
|
||||
vpdcId = Iterables.find(restContext.getApi().getBrowsingClient().getOrg(billingSiteId).getVDCs(),
|
||||
new Predicate<Resource>() {
|
||||
|
||||
// try to find the first VDC owned by the current user
|
||||
// check here for what the email property might be, or in
|
||||
// the jclouds-wire.log
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
}
|
||||
// try to find the first VDC owned by the current user
|
||||
// check here for what the email property might be, or in
|
||||
// the jclouds-wire.log
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
String description = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId,
|
||||
arg0.getId()).getDescription();
|
||||
return description.indexOf(email) != -1;
|
||||
}
|
||||
|
||||
}).getId();
|
||||
}).getId();
|
||||
|
||||
VDC vpdc = restContext.getApi().getBrowsingClient().getVDCInOrg(billingSiteId, vpdcId);
|
||||
URI vmURI = Iterables.find(vpdc.getResourceEntities(), new Predicate<Resource>() {
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
if(VCloudMediaType.VAPP_XML.equals(arg0.getType())){
|
||||
VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null);
|
||||
System.out.printf("powering on vm - %s%n", response1.getName());
|
||||
if(response1.getStatus().equals(Status.OFF)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean apply(Resource arg0) {
|
||||
if (VCloudMediaType.VAPP_XML.equals(arg0.getType())) {
|
||||
VM response1 = restContext.getApi().getBrowsingClient().getVM(arg0.getHref(), (GetVMOptions[]) null);
|
||||
System.out.printf("powering on vm - %s%n", response1.getName());
|
||||
if (response1.getStatus().equals(Status.OFF)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}).getHref();
|
||||
}).getHref();
|
||||
|
||||
Task task = client.powerOnVM(vmURI);
|
||||
|
||||
|
|
Loading…
Reference in New Issue