diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index abb1851818..b7e4972234 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -24,6 +24,7 @@ import static org.jclouds.vcloud.VCloudMediaType.TASK_XML; import static org.jclouds.vcloud.VCloudMediaType.UNDEPLOYVAPPPARAMS_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPPTEMPLATE_XML; import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; +import static org.jclouds.vcloud.VCloudMediaType.VM_XML; import java.net.URI; @@ -51,6 +52,7 @@ import org.jclouds.vcloud.binders.BindUndeployVAppParamsToXmlPayload; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint; import org.jclouds.vcloud.functions.OrgNameVDCNameResourceEntityNameToEndpoint; @@ -59,6 +61,7 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.VAppHandler; import org.jclouds.vcloud.xml.VAppTemplateHandler; +import org.jclouds.vcloud.xml.VmHandler; import com.google.common.util.concurrent.ListenableFuture; @@ -142,6 +145,15 @@ public interface VCloudAsyncClient extends CommonVCloudAsyncClient { @ExceptionParser(ReturnNullOnNotFoundOr404.class) ListenableFuture getVApp(@EndpointParam URI vApp); + /** + * @see VCloudClient#getVm + */ + @GET + @Consumes(VM_XML) + @XMLResponseParser(VmHandler.class) + @ExceptionParser(ReturnNullOnNotFoundOr404.class) + ListenableFuture getVm(@EndpointParam URI vm); + /** * @see VCloudClient#deployVAppOrVm */ diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java index 96e279f097..f102a674cf 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -29,6 +29,7 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.options.CloneVAppOptions; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -69,6 +70,8 @@ public interface VCloudClient extends CommonVCloudClient { VApp getVApp(URI vApp); + 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, diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Vm.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Vm.java index a2e26b7a27..18dca3876b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Vm.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Vm.java @@ -23,6 +23,10 @@ import java.util.List; import javax.annotation.Nullable; +import org.jclouds.vcloud.domain.internal.VmImpl; + +import com.google.inject.ImplementedBy; + /** * A Vm represents a virtual machine, a member of a vApp’s Children container.

note

*

@@ -31,6 +35,7 @@ import javax.annotation.Nullable; * * @author Adrian Cole */ +@ImplementedBy(VmImpl.class) public interface Vm extends ReferenceType { /** * Reference to the {@link VApp} or {@link VAppTemplate} containing this vm. diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java index 127913abc5..484c58030a 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java @@ -140,16 +140,6 @@ public class VAppImpl extends ReferenceTypeImpl implements VApp { return false; if (ovfDescriptorUploaded != other.ovfDescriptorUploaded) return false; - if (status == null) { - if (other.status != null) - return false; - } else if (!status.equals(other.status)) - return false; - if (tasks == null) { - if (other.tasks != null) - return false; - } else if (!tasks.equals(other.tasks)) - return false; if (vdc == null) { if (other.vdc != null) return false; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java index 8e8d1f5330..043738f28b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppTemplateImpl.java @@ -152,16 +152,6 @@ public class VAppTemplateImpl extends ReferenceTypeImpl implements VAppTemplate return false; if (ovfDescriptorUploaded != other.ovfDescriptorUploaded) return false; - if (status == null) { - if (other.status != null) - return false; - } else if (!status.equals(other.status)) - return false; - if (tasks == null) { - if (other.tasks != null) - return false; - } else if (!tasks.equals(other.tasks)) - return false; if (vAppScopedLocalId == null) { if (other.vAppScopedLocalId != null) return false; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VmImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VmImpl.java index 1c37c0e5fc..f3b9382b5f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VmImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VmImpl.java @@ -108,8 +108,8 @@ public class VmImpl extends ReferenceTypeImpl implements Vm { result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode()); result = prime * result + ((tasks == null) ? 0 : tasks.hashCode()); - result = prime * result + ((vAppScopedLocalId == null) ? 0 : vAppScopedLocalId.hashCode()); result = prime * result + ((vApp == null) ? 0 : vApp.hashCode()); + result = prime * result + ((vAppScopedLocalId == null) ? 0 : vAppScopedLocalId.hashCode()); return result; } @@ -127,33 +127,24 @@ public class VmImpl extends ReferenceTypeImpl implements Vm { return false; } else if (!description.equals(other.description)) return false; - if (status == null) { - if (other.status != null) + if (vApp == null) { + if (other.vApp != null) return false; - } else if (!status.equals(other.status)) - return false; - if (tasks == null) { - if (other.tasks != null) - return false; - } else if (!tasks.equals(other.tasks)) + } else if (!vApp.equals(other.vApp)) return false; if (vAppScopedLocalId == null) { if (other.vAppScopedLocalId != null) return false; } else if (!vAppScopedLocalId.equals(other.vAppScopedLocalId)) return false; - if (vApp == null) { - if (other.vApp != null) - return false; - } else if (!vApp.equals(other.vApp)) - return false; return true; } @Override public String toString() { - return "[id=" + getHref() + ", name=" + getName() + ", vApp=" + vApp + ", description=" + description + ", status=" - + status + "]"; + return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description + + ", status=" + status + ", tasks=" + tasks + ", vApp=" + vApp + ", vAppScopedLocalId=" + + vAppScopedLocalId + "]"; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java index 491c3d5ef7..5509c60985 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java @@ -76,7 +76,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equals("Children")) { inChildren = true; - } else if (qName.equals("Tasks")) { + } else if (!inChildren && qName.equals("Tasks")) { inTasks = true; } if (inChildren) { @@ -88,7 +88,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult { String status = Utils.attrOrNull(attributes, "status"); if (status != null) this.status = Status.fromValue(Integer.parseInt(status)); - } else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel")) && !inChildren) { + } else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) { vdc = newNamedResource(attributes); } @@ -97,7 +97,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult { public void endElement(String uri, String name, String qName) { if (qName.equals("Children")) { inChildren = false; - } else if (qName.equals("Tasks")) { + } else if (!inChildren && qName.equals("Tasks")) { inTasks = false; } if (inChildren) { @@ -120,6 +120,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult { public void characters(char ch[], int start, int length) { currentText.append(ch, start, length); + vmHandler.characters(ch, start, length); } protected String currentOrNull() { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java index 5dce65ec53..9d6b5ad61e 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppTemplateHandler.java @@ -77,7 +77,7 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult { protected List tasks = Lists.newArrayList(); protected String vAppScopedLocalId; + private boolean inTasks; + public Vm getResult() { return new VmImpl(vm.getName(), vm.getType(), vm.getHref(), status, vdc, description, tasks, vAppScopedLocalId); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - if (qName.equals("Vm")) { + if (qName.equals("Tasks")) { + inTasks = true; + } + if (inTasks) { + taskHandler.startElement(uri, localName, qName, attributes); + } else if (qName.equals("Vm")) { vm = newNamedResource(attributes); String status = Utils.attrOrNull(attributes, "status"); if (status != null) this.status = Status.fromValue(Integer.parseInt(status)); } else if (qName.equals("Link") && "up".equals(Utils.attrOrNull(attributes, "rel"))) { vdc = newNamedResource(attributes); - } else { - taskHandler.startElement(uri, localName, qName, attributes); } - } public void endElement(String uri, String name, String qName) { - taskHandler.endElement(uri, name, qName); - if (qName.equals("Task")) { - this.tasks.add(taskHandler.getResult()); + if (qName.equals("Tasks")) { + inTasks = false; + } + if (inTasks) { + taskHandler.endElement(uri, name, qName); + if (qName.equals("Task")) { + this.tasks.add(taskHandler.getResult()); + } } else if (qName.equals("Description")) { description = currentOrNull(); } else if (qName.equals("VAppScopedLocalId")) { diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index d284baabaa..4b8e708980 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -49,14 +49,14 @@ import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.util.Utils; import org.jclouds.vcloud.config.VCloudRestClientModule; -import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VCloudSession; import org.jclouds.vcloud.domain.internal.CatalogImpl; import org.jclouds.vcloud.domain.internal.CatalogItemImpl; -import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.OrgImpl; +import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; import org.jclouds.vcloud.domain.internal.VDCImpl; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.options.CloneVAppOptions; @@ -70,6 +70,7 @@ import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.VAppHandler; import org.jclouds.vcloud.xml.VAppTemplateHandler; import org.jclouds.vcloud.xml.VDCHandler; +import org.jclouds.vcloud.xml.VmHandler; import org.testng.annotations.Test; import com.google.common.base.Supplier; @@ -480,6 +481,22 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(request); } + 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")); + + 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"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VmHandler.class); + assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class); + + checkFilters(request); + } + public void testRebootVAppOrVm() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("rebootVAppOrVm", URI.class); HttpRequest request = processor.createRequest(method, URI diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java index 45031cd26a..e560c3b990 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -20,15 +20,17 @@ package org.jclouds.vcloud; import static com.google.common.base.Preconditions.checkNotNull; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import org.jclouds.rest.AuthorizationException; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.CatalogItem; -import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.domain.Vm; import org.testng.annotations.Test; /** @@ -83,7 +85,6 @@ public class VCloudClientLiveTest extends CommonVCloudClientLiveTesttrue true false - #!/bin/bash if [[ $1 == "postcustomization" ]]; then echo "post customization" touch /root/.postcustomization ping www.redhat.com -c 1 sleep 30 # register with RHN /usr/sbin/rhnreg_ks --profilename vic_`hostname`_`dmidecode -s system-uuid` --activationkey=281c9a9c77b8c001fe8ac8dd3b3f76d6 --force echo "rhn registered" # make hostname fully qualified to speed up sendmail start perl -i -pe "s/`hostname`/`hostname`.victory.blk/g" /etc/sysconfig/network rm /etc/ssh/*_key* service sshd restart echo "completed" fi + #!/bin/bash if [[ $1 == "postcustomization" ]]; then echo "post customization" touch /root/.postcustomization ping www.redhat.com -c 1 sleep 30 # register with RHN /usr/sbin/rhnreg_ks --profilename vic_`hostname`_`dmidecode -s system-uuid` --activationkey=XXXXXXXXXXXX --force echo "rhn registered" # make hostname fully qualified to speed up sendmail start perl -i -pe "s/`hostname`/`hostname`.victory.blk/g" /etc/sysconfig/network rm /etc/ssh/*_key* service sshd restart echo "completed" fi RHEL5 + true true false - #!/bin/bash if [[ $1 == "postcustomization" - ]]; then echo "post customization" touch - /root/.postcustomization ping www.redhat.com -c 1 sleep 30 # - register with RHN /usr/sbin/rhnreg_ks --profilename - vic_`hostname`_`dmidecode -s system-uuid` - --activationkey=281c9a9c77b8c001fe8ac8dd3b3f76d6 --force - echo "rhn registered" # make hostname fully qualified to - speed up sendmail start perl -i -pe - "s/`hostname`/`hostname`.victory.blk/g" - /etc/sysconfig/network rm /etc/ssh/*_key* service sshd - restart echo "completed" fi + #!/bin/bash if [[ $1 == "postcustomization" ]]; then echo "post customization" touch /root/.postcustomization ping www.redhat.com -c 1 sleep 30 # register with RHN /usr/sbin/rhnreg_ks --profilename vic_`hostname`_`dmidecode -s system-uuid` --activationkey=XXXXXXXXXXXX --force echo "rhn registered" # make hostname fully qualified to speed up sendmail start perl -i -pe "s/`hostname`/`hostname`.victory.blk/g" /etc/sysconfig/network rm /etc/ssh/*_key* service sshd restart echo "completed" fi RHEL5 10_rhel_template - + \ No newline at end of file