mirror of https://github.com/apache/jclouds.git
Issue 695: Added Nic/Network details to HardwareConfiguration
This commit is contained in:
parent
e911aad122
commit
0b43af5c9b
|
@ -55,6 +55,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
|||
private int processorCount;
|
||||
private Memory memory;
|
||||
private Disks disks;
|
||||
private Nics nics;
|
||||
|
||||
/**
|
||||
* @see HardwareConfiguration#getActions
|
||||
|
@ -89,9 +90,17 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
|||
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, disks);
|
||||
return new HardwareConfiguration(actions, processorCount, memory, disks, nics);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -130,7 +139,8 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
|||
return fromResource(in).actions(in.getActions())
|
||||
.processorCount(in.getProcessorCount())
|
||||
.memory(in.getMemory())
|
||||
.disks(in.getDisks());
|
||||
.disks(in.getDisks())
|
||||
.nics(in.getNics());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,11 +156,15 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
|||
@XmlElement(name = "Disks", required = false)
|
||||
private Disks disks;
|
||||
|
||||
public HardwareConfiguration(@Nullable Actions actions, int processorCount, @Nullable Memory memory, @Nullable 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() {
|
||||
|
@ -173,6 +187,10 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
|||
return disks;
|
||||
}
|
||||
|
||||
public Nics getNics() {
|
||||
return nics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -184,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;
|
||||
}
|
||||
|
@ -196,12 +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+", disks="+disks;
|
||||
", memory="+memory+", disks="+disks+", nics="+nics;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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()+"]";
|
||||
}
|
||||
|
||||
}
|
|
@ -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+"]";
|
||||
}
|
||||
}
|
|
@ -135,12 +135,13 @@ 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) {
|
||||
|
@ -150,8 +151,27 @@ public class VirtualMachineJAXBParsingTest extends BaseRestClientTest {
|
|||
Disks expectedDisks = new Disks();
|
||||
expectedDisks.setVirtualDisk(disk);
|
||||
|
||||
assertEquals(expectedDisks,disks);
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue