Issue 280: added vcloud 1.0 virtual hardware

This commit is contained in:
Adrian Cole 2010-08-24 16:36:00 -07:00
parent 053351ba12
commit 96fb5f42aa
23 changed files with 968 additions and 163 deletions

View File

@ -91,6 +91,16 @@ public interface VCloudMediaType {
public final static MediaType CATALOGITEM_XML_TYPE = new MediaType("application", public final static MediaType CATALOGITEM_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.catalogItem+xml"); "vnd.vmware.vcloud.catalogItem+xml");
/**
* "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
*/
public final static String VIRTUALHARDWARESECTION_XML = "application/vnd.vmware.vcloud.virtualHardwareSection+xml";
/**
* "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
*/
public final static MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application",
"vnd.vmware.vcloud.virtualHardwareSection+xml");
/** /**
* "application/vnd.vmware.vcloud.task+xml" * "application/vnd.vmware.vcloud.task+xml"
*/ */

View File

@ -0,0 +1,70 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
/**
* @author Adrian Cole
*
*/
public class EditableResourceAllocation extends ResourceAllocation {
private final ReferenceType edit;
public EditableResourceAllocation(int id, String name, String description, ResourceType type, String subType,
String hostResource, String address, Integer addressOnParent, Integer parent, Boolean connected,
long virtualQuantity, String virtualQuantityUnits, ReferenceType edit) {
super(id, name, description, type, subType, hostResource, address, addressOnParent, parent, connected,
virtualQuantity, virtualQuantityUnits);
this.edit = edit;
}
@Override
public String toString() {
return "[id=" + getId() + ", name=" + getName() + ", description=" + getDescription() + ", type=" + getType()
+ ", virtualQuantity=" + getVirtualQuantity() + ", virtualQuantityUnits=" + getVirtualQuantityUnits()
+ ", edit=" + edit + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((edit == null) ? 0 : edit.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
EditableResourceAllocation other = (EditableResourceAllocation) obj;
if (edit == null) {
if (other.edit != null)
return false;
} else if (!edit.equals(other.edit))
return false;
return true;
}
}

View File

@ -25,7 +25,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
public class ResourceAllocation implements Comparable<ResourceAllocation> { public class ResourceAllocation {
private final int id; private final int id;
private final String name; private final String name;
@ -33,7 +33,7 @@ public class ResourceAllocation implements Comparable<ResourceAllocation> {
private final ResourceType type; private final ResourceType type;
private final String subType; private final String subType;
private final String hostResource; private final String hostResource;
private final Integer address; private final String address;
private final Integer addressOnParent; private final Integer addressOnParent;
private final Integer parent; private final Integer parent;
private final Boolean connected; private final Boolean connected;
@ -41,7 +41,7 @@ public class ResourceAllocation implements Comparable<ResourceAllocation> {
private final String virtualQuantityUnits; private final String virtualQuantityUnits;
public ResourceAllocation(int id, String name, String description, ResourceType type, String subType, public ResourceAllocation(int id, String name, String description, ResourceType type, String subType,
String hostResource, Integer address, Integer addressOnParent, Integer parent, Boolean connected, String hostResource, String address, Integer addressOnParent, Integer parent, Boolean connected,
long virtualQuantity, String virtualQuantityUnits) { long virtualQuantity, String virtualQuantityUnits) {
this.id = id; this.id = id;
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
@ -57,27 +57,6 @@ public class ResourceAllocation implements Comparable<ResourceAllocation> {
this.virtualQuantityUnits = virtualQuantityUnits; this.virtualQuantityUnits = virtualQuantityUnits;
} }
public int compareTo(ResourceAllocation that) {
final int BEFORE = -1;
final int EQUAL = 0;
final int AFTER = 1;
if (this == that)
return EQUAL;
if (this.id < that.id)
return BEFORE;
if (this.id > that.id)
return AFTER;
if (this.addressOnParent != null && that.addressOnParent != null) {
if (this.addressOnParent < that.addressOnParent)
return BEFORE;
if (this.addressOnParent > that.addressOnParent)
return AFTER;
}
return 1;
}
public int getId() { public int getId() {
return id; return id;
} }
@ -98,7 +77,7 @@ public class ResourceAllocation implements Comparable<ResourceAllocation> {
return subType; return subType;
} }
public Integer getAddress() { public String getAddress() {
return address; return address;
} }
@ -213,10 +192,10 @@ public class ResourceAllocation implements Comparable<ResourceAllocation> {
@Override @Override
public String toString() { public String toString() {
return "ResourceAllocation [address=" + address + ", addressOnParent=" + addressOnParent + ", connected=" return "[address=" + address + ", addressOnParent=" + addressOnParent + ", connected=" + connected
+ connected + ", description=" + description + ", hostResource=" + hostResource + ", id=" + id + ", description=" + description + ", hostResource=" + hostResource + ", id=" + id + ", name=" + name
+ ", name=" + name + ", parent=" + parent + ", subType=" + subType + ", type=" + type + ", parent=" + parent + ", subType=" + subType + ", type=" + type + ", virtualQuantity="
+ ", virtualQuantity=" + virtualQuantity + ", virtualQuantityUnits=" + virtualQuantityUnits + "]"; + virtualQuantity + ", virtualQuantityUnits=" + virtualQuantityUnits + "]";
} }
} }

View File

@ -0,0 +1,91 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
/**
* @author Adrian Cole
*
*/
public class VCloudHardDisk extends ResourceAllocation {
private final long capacity;
private final int busType;
private final String busSubType;
public VCloudHardDisk(int id, String name, String description, ResourceType type, String subType,
String hostResource, String address, Integer addressOnParent, Integer parent, Boolean connected,
long virtualQuantity, String virtualQuantityUnits, long capacity, int busType, String busSubType) {
super(id, name, description, type, subType, hostResource, address, addressOnParent, parent, connected,
virtualQuantity, virtualQuantityUnits);
this.capacity = capacity;
this.busType = busType;
this.busSubType = busSubType;
}
public long getCapacity() {
return capacity;
}
public int getBusType() {
return busType;
}
public String getBusSubType() {
return busSubType;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((busSubType == null) ? 0 : busSubType.hashCode());
result = prime * result + busType;
result = prime * result + (int) (capacity ^ (capacity >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VCloudHardDisk other = (VCloudHardDisk) obj;
if (busSubType == null) {
if (other.busSubType != null)
return false;
} else if (!busSubType.equals(other.busSubType))
return false;
if (busType != other.busType)
return false;
if (capacity != other.capacity)
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getId() + ", name=" + getName() + ", description=" + getDescription() + ", type=" + getType()
+ ", virtualQuantity=" + getVirtualQuantity() + ", virtualQuantityUnits=" + getVirtualQuantityUnits()
+ ", capacity=" + capacity + ", busType=" + busType + ", busSubType=" + busSubType + "]";
}
}

View File

@ -0,0 +1,96 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
/**
* @author Adrian Cole
*
*/
public class VCloudNetworkAdapter extends ResourceAllocation {
private final String ipAddress;
private final boolean primaryNetworkConnection;
private final String ipAddressingMode;
public VCloudNetworkAdapter(int id, String name, String description, ResourceType type, String subType,
String hostResource, String address, Integer addressOnParent, Integer parent, Boolean connected,
long virtualQuantity, String virtualQuantityUnits, String ipAddress, boolean primaryNetworkConnection,
String ipAddressingMode) {
super(id, name, description, type, subType, hostResource, address, addressOnParent, parent, connected,
virtualQuantity, virtualQuantityUnits);
this.ipAddress = ipAddress;
this.primaryNetworkConnection = primaryNetworkConnection;
this.ipAddressingMode = ipAddressingMode;
}
public String getIpAddress() {
return ipAddress;
}
public boolean isPrimaryNetworkConnection() {
return primaryNetworkConnection;
}
public String getIpAddressingMode() {
return ipAddressingMode;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
result = prime * result + ((ipAddressingMode == null) ? 0 : ipAddressingMode.hashCode());
result = prime * result + (primaryNetworkConnection ? 1231 : 1237);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
VCloudNetworkAdapter other = (VCloudNetworkAdapter) obj;
if (ipAddress == null) {
if (other.ipAddress != null)
return false;
} else if (!ipAddress.equals(other.ipAddress))
return false;
if (ipAddressingMode == null) {
if (other.ipAddressingMode != null)
return false;
} else if (!ipAddressingMode.equals(other.ipAddressingMode))
return false;
if (primaryNetworkConnection != other.primaryNetworkConnection)
return false;
return true;
}
@Override
public String toString() {
return "[id=" + getId() + ", name=" + getName() + ", description=" + getDescription() + ", type=" + getType()
+ ", virtualQuantity=" + getVirtualQuantity() + ", virtualQuantityUnits=" + getVirtualQuantityUnits()
+ ", ipAddress=" + ipAddress + ", ipAddressingMode=" + ipAddressingMode + ", primaryNetworkConnection="
+ primaryNetworkConnection + "]";
}
}

View File

@ -0,0 +1,63 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.domain;
import java.net.URI;
import java.util.Set;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
/**
* A description of the virtual hardware supported by a virtual machine.
*/
public class VirtualHardware extends ReferenceTypeImpl {
private final String info;
private final VirtualSystem virtualSystem;
private final Set<ResourceAllocation> resourceAllocations = Sets.newLinkedHashSet();
public VirtualHardware(String name, String type, URI href, String info, VirtualSystem virtualSystem,
Iterable<? extends ResourceAllocation> resourceAllocations) {
super(name, type, href);
this.info = info;
this.virtualSystem = virtualSystem;
Iterables.addAll(this.resourceAllocations, resourceAllocations);
}
public String getInfo() {
return info;
}
public VirtualSystem getSystem() {
return virtualSystem;
}
public Set<? extends ResourceAllocation> getResourceAllocations() {
return resourceAllocations;
}
@Override
public String toString() {
return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", info=" + getInfo()
+ ", virtualSystem=" + getSystem() + "]";
}
}

View File

@ -68,6 +68,14 @@ public interface Vm extends ReferenceType {
*/ */
List<Task> getTasks(); List<Task> getTasks();
/**
* @return virtual hardware that comprises this VM, or null, if part of a vApp template
*
* @since vcloud api 1.0
*/
@Nullable
VirtualHardware getHardware();
/** /**
* read-only identifier created on import * read-only identifier created on import
* *

View File

@ -29,6 +29,7 @@ import javax.annotation.Nullable;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VirtualHardware;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -48,15 +49,19 @@ public class VmImpl extends ReferenceTypeImpl implements Vm {
@Nullable @Nullable
private final String description; private final String description;
private final List<Task> tasks = Lists.newArrayList(); private final List<Task> tasks = Lists.newArrayList();
@Nullable
private final VirtualHardware hardware;
private final String vAppScopedLocalId; private final String vAppScopedLocalId;
public VmImpl(String name, String type, URI id, @Nullable Status status, ReferenceType vApp, public VmImpl(String name, String type, URI id, @Nullable Status status, ReferenceType vApp,
@Nullable String description, Iterable<Task> tasks, @Nullable String vAppScopedLocalId) { @Nullable String description, Iterable<Task> tasks, @Nullable VirtualHardware hardware,
@Nullable String vAppScopedLocalId) {
super(name, type, id); super(name, type, id);
this.status = status; this.status = status;
this.vApp = vApp;// TODO: once <1.0 is killed check not null this.vApp = vApp;// TODO: once <1.0 is killed check not null
this.description = description; this.description = description;
Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks")); Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks"));
this.hardware = hardware;
this.vAppScopedLocalId = vAppScopedLocalId; this.vAppScopedLocalId = vAppScopedLocalId;
} }
@ -93,6 +98,14 @@ public class VmImpl extends ReferenceTypeImpl implements Vm {
return tasks; return tasks;
} }
/**
* {@inheritDoc}
*/
@Override
public VirtualHardware getHardware() {
return hardware;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -106,6 +119,7 @@ public class VmImpl extends ReferenceTypeImpl implements Vm {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((hardware == null) ? 0 : hardware.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((tasks == null) ? 0 : tasks.hashCode()); result = prime * result + ((tasks == null) ? 0 : tasks.hashCode());
result = prime * result + ((vApp == null) ? 0 : vApp.hashCode()); result = prime * result + ((vApp == null) ? 0 : vApp.hashCode());
@ -127,6 +141,21 @@ public class VmImpl extends ReferenceTypeImpl implements Vm {
return false; return false;
} else if (!description.equals(other.description)) } else if (!description.equals(other.description))
return false; return false;
if (hardware == null) {
if (other.hardware != null)
return false;
} else if (!hardware.equals(other.hardware))
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 (vApp == null) { if (vApp == null) {
if (other.vApp != null) if (other.vApp != null)
return false; return false;
@ -143,8 +172,8 @@ public class VmImpl extends ReferenceTypeImpl implements Vm {
@Override @Override
public String toString() { public String toString() {
return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description return "[href=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" + description
+ ", status=" + status + ", tasks=" + tasks + ", vApp=" + vApp + ", vAppScopedLocalId=" + ", status=" + status + ", tasks=" + tasks + ", vApp=" + vApp + ", hardware=" + hardware
+ vAppScopedLocalId + "]"; + ", vAppScopedLocalId=" + vAppScopedLocalId + "]";
} }
} }

View File

@ -23,49 +23,67 @@ import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.ResourceType;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<ResourceAllocation> { public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<ResourceAllocation> {
private StringBuilder currentText = new StringBuilder(); protected StringBuilder currentText = new StringBuilder();
Integer address; protected String address;
Integer addressOnParent; protected Integer addressOnParent;
String hostResource; protected String hostResource;
String allocationUnits; protected String allocationUnits;
String automaticAllocation; protected String automaticAllocation;
Boolean connected; protected Boolean connected;
String description; protected String description;
String elementName; protected String elementName;
int instanceID; protected int instanceID;
Integer parent; protected Integer parent;
String resourceSubType; protected String resourceSubType;
ResourceType resourceType; protected ResourceType resourceType;
long virtualQuantity = 1; protected long virtualQuantity = 1;
String virtualQuantityUnits; protected String virtualQuantityUnits;
private org.jclouds.vcloud.domain.ResourceAllocation allocation;
public org.jclouds.vcloud.domain.ResourceAllocation getResult() { public org.jclouds.vcloud.domain.ResourceAllocation getResult() {
if (allocationUnits != null)
virtualQuantityUnits = allocationUnits;
ResourceAllocation allocation = newResourceAllocation();
address = null;
addressOnParent = null;
allocationUnits = null;
automaticAllocation = null;
connected = null;
description = null;
elementName = null;
instanceID = -1;
parent = null;
resourceSubType = null;
resourceType = null;
virtualQuantity = 1;
virtualQuantityUnits = null;
hostResource = null;
return allocation; return allocation;
} }
protected ResourceAllocation newResourceAllocation() {
return new ResourceAllocation(instanceID, elementName, description, resourceType, resourceSubType, hostResource,
address, addressOnParent, parent, connected, virtualQuantity, virtualQuantityUnits);
}
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attributes) public void startElement(String uri, String localName, String qName, Attributes attributes) {
throws SAXException {
if (qName.endsWith("Connection")) { if (qName.endsWith("Connection")) {
connected = new Boolean(attributes.getValue(attributes.getIndex("connected"))); connected = new Boolean(attributes.getValue(attributes.getIndex("connected")));
} }
} }
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) {
String current = currentOrNull(); String current = currentOrNull();
if (current != null) { if (current != null) {
if (qName.endsWith("Address")) { if (qName.endsWith("Address")) {
address = Integer.parseInt(current); address = current;
} else if (qName.endsWith("AddressOnParent")) { } else if (qName.endsWith("AddressOnParent")) {
addressOnParent = Integer.parseInt(current); addressOnParent = Integer.parseInt(current);
} else if (qName.endsWith("AllocationUnits")) { } else if (qName.endsWith("AllocationUnits")) {
@ -91,28 +109,7 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<Resour
virtualQuantity = Long.parseLong(current); virtualQuantity = Long.parseLong(current);
virtualQuantityUnits = "byte * 2^20"; virtualQuantityUnits = "byte * 2^20";
} }
} else if (qName.endsWith("Item")) {
if (allocationUnits != null)
virtualQuantityUnits = allocationUnits;
this.allocation = new ResourceAllocation(instanceID, elementName, description,
resourceType, resourceSubType, hostResource, address, addressOnParent, parent,
connected, virtualQuantity, virtualQuantityUnits);
address = null;
addressOnParent = null;
allocationUnits = null;
automaticAllocation = null;
connected = null;
description = null;
elementName = null;
instanceID = -1;
parent = null;
resourceSubType = null;
resourceType = null;
virtualQuantity = 1;
virtualQuantityUnits = null;
hostResource = null;
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -117,4 +117,7 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
} }
} }
public void characters(char ch[], int start, int length) {
}
} }

View File

@ -76,9 +76,9 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.equals("Children")) { if (qName.endsWith("Children")) {
inChildren = true; inChildren = true;
} else if (!inChildren && qName.equals("Tasks")) { } else if (qName.endsWith("Tasks")) {
inTasks = true; inTasks = true;
} }
if (inChildren) { if (inChildren) {
@ -96,21 +96,17 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("Children")) { if (qName.endsWith("Children")) {
inChildren = false; inChildren = false;
} else if (!inChildren && qName.equals("Tasks")) { this.children.add(vmHandler.getResult());
} else if (qName.endsWith("Tasks")) {
inTasks = false; inTasks = false;
this.tasks.add(taskHandler.getResult());
} }
if (inChildren) { if (inChildren) {
vmHandler.endElement(uri, name, qName); vmHandler.endElement(uri, name, qName);
if (qName.equals("Vm")) {
this.children.add(vmHandler.getResult());
}
} else if (inTasks) { } else if (inTasks) {
taskHandler.endElement(uri, name, qName); taskHandler.endElement(uri, name, qName);
if (qName.equals("Task")) {
this.tasks.add(taskHandler.getResult());
}
} else if (qName.equals("Description")) { } else if (qName.equals("Description")) {
description = currentOrNull(); description = currentOrNull();
} else if (qName.equals("ovfDescriptorUploaded")) { } else if (qName.equals("ovfDescriptorUploaded")) {
@ -121,6 +117,9 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
public void characters(char ch[], int start, int length) { public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length); currentText.append(ch, start, length);
if (inTasks)
taskHandler.characters(ch, start, length);
if (inChildren)
vmHandler.characters(ch, start, length); vmHandler.characters(ch, start, length);
} }

View File

@ -77,9 +77,9 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.equals("Children")) { if (qName.endsWith("Children")) {
inChildren = true; inChildren = true;
} else if (!inChildren && qName.equals("Tasks")) { } else if (qName.endsWith("Tasks")) {
inTasks = true; inTasks = true;
} }
if (inChildren) { if (inChildren) {
@ -97,21 +97,17 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("Children")) { if (qName.endsWith("Children")) {
inChildren = false; inChildren = false;
} else if (!inChildren && qName.equals("Tasks")) { this.children.add(vmHandler.getResult());
} else if (qName.endsWith("Tasks")) {
inTasks = false; inTasks = false;
this.tasks.add(taskHandler.getResult());
} }
if (inChildren) { if (inChildren) {
vmHandler.endElement(uri, name, qName); vmHandler.endElement(uri, name, qName);
if (qName.equals("Vm")) {
this.children.add(vmHandler.getResult());
}
} else if (inTasks) { } else if (inTasks) {
taskHandler.endElement(uri, name, qName); taskHandler.endElement(uri, name, qName);
if (qName.equals("Task")) {
this.tasks.add(taskHandler.getResult());
}
} else if (qName.equals("Description")) { } else if (qName.equals("Description")) {
description = currentOrNull(); description = currentOrNull();
} else if (qName.equals("VAppScopedLocalId")) { } else if (qName.equals("VAppScopedLocalId")) {
@ -123,8 +119,11 @@ public class VAppTemplateHandler extends ParseSax.HandlerWithResult<VAppTemplate
} }
public void characters(char ch[], int start, int length) { public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length); if (inTasks)
taskHandler.characters(ch, start, length);
if (inChildren)
vmHandler.characters(ch, start, length); vmHandler.characters(ch, start, length);
currentText.append(ch, start, length);
} }
protected String currentOrNull() { protected String currentOrNull() {

View File

@ -0,0 +1,92 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.xml;
import java.util.Map;
import org.jclouds.vcloud.domain.EditableResourceAllocation;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VCloudHardDisk;
import org.jclouds.vcloud.domain.VCloudNetworkAdapter;
import org.jclouds.vcloud.util.Utils;
import org.xml.sax.Attributes;
/**
* @author Adrian Cole
*/
public class VCloudResourceAllocationHandler extends ResourceAllocationHandler {
private ReferenceType edit;
private long capacity;
private int busType;
private String busSubType;
private String ipAddress;
private boolean primaryNetworkConnection;
private String ipAddressingMode;
protected ResourceAllocation newResourceAllocation() {
if (edit != null) {
ResourceAllocation allocation = new EditableResourceAllocation(instanceID, elementName, description,
resourceType, resourceSubType, hostResource, address, addressOnParent, parent, connected,
virtualQuantity, virtualQuantityUnits, edit);
this.edit = null;
return allocation;
} else if (busSubType != null) {
ResourceAllocation allocation = new VCloudHardDisk(instanceID, elementName, description, resourceType,
resourceSubType, hostResource, address, addressOnParent, parent, connected, virtualQuantity,
virtualQuantityUnits, capacity, busType, busSubType);
capacity = -1;
busType = -1;
busSubType = null;
return allocation;
} else if (ipAddress != null) {
ResourceAllocation allocation = new VCloudNetworkAdapter(instanceID, elementName, description, resourceType,
resourceSubType, hostResource, address, addressOnParent, parent, connected, virtualQuantity,
virtualQuantityUnits, ipAddress, primaryNetworkConnection, ipAddressingMode);
ipAddress = null;
primaryNetworkConnection = false;
ipAddressingMode = null;
return allocation;
} else {
return super.newResourceAllocation();
}
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attrs) {
Map<String, String> attributes = Utils.cleanseAttributes(attrs);
if (qName.endsWith("Link")) {
this.edit = Utils.newReferenceType(attributes);
} else if (qName.endsWith("HostResource") && attributes.size() > 0) {
capacity = Long.parseLong(attributes.get("capacity"));
busType = Integer.parseInt(attributes.get("busType"));
busSubType = attributes.get("busSubType");
} else if (qName.endsWith("Connection") && attributes.size() > 0) {
ipAddress = attributes.get("ipAddress");
primaryNetworkConnection = Boolean.parseBoolean(attributes.get("primaryNetworkConnection"));
ipAddressingMode = attributes.get("ipAddressingMode");
}
super.startElement(uri, localName, qName, attrs);
}
}

View File

@ -0,0 +1,115 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.xml;
import static org.jclouds.vcloud.util.Utils.cleanseAttributes;
import static org.jclouds.vcloud.util.Utils.newReferenceType;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VirtualHardware;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.xml.sax.Attributes;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class VirtualHardwareHandler extends ParseSax.HandlerWithResult<VirtualHardware> {
protected StringBuilder currentText = new StringBuilder();
private final VirtualSystemHandler systemHandler;
private final VCloudResourceAllocationHandler allocationHandler;
@Inject
public VirtualHardwareHandler(VirtualSystemHandler systemHandler, VCloudResourceAllocationHandler allocationHandler) {
this.systemHandler = systemHandler;
this.allocationHandler = allocationHandler;
}
private ReferenceType hardware;
private String info;
protected VirtualSystem system;
protected Set<ResourceAllocation> allocations = Sets.newLinkedHashSet();
private boolean inItem;
private boolean inSystem;
public VirtualHardware getResult() {
return new VirtualHardware(hardware.getName(), hardware.getType(), hardware.getHref(), info, system, allocations);
}
public void startElement(String uri, String localName, String qName, Attributes attrs) {
Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.endsWith("System")) {
inSystem = true;
} else if (!inSystem && qName.endsWith("Item")) {
inItem = true;
}
if (inSystem) {
systemHandler.startElement(uri, localName, qName, attrs);
} else if (inItem) {
allocationHandler.startElement(uri, localName, qName, attrs);
} else if (qName.endsWith("VirtualHardwareSection")) {
if (attributes.containsKey("href") && attributes.get("href").endsWith("/")) {
String href = attributes.get("href");
attributes.put("href", href.substring(0, href.lastIndexOf('/')));
}
hardware = newReferenceType(attributes);
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if (qName.endsWith("System")) {
inSystem = false;
system = systemHandler.getResult();
} else if (qName.endsWith("Item")) {
inItem = false;
allocations.add(allocationHandler.getResult());
}
if (inSystem) {
systemHandler.endElement(uri, localName, qName);
} else if (inItem) {
allocationHandler.endElement(uri, localName, qName);
} else if (qName.endsWith("Info")) {
this.info = currentText.toString().trim();
}
currentText = new StringBuilder();
}
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
if (inSystem)
systemHandler.characters(ch, start, length);
if (inItem)
allocationHandler.characters(ch, start, length);
}
}

View File

@ -21,7 +21,7 @@ package org.jclouds.vcloud.xml;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.VirtualSystem; import org.jclouds.vcloud.domain.VirtualSystem;
import org.xml.sax.SAXException; import org.xml.sax.Attributes;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -34,15 +34,22 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSyst
private String virtualSystemIdentifier; private String virtualSystemIdentifier;
private String virtualSystemType; private String virtualSystemType;
private org.jclouds.vcloud.domain.VirtualSystem system; public VirtualSystem getResult() {
VirtualSystem system = new org.jclouds.vcloud.domain.VirtualSystem(instanceID, elementName,
public org.jclouds.vcloud.domain.VirtualSystem getResult() { virtualSystemIdentifier, virtualSystemType);
this.elementName = null;
this.instanceID = -1;
this.virtualSystemIdentifier = null;
this.virtualSystemType = null;
return system; return system;
} }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) {
public void endElement(String uri, String localName, String qName) throws SAXException { // no op
}
@Override
public void endElement(String uri, String localName, String qName) {
if (qName.endsWith("ElementName")) { if (qName.endsWith("ElementName")) {
this.elementName = currentText.toString().trim(); this.elementName = currentText.toString().trim();
} else if (qName.endsWith("InstanceID")) { } else if (qName.endsWith("InstanceID")) {
@ -51,15 +58,7 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSyst
this.virtualSystemIdentifier = currentText.toString().trim(); this.virtualSystemIdentifier = currentText.toString().trim();
} else if (qName.endsWith("VirtualSystemType")) { } else if (qName.endsWith("VirtualSystemType")) {
this.virtualSystemType = currentText.toString().trim(); this.virtualSystemType = currentText.toString().trim();
} else if (qName.endsWith("System")) {
this.system = new org.jclouds.vcloud.domain.VirtualSystem(instanceID, elementName,
virtualSystemIdentifier, virtualSystemType);
this.elementName = null;
this.instanceID = -1;
this.virtualSystemIdentifier = null;
this.virtualSystemType = null;
} }
currentText = new StringBuilder(); currentText = new StringBuilder();
} }

View File

@ -31,6 +31,7 @@ import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.ReferenceType; import org.jclouds.vcloud.domain.ReferenceType;
import org.jclouds.vcloud.domain.Status; import org.jclouds.vcloud.domain.Status;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VirtualHardware;
import org.jclouds.vcloud.domain.Vm; import org.jclouds.vcloud.domain.Vm;
import org.jclouds.vcloud.domain.internal.VmImpl; import org.jclouds.vcloud.domain.internal.VmImpl;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -44,10 +45,12 @@ import com.google.common.collect.Lists;
public class VmHandler extends ParseSax.HandlerWithResult<Vm> { public class VmHandler extends ParseSax.HandlerWithResult<Vm> {
protected final TaskHandler taskHandler; protected final TaskHandler taskHandler;
protected final VirtualHardwareHandler virtualHardwareHandler;
@Inject @Inject
public VmHandler(TaskHandler taskHandler) { public VmHandler(TaskHandler taskHandler, VirtualHardwareHandler virtualHardwareHandler) {
this.taskHandler = taskHandler; this.taskHandler = taskHandler;
this.virtualHardwareHandler = virtualHardwareHandler;
} }
protected StringBuilder currentText = new StringBuilder(); protected StringBuilder currentText = new StringBuilder();
@ -57,21 +60,28 @@ public class VmHandler extends ParseSax.HandlerWithResult<Vm> {
protected ReferenceType vdc; protected ReferenceType vdc;
protected String description; protected String description;
protected List<Task> tasks = Lists.newArrayList(); protected List<Task> tasks = Lists.newArrayList();
protected VirtualHardware hardware;
protected String vAppScopedLocalId; protected String vAppScopedLocalId;
private boolean inTasks; private boolean inTasks;
private boolean inHardware;
public Vm getResult() { public Vm getResult() {
return new VmImpl(vm.getName(), vm.getType(), vm.getHref(), status, vdc, description, tasks, vAppScopedLocalId); return new VmImpl(vm.getName(), vm.getType(), vm.getHref(), status, vdc, description, tasks, hardware,
vAppScopedLocalId);
} }
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
Map<String, String> attributes = cleanseAttributes(attrs); Map<String, String> attributes = cleanseAttributes(attrs);
if (qName.equals("Tasks")) { if (qName.endsWith("VirtualHardwareSection")) {
inHardware = true;
} else if (qName.endsWith("Tasks")) {
inTasks = true; inTasks = true;
} }
if (inTasks) { if (inHardware) {
virtualHardwareHandler.startElement(uri, localName, qName, attrs);
} else if (inTasks) {
taskHandler.startElement(uri, localName, qName, attrs); taskHandler.startElement(uri, localName, qName, attrs);
} else if (qName.equals("Vm")) { } else if (qName.equals("Vm")) {
vm = newReferenceType(attributes); vm = newReferenceType(attributes);
@ -84,14 +94,17 @@ public class VmHandler extends ParseSax.HandlerWithResult<Vm> {
} }
public void endElement(String uri, String name, String qName) { public void endElement(String uri, String name, String qName) {
if (qName.equals("Tasks")) { if (qName.endsWith("VirtualHardwareSection")) {
inHardware = false;
this.hardware = virtualHardwareHandler.getResult();
} else if (qName.endsWith("Tasks")) {
inTasks = false; inTasks = false;
}
if (inTasks) {
taskHandler.endElement(uri, name, qName);
if (qName.equals("Task")) {
this.tasks.add(taskHandler.getResult()); this.tasks.add(taskHandler.getResult());
} }
if (inHardware) {
virtualHardwareHandler.endElement(uri, name, qName);
} else if (inTasks) {
taskHandler.endElement(uri, name, qName);
} else if (qName.equals("Description")) { } else if (qName.equals("Description")) {
description = currentOrNull(); description = currentOrNull();
} else if (qName.equals("VAppScopedLocalId")) { } else if (qName.equals("VAppScopedLocalId")) {
@ -101,6 +114,10 @@ public class VmHandler extends ParseSax.HandlerWithResult<Vm> {
} }
public void characters(char ch[], int start, int length) { public void characters(char ch[], int start, int length) {
if (inTasks)
taskHandler.characters(ch, start, length);
if (inHardware)
virtualHardwareHandler.characters(ch, start, length);
currentText.append(ch, start, length); currentText.append(ch, start, length);
} }

View File

@ -52,8 +52,7 @@ public class VAppHandlerTest {
Factory factory = injector.getInstance(ParseSax.Factory.class); Factory factory = injector.getInstance(ParseSax.Factory.class);
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is); VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
assertEquals(result.getName(), "vApp_acole_2"); assertEquals(result.getName(), "vApp_acole_2");
assertEquals(result.getHref(), URI assertEquals(result.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320"));
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320"));
assertEquals(result.getType(), "application/vnd.vmware.vcloud.vApp+xml"); assertEquals(result.getType(), "application/vnd.vmware.vcloud.vApp+xml");
assertEquals(result.getStatus(), Status.OFF); assertEquals(result.getStatus(), Status.OFF);
assertEquals(result.getVDC(), new ReferenceTypeImpl(null, VCloudMediaType.VDC_XML, URI assertEquals(result.getVDC(), new ReferenceTypeImpl(null, VCloudMediaType.VDC_XML, URI
@ -62,15 +61,7 @@ public class VAppHandlerTest {
assertEquals(result.getTasks(), ImmutableList.of()); assertEquals(result.getTasks(), ImmutableList.of());
assert result.isOvfDescriptorUploaded(); assert result.isOvfDescriptorUploaded();
Vm vm = Iterables.getOnlyElement(result.getChildren()); Vm vm = Iterables.getOnlyElement(result.getChildren());
assertEquals(vm.getName(), "RHEL5"); VmHandlerTest.checkVm(vm);
assertEquals(vm.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248"));
assertEquals(vm.getType(), "application/vnd.vmware.vcloud.vm+xml");
assertEquals(vm.getStatus(), Status.OFF);
assertEquals(vm.getParent(), new ReferenceTypeImpl(null, VCloudMediaType.VAPP_XML, URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vapp-607806320")));
assertEquals(vm.getDescription(), null);
assertEquals(vm.getTasks(), ImmutableList.of());
assertEquals(vm.getVAppScopedLocalId(), "10_rhel_template");
} }
} }

View File

@ -25,7 +25,7 @@ import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Properties; import java.util.Properties;
import java.util.SortedSet; import java.util.Set;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
@ -43,7 +43,6 @@ import org.testng.annotations.Test;
import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
@ -93,17 +92,15 @@ public class VCloudExpressVAppHandlerTest extends BaseHandlerTest {
"10.150.4.93"); "10.150.4.93");
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "centos53", "vmx-07"); VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "centos53", "vmx-07");
SortedSet<ResourceAllocation> resourceAllocations = ImmutableSortedSet.<ResourceAllocation> naturalOrder().add( Set<ResourceAllocation> resourceAllocations = ImmutableSet.<ResourceAllocation> of(new ResourceAllocation(1,
new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs", ResourceType.PROCESSOR, null, "1 virtual CPU(s)", "Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null,
null, null, null, null, null, 1, "hertz * 10^6"), null, 1, "hertz * 10^6"), new ResourceAllocation(2, "16MB of memory", "Memory Size",
new ResourceAllocation(2, "16MB of memory", "Memory Size", ResourceType.MEMORY, null, null, null, null, ResourceType.MEMORY, null, null, null, null, null, null, 16, "byte * 2^20"), new ResourceAllocation(3,
null, null, 16, "byte * 2^20")).add( "SCSI Controller 0", "SCSI Controller", ResourceType.SCSI_CONTROLLER, "lsilogic", null, "0", null, null,
new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller", ResourceType.SCSI_CONTROLLER, null, 1, null), new ResourceAllocation(8, "Network Adapter 1",
"lsilogic", null, 0, null, null, null, 1, null)).add( "PCNet32 ethernet adapter on \"Internal\" network", ResourceType.ETHERNET_ADAPTER, "PCNet32", null,
new ResourceAllocation(8, "Network Adapter 1", "PCNet32 ethernet adapter on \"Internal\" network", null, 7, null, true, 1, null), new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE,
ResourceType.ETHERNET_ADAPTER, "PCNet32", null, null, 7, null, true, 1, null)).add( null, "104857", null, 0, 3, null, 104857, "byte * 2^20"));
new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE, null, "104857", null, 0, 3,
null, 104857, "byte * 2^20")).build();
VCloudExpressVApp expects = new VCloudExpressVAppImpl("centos53", URI VCloudExpressVApp expects = new VCloudExpressVAppImpl("centos53", URI
.create("http://10.150.4.49/api/v0.8/vApp/10"), Status.ON, new Long(104857), new ReferenceTypeImpl(null, .create("http://10.150.4.49/api/v0.8/vApp/10"), Status.ON, new Long(104857), new ReferenceTypeImpl(null,
@ -130,17 +127,15 @@ public class VCloudExpressVAppHandlerTest extends BaseHandlerTest {
"10.23.119.221"); "10.23.119.221");
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "m1", "vmx-07"); VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "m1", "vmx-07");
SortedSet<ResourceAllocation> resourceAllocations = ImmutableSortedSet.<ResourceAllocation> naturalOrder().add( Set<ResourceAllocation> resourceAllocations = ImmutableSet.<ResourceAllocation> of(new ResourceAllocation(1,
new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs", ResourceType.PROCESSOR, null, "1 virtual CPU(s)", "Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null,
null, null, null, null, null, 1, "hertz * 10^6"), null, 1, "hertz * 10^6"), new ResourceAllocation(2, "512MB of memory", "Memory Size",
new ResourceAllocation(2, "512MB of memory", "Memory Size", ResourceType.MEMORY, null, null, null, null, ResourceType.MEMORY, null, null, null, null, null, null, 512, "byte * 2^20"), new ResourceAllocation(3,
null, null, 512, "byte * 2^20")).add( "SCSI Controller 0", "SCSI Controller", ResourceType.SCSI_CONTROLLER, "lsilogic", null, "0", null, null,
new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller", ResourceType.SCSI_CONTROLLER, null, 1, null), new ResourceAllocation(8, "Network Adapter 1",
"lsilogic", null, 0, null, null, null, 1, null)).add( "PCNet32 ethernet adapter on \"Internal\" network", ResourceType.ETHERNET_ADAPTER, "PCNet32", null,
new ResourceAllocation(8, "Network Adapter 1", "PCNet32 ethernet adapter on \"Internal\" network", null, 7, null, true, 1, null), new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE,
ResourceType.ETHERNET_ADAPTER, "PCNet32", null, null, 7, null, true, 1, null)).add( null, "10485760", null, 0, 3, null, 10485760, "byte * 2^20"));
new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE, null, "10485760", null, 0, 3,
null, 10485760, "byte * 2^20")).build();
VCloudExpressVApp expects = new VCloudExpressVAppImpl("m1", URI.create("http://localhost:8000/api/v0.8/vApp/80"), VCloudExpressVApp expects = new VCloudExpressVAppImpl("m1", URI.create("http://localhost:8000/api/v0.8/vApp/80"),
Status.ON, new Long(10485760), new ReferenceTypeImpl(null, "application/vnd.vmware.vcloud.vdc+xml", URI Status.ON, new Long(10485760), new ReferenceTypeImpl(null, "application/vnd.vmware.vcloud.vdc+xml", URI
@ -157,5 +152,4 @@ public class VCloudExpressVAppHandlerTest extends BaseHandlerTest {
assertEquals(result.getType(), expects.getType()); assertEquals(result.getType(), expects.getType());
assertEquals(result.getVDC(), expects.getVDC()); assertEquals(result.getVDC(), expects.getVDC());
} }
} }

View File

@ -0,0 +1,129 @@
/**
*
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.URI;
import java.net.UnknownHostException;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.EditableResourceAllocation;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VCloudHardDisk;
import org.jclouds.vcloud.domain.VCloudNetworkAdapter;
import org.jclouds.vcloud.domain.VirtualHardware;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* Tests behavior of {@code VirtualHardwareHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VirtualHardwareHandlerTest")
public class VirtualHardwareHandlerTest extends BaseHandlerTest {
public void testDefault() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/virtualhardwaresection.xml");
VirtualHardware result = factory.create(injector.getInstance(VirtualHardwareHandler.class)).parse(is);
checkHardware(result);
}
static void checkHardware(VirtualHardware result) {
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "RHEL5", "vmx-07");
assertEquals(result.getHref(), URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection"));
assertEquals(result.getName(), null);
assertEquals(result.getType(), "application/vnd.vmware.vcloud.virtualHardwareSection+xml");
assertEquals(result.getSystem(), system);
assertEquals(result.getInfo(), "Virtual hardware requirements");
assertEquals(Iterables.get(result.getResourceAllocations(), 0), new VCloudNetworkAdapter(1, "Network adapter 0",
"PCNet32 ethernet adapter", ResourceType.ETHERNET_ADAPTER, "PCNet32", null, "00:50:56:01:01:f2", 0,
null, false, 1, null, "174.47.101.164", true, "POOL"));
assertEquals(Iterables.get(result.getResourceAllocations(), 1), new ResourceAllocation(2, "SCSI Controller 0",
"SCSI Controller", ResourceType.SCSI_CONTROLLER, "lsilogic", null, "0", null, null, null, 1, null));
assertEquals(Iterables.get(result.getResourceAllocations(), 2), new VCloudHardDisk(2000, "Hard disk 1",
"Hard disk", ResourceType.DISK_DRIVE, null, null, null, 0, 2, null, 1, null, 30720, 6, "lsilogic"));
assertEquals(Iterables.get(result.getResourceAllocations(), 3), new ResourceAllocation(3, "IDE Controller 0",
"IDE Controller", ResourceType.IDE_CONTROLLER, null, null, "0", null, null, null, 1, null));
assertEquals(Iterables.get(result.getResourceAllocations(), 4), new ResourceAllocation(3002, "CD/DVD Drive 1",
"CD/DVD Drive", ResourceType.CD_DRIVE, null, null, null, 0, 3, null, 1, null));
assertEquals(Iterables.get(result.getResourceAllocations(), 5), new ResourceAllocation(8000, "Floppy Drive 1",
"Floppy Drive", ResourceType.FLOPPY_DRIVE, null, null, null, 0, null, null, 1, null));
assertEquals(
Iterables.get(result.getResourceAllocations(), 6),
new EditableResourceAllocation(
4,
"1 virtual CPU(s)",
"Number of Virtual CPUs",
ResourceType.PROCESSOR,
null,
null,
null,
null,
null,
null,
1,
"hertz * 10^6",
new ReferenceTypeImpl(
null,
"application/vnd.vmware.vcloud.rasdItem+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/cpu"))));
assertEquals(
Iterables.get(result.getResourceAllocations(), 7),
new EditableResourceAllocation(
5,
"384 MB of memory",
"Memory Size",
ResourceType.MEMORY,
null,
null,
null,
null,
null,
null,
384,
"byte * 2^20",
new ReferenceTypeImpl(
null,
"application/vnd.vmware.vcloud.rasdItem+xml",
URI
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/memory"))));
}
}

View File

@ -49,9 +49,12 @@ public class VmHandlerTest {
Injector injector = Guice.createInjector(new SaxParserModule()); Injector injector = Guice.createInjector(new SaxParserModule());
Factory factory = injector.getInstance(ParseSax.Factory.class); Factory factory = injector.getInstance(ParseSax.Factory.class);
Vm result = factory.create(injector.getInstance(VmHandler.class)).parse(is); Vm result = factory.create(injector.getInstance(VmHandler.class)).parse(is);
checkVm(result);
}
static void checkVm(Vm result) {
assertEquals(result.getName(), "RHEL5"); assertEquals(result.getName(), "RHEL5");
assertEquals(result.getHref(), URI assertEquals(result.getHref(), URI.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248"));
.create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248"));
assertEquals(result.getType(), "application/vnd.vmware.vcloud.vm+xml"); assertEquals(result.getType(), "application/vnd.vmware.vcloud.vm+xml");
assertEquals(result.getStatus(), Status.OFF); assertEquals(result.getStatus(), Status.OFF);
assertEquals(result.getParent(), new ReferenceTypeImpl(null, VCloudMediaType.VAPP_XML, URI assertEquals(result.getParent(), new ReferenceTypeImpl(null, VCloudMediaType.VAPP_XML, URI
@ -59,6 +62,7 @@ public class VmHandlerTest {
assertEquals(result.getDescription(), null); assertEquals(result.getDescription(), null);
assertEquals(result.getTasks(), ImmutableList.of()); assertEquals(result.getTasks(), ImmutableList.of());
assertEquals(result.getVAppScopedLocalId(), "10_rhel_template"); assertEquals(result.getVAppScopedLocalId(), "10_rhel_template");
VirtualHardwareHandlerTest.checkHardware(result.getHardware());
} }
} }

View File

@ -0,0 +1,118 @@
<ovf:VirtualHardwareSection xmlns:vcloud="http://www.vmware.com/vcloud/v1"
vcloud:href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/"
vcloud:type="application/vnd.vmware.vcloud.virtualHardwareSection+xml">
<ovf:Info>Virtual hardware requirements</ovf:Info>
<ovf:System>
<vssd:ElementName>Virtual Hardware Family</vssd:ElementName>
<vssd:InstanceID>0</vssd:InstanceID>
<vssd:VirtualSystemIdentifier>RHEL5</vssd:VirtualSystemIdentifier>
<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>
</ovf:System>
<ovf:Item>
<rasd:Address>00:50:56:01:01:f2</rasd:Address>
<rasd:AddressOnParent>0</rasd:AddressOnParent>
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
<rasd:Connection vcloud:ipAddress="174.47.101.164"
vcloud:primaryNetworkConnection="true"
vcloud:ipAddressingMode="POOL">internet01</rasd:Connection>
<rasd:Description>PCNet32 ethernet adapter</rasd:Description>
<rasd:ElementName>Network adapter 0</rasd:ElementName>
<rasd:InstanceID>1</rasd:InstanceID>
<rasd:ResourceSubType>PCNet32</rasd:ResourceSubType>
<rasd:ResourceType>10</rasd:ResourceType>
</ovf:Item>
<ovf:Item>
<rasd:Address>0</rasd:Address>
<rasd:Description>SCSI Controller</rasd:Description>
<rasd:ElementName>SCSI Controller 0</rasd:ElementName>
<rasd:InstanceID>2</rasd:InstanceID>
<rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>
<rasd:ResourceType>6</rasd:ResourceType>
</ovf:Item>
<ovf:Item>
<rasd:AddressOnParent>0</rasd:AddressOnParent>
<rasd:Description>Hard disk</rasd:Description>
<rasd:ElementName>Hard disk 1</rasd:ElementName>
<rasd:HostResource vcloud:capacity="30720"
vcloud:busType="6" vcloud:busSubType="lsilogic" />
<rasd:InstanceID>2000</rasd:InstanceID>
<rasd:Parent>2</rasd:Parent>
<rasd:ResourceType>17</rasd:ResourceType>
</ovf:Item>
<ovf:Item>
<rasd:Address>0</rasd:Address>
<rasd:Description>IDE Controller</rasd:Description>
<rasd:ElementName>IDE Controller 0</rasd:ElementName>
<rasd:InstanceID>3</rasd:InstanceID>
<rasd:ResourceType>5</rasd:ResourceType>
</ovf:Item>
<ovf:Item>
<rasd:AddressOnParent>0</rasd:AddressOnParent>
<rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
<rasd:Description>CD/DVD Drive</rasd:Description>
<rasd:ElementName>CD/DVD Drive 1</rasd:ElementName>
<rasd:HostResource />
<rasd:InstanceID>3002</rasd:InstanceID>
<rasd:Parent>3</rasd:Parent>
<rasd:ResourceType>15</rasd:ResourceType>
</ovf:Item>
<ovf:Item>
<rasd:AddressOnParent>0</rasd:AddressOnParent>
<rasd:AutomaticAllocation>false</rasd:AutomaticAllocation>
<rasd:Description>Floppy Drive</rasd:Description>
<rasd:ElementName>Floppy Drive 1</rasd:ElementName>
<rasd:HostResource />
<rasd:InstanceID>8000</rasd:InstanceID>
<rasd:ResourceType>14</rasd:ResourceType>
</ovf:Item>
<ovf:Item
vcloud:href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/cpu"
vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml">
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
<rasd:Description>Number of Virtual CPUs</rasd:Description>
<rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
<rasd:InstanceID>4</rasd:InstanceID>
<rasd:Reservation>0</rasd:Reservation>
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<rasd:Weight>0</rasd:Weight>
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/cpu" />
</ovf:Item>
<ovf:Item
vcloud:href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/memory"
vcloud:type="application/vnd.vmware.vcloud.rasdItem+xml">
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
<rasd:Description>Memory Size</rasd:Description>
<rasd:ElementName>384 MB of memory</rasd:ElementName>
<rasd:InstanceID>5</rasd:InstanceID>
<rasd:Reservation>0</rasd:Reservation>
<rasd:ResourceType>4</rasd:ResourceType>
<rasd:VirtualQuantity>384</rasd:VirtualQuantity>
<rasd:Weight>0</rasd:Weight>
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/memory" />
</ovf:Item>
<Link rel="edit"
type="application/vnd.vmware.vcloud.virtualHardwareSection+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/" />
<Link rel="down" type="application/vnd.vmware.vcloud.rasdItem+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/cpu" />
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/cpu" />
<Link rel="down" type="application/vnd.vmware.vcloud.rasdItem+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/memory" />
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItem+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/memory" />
<Link rel="down" type="application/vnd.vmware.vcloud.rasdItemsList+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/disks" />
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItemsList+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/disks" />
<Link rel="down" type="application/vnd.vmware.vcloud.rasdItemsList+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/media" />
<Link rel="down" type="application/vnd.vmware.vcloud.rasdItemsList+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/networkCards" />
<Link rel="edit" type="application/vnd.vmware.vcloud.rasdItemsList+xml"
href="https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/virtualHardwareSection/networkCards" />
</ovf:VirtualHardwareSection>

View File

@ -49,7 +49,7 @@ public class ResourceAllocationHandlerTest extends BaseHandlerTest {
ResourceAllocation result = (ResourceAllocation) factory.create( ResourceAllocation result = (ResourceAllocation) factory.create(
injector.getInstance(ResourceAllocationHandler.class)).parse(is); injector.getInstance(ResourceAllocationHandler.class)).parse(is);
assertEquals(result.getAddress(), new Integer(0)); assertEquals(result.getAddress(), "0");
assertEquals(result.getDescription(), "SCSI Controller"); assertEquals(result.getDescription(), "SCSI Controller");
assertEquals(result.getName(), "SCSI Controller 0"); assertEquals(result.getName(), "SCSI Controller 0");
assertEquals(result.getId(), 3); assertEquals(result.getId(), 3);

View File

@ -79,7 +79,8 @@ public class VAppHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/launched_vapp.xml"); InputStream is = getClass().getResourceAsStream("/terremark/launched_vapp.xml");
VCloudExpressVApp result = (VCloudExpressVApp) factory.create(injector.getInstance(VCloudExpressVAppHandler.class)).parse(is); VCloudExpressVApp result = (VCloudExpressVApp) factory.create(
injector.getInstance(VCloudExpressVAppHandler.class)).parse(is);
assertEquals(result.getName(), "adriantest"); assertEquals(result.getName(), "adriantest");
assertEquals(result.getStatus(), Status.UNRESOLVED); assertEquals(result.getStatus(), Status.UNRESOLVED);
@ -95,7 +96,8 @@ public class VAppHandlerTest extends BaseHandlerTest {
public void testGetVApp() throws UnknownHostException { public void testGetVApp() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/terremark/get_vapp.xml"); InputStream is = getClass().getResourceAsStream("/terremark/get_vapp.xml");
VCloudExpressVApp result = (VCloudExpressVApp) factory.create(injector.getInstance(VCloudExpressVAppHandler.class)).parse(is); VCloudExpressVApp result = (VCloudExpressVApp) factory.create(
injector.getInstance(VCloudExpressVAppHandler.class)).parse(is);
assertEquals(result.getName(), "centos-53"); assertEquals(result.getName(), "centos-53");
assertEquals(result.getStatus(), Status.OFF); assertEquals(result.getStatus(), Status.OFF);
@ -114,7 +116,7 @@ public class VAppHandlerTest extends BaseHandlerTest {
ResourceType.PROCESSOR, null, null, null, null, null, null, 1, "hertz * 10^6"); ResourceType.PROCESSOR, null, null, null, null, null, null, 1, "hertz * 10^6");
ResourceAllocation controller = new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller", ResourceAllocation controller = new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller",
ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null, null, 1, null); ResourceType.SCSI_CONTROLLER, "lsilogic", null, "0", null, null, null, 1, null);
ResourceAllocation memory = new ResourceAllocation(2, "512MB of memory", "Memory Size", ResourceType.MEMORY, ResourceAllocation memory = new ResourceAllocation(2, "512MB of memory", "Memory Size", ResourceType.MEMORY,
null, null, null, null, null, null, 512, "byte * 2^20"); null, null, null, null, null, null, 512, "byte * 2^20");
ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE, null, ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE, null,
@ -152,7 +154,7 @@ public class VAppHandlerTest extends BaseHandlerTest {
ResourceType.PROCESSOR, null, null, null, null, null, null, 2, "hertz * 10^6"); ResourceType.PROCESSOR, null, null, null, null, null, null, 2, "hertz * 10^6");
ResourceAllocation controller = new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller", ResourceAllocation controller = new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller",
ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null, null, 1, null); ResourceType.SCSI_CONTROLLER, "lsilogic", null, "0", null, null, null, 1, null);
ResourceAllocation memory = new ResourceAllocation(2, "1024MB of memory", "Memory Size", ResourceType.MEMORY, ResourceAllocation memory = new ResourceAllocation(2, "1024MB of memory", "Memory Size", ResourceType.MEMORY,
null, null, null, null, null, null, 1024, "byte * 2^20"); null, null, null, null, null, null, 1024, "byte * 2^20");
ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE, null, ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE, null,