You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by wi...@apache.org on 2012/06/23 11:40:28 UTC
[5/7] agent: Replace tabs by 4 spaces
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/LibvirtConnection.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtConnection.java b/agent/src/com/cloud/agent/resource/computing/LibvirtConnection.java
index 874ad98..d3a2318 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtConnection.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtConnection.java
@@ -21,28 +21,28 @@ import org.libvirt.Connect;
import org.libvirt.LibvirtException;
public class LibvirtConnection {
- private static final Logger s_logger = Logger
- .getLogger(LibvirtConnection.class);
- static private Connect _connection;
- static private String _hypervisorURI;
+ private static final Logger s_logger = Logger
+ .getLogger(LibvirtConnection.class);
+ static private Connect _connection;
+ static private String _hypervisorURI;
- static public Connect getConnection() throws LibvirtException {
- if (_connection == null) {
- _connection = new Connect(_hypervisorURI, false);
- } else {
- try {
- _connection.getVersion();
- } catch (LibvirtException e) {
- s_logger.debug("Connection with libvirtd is broken, due to "
- + e.getMessage());
- _connection = new Connect(_hypervisorURI, false);
- }
- }
+ static public Connect getConnection() throws LibvirtException {
+ if (_connection == null) {
+ _connection = new Connect(_hypervisorURI, false);
+ } else {
+ try {
+ _connection.getVersion();
+ } catch (LibvirtException e) {
+ s_logger.debug("Connection with libvirtd is broken, due to "
+ + e.getMessage());
+ _connection = new Connect(_hypervisorURI, false);
+ }
+ }
- return _connection;
- }
+ return _connection;
+ }
- static void initialize(String hypervisorURI) {
- _hypervisorURI = hypervisorURI;
- }
+ static void initialize(String hypervisorURI) {
+ _hypervisorURI = hypervisorURI;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java b/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java
index f51d7ae..6215534 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java
@@ -45,209 +45,209 @@ import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef.nicModel;
*
*/
public class LibvirtDomainXMLParser {
- private static final Logger s_logger = Logger
- .getLogger(LibvirtDomainXMLParser.class);
- private final List<InterfaceDef> interfaces = new ArrayList<InterfaceDef>();
- private final List<DiskDef> diskDefs = new ArrayList<DiskDef>();
- private Integer vncPort;
- private String desc;
-
- public boolean parseDomainXML(String domXML) {
- DocumentBuilder builder;
- try {
- builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
-
- InputSource is = new InputSource();
- is.setCharacterStream(new StringReader(domXML));
- Document doc = builder.parse(is);
-
- Element rootElement = doc.getDocumentElement();
-
- desc = getTagValue("description", rootElement);
-
- Element devices = (Element) rootElement.getElementsByTagName(
- "devices").item(0);
- NodeList disks = devices.getElementsByTagName("disk");
- for (int i = 0; i < disks.getLength(); i++) {
- Element disk = (Element) disks.item(i);
- String diskFmtType = getAttrValue("driver", "type", disk);
- String diskFile = getAttrValue("source", "file", disk);
- String diskDev = getAttrValue("source", "dev", disk);
-
- String diskLabel = getAttrValue("target", "dev", disk);
- String bus = getAttrValue("target", "bus", disk);
- String type = disk.getAttribute("type");
- String device = disk.getAttribute("device");
-
- DiskDef def = new DiskDef();
- if (type.equalsIgnoreCase("file")) {
- if (device.equalsIgnoreCase("disk")) {
- DiskDef.diskFmtType fmt = null;
- if (diskFmtType != null) {
- fmt = DiskDef.diskFmtType.valueOf(diskFmtType
- .toUpperCase());
- }
- def.defFileBasedDisk(diskFile, diskLabel,
- DiskDef.diskBus.valueOf(bus.toUpperCase()), fmt);
- } else if (device.equalsIgnoreCase("cdrom")) {
- def.defISODisk(diskFile);
- }
- } else if (type.equalsIgnoreCase("block")) {
- def.defBlockBasedDisk(diskDev, diskLabel,
- DiskDef.diskBus.valueOf(bus.toUpperCase()));
- }
- diskDefs.add(def);
- }
-
- NodeList nics = devices.getElementsByTagName("interface");
- for (int i = 0; i < nics.getLength(); i++) {
- Element nic = (Element) nics.item(i);
-
- String type = nic.getAttribute("type");
- String mac = getAttrValue("mac", "address", nic);
- String dev = getAttrValue("target", "dev", nic);
- String model = getAttrValue("model", "type", nic);
- InterfaceDef def = new InterfaceDef();
-
- if (type.equalsIgnoreCase("network")) {
- String network = getAttrValue("source", "network", nic);
- def.defPrivateNet(network, dev, mac,
- nicModel.valueOf(model.toUpperCase()));
- } else if (type.equalsIgnoreCase("bridge")) {
- String bridge = getAttrValue("source", "bridge", nic);
- def.defBridgeNet(bridge, dev, mac,
- nicModel.valueOf(model.toUpperCase()));
- }
- interfaces.add(def);
- }
-
- Element graphic = (Element) devices
- .getElementsByTagName("graphics").item(0);
- String port = graphic.getAttribute("port");
- if (port != null) {
- try {
- vncPort = Integer.parseInt(port);
- if (vncPort != -1) {
- vncPort = vncPort - 5900;
- } else {
- vncPort = null;
- }
- } catch (NumberFormatException nfe) {
- vncPort = null;
- }
- }
-
- return true;
- } catch (ParserConfigurationException e) {
- s_logger.debug(e.toString());
- } catch (SAXException e) {
- s_logger.debug(e.toString());
- } catch (IOException e) {
- s_logger.debug(e.toString());
- }
- return false;
- }
-
- private static String getTagValue(String tag, Element eElement) {
- NodeList tagNodeList = eElement.getElementsByTagName(tag);
- if (tagNodeList == null || tagNodeList.getLength() == 0) {
- return null;
- }
-
- NodeList nlList = tagNodeList.item(0).getChildNodes();
-
- Node nValue = (Node) nlList.item(0);
-
- return nValue.getNodeValue();
- }
-
- private static String getAttrValue(String tag, String attr, Element eElement) {
- NodeList tagNode = eElement.getElementsByTagName(tag);
- if (tagNode.getLength() == 0) {
- return null;
- }
- Element node = (Element) tagNode.item(0);
- return node.getAttribute(attr);
- }
-
- public Integer getVncPort() {
- return vncPort;
- }
-
- public List<InterfaceDef> getInterfaces() {
- return interfaces;
- }
-
- public List<DiskDef> getDisks() {
- return diskDefs;
- }
-
- public String getDescription() {
- return desc;
- }
-
- public static void main(String[] args) {
- LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
- parser.parseDomainXML("<domain type='kvm' id='12'>"
- + "<name>r-6-CV-5002-1</name>"
- + "<uuid>581b5a4b-b496-8d4d-e44e-a7dcbe9df0b5</uuid>"
- + "<description>testVM</description>"
- + "<memory>131072</memory>"
- + "<currentMemory>131072</currentMemory>"
- + "<vcpu>1</vcpu>"
- + "<os>"
- + "<type arch='i686' machine='pc-0.11'>hvm</type>"
- + "<kernel>/var/lib/libvirt/qemu/vmlinuz-2.6.31.6-166.fc12.i686</kernel>"
- + "<cmdline>ro root=/dev/sda1 acpi=force selinux=0 eth0ip=10.1.1.1 eth0mask=255.255.255.0 eth2ip=192.168.10.152 eth2mask=255.255.255.0 gateway=192.168.10.1 dns1=72.52.126.11 dns2=72.52.126.12 domain=v4.myvm.com</cmdline>"
- + "<boot dev='hd'/>"
- + "</os>"
- + "<features>"
- + "<acpi/>"
- + "<pae/>"
- + "</features>"
- + "<clock offset='utc'/>"
- + "<on_poweroff>destroy</on_poweroff>"
- + "<on_reboot>restart</on_reboot>"
- + "<on_crash>destroy</on_crash>"
- + "<devices>"
- + "<emulator>/usr/bin/qemu-kvm</emulator>"
- + "<disk type='file' device='disk'>"
- + "<driver name='qemu' type='raw'/>"
- + "<source file='/mnt/tank//vmops/CV/vm/u000004/r000006/rootdisk'/>"
- + "<target dev='hda' bus='ide'/>" + "</disk>"
- + "<interface type='bridge'>"
- + "<mac address='02:00:50:02:00:01'/>"
- + "<source bridge='vnbr5002'/>" + "<target dev='vtap5002'/>"
- + "<model type='e1000'/>" + "</interface>"
- + "<interface type='network'>"
- + "<mac address='00:16:3e:77:e2:a1'/>"
- + "<source network='vmops-private'/>" + "<target dev='vnet3'/>"
- + "<model type='e1000'/>" + "</interface>"
- + "<interface type='bridge'>"
- + "<mac address='06:85:00:00:00:04'/>"
- + "<source bridge='br0'/>" + "<target dev='tap5002'/>"
- + "<model type='e1000'/>" + "</interface>"
- + "<input type='mouse' bus='ps2'/>"
- + "<graphics type='vnc' port='6031' autoport='no' listen=''/>"
- + "<video>" + "<model type='cirrus' vram='9216' heads='1'/>"
- + "</video>" + "</devices>" + "</domain>"
-
- );
- for (InterfaceDef intf : parser.getInterfaces()) {
- System.out.println(intf);
- }
- for (DiskDef disk : parser.getDisks()) {
- System.out.println(disk);
- }
- System.out.println(parser.getVncPort());
- System.out.println(parser.getDescription());
-
- List<String> test = new ArrayList<String>(1);
- test.add("1");
- test.add("2");
- if (test.contains("1")) {
- System.out.print("fdf");
- }
- }
+ private static final Logger s_logger = Logger
+ .getLogger(LibvirtDomainXMLParser.class);
+ private final List<InterfaceDef> interfaces = new ArrayList<InterfaceDef>();
+ private final List<DiskDef> diskDefs = new ArrayList<DiskDef>();
+ private Integer vncPort;
+ private String desc;
+
+ public boolean parseDomainXML(String domXML) {
+ DocumentBuilder builder;
+ try {
+ builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+
+ InputSource is = new InputSource();
+ is.setCharacterStream(new StringReader(domXML));
+ Document doc = builder.parse(is);
+
+ Element rootElement = doc.getDocumentElement();
+
+ desc = getTagValue("description", rootElement);
+
+ Element devices = (Element) rootElement.getElementsByTagName(
+ "devices").item(0);
+ NodeList disks = devices.getElementsByTagName("disk");
+ for (int i = 0; i < disks.getLength(); i++) {
+ Element disk = (Element) disks.item(i);
+ String diskFmtType = getAttrValue("driver", "type", disk);
+ String diskFile = getAttrValue("source", "file", disk);
+ String diskDev = getAttrValue("source", "dev", disk);
+
+ String diskLabel = getAttrValue("target", "dev", disk);
+ String bus = getAttrValue("target", "bus", disk);
+ String type = disk.getAttribute("type");
+ String device = disk.getAttribute("device");
+
+ DiskDef def = new DiskDef();
+ if (type.equalsIgnoreCase("file")) {
+ if (device.equalsIgnoreCase("disk")) {
+ DiskDef.diskFmtType fmt = null;
+ if (diskFmtType != null) {
+ fmt = DiskDef.diskFmtType.valueOf(diskFmtType
+ .toUpperCase());
+ }
+ def.defFileBasedDisk(diskFile, diskLabel,
+ DiskDef.diskBus.valueOf(bus.toUpperCase()), fmt);
+ } else if (device.equalsIgnoreCase("cdrom")) {
+ def.defISODisk(diskFile);
+ }
+ } else if (type.equalsIgnoreCase("block")) {
+ def.defBlockBasedDisk(diskDev, diskLabel,
+ DiskDef.diskBus.valueOf(bus.toUpperCase()));
+ }
+ diskDefs.add(def);
+ }
+
+ NodeList nics = devices.getElementsByTagName("interface");
+ for (int i = 0; i < nics.getLength(); i++) {
+ Element nic = (Element) nics.item(i);
+
+ String type = nic.getAttribute("type");
+ String mac = getAttrValue("mac", "address", nic);
+ String dev = getAttrValue("target", "dev", nic);
+ String model = getAttrValue("model", "type", nic);
+ InterfaceDef def = new InterfaceDef();
+
+ if (type.equalsIgnoreCase("network")) {
+ String network = getAttrValue("source", "network", nic);
+ def.defPrivateNet(network, dev, mac,
+ nicModel.valueOf(model.toUpperCase()));
+ } else if (type.equalsIgnoreCase("bridge")) {
+ String bridge = getAttrValue("source", "bridge", nic);
+ def.defBridgeNet(bridge, dev, mac,
+ nicModel.valueOf(model.toUpperCase()));
+ }
+ interfaces.add(def);
+ }
+
+ Element graphic = (Element) devices
+ .getElementsByTagName("graphics").item(0);
+ String port = graphic.getAttribute("port");
+ if (port != null) {
+ try {
+ vncPort = Integer.parseInt(port);
+ if (vncPort != -1) {
+ vncPort = vncPort - 5900;
+ } else {
+ vncPort = null;
+ }
+ } catch (NumberFormatException nfe) {
+ vncPort = null;
+ }
+ }
+
+ return true;
+ } catch (ParserConfigurationException e) {
+ s_logger.debug(e.toString());
+ } catch (SAXException e) {
+ s_logger.debug(e.toString());
+ } catch (IOException e) {
+ s_logger.debug(e.toString());
+ }
+ return false;
+ }
+
+ private static String getTagValue(String tag, Element eElement) {
+ NodeList tagNodeList = eElement.getElementsByTagName(tag);
+ if (tagNodeList == null || tagNodeList.getLength() == 0) {
+ return null;
+ }
+
+ NodeList nlList = tagNodeList.item(0).getChildNodes();
+
+ Node nValue = (Node) nlList.item(0);
+
+ return nValue.getNodeValue();
+ }
+
+ private static String getAttrValue(String tag, String attr, Element eElement) {
+ NodeList tagNode = eElement.getElementsByTagName(tag);
+ if (tagNode.getLength() == 0) {
+ return null;
+ }
+ Element node = (Element) tagNode.item(0);
+ return node.getAttribute(attr);
+ }
+
+ public Integer getVncPort() {
+ return vncPort;
+ }
+
+ public List<InterfaceDef> getInterfaces() {
+ return interfaces;
+ }
+
+ public List<DiskDef> getDisks() {
+ return diskDefs;
+ }
+
+ public String getDescription() {
+ return desc;
+ }
+
+ public static void main(String[] args) {
+ LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
+ parser.parseDomainXML("<domain type='kvm' id='12'>"
+ + "<name>r-6-CV-5002-1</name>"
+ + "<uuid>581b5a4b-b496-8d4d-e44e-a7dcbe9df0b5</uuid>"
+ + "<description>testVM</description>"
+ + "<memory>131072</memory>"
+ + "<currentMemory>131072</currentMemory>"
+ + "<vcpu>1</vcpu>"
+ + "<os>"
+ + "<type arch='i686' machine='pc-0.11'>hvm</type>"
+ + "<kernel>/var/lib/libvirt/qemu/vmlinuz-2.6.31.6-166.fc12.i686</kernel>"
+ + "<cmdline>ro root=/dev/sda1 acpi=force selinux=0 eth0ip=10.1.1.1 eth0mask=255.255.255.0 eth2ip=192.168.10.152 eth2mask=255.255.255.0 gateway=192.168.10.1 dns1=72.52.126.11 dns2=72.52.126.12 domain=v4.myvm.com</cmdline>"
+ + "<boot dev='hd'/>"
+ + "</os>"
+ + "<features>"
+ + "<acpi/>"
+ + "<pae/>"
+ + "</features>"
+ + "<clock offset='utc'/>"
+ + "<on_poweroff>destroy</on_poweroff>"
+ + "<on_reboot>restart</on_reboot>"
+ + "<on_crash>destroy</on_crash>"
+ + "<devices>"
+ + "<emulator>/usr/bin/qemu-kvm</emulator>"
+ + "<disk type='file' device='disk'>"
+ + "<driver name='qemu' type='raw'/>"
+ + "<source file='/mnt/tank//vmops/CV/vm/u000004/r000006/rootdisk'/>"
+ + "<target dev='hda' bus='ide'/>" + "</disk>"
+ + "<interface type='bridge'>"
+ + "<mac address='02:00:50:02:00:01'/>"
+ + "<source bridge='vnbr5002'/>" + "<target dev='vtap5002'/>"
+ + "<model type='e1000'/>" + "</interface>"
+ + "<interface type='network'>"
+ + "<mac address='00:16:3e:77:e2:a1'/>"
+ + "<source network='vmops-private'/>" + "<target dev='vnet3'/>"
+ + "<model type='e1000'/>" + "</interface>"
+ + "<interface type='bridge'>"
+ + "<mac address='06:85:00:00:00:04'/>"
+ + "<source bridge='br0'/>" + "<target dev='tap5002'/>"
+ + "<model type='e1000'/>" + "</interface>"
+ + "<input type='mouse' bus='ps2'/>"
+ + "<graphics type='vnc' port='6031' autoport='no' listen=''/>"
+ + "<video>" + "<model type='cirrus' vram='9216' heads='1'/>"
+ + "</video>" + "</devices>" + "</domain>"
+
+ );
+ for (InterfaceDef intf : parser.getInterfaces()) {
+ System.out.println(intf);
+ }
+ for (DiskDef disk : parser.getDisks()) {
+ System.out.println(disk);
+ }
+ System.out.println(parser.getVncPort());
+ System.out.println(parser.getDescription());
+
+ List<String> test = new ArrayList<String>(1);
+ test.add("1");
+ test.add("2");
+ if (test.contains("1")) {
+ System.out.print("fdf");
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/LibvirtNetworkDef.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtNetworkDef.java b/agent/src/com/cloud/agent/resource/computing/LibvirtNetworkDef.java
index 4c3db46..7f757de 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtNetworkDef.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtNetworkDef.java
@@ -20,174 +20,174 @@ import java.util.ArrayList;
import java.util.List;
public class LibvirtNetworkDef {
- enum netType {
- BRIDGE, NAT, LOCAL
- }
-
- private final String _networkName;
- private final String _uuid;
- private netType _networkType;
- private String _brName;
- private boolean _stp;
- private int _delay;
- private String _fwDev;
- private final String _domainName;
- private String _brIPAddr;
- private String _brNetMask;
- private final List<IPRange> ipranges = new ArrayList<IPRange>();
- private final List<dhcpMapping> dhcpMaps = new ArrayList<dhcpMapping>();
-
- public static class dhcpMapping {
- String _mac;
- String _name;
- String _ip;
-
- public dhcpMapping(String mac, String name, String ip) {
- _mac = mac;
- _name = name;
- _ip = ip;
- }
- }
-
- public static class IPRange {
- String _start;
- String _end;
-
- public IPRange(String start, String end) {
- _start = start;
- _end = end;
- }
- }
-
- public LibvirtNetworkDef(String netName, String uuid, String domName) {
- _networkName = netName;
- _uuid = uuid;
- _domainName = domName;
- }
-
- public void defNATNetwork(String brName, boolean stp, int delay,
- String fwNic, String ipAddr, String netMask) {
- _networkType = netType.NAT;
- _brName = brName;
- _stp = stp;
- _delay = delay;
- _fwDev = fwNic;
- _brIPAddr = ipAddr;
- _brNetMask = netMask;
- }
-
- public void defBrNetwork(String brName, boolean stp, int delay,
- String fwNic, String ipAddr, String netMask) {
- _networkType = netType.BRIDGE;
- _brName = brName;
- _stp = stp;
- _delay = delay;
- _fwDev = fwNic;
- _brIPAddr = ipAddr;
- _brNetMask = netMask;
- }
-
- public void defLocalNetwork(String brName, boolean stp, int delay,
- String ipAddr, String netMask) {
- _networkType = netType.LOCAL;
- _brName = brName;
- _stp = stp;
- _delay = delay;
- _brIPAddr = ipAddr;
- _brNetMask = netMask;
- }
-
- public void adddhcpIPRange(String start, String end) {
- IPRange ipr = new IPRange(start, end);
- ipranges.add(ipr);
- }
-
- public void adddhcpMapping(String mac, String host, String ip) {
- dhcpMapping map = new dhcpMapping(mac, host, ip);
- dhcpMaps.add(map);
- }
-
- @Override
- public String toString() {
- StringBuilder netBuilder = new StringBuilder();
- netBuilder.append("<network>\n");
- netBuilder.append("<name>" + _networkName + "</name>\n");
- if (_uuid != null)
- netBuilder.append("<uuid>" + _uuid + "</uuid>\n");
- if (_brName != null) {
- netBuilder.append("<bridge name='" + _brName + "'");
- if (_stp) {
- netBuilder.append(" stp='on'");
- } else {
- netBuilder.append(" stp='off'");
- }
- if (_delay != -1) {
- netBuilder.append(" delay='" + _delay + "'");
- }
- netBuilder.append("/>\n");
- }
- if (_domainName != null) {
- netBuilder.append("<domain name='" + _domainName + "'/>\n");
- }
- if (_networkType == netType.BRIDGE) {
- netBuilder.append("<forward mode='route'");
- if (_fwDev != null) {
- netBuilder.append(" dev='" + _fwDev + "'");
- }
- netBuilder.append("/>\n");
- } else if (_networkType == netType.NAT) {
- netBuilder.append("<forward mode='nat'");
- if (_fwDev != null) {
- netBuilder.append(" dev='" + _fwDev + "'");
- }
- netBuilder.append("/>\n");
- }
- if (_brIPAddr != null || _brNetMask != null || !ipranges.isEmpty()
- || !dhcpMaps.isEmpty()) {
- netBuilder.append("<ip");
- if (_brIPAddr != null)
- netBuilder.append(" address='" + _brIPAddr + "'");
- if (_brNetMask != null) {
- netBuilder.append(" netmask='" + _brNetMask + "'");
- }
- netBuilder.append(">\n");
-
- if (!ipranges.isEmpty() || !dhcpMaps.isEmpty()) {
- netBuilder.append("<dhcp>\n");
- for (IPRange ip : ipranges) {
- netBuilder.append("<range start='" + ip._start + "'"
- + " end='" + ip._end + "'/>\n");
- }
- for (dhcpMapping map : dhcpMaps) {
- netBuilder.append("<host mac='" + map._mac + "' name='"
- + map._name + "' ip='" + map._ip + "'/>\n");
- }
- netBuilder.append("</dhcp>\n");
- }
- netBuilder.append("</ip>\n");
- }
- netBuilder.append("</network>\n");
- return netBuilder.toString();
- }
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- LibvirtNetworkDef net = new LibvirtNetworkDef("cloudPrivate", null,
- "cloud.com");
- net.defNATNetwork("cloudbr0", false, 0, null, "192.168.168.1",
- "255.255.255.0");
- net.adddhcpIPRange("192.168.168.100", "192.168.168.220");
- net.adddhcpIPRange("192.168.168.10", "192.168.168.50");
- net.adddhcpMapping("branch0.cloud.com", "00:16:3e:77:e2:ed",
- "192.168.168.100");
- net.adddhcpMapping("branch1.cloud.com", "00:16:3e:77:e2:ef",
- "192.168.168.101");
- net.adddhcpMapping("branch2.cloud.com", "00:16:3e:77:e2:f0",
- "192.168.168.102");
- System.out.println(net.toString());
-
- }
+ enum netType {
+ BRIDGE, NAT, LOCAL
+ }
+
+ private final String _networkName;
+ private final String _uuid;
+ private netType _networkType;
+ private String _brName;
+ private boolean _stp;
+ private int _delay;
+ private String _fwDev;
+ private final String _domainName;
+ private String _brIPAddr;
+ private String _brNetMask;
+ private final List<IPRange> ipranges = new ArrayList<IPRange>();
+ private final List<dhcpMapping> dhcpMaps = new ArrayList<dhcpMapping>();
+
+ public static class dhcpMapping {
+ String _mac;
+ String _name;
+ String _ip;
+
+ public dhcpMapping(String mac, String name, String ip) {
+ _mac = mac;
+ _name = name;
+ _ip = ip;
+ }
+ }
+
+ public static class IPRange {
+ String _start;
+ String _end;
+
+ public IPRange(String start, String end) {
+ _start = start;
+ _end = end;
+ }
+ }
+
+ public LibvirtNetworkDef(String netName, String uuid, String domName) {
+ _networkName = netName;
+ _uuid = uuid;
+ _domainName = domName;
+ }
+
+ public void defNATNetwork(String brName, boolean stp, int delay,
+ String fwNic, String ipAddr, String netMask) {
+ _networkType = netType.NAT;
+ _brName = brName;
+ _stp = stp;
+ _delay = delay;
+ _fwDev = fwNic;
+ _brIPAddr = ipAddr;
+ _brNetMask = netMask;
+ }
+
+ public void defBrNetwork(String brName, boolean stp, int delay,
+ String fwNic, String ipAddr, String netMask) {
+ _networkType = netType.BRIDGE;
+ _brName = brName;
+ _stp = stp;
+ _delay = delay;
+ _fwDev = fwNic;
+ _brIPAddr = ipAddr;
+ _brNetMask = netMask;
+ }
+
+ public void defLocalNetwork(String brName, boolean stp, int delay,
+ String ipAddr, String netMask) {
+ _networkType = netType.LOCAL;
+ _brName = brName;
+ _stp = stp;
+ _delay = delay;
+ _brIPAddr = ipAddr;
+ _brNetMask = netMask;
+ }
+
+ public void adddhcpIPRange(String start, String end) {
+ IPRange ipr = new IPRange(start, end);
+ ipranges.add(ipr);
+ }
+
+ public void adddhcpMapping(String mac, String host, String ip) {
+ dhcpMapping map = new dhcpMapping(mac, host, ip);
+ dhcpMaps.add(map);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder netBuilder = new StringBuilder();
+ netBuilder.append("<network>\n");
+ netBuilder.append("<name>" + _networkName + "</name>\n");
+ if (_uuid != null)
+ netBuilder.append("<uuid>" + _uuid + "</uuid>\n");
+ if (_brName != null) {
+ netBuilder.append("<bridge name='" + _brName + "'");
+ if (_stp) {
+ netBuilder.append(" stp='on'");
+ } else {
+ netBuilder.append(" stp='off'");
+ }
+ if (_delay != -1) {
+ netBuilder.append(" delay='" + _delay + "'");
+ }
+ netBuilder.append("/>\n");
+ }
+ if (_domainName != null) {
+ netBuilder.append("<domain name='" + _domainName + "'/>\n");
+ }
+ if (_networkType == netType.BRIDGE) {
+ netBuilder.append("<forward mode='route'");
+ if (_fwDev != null) {
+ netBuilder.append(" dev='" + _fwDev + "'");
+ }
+ netBuilder.append("/>\n");
+ } else if (_networkType == netType.NAT) {
+ netBuilder.append("<forward mode='nat'");
+ if (_fwDev != null) {
+ netBuilder.append(" dev='" + _fwDev + "'");
+ }
+ netBuilder.append("/>\n");
+ }
+ if (_brIPAddr != null || _brNetMask != null || !ipranges.isEmpty()
+ || !dhcpMaps.isEmpty()) {
+ netBuilder.append("<ip");
+ if (_brIPAddr != null)
+ netBuilder.append(" address='" + _brIPAddr + "'");
+ if (_brNetMask != null) {
+ netBuilder.append(" netmask='" + _brNetMask + "'");
+ }
+ netBuilder.append(">\n");
+
+ if (!ipranges.isEmpty() || !dhcpMaps.isEmpty()) {
+ netBuilder.append("<dhcp>\n");
+ for (IPRange ip : ipranges) {
+ netBuilder.append("<range start='" + ip._start + "'"
+ + " end='" + ip._end + "'/>\n");
+ }
+ for (dhcpMapping map : dhcpMaps) {
+ netBuilder.append("<host mac='" + map._mac + "' name='"
+ + map._name + "' ip='" + map._ip + "'/>\n");
+ }
+ netBuilder.append("</dhcp>\n");
+ }
+ netBuilder.append("</ip>\n");
+ }
+ netBuilder.append("</network>\n");
+ return netBuilder.toString();
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ LibvirtNetworkDef net = new LibvirtNetworkDef("cloudPrivate", null,
+ "cloud.com");
+ net.defNATNetwork("cloudbr0", false, 0, null, "192.168.168.1",
+ "255.255.255.0");
+ net.adddhcpIPRange("192.168.168.100", "192.168.168.220");
+ net.adddhcpIPRange("192.168.168.10", "192.168.168.50");
+ net.adddhcpMapping("branch0.cloud.com", "00:16:3e:77:e2:ed",
+ "192.168.168.100");
+ net.adddhcpMapping("branch1.cloud.com", "00:16:3e:77:e2:ef",
+ "192.168.168.101");
+ net.adddhcpMapping("branch2.cloud.com", "00:16:3e:77:e2:f0",
+ "192.168.168.102");
+ System.out.println(net.toString());
+
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolDef.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolDef.java b/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolDef.java
index 5e0a841..582cd2e 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolDef.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolDef.java
@@ -17,74 +17,74 @@
package com.cloud.agent.resource.computing;
public class LibvirtStoragePoolDef {
- public enum poolType {
- ISCSI("iscsi"), NETFS("netfs"), LOGICAL("logical"), DIR("dir");
- String _poolType;
+ public enum poolType {
+ ISCSI("iscsi"), NETFS("netfs"), LOGICAL("logical"), DIR("dir");
+ String _poolType;
- poolType(String poolType) {
- _poolType = poolType;
- }
+ poolType(String poolType) {
+ _poolType = poolType;
+ }
- @Override
- public String toString() {
- return _poolType;
- }
- }
+ @Override
+ public String toString() {
+ return _poolType;
+ }
+ }
- private poolType _poolType;
- private String _poolName;
- private String _uuid;
- private String _sourceHost;
- private String _sourceDir;
- private String _targetPath;
+ private poolType _poolType;
+ private String _poolName;
+ private String _uuid;
+ private String _sourceHost;
+ private String _sourceDir;
+ private String _targetPath;
- public LibvirtStoragePoolDef(poolType type, String poolName, String uuid,
- String host, String dir, String targetPath) {
- _poolType = type;
- _poolName = poolName;
- _uuid = uuid;
- _sourceHost = host;
- _sourceDir = dir;
- _targetPath = targetPath;
- }
+ public LibvirtStoragePoolDef(poolType type, String poolName, String uuid,
+ String host, String dir, String targetPath) {
+ _poolType = type;
+ _poolName = poolName;
+ _uuid = uuid;
+ _sourceHost = host;
+ _sourceDir = dir;
+ _targetPath = targetPath;
+ }
- public String getPoolName() {
- return _poolName;
- }
+ public String getPoolName() {
+ return _poolName;
+ }
- public poolType getPoolType() {
- return _poolType;
- }
+ public poolType getPoolType() {
+ return _poolType;
+ }
- public String getSourceHost() {
- return _sourceHost;
- }
+ public String getSourceHost() {
+ return _sourceHost;
+ }
- public String getSourceDir() {
- return _sourceDir;
- }
+ public String getSourceDir() {
+ return _sourceDir;
+ }
- public String getTargetPath() {
- return _targetPath;
- }
+ public String getTargetPath() {
+ return _targetPath;
+ }
- @Override
- public String toString() {
- StringBuilder storagePoolBuilder = new StringBuilder();
- storagePoolBuilder.append("<pool type='" + _poolType + "'>\n");
- storagePoolBuilder.append("<name>" + _poolName + "</name>\n");
- if (_uuid != null)
- storagePoolBuilder.append("<uuid>" + _uuid + "</uuid>\n");
- if (_poolType == poolType.NETFS) {
- storagePoolBuilder.append("<source>\n");
- storagePoolBuilder.append("<host name='" + _sourceHost + "'/>\n");
- storagePoolBuilder.append("<dir path='" + _sourceDir + "'/>\n");
- storagePoolBuilder.append("</source>\n");
- }
- storagePoolBuilder.append("<target>\n");
- storagePoolBuilder.append("<path>" + _targetPath + "</path>\n");
- storagePoolBuilder.append("</target>\n");
- storagePoolBuilder.append("</pool>\n");
- return storagePoolBuilder.toString();
- }
+ @Override
+ public String toString() {
+ StringBuilder storagePoolBuilder = new StringBuilder();
+ storagePoolBuilder.append("<pool type='" + _poolType + "'>\n");
+ storagePoolBuilder.append("<name>" + _poolName + "</name>\n");
+ if (_uuid != null)
+ storagePoolBuilder.append("<uuid>" + _uuid + "</uuid>\n");
+ if (_poolType == poolType.NETFS) {
+ storagePoolBuilder.append("<source>\n");
+ storagePoolBuilder.append("<host name='" + _sourceHost + "'/>\n");
+ storagePoolBuilder.append("<dir path='" + _sourceDir + "'/>\n");
+ storagePoolBuilder.append("</source>\n");
+ }
+ storagePoolBuilder.append("<target>\n");
+ storagePoolBuilder.append("<path>" + _targetPath + "</path>\n");
+ storagePoolBuilder.append("</target>\n");
+ storagePoolBuilder.append("</pool>\n");
+ return storagePoolBuilder.toString();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolXMLParser.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolXMLParser.java b/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolXMLParser.java
index 2adcfed..5c45d76 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolXMLParser.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolXMLParser.java
@@ -29,81 +29,81 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class LibvirtStoragePoolXMLParser {
- private static final Logger s_logger = Logger
- .getLogger(LibvirtStoragePoolXMLParser.class);
-
- public LibvirtStoragePoolDef parseStoragePoolXML(String poolXML) {
- DocumentBuilder builder;
- try {
- builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
-
- InputSource is = new InputSource();
- is.setCharacterStream(new StringReader(poolXML));
- Document doc = builder.parse(is);
-
- Element rootElement = doc.getDocumentElement();
- String type = rootElement.getAttribute("type");
-
- String uuid = getTagValue("uuid", rootElement);
-
- String poolName = getTagValue("name", rootElement);
-
- Element source = (Element) rootElement.getElementsByTagName(
- "source").item(0);
- String host = getAttrValue("host", "name", source);
- String path = getAttrValue("dir", "path", source);
-
- Element target = (Element) rootElement.getElementsByTagName(
- "target").item(0);
- String targetPath = getTagValue("path", target);
-
- return new LibvirtStoragePoolDef(
- LibvirtStoragePoolDef.poolType.valueOf(type.toUpperCase()),
- poolName, uuid, host, path, targetPath);
- } catch (ParserConfigurationException e) {
- s_logger.debug(e.toString());
- } catch (SAXException e) {
- s_logger.debug(e.toString());
- } catch (IOException e) {
- s_logger.debug(e.toString());
- }
- return null;
- }
-
- private static String getTagValue(String tag, Element eElement) {
- NodeList nlList = eElement.getElementsByTagName(tag).item(0)
- .getChildNodes();
- Node nValue = (Node) nlList.item(0);
-
- return nValue.getNodeValue();
- }
-
- private static String getAttrValue(String tag, String attr, Element eElement) {
- NodeList tagNode = eElement.getElementsByTagName(tag);
- if (tagNode.getLength() == 0) {
- return null;
- }
- Element node = (Element) tagNode.item(0);
- return node.getAttribute(attr);
- }
-
- public static void main(String[] args) {
- s_logger.addAppender(new org.apache.log4j.ConsoleAppender(
- new org.apache.log4j.PatternLayout(), "System.out"));
- String storagePool = "<pool type='dir'>" + "<name>test</name>"
- + "<uuid>bf723c83-4b95-259c-7089-60776e61a11f</uuid>"
- + "<capacity>20314165248</capacity>"
- + "<allocation>1955450880</allocation>"
- + "<available>18358714368</available>" + "<source>"
- + "<host name='nfs1.lab.vmops.com'/>"
- + "<dir path='/export/home/edison/kvm/primary'/>"
- + "<format type='auto'/>" + "</source>" + "<target>"
- + "<path>/media</path>" + "<permissions>" + "<mode>0700</mode>"
- + "<owner>0</owner>" + "<group>0</group>" + "</permissions>"
- + "</target>" + "</pool>";
-
- LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
- LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
- s_logger.debug(pool.toString());
- }
+ private static final Logger s_logger = Logger
+ .getLogger(LibvirtStoragePoolXMLParser.class);
+
+ public LibvirtStoragePoolDef parseStoragePoolXML(String poolXML) {
+ DocumentBuilder builder;
+ try {
+ builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+
+ InputSource is = new InputSource();
+ is.setCharacterStream(new StringReader(poolXML));
+ Document doc = builder.parse(is);
+
+ Element rootElement = doc.getDocumentElement();
+ String type = rootElement.getAttribute("type");
+
+ String uuid = getTagValue("uuid", rootElement);
+
+ String poolName = getTagValue("name", rootElement);
+
+ Element source = (Element) rootElement.getElementsByTagName(
+ "source").item(0);
+ String host = getAttrValue("host", "name", source);
+ String path = getAttrValue("dir", "path", source);
+
+ Element target = (Element) rootElement.getElementsByTagName(
+ "target").item(0);
+ String targetPath = getTagValue("path", target);
+
+ return new LibvirtStoragePoolDef(
+ LibvirtStoragePoolDef.poolType.valueOf(type.toUpperCase()),
+ poolName, uuid, host, path, targetPath);
+ } catch (ParserConfigurationException e) {
+ s_logger.debug(e.toString());
+ } catch (SAXException e) {
+ s_logger.debug(e.toString());
+ } catch (IOException e) {
+ s_logger.debug(e.toString());
+ }
+ return null;
+ }
+
+ private static String getTagValue(String tag, Element eElement) {
+ NodeList nlList = eElement.getElementsByTagName(tag).item(0)
+ .getChildNodes();
+ Node nValue = (Node) nlList.item(0);
+
+ return nValue.getNodeValue();
+ }
+
+ private static String getAttrValue(String tag, String attr, Element eElement) {
+ NodeList tagNode = eElement.getElementsByTagName(tag);
+ if (tagNode.getLength() == 0) {
+ return null;
+ }
+ Element node = (Element) tagNode.item(0);
+ return node.getAttribute(attr);
+ }
+
+ public static void main(String[] args) {
+ s_logger.addAppender(new org.apache.log4j.ConsoleAppender(
+ new org.apache.log4j.PatternLayout(), "System.out"));
+ String storagePool = "<pool type='dir'>" + "<name>test</name>"
+ + "<uuid>bf723c83-4b95-259c-7089-60776e61a11f</uuid>"
+ + "<capacity>20314165248</capacity>"
+ + "<allocation>1955450880</allocation>"
+ + "<available>18358714368</available>" + "<source>"
+ + "<host name='nfs1.lab.vmops.com'/>"
+ + "<dir path='/export/home/edison/kvm/primary'/>"
+ + "<format type='auto'/>" + "</source>" + "<target>"
+ + "<path>/media</path>" + "<permissions>" + "<mode>0700</mode>"
+ + "<owner>0</owner>" + "<group>0</group>" + "</permissions>"
+ + "</target>" + "</pool>";
+
+ LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
+ LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
+ s_logger.debug(pool.toString());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeDef.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeDef.java b/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeDef.java
index e00ecaa..ef8e22e 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeDef.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeDef.java
@@ -17,75 +17,75 @@
package com.cloud.agent.resource.computing;
public class LibvirtStorageVolumeDef {
- public enum volFormat {
- RAW("raw"), QCOW2("qcow2"), DIR("dir");
- private String _format;
+ public enum volFormat {
+ RAW("raw"), QCOW2("qcow2"), DIR("dir");
+ private String _format;
- volFormat(String format) {
- _format = format;
- }
+ volFormat(String format) {
+ _format = format;
+ }
- @Override
- public String toString() {
- return _format;
- }
+ @Override
+ public String toString() {
+ return _format;
+ }
- public static volFormat getFormat(String format) {
- if (format == null) {
- return null;
- }
- if (format.equalsIgnoreCase("raw")) {
- return RAW;
- } else if (format.equalsIgnoreCase("qcow2")) {
- return QCOW2;
- }
- return null;
- }
- }
+ public static volFormat getFormat(String format) {
+ if (format == null) {
+ return null;
+ }
+ if (format.equalsIgnoreCase("raw")) {
+ return RAW;
+ } else if (format.equalsIgnoreCase("qcow2")) {
+ return QCOW2;
+ }
+ return null;
+ }
+ }
- private String _volName;
- private Long _volSize;
- private volFormat _volFormat;
- private String _backingPath;
- private volFormat _backingFormat;
+ private String _volName;
+ private Long _volSize;
+ private volFormat _volFormat;
+ private String _backingPath;
+ private volFormat _backingFormat;
- public LibvirtStorageVolumeDef(String volName, Long size, volFormat format,
- String tmplPath, volFormat tmplFormat) {
- _volName = volName;
- _volSize = size;
- _volFormat = format;
- _backingPath = tmplPath;
- _backingFormat = tmplFormat;
- }
+ public LibvirtStorageVolumeDef(String volName, Long size, volFormat format,
+ String tmplPath, volFormat tmplFormat) {
+ _volName = volName;
+ _volSize = size;
+ _volFormat = format;
+ _backingPath = tmplPath;
+ _backingFormat = tmplFormat;
+ }
- public volFormat getFormat() {
- return this._volFormat;
- }
+ public volFormat getFormat() {
+ return this._volFormat;
+ }
- @Override
- public String toString() {
- StringBuilder storageVolBuilder = new StringBuilder();
- storageVolBuilder.append("<volume>\n");
- storageVolBuilder.append("<name>" + _volName + "</name>\n");
- if (_volSize != null) {
- storageVolBuilder
- .append("<capacity >" + _volSize + "</capacity>\n");
- }
- storageVolBuilder.append("<target>\n");
- storageVolBuilder.append("<format type='" + _volFormat + "'/>\n");
- storageVolBuilder.append("<permissions>");
- storageVolBuilder.append("<mode>0744</mode>");
- storageVolBuilder.append("</permissions>");
- storageVolBuilder.append("</target>\n");
- if (_backingPath != null) {
- storageVolBuilder.append("<backingStore>\n");
- storageVolBuilder.append("<path>" + _backingPath + "</path>\n");
- storageVolBuilder.append("<format type='" + _backingFormat
- + "'/>\n");
- storageVolBuilder.append("</backingStore>\n");
- }
- storageVolBuilder.append("</volume>\n");
- return storageVolBuilder.toString();
- }
+ @Override
+ public String toString() {
+ StringBuilder storageVolBuilder = new StringBuilder();
+ storageVolBuilder.append("<volume>\n");
+ storageVolBuilder.append("<name>" + _volName + "</name>\n");
+ if (_volSize != null) {
+ storageVolBuilder
+ .append("<capacity >" + _volSize + "</capacity>\n");
+ }
+ storageVolBuilder.append("<target>\n");
+ storageVolBuilder.append("<format type='" + _volFormat + "'/>\n");
+ storageVolBuilder.append("<permissions>");
+ storageVolBuilder.append("<mode>0744</mode>");
+ storageVolBuilder.append("</permissions>");
+ storageVolBuilder.append("</target>\n");
+ if (_backingPath != null) {
+ storageVolBuilder.append("<backingStore>\n");
+ storageVolBuilder.append("<path>" + _backingPath + "</path>\n");
+ storageVolBuilder.append("<format type='" + _backingFormat
+ + "'/>\n");
+ storageVolBuilder.append("</backingStore>\n");
+ }
+ storageVolBuilder.append("</volume>\n");
+ return storageVolBuilder.toString();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/5e9a193f/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeXMLParser.java
----------------------------------------------------------------------
diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeXMLParser.java b/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeXMLParser.java
index c4fe6df..163ca2b 100644
--- a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeXMLParser.java
+++ b/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeXMLParser.java
@@ -32,73 +32,73 @@ import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class LibvirtStorageVolumeXMLParser {
- private static final Logger s_logger = Logger
- .getLogger(LibvirtStorageVolumeXMLParser.class);
+ private static final Logger s_logger = Logger
+ .getLogger(LibvirtStorageVolumeXMLParser.class);
- public LibvirtStorageVolumeDef parseStorageVolumeXML(String volXML) {
- DocumentBuilder builder;
- try {
- builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ public LibvirtStorageVolumeDef parseStorageVolumeXML(String volXML) {
+ DocumentBuilder builder;
+ try {
+ builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- InputSource is = new InputSource();
- is.setCharacterStream(new StringReader(volXML));
- Document doc = builder.parse(is);
+ InputSource is = new InputSource();
+ is.setCharacterStream(new StringReader(volXML));
+ Document doc = builder.parse(is);
- Element rootElement = doc.getDocumentElement();
+ Element rootElement = doc.getDocumentElement();
- String VolName = getTagValue("name", rootElement);
- Element target = (Element) rootElement.getElementsByTagName(
- "target").item(0);
- String format = getAttrValue("type", "format", target);
- Long capacity = Long
- .parseLong(getTagValue("capacity", rootElement));
- return new LibvirtStorageVolumeDef(VolName, capacity,
- LibvirtStorageVolumeDef.volFormat.getFormat(format), null,
- null);
- } catch (ParserConfigurationException e) {
- s_logger.debug(e.toString());
- } catch (SAXException e) {
- s_logger.debug(e.toString());
- } catch (IOException e) {
- s_logger.debug(e.toString());
- }
- return null;
- }
+ String VolName = getTagValue("name", rootElement);
+ Element target = (Element) rootElement.getElementsByTagName(
+ "target").item(0);
+ String format = getAttrValue("type", "format", target);
+ Long capacity = Long
+ .parseLong(getTagValue("capacity", rootElement));
+ return new LibvirtStorageVolumeDef(VolName, capacity,
+ LibvirtStorageVolumeDef.volFormat.getFormat(format), null,
+ null);
+ } catch (ParserConfigurationException e) {
+ s_logger.debug(e.toString());
+ } catch (SAXException e) {
+ s_logger.debug(e.toString());
+ } catch (IOException e) {
+ s_logger.debug(e.toString());
+ }
+ return null;
+ }
- private static String getTagValue(String tag, Element eElement) {
- NodeList nlList = eElement.getElementsByTagName(tag).item(0)
- .getChildNodes();
- Node nValue = (Node) nlList.item(0);
+ private static String getTagValue(String tag, Element eElement) {
+ NodeList nlList = eElement.getElementsByTagName(tag).item(0)
+ .getChildNodes();
+ Node nValue = (Node) nlList.item(0);
- return nValue.getNodeValue();
- }
+ return nValue.getNodeValue();
+ }
- private static String getAttrValue(String tag, String attr, Element eElement) {
- NodeList tagNode = eElement.getElementsByTagName(tag);
- if (tagNode.getLength() == 0) {
- return null;
- }
- Element node = (Element) tagNode.item(0);
- return node.getAttribute(attr);
- }
+ private static String getAttrValue(String tag, String attr, Element eElement) {
+ NodeList tagNode = eElement.getElementsByTagName(tag);
+ if (tagNode.getLength() == 0) {
+ return null;
+ }
+ Element node = (Element) tagNode.item(0);
+ return node.getAttribute(attr);
+ }
- public static void main(String[] args) {
- s_logger.addAppender(new org.apache.log4j.ConsoleAppender(
- new org.apache.log4j.PatternLayout(), "System.out"));
- String storagePool = "<pool type='dir'>" + "<name>test</name>"
- + "<uuid>bf723c83-4b95-259c-7089-60776e61a11f</uuid>"
- + "<capacity>20314165248</capacity>"
- + "<allocation>1955450880</allocation>"
- + "<available>18358714368</available>" + "<source>"
- + "<host name='nfs1.lab.vmops.com'/>"
- + "<dir path='/export/home/edison/kvm/primary'/>"
- + "<format type='auto'/>" + "</source>" + "<target>"
- + "<path>/media</path>" + "<permissions>" + "<mode>0700</mode>"
- + "<owner>0</owner>" + "<group>0</group>" + "</permissions>"
- + "</target>" + "</pool>";
+ public static void main(String[] args) {
+ s_logger.addAppender(new org.apache.log4j.ConsoleAppender(
+ new org.apache.log4j.PatternLayout(), "System.out"));
+ String storagePool = "<pool type='dir'>" + "<name>test</name>"
+ + "<uuid>bf723c83-4b95-259c-7089-60776e61a11f</uuid>"
+ + "<capacity>20314165248</capacity>"
+ + "<allocation>1955450880</allocation>"
+ + "<available>18358714368</available>" + "<source>"
+ + "<host name='nfs1.lab.vmops.com'/>"
+ + "<dir path='/export/home/edison/kvm/primary'/>"
+ + "<format type='auto'/>" + "</source>" + "<target>"
+ + "<path>/media</path>" + "<permissions>" + "<mode>0700</mode>"
+ + "<owner>0</owner>" + "<group>0</group>" + "</permissions>"
+ + "</target>" + "</pool>";
- LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
- LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
- s_logger.debug(pool.toString());
- }
+ LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
+ LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
+ s_logger.debug(pool.toString());
+ }
}