Issue 695: Added IpAddress Section of VirtualMachine

This commit is contained in:
Jason King 2011-11-17 19:58:35 +00:00
parent 0b43af5c9b
commit f86106cb09
8 changed files with 345 additions and 4 deletions

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

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

@ -38,6 +38,7 @@ import org.jclouds.tmrk.enterprisecloud.domain.*;
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine.VirtualMachineStatus; import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine.VirtualMachineStatus;
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient; import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
import org.testng.Assert; import org.testng.Assert;
import org.testng.AssertJUnit;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -119,6 +120,7 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
assertTrue(virtualMachine.isCustomizationPending(),"virtual machine is pending customization"); assertTrue(virtualMachine.isCustomizationPending(),"virtual machine is pending customization");
assertOperatingSystem(virtualMachine.getOperatingSystem()); assertOperatingSystem(virtualMachine.getOperatingSystem());
assertHardwareConfiguration(virtualMachine.getHardwareConfiguration()); assertHardwareConfiguration(virtualMachine.getHardwareConfiguration());
assertIpAddresses(virtualMachine.getIpAddresses());
} }
private void assertLayout(Layout layout) { private void assertLayout(Layout layout) {
@ -174,4 +176,16 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
.build(); .build();
assertEquals(nic,nics.iterator().next()); 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"> type="application/vnd.tmrk.cloud.network">
<IpAddresses> <IpAddresses>
<IpAddress>10.146.204.67</IpAddress> <IpAddress>10.146.204.67</IpAddress>
<IpAddress>10.146.204.68</IpAddress>
</IpAddresses> </IpAddresses>
</Network> </Network>
</Networks> </Networks>