Merge pull request #168 from jsonking/695-1

Issue 695 - more domain objects for Virtual Machine
This commit is contained in:
Adrian Cole 2011-11-17 23:40:54 -08:00
commit a2971c22ce
18 changed files with 1170 additions and 11 deletions

View File

@ -45,6 +45,23 @@ public class Actions {
return Collections.unmodifiableSet(actions);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Actions actions1 = (Actions) o;
if (!actions.equals(actions1.actions)) return false;
return true;
}
@Override
public int hashCode() {
return actions.hashCode();
}
public String toString() {
return "["+ actions.toString()+"]";
}

View File

@ -0,0 +1,82 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import javax.xml.bind.annotation.XmlElement;
import java.net.URI;
/**
* @author Jason King
*/
public class AssignedIpAddresses extends BaseResource<AssignedIpAddresses> {
//TODO builder stuff
@XmlElement(name = "Actions", required = true)
private Actions actions;
@XmlElement(name = "Networks", required = true)
private DeviceNetworks networks;
public AssignedIpAddresses(URI href, String type, Actions actions, DeviceNetworks networks) {
super(href, type);
}
protected AssignedIpAddresses() {
//For JAXB
}
public Actions getActions() {
return actions;
}
public DeviceNetworks getNetworks() {
return networks;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
AssignedIpAddresses that = (AssignedIpAddresses) o;
if (!actions.equals(that.actions)) return false;
if (!networks.equals(that.networks)) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + actions.hashCode();
result = 31 * result + networks.hashCode();
return result;
}
@Override
public String string() {
return super.string()+", actions="+actions+", networks="+networks;
}
}

View File

@ -0,0 +1,70 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import com.google.common.collect.Sets;
import javax.xml.bind.annotation.XmlElement;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* Wraps individual IpAddresses
* @author Jason King
*/
public class DeviceIps {
private LinkedHashSet<String> ipAddresses = Sets.newLinkedHashSet();
protected DeviceIps() {
// For JAXB
}
@XmlElement(name = "IpAddress")
void setIpAddress(String ipAddress) {
this.ipAddresses.add(ipAddress);
}
public Set<String> getIpAddresses() {
return Collections.unmodifiableSet(ipAddresses);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DeviceIps deviceIps = (DeviceIps) o;
if (!ipAddresses.equals(deviceIps.ipAddresses)) return false;
return true;
}
@Override
public int hashCode() {
return ipAddresses.hashCode();
}
public String toString() {
return "["+ ipAddresses.toString()+"]";
}
}

View File

@ -0,0 +1,46 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import javax.xml.bind.annotation.XmlElement;
/**
* Container for DeviceIps (ipAddresses)
* @author Jason King
*/
public class DeviceNetwork extends BaseNamedResource<DeviceNetwork> {
@XmlElement(name = "IpAddresses")
private DeviceIps ipAddresses;
protected DeviceNetwork() {
//For JAXB
}
public DeviceIps getIpAddresses() {
return ipAddresses;
}
@Override
public String string() {
return super.string()+"ipAddresses="+ ipAddresses;
}
}

View File

@ -0,0 +1,53 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import com.google.common.collect.Sets;
import javax.xml.bind.annotation.XmlElement;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* Container for DeviceNetwork items
* @author Jason King
*/
public class DeviceNetworks {
private LinkedHashSet<DeviceNetwork> deviceNetworks = Sets.newLinkedHashSet();
protected DeviceNetworks() {
//For JAXB
}
@XmlElement(name = "Network")
void setDeviceNetwork(DeviceNetwork deviceNetwork) {
this.deviceNetworks.add(deviceNetwork);
}
public Set<DeviceNetwork> getDeviceNetworks() {
return Collections.unmodifiableSet(deviceNetworks);
}
@Override
public String toString() {
return "[deviceNetworks="+deviceNetworks+"]";
}
}

View File

@ -0,0 +1,69 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import com.google.common.collect.Sets;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* Wraps individual Disk elements.
* Needed because parsing is done with JAXB and it does not handle Generic collections
* @author Jason King
*/
@XmlRootElement(name = "Disks")
public class Disks {
private LinkedHashSet<VirtualDisk> disks = Sets.newLinkedHashSet();
@XmlElement(name = "Disk")
public void setVirtualDisk(VirtualDisk disk) {
this.disks.add(disk);
}
public Set<VirtualDisk> getVirtualDisks() {
return Collections.unmodifiableSet(disks);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Disks disks1 = (Disks) o;
if (!disks.equals(disks1.disks)) return false;
return true;
}
@Override
public int hashCode() {
return disks.hashCode();
}
public String toString() {
return "["+ disks.toString()+"]";
}
}

View File

@ -54,6 +54,8 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
private Actions actions;
private int processorCount;
private Memory memory;
private Disks disks;
private Nics nics;
/**
* @see HardwareConfiguration#getActions
@ -80,9 +82,25 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
return this;
}
/**
* @see HardwareConfiguration#getDisks
*/
public Builder disks(Disks disks) {
this.disks = disks;
return this;
}
/**
* @see HardwareConfiguration#getDisks
*/
public Builder nics(Nics nics) {
this.nics = nics;
return this;
}
@Override
public HardwareConfiguration build() {
return new HardwareConfiguration(actions, processorCount, memory);
return new HardwareConfiguration(actions, processorCount, memory, disks, nics);
}
/**
@ -119,23 +137,34 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
public Builder fromHardwareConfiguration(HardwareConfiguration in) {
return fromResource(in).actions(in.getActions())
.processorCount(in.getProcessorCount());
.processorCount(in.getProcessorCount())
.memory(in.getMemory())
.disks(in.getDisks())
.nics(in.getNics());
}
}
@XmlElement(name = "Actions", required = true)
@XmlElement(name = "Actions", required = false)
private Actions actions;
@XmlElement(name = "ProcessorCount", required = true)
private int processorCount;
@XmlElement(name = "Memory", required = true)
@XmlElement(name = "Memory", required = false)
private Memory memory;
public HardwareConfiguration(@Nullable Actions actions, int processorCount, @Nullable Memory memory) {
@XmlElement(name = "Disks", required = false)
private Disks disks;
@XmlElement(name = "Nics", required = false)
private Nics nics;
public HardwareConfiguration(@Nullable Actions actions, int processorCount, @Nullable Memory memory, @Nullable Disks disks, @Nullable Nics nics) {
this.actions = checkNotNull(actions, "actions");
this.processorCount = processorCount;
this.memory = memory;
this.disks = disks;
this.nics = nics;
}
protected HardwareConfiguration() {
@ -154,6 +183,14 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
return memory;
}
public Disks getDisks() {
return disks;
}
public Nics getNics() {
return nics;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -165,8 +202,12 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
if (processorCount != that.processorCount) return false;
if (actions != null ? !actions.equals(that.actions) : that.actions != null)
return false;
if (disks != null ? !disks.equals(that.disks) : that.disks != null)
return false;
if (memory != null ? !memory.equals(that.memory) : that.memory != null)
return false;
if (nics != null ? !nics.equals(that.nics) : that.nics != null)
return false;
return true;
}
@ -177,11 +218,14 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
result = 31 * result + (actions != null ? actions.hashCode() : 0);
result = 31 * result + processorCount;
result = 31 * result + (memory != null ? memory.hashCode() : 0);
result = 31 * result + (disks != null ? disks.hashCode() : 0);
result = 31 * result + (nics != null ? nics.hashCode() : 0);
return result;
}
@Override
public String string() {
return super.string()+", actions="+actions+", processorCount="+processorCount+", memory="+memory;
return super.string()+", actions="+actions+", processorCount="+processorCount+
", memory="+memory+", disks="+disks+", nics="+nics;
}
}

View File

@ -45,6 +45,23 @@ public class Links {
return Collections.unmodifiableSet(links);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Links links1 = (Links) o;
if (!links.equals(links1.links)) return false;
return true;
}
@Override
public int hashCode() {
return links.hashCode();
}
public String toString() {
return "["+ links.toString()+"]";
}

View File

@ -0,0 +1,157 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlEnumValue;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE;
/**
*
* @author Jason King
*
*/
@XmlRootElement(name = "Network")
public class NetworkReference extends BaseNamedResource<NetworkReference> {
@XmlEnum
public static enum NetworkType {
@XmlEnumValue("Dmz")
DMZ,
@XmlEnumValue("Internal")
INTERNAL;
public String value() {
return UPPER_UNDERSCORE.to(LOWER_CAMEL, name());
}
@Override
public String toString() {
return value();
}
}
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromNetworkReference(this);
}
public static class Builder extends BaseNamedResource.Builder<NetworkReference> {
private NetworkType networkType;
/**
* @see NetworkReference#getNetworkType
*/
public Builder networkType(NetworkType networkType) {
this.networkType = networkType;
return this;
}
@Override
public NetworkReference build() {
return new NetworkReference(href, type, name, networkType);
}
public Builder fromNetworkReference(NetworkReference in) {
return fromNamedResource(in).networkType(in.getNetworkType());
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(BaseResource<NetworkReference> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromNamedResource(BaseNamedResource<NetworkReference> in) {
return Builder.class.cast(super.fromNamedResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder name(String name) {
return Builder.class.cast(super.name(name));
}
/**
* {@inheritDoc}
*/
@Override
public Builder href(URI href) {
return Builder.class.cast(super.href(href));
}
/**
* {@inheritDoc}
*/
@Override
public Builder type(String type) {
return Builder.class.cast(super.type(type));
}
}
@XmlElement(name = "NetworkType")
private NetworkType networkType;
public NetworkReference(URI href, String type, String name, NetworkType networkType) {
super(href, type, name);
this.networkType = networkType;
}
protected NetworkReference() {
//For JAXB
}
@Nullable
public NetworkType getNetworkType() {
return networkType;
}
@Override
public String string() {
return super.string()+", networkType="+networkType;
}
}

View File

@ -0,0 +1,69 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import com.google.common.collect.Sets;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* Wraps individual VirtualNic elements.
* Needed because parsing is done with JAXB and it does not handle Generic collections
* @author Jason King
*/
@XmlRootElement(name = "Nics")
public class Nics {
private LinkedHashSet<VirtualNic> nics = Sets.newLinkedHashSet();
@XmlElement(name = "Nic")
void setVirtualNic(VirtualNic nic) {
this.nics.add(nic);
}
public Set<VirtualNic> getVirtualNics() {
return Collections.unmodifiableSet(nics);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Nics nics1 = (Nics) o;
if (!nics.equals(nics1.nics)) return false;
return true;
}
@Override
public int hashCode() {
return nics.hashCode();
}
public String toString() {
return "["+ nics.toString()+"]";
}
}

View File

@ -0,0 +1,87 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Jason King
*/
@XmlRootElement(name = "Size")
public class Size extends ResourceCapacity<Size> {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
@Override
public Builder toBuilder() {
return new Builder().fromSize(this);
}
public static class Builder extends ResourceCapacity.Builder<Size> {
@Override
public Size build() {
return new Size(value,unit);
}
public Builder fromSize(Size in) {
return fromResource(in);
}
/**
* {@inheritDoc}
*/
@Override
public Builder fromResource(ResourceCapacity<Size> in) {
return Builder.class.cast(super.fromResource(in));
}
/**
* {@inheritDoc}
*/
@Override
public Builder value(double value) {
return Builder.class.cast(super.value(value));
}
/**
* {@inheritDoc}
*/
@Override
public Builder unit(String unit) {
return Builder.class.cast(super.unit(unit));
}
}
public Size(double value, String unit) {
super(value, unit);
}
protected Size() {
//For JAXB
}
}

View File

@ -45,6 +45,23 @@ public class Tasks {
return Collections.unmodifiableSet(tasks);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tasks tasks1 = (Tasks) o;
if (!tasks.equals(tasks1.tasks)) return false;
return true;
}
@Override
public int hashCode() {
return tasks.hashCode();
}
public String toString() {
return "["+tasks.toString()+"]";
}

View File

@ -0,0 +1,144 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import org.jclouds.javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Jason King
*/
@XmlRootElement(name = "Disk")
public class VirtualDisk {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
/**
* {@inheritDoc}
*/
public Builder toBuilder() {
return new Builder().fromVirtualDisk(this);
}
public static class Builder {
private String name;
private Size size;
private int index;
/**
* @see VirtualDisk#getName
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see VirtualDisk#getSize
*/
public Builder size(Size size) {
this.size = size;
return this;
}
/**
* @see VirtualDisk#getIndex
*/
public Builder index(int index) {
this.index = index;
return this;
}
public VirtualDisk build() {
return new VirtualDisk(name, size, index);
}
public Builder fromVirtualDisk(VirtualDisk in) {
return name(in.getName())
.size(in.getSize())
.index(in.getIndex());
}
}
@XmlElement(name = "Name", required = false)
private String name;
@XmlElement(name = "Size", required = false)
private Size size;
@XmlElement(name = "Index", required = false)
private int index;
public VirtualDisk(@Nullable String name, @Nullable Size size, int index) {
this.name = name;
this.size = size;
this.index = index;
}
protected VirtualDisk() {
//For JAXB
}
public String getName() {
return name;
}
public Size getSize() {
return size;
}
public int getIndex() {
return index;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VirtualDisk disk = (VirtualDisk) o;
if (index != disk.index) return false;
if (name != null ? !name.equals(disk.name) : disk.name != null)
return false;
if (size != null ? !size.equals(disk.size) : disk.size != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (size != null ? size.hashCode() : 0);
result = 31 * result + index;
return result;
}
@Override
public String toString() {
return "[name="+name+", size="+size+", index="+index+"]";
}
}

View File

@ -70,6 +70,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
private boolean customizationPending;
private OperatingSystem operatingSystem;
private HardwareConfiguration hardwareConfiguration;
private VirtualMachineIpAddresses ipAddresses;
/**
* @see VirtualMachine#getLinks
@ -179,11 +180,19 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
return this;
}
/**
* @see VirtualMachine#getIpAddresses()
*/
public Builder ipAddresses(VirtualMachineIpAddresses ipAddresses) {
this.ipAddresses = ipAddresses;
return this;
}
@Override
public VirtualMachine build() {
return new VirtualMachine(href, type, name, tasks, actions, links, description, layout,
status, poweredOn, toolsStatus, mediaStatus, customizationPending, operatingSystem,
hardwareConfiguration);
hardwareConfiguration, ipAddresses);
}
public Builder fromVirtualMachine(VirtualMachine in) {
@ -199,7 +208,8 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
.mediaStatus(in.getMediaStatus())
.customizationPending(in.isCustomizationPending())
.operatingSystem(in.getOperatingSystem())
.hardwareConfiguration(in.getHardwareConfiguration());
.hardwareConfiguration(in.getHardwareConfiguration())
.ipAddresses(in.getIpAddresses());
}
/**
@ -289,9 +299,12 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
@XmlElement(name = "HardwareConfiguration", required = false)
private HardwareConfiguration hardwareConfiguation;
@XmlElement(name = "IpAddresses", required = false)
private VirtualMachineIpAddresses ipAddresses;
public VirtualMachine(URI href, String type, String name, Tasks tasks, Actions actions, Links links, String description, @Nullable Layout layout,
VirtualMachineStatus status, boolean poweredOn, @Nullable ToolsStatus toolsStatus, @Nullable VirtualMachineMediaStatus mediaStatus, boolean customizationPending,
@Nullable OperatingSystem operatingSystem, @Nullable HardwareConfiguration hardwareConfiguration ) {
@Nullable OperatingSystem operatingSystem, @Nullable HardwareConfiguration hardwareConfiguration, @Nullable VirtualMachineIpAddresses ipAddresses) {
super(href, type, name);
this.description = checkNotNull(description, "description");
this.links = checkNotNull(links, "links");
@ -306,6 +319,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
this.customizationPending = customizationPending;
this.operatingSystem = operatingSystem;
this.hardwareConfiguation = hardwareConfiguration;
this.ipAddresses = ipAddresses;
}
protected VirtualMachine() {
@ -379,6 +393,13 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
return operatingSystem;
}
/**
* Is optional, so may return null
*/
public VirtualMachineIpAddresses getIpAddresses() {
return ipAddresses;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -393,6 +414,8 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
if (!description.equals(that.description)) return false;
if (hardwareConfiguation != null ? !hardwareConfiguation.equals(that.hardwareConfiguation) : that.hardwareConfiguation != null)
return false;
if (ipAddresses != null ? !ipAddresses.equals(that.ipAddresses) : that.ipAddresses != null)
return false;
if (layout != null ? !layout.equals(that.layout) : that.layout != null)
return false;
if (!links.equals(that.links)) return false;
@ -421,6 +444,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
result = 31 * result + (customizationPending ? 1 : 0);
result = 31 * result + (operatingSystem != null ? operatingSystem.hashCode() : 0);
result = 31 * result + (hardwareConfiguation != null ? hardwareConfiguation.hashCode() : 0);
result = 31 * result + (ipAddresses != null ? ipAddresses.hashCode() : 0);
return result;
}
@ -428,7 +452,8 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
public String string() {
return super.string()+", links="+links+", tasks="+tasks+", actions="+actions+", description="+description+", layout="+layout+
", status="+status+", poweredOn="+poweredOn+", toolsStatus="+toolsStatus+", mediaStatus="+mediaStatus+
", customizationPending="+customizationPending+", operatingSystem="+operatingSystem+", hardwareConfiguration="+hardwareConfiguation;
", customizationPending="+customizationPending+", operatingSystem="+operatingSystem+", hardwareConfiguration="+hardwareConfiguation+
", ipAddresses="+ipAddresses;
}
@XmlEnum

View File

@ -0,0 +1,50 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import com.google.common.collect.Sets;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* @author Jason King
*/
public class VirtualMachineIpAddresses {
@XmlElement(name = "AssignedIpAddresses")
private AssignedIpAddresses assignedIpAddresses;
protected VirtualMachineIpAddresses() {
// For JAXB
}
public AssignedIpAddresses getAssignedIpAddresses() {
return assignedIpAddresses;
}
@Override
public String toString() {
return "["+assignedIpAddresses+"]";
}
}

View File

@ -0,0 +1,165 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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.tmrk.enterprisecloud.domain;
import org.jclouds.javax.annotation.Nullable;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
/**
* @author Jason King
*/
@XmlRootElement(name = "Nic")
public class VirtualNic {
@SuppressWarnings("unchecked")
public static Builder builder() {
return new Builder();
}
public Builder toBuilder() {
return new Builder().fromVirtualNic(this);
}
public static class Builder {
private String name;
private String macAddress;
private int unitNumber;
private NetworkReference network;
/**
* @see VirtualNic#getName
*/
public Builder name(String name) {
this.name = name;
return this;
}
/**
* @see VirtualNic#getMacAddress
*/
public Builder macAddress(String macAddress) {
this.macAddress = macAddress;
return this;
}
/**
* @see VirtualNic#getUnitNumber
*/
public Builder unitNumber(int unitNumber) {
this.unitNumber = unitNumber;
return this;
}
/**
* @see VirtualNic#getNetwork
*/
public Builder network(NetworkReference network) {
this.network = network;
return this;
}
public VirtualNic build() {
return new VirtualNic(name, macAddress, unitNumber, network);
}
public Builder fromVirtualNic(VirtualNic in) {
return name(in.getName())
.macAddress(in.getMacAddress())
.unitNumber(in.getUnitNumber())
.network(in.getNetwork());
}
}
@XmlElement(name = "Name")
private String name;
@XmlElement(name = "MacAddress")
private String macAddress;
@XmlElement(name = "UnitNumber")
private int unitNumber;
@XmlElement(name = "Network")
private NetworkReference network;
public VirtualNic(@Nullable String name, @Nullable String macAddress, int unitNumber, @Nullable NetworkReference network) {
this.name = name;
this.macAddress = macAddress;
this.unitNumber = unitNumber;
this.network = network;
}
protected VirtualNic() {
//For JAXB
}
@Nullable
public String getName() {
return name;
}
@Nullable
public String getMacAddress() {
return macAddress;
}
public int getUnitNumber() {
return unitNumber;
}
@Nullable
public NetworkReference getNetwork() {
return network;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
VirtualNic that = (VirtualNic) o;
if (unitNumber != that.unitNumber) return false;
if (macAddress != null ? !macAddress.equals(that.macAddress) : that.macAddress != null)
return false;
if (name != null ? !name.equals(that.name) : that.name != null)
return false;
if (network != null ? !network.equals(that.network) : that.network != null)
return false;
return true;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (macAddress != null ? macAddress.hashCode() : 0);
result = 31 * result + unitNumber;
result = 31 * result + (network != null ? network.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "[name="+name+",macAddress="+macAddress+",unitNumber="+unitNumber+",network="+network+"]";
}
}

View File

@ -38,6 +38,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.*;
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine.VirtualMachineStatus;
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
import org.testng.Assert;
import org.testng.AssertJUnit;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@ -119,6 +120,7 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
assertTrue(virtualMachine.isCustomizationPending(),"virtual machine is pending customization");
assertOperatingSystem(virtualMachine.getOperatingSystem());
assertHardwareConfiguration(virtualMachine.getHardwareConfiguration());
assertIpAddresses(virtualMachine.getIpAddresses());
}
private void assertLayout(Layout layout) {
@ -135,11 +137,55 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
Assert.assertEquals(os, operatingSystem);
}
private void assertHardwareConfiguration(HardwareConfiguration hardwareConfiguration) {
private void assertHardwareConfiguration(HardwareConfiguration hardwareConfiguration) throws Exception {
assertEquals(1,hardwareConfiguration.getActions().size());
assertEquals(1,hardwareConfiguration.getProcessorCount());
Memory memory = Memory.builder().value(384).unit("MB").build();
assertEquals(memory,hardwareConfiguration.getMemory());
assertDisks(hardwareConfiguration.getDisks());
assertNics(hardwareConfiguration.getNics().getVirtualNics());
}
private void assertDisks(Disks disks) {
VirtualDisk disk = VirtualDisk.builder().index(0).name("Hard Disk 1")
.size(Size.builder().value(10).unit("GB").build())
.build();
Disks expectedDisks = new Disks();
expectedDisks.setVirtualDisk(disk);
assertEquals(expectedDisks, disks);
}
private void assertNics(Set<VirtualNic> nics) throws Exception {
assertEquals(1, nics.size());
NetworkReference network = NetworkReference.builder()
.href(new URI("/cloudapi/ecloud/networks/3936"))
.name("10.146.204.64/28")
.type("application/vnd.tmrk.cloud.network")
.networkType(NetworkReference.NetworkType.INTERNAL)
.build();
VirtualNic nic = VirtualNic.builder()
.macAddress("00:50:56:b8:00:58")
.name("Network adapter 1")
.network(network)
.unitNumber(7)
.build();
assertEquals(nic,nics.iterator().next());
}
private void assertIpAddresses(VirtualMachineIpAddresses ipAddresses) {
AssignedIpAddresses assignedIpAddresses = ipAddresses.getAssignedIpAddresses();
Assert.assertNotNull(assignedIpAddresses);
Set<DeviceNetwork> deviceNetworks = assignedIpAddresses.getNetworks().getDeviceNetworks();
assertEquals(1,deviceNetworks.size());
DeviceNetwork network = deviceNetworks.iterator().next(); //todo use guava instead.
Set<String> ips = network.getIpAddresses().getIpAddresses();
assertEquals(2,ips.size());
assertTrue(ips.contains("10.146.204.67"));
assertTrue(ips.contains("10.146.204.68"));
}
}

View File

@ -128,6 +128,7 @@
type="application/vnd.tmrk.cloud.network">
<IpAddresses>
<IpAddress>10.146.204.67</IpAddress>
<IpAddress>10.146.204.68</IpAddress>
</IpAddresses>
</Network>
</Networks>