mirror of https://github.com/apache/jclouds.git
Oops, missed some files in previous commit. New files for vApp extended info.
This commit is contained in:
parent
d9b9c61ce6
commit
35d5131ba9
|
@ -0,0 +1,92 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 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.terremark.domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Seshu Pasam
|
||||||
|
*/
|
||||||
|
public class NetworkAdapter implements Comparable<NetworkAdapter> {
|
||||||
|
private final String macAddress;
|
||||||
|
private final String name;
|
||||||
|
private final Subnet subnet;
|
||||||
|
|
||||||
|
public NetworkAdapter(String macAddress, String name, Subnet subnet) {
|
||||||
|
this.macAddress = macAddress;
|
||||||
|
this.name = name;
|
||||||
|
this.subnet = subnet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(NetworkAdapter that) {
|
||||||
|
return (this == that) ? 0 : getMacAddress().compareTo(that.getMacAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMacAddress() {
|
||||||
|
return macAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Subnet getSubnet() {
|
||||||
|
return subnet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((macAddress== null) ? 0 : macAddress.hashCode());
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
result = prime * result + ((subnet == null) ? 0 : subnet.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
NetworkAdapter other = (NetworkAdapter) obj;
|
||||||
|
if (macAddress == null) {
|
||||||
|
if (other.macAddress != null)
|
||||||
|
return false;
|
||||||
|
} else if (!macAddress.equals(other.macAddress))
|
||||||
|
return false;
|
||||||
|
if (name == null) {
|
||||||
|
if (other.name != null)
|
||||||
|
return false;
|
||||||
|
} else if (!name.equals(other.name))
|
||||||
|
return false;
|
||||||
|
if (subnet == null) {
|
||||||
|
if (other.subnet != null)
|
||||||
|
return false;
|
||||||
|
} else if (!subnet.equals(other.subnet))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "[MAC address=" + macAddress + ", name=" + name + ", subnet=" + subnet + "]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 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.terremark.domain;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Seshu Pasam
|
||||||
|
*/
|
||||||
|
public class Subnet implements Comparable<Subnet> {
|
||||||
|
private final URI href;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
public Subnet(URI href, String name) {
|
||||||
|
this.href = href;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(Subnet that) {
|
||||||
|
return (this == that) ? 0 : getHref().compareTo(that.getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI getHref() {
|
||||||
|
return href;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((href == null) ? 0 : href.hashCode());
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
Subnet other = (Subnet) obj;
|
||||||
|
if (href == null) {
|
||||||
|
if (other.href != null)
|
||||||
|
return false;
|
||||||
|
} else if (!href.equals(other.href))
|
||||||
|
return false;
|
||||||
|
if (name == null) {
|
||||||
|
if (other.name != null)
|
||||||
|
return false;
|
||||||
|
} else if (!name.equals(other.name))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "[href=" + href + ", name=" + name + "]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,128 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 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.terremark.domain;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Seshu Pasam
|
||||||
|
*/
|
||||||
|
public class VAppExtendedInfo implements Comparable<VAppExtendedInfo> {
|
||||||
|
private final String id;
|
||||||
|
private final URI href;
|
||||||
|
private final String name;
|
||||||
|
private final List<String> tags;
|
||||||
|
private final String longName;
|
||||||
|
private final List<NetworkAdapter> networkAdapters;
|
||||||
|
|
||||||
|
public VAppExtendedInfo(String id, URI href, String name, List<String> tags, String longName,
|
||||||
|
List<NetworkAdapter> networkAdapters) {
|
||||||
|
this.id = id;
|
||||||
|
this.href = href;
|
||||||
|
this.name = name;
|
||||||
|
this.tags = tags;
|
||||||
|
this.longName = longName;
|
||||||
|
this.networkAdapters = networkAdapters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(VAppExtendedInfo that) {
|
||||||
|
return (this == that) ? 0 : getHref().compareTo(that.getHref());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URI getHref() {
|
||||||
|
return href;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTags() {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLongName() {
|
||||||
|
return longName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<NetworkAdapter> getNetworkAdapters() {
|
||||||
|
return networkAdapters;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
final int prime = 31;
|
||||||
|
int result = 1;
|
||||||
|
result = prime * result + ((href == null) ? 0 : href.hashCode());
|
||||||
|
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||||
|
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||||
|
result = prime * result + ((longName == null) ? 0 : longName.hashCode());
|
||||||
|
result = prime * result + ((tags == null) ? 0 : tags.hashCode());
|
||||||
|
result = prime * result + ((networkAdapters == null) ? 0 : networkAdapters.hashCode());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null)
|
||||||
|
return false;
|
||||||
|
if (getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
VAppExtendedInfo other = (VAppExtendedInfo) obj;
|
||||||
|
if (href == null) {
|
||||||
|
if (other.href != null)
|
||||||
|
return false;
|
||||||
|
} else if (!href.equals(other.href))
|
||||||
|
return false;
|
||||||
|
if (id == null) {
|
||||||
|
if (other.id != null)
|
||||||
|
return false;
|
||||||
|
} else if (!id.equals(other.id))
|
||||||
|
return false;
|
||||||
|
if (name == null) {
|
||||||
|
if (other.name != null)
|
||||||
|
return false;
|
||||||
|
} else if (!name.equals(other.name))
|
||||||
|
return false;
|
||||||
|
if (tags == null) {
|
||||||
|
if (other.tags != null)
|
||||||
|
return false;
|
||||||
|
} else if (!tags.equals(other.tags))
|
||||||
|
return false;
|
||||||
|
if (networkAdapters == null) {
|
||||||
|
if (other.networkAdapters != null)
|
||||||
|
return false;
|
||||||
|
} else if (!networkAdapters.equals(other.networkAdapters))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "[href=" + href + ", id=" + id + ", name=" + name + ", long name=" + longName
|
||||||
|
+ ", tags=" + tags.toString() + ", network adapters=" + networkAdapters.toString() + "]";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,125 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2011 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.terremark.xml;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
|
import org.jclouds.vcloud.terremark.domain.VAppExtendedInfo;
|
||||||
|
import org.jclouds.vcloud.terremark.domain.NetworkAdapter;
|
||||||
|
import org.jclouds.vcloud.terremark.domain.Subnet;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Seshu Pasam
|
||||||
|
*/
|
||||||
|
public class VAppExtendedInfoHandler extends HandlerWithResult<VAppExtendedInfo> {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
private StringBuilder currentText = new StringBuilder();
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private URI href;
|
||||||
|
private String name;
|
||||||
|
private String longName;
|
||||||
|
private List<String> tags;
|
||||||
|
private List<NetworkAdapter> networkAdapters = Lists.newArrayList();
|
||||||
|
private boolean inAdapters;
|
||||||
|
private String macAddress;
|
||||||
|
private String adapterName;
|
||||||
|
private boolean inSubnet;
|
||||||
|
private Subnet subnet;
|
||||||
|
private URI subnetLocation;
|
||||||
|
private String subnetName;
|
||||||
|
|
||||||
|
protected String currentOrNull() {
|
||||||
|
String returnVal = currentText.toString().trim();
|
||||||
|
return returnVal.equals("") ? null : returnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VAppExtendedInfo getResult() {
|
||||||
|
return new VAppExtendedInfo(id, href, name, tags, longName, networkAdapters);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||||
|
if (qName.equals("NetworkAdapters")) {
|
||||||
|
inAdapters = true;
|
||||||
|
} else if (qName.equals("Subnet")) {
|
||||||
|
inSubnet = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endElement(String uri, String name, String qName) {
|
||||||
|
String current = currentOrNull();
|
||||||
|
if (current != null) {
|
||||||
|
if (qName.equals("Id")) {
|
||||||
|
this.id = current;
|
||||||
|
} else if (qName.equals("Tags")) {
|
||||||
|
this.tags = Arrays.asList(current.split(","));
|
||||||
|
} else if (qName.equals("LongName")) {
|
||||||
|
this.longName = current;
|
||||||
|
} else if (qName.equals("Href")) {
|
||||||
|
if (inSubnet) {
|
||||||
|
this.subnetLocation = URI.create(current);
|
||||||
|
} else {
|
||||||
|
this.href = URI.create(current);
|
||||||
|
}
|
||||||
|
} else if (qName.equals("Name")) {
|
||||||
|
if (inSubnet) {
|
||||||
|
this.subnetName = current;
|
||||||
|
} else if (inAdapters) {
|
||||||
|
this.adapterName = current;
|
||||||
|
} else {
|
||||||
|
this.name = current;
|
||||||
|
}
|
||||||
|
} else if (qName.equals("NetworkAdapters")) {
|
||||||
|
inAdapters = false;
|
||||||
|
} else if (qName.equals("NetworkAdapter")) {
|
||||||
|
networkAdapters.add(new NetworkAdapter(macAddress, adapterName, subnet));
|
||||||
|
macAddress = null;
|
||||||
|
adapterName = null;
|
||||||
|
subnet = null;
|
||||||
|
} else if (qName.equals("MacAddress")) {
|
||||||
|
macAddress = current;
|
||||||
|
} else if (qName.equals("Subnet")) {
|
||||||
|
subnet = new Subnet(subnetLocation, subnetName);
|
||||||
|
subnetLocation = null;
|
||||||
|
subnetName = null;
|
||||||
|
inSubnet = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentText = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void characters(char ch[], int start, int length) {
|
||||||
|
currentText.append(ch, start, length);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue