Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7CA38D7CA for ; Mon, 30 Jul 2012 21:56:05 +0000 (UTC) Received: (qmail 64435 invoked by uid 500); 30 Jul 2012 21:56:05 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 64344 invoked by uid 500); 30 Jul 2012 21:56:05 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 64211 invoked by uid 99); 30 Jul 2012 21:56:05 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Jul 2012 21:56:05 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id C98641A338; Mon, 30 Jul 2012 21:56:04 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: edison@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [3/8] Move KVM related code into plugins/hypervisor/kvm, a new jar file is created: cloud-kvm.jar Message-Id: <20120730215604.C98641A338@tyr.zones.apache.org> Date: Mon, 30 Jul 2012 21:56:04 +0000 (UTC) http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7a0a9231/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 deleted file mode 100644 index d3a2318..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtConnection.java +++ /dev/null @@ -1,48 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -import org.apache.log4j.Logger; -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; - - 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; - } - - static void initialize(String hypervisorURI) { - _hypervisorURI = hypervisorURI; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7a0a9231/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 deleted file mode 100644 index 6215534..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtDomainXMLParser.java +++ /dev/null @@ -1,253 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; -import java.util.SortedMap; -import java.util.TreeMap; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -import com.cloud.agent.resource.computing.LibvirtVMDef.DiskDef; -import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef; -import com.cloud.agent.resource.computing.LibvirtVMDef.InterfaceDef.nicModel; - -/** - * @author chiradeep - * - */ -public class LibvirtDomainXMLParser { - private static final Logger s_logger = Logger - .getLogger(LibvirtDomainXMLParser.class); - private final List interfaces = new ArrayList(); - private final List diskDefs = new ArrayList(); - 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 getInterfaces() { - return interfaces; - } - - public List getDisks() { - return diskDefs; - } - - public String getDescription() { - return desc; - } - - public static void main(String[] args) { - LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser(); - parser.parseDomainXML("" - + "r-6-CV-5002-1" - + "581b5a4b-b496-8d4d-e44e-a7dcbe9df0b5" - + "testVM" - + "131072" - + "131072" - + "1" - + "" - + "hvm" - + "/var/lib/libvirt/qemu/vmlinuz-2.6.31.6-166.fc12.i686" - + "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" - + "" - + "" - + "" - + "" - + "" - + "" - + "" - + "destroy" - + "restart" - + "destroy" - + "" - + "/usr/bin/qemu-kvm" - + "" - + "" - + "" - + "" + "" - + "" - + "" - + "" + "" - + "" + "" - + "" - + "" - + "" + "" - + "" + "" - + "" - + "" - + "" + "" - + "" + "" - + "" - + "" - + "" + "" + "" - - ); - 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 test = new ArrayList(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/7a0a9231/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 deleted file mode 100644 index 7f757de..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtNetworkDef.java +++ /dev/null @@ -1,193 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -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 ipranges = new ArrayList(); - private final List dhcpMaps = new ArrayList(); - - 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("\n"); - netBuilder.append("" + _networkName + "\n"); - if (_uuid != null) - netBuilder.append("" + _uuid + "\n"); - if (_brName != null) { - netBuilder.append("\n"); - } - if (_domainName != null) { - netBuilder.append("\n"); - } - if (_networkType == netType.BRIDGE) { - netBuilder.append("\n"); - } else if (_networkType == netType.NAT) { - netBuilder.append("\n"); - } - if (_brIPAddr != null || _brNetMask != null || !ipranges.isEmpty() - || !dhcpMaps.isEmpty()) { - netBuilder.append("\n"); - - if (!ipranges.isEmpty() || !dhcpMaps.isEmpty()) { - netBuilder.append("\n"); - for (IPRange ip : ipranges) { - netBuilder.append("\n"); - } - for (dhcpMapping map : dhcpMaps) { - netBuilder.append("\n"); - } - netBuilder.append("\n"); - } - netBuilder.append("\n"); - } - netBuilder.append("\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/7a0a9231/agent/src/com/cloud/agent/resource/computing/LibvirtSecretDef.java ---------------------------------------------------------------------- diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtSecretDef.java b/agent/src/com/cloud/agent/resource/computing/LibvirtSecretDef.java deleted file mode 100644 index f7e10c3..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtSecretDef.java +++ /dev/null @@ -1,106 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -public class LibvirtSecretDef { - - public enum usage { - VOLUME("volume"), CEPH("ceph"); - String _usage; - - usage(String usage) { - _usage = usage; - } - - @Override - public String toString() { - return _usage; - } - } - - private usage _usage; - private boolean _ephemeral; - private boolean _private; - private String _uuid; - private String _description; - private String _cephName; - private String _volumeVolume; - - public LibvirtSecretDef (usage usage, String uuid) { - _usage = usage; - _uuid = uuid; - } - - public LibvirtSecretDef (usage usage, String uuid, String description) { - _usage = usage; - _uuid = uuid; - _description = description; - } - - public boolean getEphemeral() { - return _ephemeral; - } - - public boolean getPrivate() { - return _private; - } - - public String getUuid() { - return _uuid; - } - - public String getDescription() { - return _description; - } - - public String getVolumeVolume() { - return _volumeVolume; - } - - public String getCephName() { - return _cephName; - } - - public void setVolumeVolume(String volume) { - _volumeVolume = volume; - } - - public void setCephName(String name) { - _cephName = name; - } - - @Override - public String toString() { - StringBuilder secretBuilder = new StringBuilder(); - secretBuilder.append("\n"); - secretBuilder.append("" + _uuid + "\n"); - if (_description != null) { - secretBuilder.append("" + _description + "\n"); - } - secretBuilder.append("\n"); - if (_usage == _usage.VOLUME) { - secretBuilder.append("" + _volumeVolume + "\n"); - } - if (_usage == _usage.CEPH) { - secretBuilder.append("" + _cephName + "\n"); - } - secretBuilder.append("\n"); - secretBuilder.append("\n"); - return secretBuilder.toString(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7a0a9231/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 deleted file mode 100644 index 9c28528..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolDef.java +++ /dev/null @@ -1,162 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -public class LibvirtStoragePoolDef { - public enum poolType { - ISCSI("iscsi"), NETFS("netfs"), LOGICAL("logical"), DIR("dir"), RBD("rbd"); - String _poolType; - - poolType(String poolType) { - _poolType = poolType; - } - - @Override - public String toString() { - return _poolType; - } - } - - public enum authType { - CHAP("chap"), CEPH("ceph"); - String _authType; - - authType(String authType) { - _authType = authType; - } - - @Override - public String toString() { - return _authType; - } - } - - private poolType _poolType; - private String _poolName; - private String _uuid; - private String _sourceHost; - private int _sourcePort; - private String _sourceDir; - private String _targetPath; - private String _authUsername; - private authType _authType; - private String _secretUuid; - - public LibvirtStoragePoolDef(poolType type, String poolName, String uuid, - String host, int port, String dir, String targetPath) { - _poolType = type; - _poolName = poolName; - _uuid = uuid; - _sourceHost = host; - _sourcePort = port; - _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 LibvirtStoragePoolDef(poolType type, String poolName, String uuid, - String sourceHost, int sourcePort, String dir, String authUsername, - authType authType, String secretUuid) { - _poolType = type; - _poolName = poolName; - _uuid = uuid; - _sourceHost = sourceHost; - _sourcePort = sourcePort; - _sourceDir = dir; - _authUsername = authUsername; - _authType = authType; - _secretUuid = secretUuid; - } - - public String getPoolName() { - return _poolName; - } - - public poolType getPoolType() { - return _poolType; - } - - public String getSourceHost() { - return _sourceHost; - } - - public int getSourcePort() { - return _sourcePort; - } - - public String getSourceDir() { - return _sourceDir; - } - - public String getTargetPath() { - return _targetPath; - } - - public String getAuthUserName() { - return _authUsername; - } - - public String getSecretUUID() { - return _secretUuid; - } - - public authType getAuthType() { - return _authType; - } - - @Override - public String toString() { - StringBuilder storagePoolBuilder = new StringBuilder(); - storagePoolBuilder.append("\n"); - storagePoolBuilder.append("" + _poolName + "\n"); - if (_uuid != null) - storagePoolBuilder.append("" + _uuid + "\n"); - if (_poolType == poolType.NETFS) { - storagePoolBuilder.append("\n"); - storagePoolBuilder.append("\n"); - storagePoolBuilder.append("\n"); - storagePoolBuilder.append("\n"); - } - if (_poolType == poolType.RBD) { - storagePoolBuilder.append("\n"); - storagePoolBuilder.append("\n"); - storagePoolBuilder.append("" + _sourceDir + "\n"); - if (_authUsername != null) { - storagePoolBuilder.append("\n"); - storagePoolBuilder.append("\n"); - storagePoolBuilder.append("\n"); - } - storagePoolBuilder.append("\n"); - } - if (_poolType != poolType.RBD) { - storagePoolBuilder.append("\n"); - storagePoolBuilder.append("" + _targetPath + "\n"); - storagePoolBuilder.append("\n"); - } - storagePoolBuilder.append("\n"); - return storagePoolBuilder.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7a0a9231/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 deleted file mode 100644 index cff4c2b..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtStoragePoolXMLParser.java +++ /dev/null @@ -1,128 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -import java.io.IOException; -import java.io.StringReader; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.log4j.Logger; -import org.w3c.dom.*; -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); - - if (type.equalsIgnoreCase("rbd")) { - int port = Integer.parseInt(getAttrValue("host", "port", source)); - String pool = getTagValue("name", source); - - Element auth = (Element) source.getElementsByTagName( - "auth").item(0); - - if (auth != null) { - String authUsername = auth.getAttribute("username"); - String authType = auth.getAttribute("type"); - return new LibvirtStoragePoolDef(LibvirtStoragePoolDef.poolType.valueOf(type.toUpperCase()), - poolName, uuid, host, port, pool, authUsername, LibvirtStoragePoolDef.authType.valueOf(authType.toUpperCase()), uuid); - } else { - return new LibvirtStoragePoolDef(LibvirtStoragePoolDef.poolType.valueOf(type.toUpperCase()), - poolName, uuid, host, port, pool, ""); - } - } else { - 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 = "" + "test" - + "bf723c83-4b95-259c-7089-60776e61a11f" - + "20314165248" - + "1955450880" - + "18358714368" + "" - + "" - + "" - + "" + "" + "" - + "/media" + "" + "0700" - + "0" + "0" + "" - + "" + ""; - - 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/7a0a9231/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 deleted file mode 100644 index ef8e22e..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeDef.java +++ /dev/null @@ -1,91 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -public class LibvirtStorageVolumeDef { - public enum volFormat { - RAW("raw"), QCOW2("qcow2"), DIR("dir"); - private String _format; - - volFormat(String format) { - _format = 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; - } - } - - 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 volFormat getFormat() { - return this._volFormat; - } - - @Override - public String toString() { - StringBuilder storageVolBuilder = new StringBuilder(); - storageVolBuilder.append("\n"); - storageVolBuilder.append("" + _volName + "\n"); - if (_volSize != null) { - storageVolBuilder - .append("" + _volSize + "\n"); - } - storageVolBuilder.append("\n"); - storageVolBuilder.append("\n"); - storageVolBuilder.append(""); - storageVolBuilder.append("0744"); - storageVolBuilder.append(""); - storageVolBuilder.append("\n"); - if (_backingPath != null) { - storageVolBuilder.append("\n"); - storageVolBuilder.append("" + _backingPath + "\n"); - storageVolBuilder.append("\n"); - storageVolBuilder.append("\n"); - } - storageVolBuilder.append("\n"); - return storageVolBuilder.toString(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7a0a9231/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 deleted file mode 100644 index 163ca2b..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtStorageVolumeXMLParser.java +++ /dev/null @@ -1,104 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -import java.io.IOException; -import java.io.StringReader; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.apache.log4j.Logger; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; - -public class LibvirtStorageVolumeXMLParser { - private static final Logger s_logger = Logger - .getLogger(LibvirtStorageVolumeXMLParser.class); - - 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); - - 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; - } - - 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 = "" + "test" - + "bf723c83-4b95-259c-7089-60776e61a11f" - + "20314165248" - + "1955450880" - + "18358714368" + "" - + "" - + "" - + "" + "" + "" - + "/media" + "" + "0700" - + "0" + "0" + "" - + "" + ""; - - 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/7a0a9231/agent/src/com/cloud/agent/resource/computing/LibvirtVMDef.java ---------------------------------------------------------------------- diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtVMDef.java b/agent/src/com/cloud/agent/resource/computing/LibvirtVMDef.java deleted file mode 100644 index 3b07bcd..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtVMDef.java +++ /dev/null @@ -1,964 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -public class LibvirtVMDef { - private String _hvsType; - private String _domName; - private String _domUUID; - private String _desc; - private final Map components = new HashMap(); - - public static class GuestDef { - enum guestType { - KVM, XEN, EXE - } - - enum bootOrder { - HARDISK("hd"), CDROM("cdrom"), FLOOPY("fd"), NETWORK("network"); - String _order; - - bootOrder(String order) { - _order = order; - } - - @Override - public String toString() { - return _order; - } - } - - private guestType _type; - private String _arch; - private String _loader; - private String _kernel; - private String _initrd; - private String _root; - private String _cmdline; - private List _bootdevs = new ArrayList(); - private String _machine; - - public void setGuestType(guestType type) { - _type = type; - } - - public void setGuestArch(String arch) { - _arch = arch; - } - - public void setMachineType(String machine) { - _machine = machine; - } - - public void setLoader(String loader) { - _loader = loader; - } - - public void setBootKernel(String kernel, String initrd, String rootdev, - String cmdline) { - _kernel = kernel; - _initrd = initrd; - _root = rootdev; - _cmdline = cmdline; - } - - public void setBootOrder(bootOrder order) { - _bootdevs.add(order); - } - - @Override - public String toString() { - if (_type == guestType.KVM) { - StringBuilder guestDef = new StringBuilder(); - guestDef.append("\n"); - guestDef.append("hvm\n"); - if (!_bootdevs.isEmpty()) { - for (bootOrder bo : _bootdevs) { - guestDef.append("\n"); - } - } - guestDef.append("\n"); - return guestDef.toString(); - } else - return null; - } - } - - public static class GuestResourceDef { - private long _mem; - private int _currentMem = -1; - private String _memBacking; - private int _vcpu = -1; - - public void setMemorySize(long mem) { - _mem = mem; - } - - public void setCurrentMem(int currMem) { - _currentMem = currMem; - } - - public void setMemBacking(String memBacking) { - _memBacking = memBacking; - } - - public void setVcpuNum(int vcpu) { - _vcpu = vcpu; - } - - @Override - public String toString() { - StringBuilder resBuidler = new StringBuilder(); - resBuidler.append("" + _mem + "\n"); - if (_currentMem != -1) { - resBuidler.append("" + _currentMem - + "\n"); - } - if (_memBacking != null) { - resBuidler.append("" + "<" + _memBacking + "/>" - + "\n"); - } - if (_vcpu != -1) { - resBuidler.append("" + _vcpu + "\n"); - } - return resBuidler.toString(); - } - } - - public static class FeaturesDef { - private final List _features = new ArrayList(); - - public void addFeatures(String feature) { - _features.add(feature); - } - - @Override - public String toString() { - StringBuilder feaBuilder = new StringBuilder(); - feaBuilder.append("\n"); - for (String feature : _features) { - feaBuilder.append("<" + feature + "/>\n"); - } - feaBuilder.append("\n"); - return feaBuilder.toString(); - } - } - - public static class TermPolicy { - private String _reboot; - private String _powerOff; - private String _crash; - - public TermPolicy() { - _reboot = _powerOff = _crash = "destroy"; - } - - public void setRebootPolicy(String rbPolicy) { - _reboot = rbPolicy; - } - - public void setPowerOffPolicy(String poPolicy) { - _powerOff = poPolicy; - } - - public void setCrashPolicy(String crashPolicy) { - _crash = crashPolicy; - } - - @Override - public String toString() { - StringBuilder term = new StringBuilder(); - term.append("" + _reboot + "\n"); - term.append("" + _powerOff + "\n"); - term.append("" + _powerOff + "\n"); - return term.toString(); - } - } - - public static class ClockDef { - public enum ClockOffset { - UTC("utc"), LOCALTIME("localtime"), TIMEZONE("timezone"), VARIABLE( - "variable"); - - private String _offset; - - private ClockOffset(String offset) { - _offset = offset; - } - - @Override - public String toString() { - return _offset; - } - } - - private ClockOffset _offset; - private String _timerName; - private String _tickPolicy; - private String _track; - - public ClockDef() { - _offset = ClockOffset.UTC; - } - - public void setClockOffset(ClockOffset offset) { - _offset = offset; - } - - public void setTimer(String timerName, String tickPolicy, String track) { - _timerName = timerName; - _tickPolicy = tickPolicy; - _track = track; - } - - @Override - public String toString() { - StringBuilder clockBuilder = new StringBuilder(); - clockBuilder.append("\n"); - if (_timerName != null) { - clockBuilder.append("\n"); - clockBuilder.append("\n"); - } - clockBuilder.append("\n"); - return clockBuilder.toString(); - } - } - - public static class DevicesDef { - private String _emulator; - private final Map> devices = new HashMap>(); - - public boolean addDevice(Object device) { - Object dev = devices.get(device.getClass().toString()); - if (dev == null) { - List devs = new ArrayList(); - devs.add(device); - devices.put(device.getClass().toString(), devs); - } else { - List devs = (List) dev; - devs.add(device); - } - return true; - } - - public void setEmulatorPath(String emulator) { - _emulator = emulator; - } - - @Override - public String toString() { - StringBuilder devicesBuilder = new StringBuilder(); - devicesBuilder.append("\n"); - if (_emulator != null) { - devicesBuilder.append("" + _emulator - + "\n"); - } - - for (List devs : devices.values()) { - for (Object dev : devs) { - devicesBuilder.append(dev.toString()); - } - } - devicesBuilder.append("\n"); - return devicesBuilder.toString(); - } - - @SuppressWarnings("unchecked") - public List getDisks() { - return (List) devices.get(DiskDef.class.toString()); - } - - @SuppressWarnings("unchecked") - public List getInterfaces() { - return (List) devices.get(InterfaceDef.class - .toString()); - } - - } - - public static class DiskDef { - enum deviceType { - FLOOPY("floopy"), DISK("disk"), CDROM("cdrom"); - String _type; - - deviceType(String type) { - _type = type; - } - - @Override - public String toString() { - return _type; - } - } - - enum diskType { - FILE("file"), BLOCK("block"), DIRECTROY("dir"), NETWORK("network"); - String _diskType; - - diskType(String type) { - _diskType = type; - } - - @Override - public String toString() { - return _diskType; - } - } - - enum diskProtocol { - RBD("rbd"), SHEEPDOG("sheepdog"); - String _diskProtocol; - - diskProtocol(String protocol) { - _diskProtocol = protocol; - } - - @Override - public String toString() { - return _diskProtocol; - } - } - - enum diskBus { - IDE("ide"), SCSI("scsi"), VIRTIO("virtio"), XEN("xen"), USB("usb"), UML( - "uml"), FDC("fdc"); - String _bus; - - diskBus(String bus) { - _bus = bus; - } - - @Override - public String toString() { - return _bus; - } - } - - enum diskFmtType { - RAW("raw"), QCOW2("qcow2"); - String _fmtType; - - diskFmtType(String fmt) { - _fmtType = fmt; - } - - @Override - public String toString() { - return _fmtType; - } - } - - private deviceType _deviceType; /* floppy, disk, cdrom */ - private diskType _diskType; - private diskProtocol _diskProtocol; - private String _sourcePath; - private String _sourceHost; - private int _sourcePort; - private String _authUserName; - private String _authSecretUUID; - private String _diskLabel; - private diskBus _bus; - private diskFmtType _diskFmtType; /* qcow2, raw etc. */ - private boolean _readonly = false; - private boolean _shareable = false; - private boolean _deferAttach = false; - - public void setDeviceType(deviceType deviceType) { - _deviceType = deviceType; - } - - public void defFileBasedDisk(String filePath, String diskLabel, - diskBus bus, diskFmtType diskFmtType) { - _diskType = diskType.FILE; - _deviceType = deviceType.DISK; - _sourcePath = filePath; - _diskLabel = diskLabel; - _diskFmtType = diskFmtType; - _bus = bus; - - } - - /* skip iso label */ - private String getDevLabel(int devId, diskBus bus) { - if (devId == 2) { - devId++; - } - - char suffix = (char) ('a' + devId); - if (bus == diskBus.SCSI) { - return "sd" + suffix; - } else if (bus == diskBus.VIRTIO) { - return "vd" + suffix; - } - return "hd" + suffix; - - } - - public void defFileBasedDisk(String filePath, int devId, diskBus bus, - diskFmtType diskFmtType) { - - _diskType = diskType.FILE; - _deviceType = deviceType.DISK; - _sourcePath = filePath; - _diskLabel = getDevLabel(devId, bus); - _diskFmtType = diskFmtType; - _bus = bus; - - } - - public void defISODisk(String volPath) { - _diskType = diskType.FILE; - _deviceType = deviceType.CDROM; - _sourcePath = volPath; - _diskLabel = "hdc"; - _diskFmtType = diskFmtType.RAW; - _bus = diskBus.IDE; - } - - public void defBlockBasedDisk(String diskName, int devId, diskBus bus) { - _diskType = diskType.BLOCK; - _deviceType = deviceType.DISK; - _diskFmtType = diskFmtType.RAW; - _sourcePath = diskName; - _diskLabel = getDevLabel(devId, bus); - _bus = bus; - } - - public void defBlockBasedDisk(String diskName, String diskLabel, - diskBus bus) { - _diskType = diskType.BLOCK; - _deviceType = deviceType.DISK; - _diskFmtType = diskFmtType.RAW; - _sourcePath = diskName; - _diskLabel = diskLabel; - _bus = bus; - } - - public void defNetworkBasedDisk(String diskName, String sourceHost, int sourcePort, - String authUserName, String authSecretUUID, - int devId, diskBus bus, diskProtocol protocol) { - _diskType = diskType.NETWORK; - _deviceType = deviceType.DISK; - _diskFmtType = diskFmtType.RAW; - _sourcePath = diskName; - _sourceHost = sourceHost; - _sourcePort = sourcePort; - _authUserName = authUserName; - _authSecretUUID = authSecretUUID; - _diskLabel = getDevLabel(devId, bus); - _bus = bus; - _diskProtocol = protocol; - } - - public void defNetworkBasedDisk(String diskName, String sourceHost, int sourcePort, - String authUserName, String authSecretUUID, - String diskLabel, diskBus bus, diskProtocol protocol) { - _diskType = diskType.NETWORK; - _deviceType = deviceType.DISK; - _diskFmtType = diskFmtType.RAW; - _sourcePath = diskName; - _sourceHost = sourceHost; - _sourcePort = sourcePort; - _authUserName = authUserName; - _authSecretUUID = authSecretUUID; - _diskLabel = diskLabel; - _bus = bus; - _diskProtocol = protocol; - } - - public void setReadonly() { - _readonly = true; - } - - public void setSharable() { - _shareable = true; - } - - public void setAttachDeferred(boolean deferAttach) { - _deferAttach = deferAttach; - } - - public boolean isAttachDeferred() { - return _deferAttach; - } - - public String getDiskPath() { - return _sourcePath; - } - - public String getDiskLabel() { - return _diskLabel; - } - - public deviceType getDeviceType() { - return _deviceType; - } - - public void setDiskPath(String volPath) { - this._sourcePath = volPath; - } - - public diskBus getBusType() { - return _bus; - } - - public int getDiskSeq() { - char suffix = this._diskLabel.charAt(this._diskLabel.length() - 1); - return suffix - 'a'; - } - - @Override - public String toString() { - StringBuilder diskBuilder = new StringBuilder(); - diskBuilder.append("\n"); - diskBuilder.append("\n"); - if (_diskType == diskType.FILE) { - diskBuilder.append("\n"); - } else if (_diskType == diskType.BLOCK) { - diskBuilder.append("\n"); - } else if (_diskType == diskType.NETWORK) { - diskBuilder.append("\n"); - diskBuilder.append("\n"); - diskBuilder.append("\n"); - if (_authUserName != null) { - diskBuilder.append("\n"); - diskBuilder.append("\n"); - diskBuilder.append("\n"); - } - } - diskBuilder.append("\n"); - diskBuilder.append("\n"); - return diskBuilder.toString(); - } - } - - public static class InterfaceDef { - enum guestNetType { - BRIDGE("bridge"), NETWORK("network"), USER("user"), ETHERNET( - "ethernet"), INTERNAL("internal"); - String _type; - - guestNetType(String type) { - _type = type; - } - - @Override - public String toString() { - return _type; - } - } - - enum nicModel { - E1000("e1000"), VIRTIO("virtio"), RTL8139("rtl8139"), NE2KPCI( - "ne2k_pci"); - String _model; - - nicModel(String model) { - _model = model; - } - - @Override - public String toString() { - return _model; - } - } - - enum hostNicType { - DIRECT_ATTACHED_WITHOUT_DHCP, DIRECT_ATTACHED_WITH_DHCP, VNET, VLAN; - } - - private guestNetType _netType; /* - * bridge, ethernet, network, user, - * internal - */ - private hostNicType _hostNetType; /* Only used by agent java code */ - private String _sourceName; - private String _networkName; - private String _macAddr; - private String _ipAddr; - private String _scriptPath; - private nicModel _model; - - public void defBridgeNet(String brName, String targetBrName, - String macAddr, nicModel model) { - _netType = guestNetType.BRIDGE; - _sourceName = brName; - _networkName = targetBrName; - _macAddr = macAddr; - _model = model; - } - - public void defPrivateNet(String networkName, String targetName, - String macAddr, nicModel model) { - _netType = guestNetType.NETWORK; - _sourceName = networkName; - _networkName = targetName; - _macAddr = macAddr; - _model = model; - } - - public void setHostNetType(hostNicType hostNetType) { - _hostNetType = hostNetType; - } - - public hostNicType getHostNetType() { - return _hostNetType; - } - - public String getBrName() { - return _sourceName; - } - - public guestNetType getNetType() { - return _netType; - } - - public String getDevName() { - return _networkName; - } - - public String getMacAddress() { - return _macAddr; - } - - @Override - public String toString() { - StringBuilder netBuilder = new StringBuilder(); - netBuilder.append("\n"); - if (_netType == guestNetType.BRIDGE) { - netBuilder.append("\n"); - } else if (_netType == guestNetType.NETWORK) { - netBuilder.append("\n"); - } - if (_networkName != null) { - netBuilder.append("\n"); - } - if (_macAddr != null) { - netBuilder.append("\n"); - } - if (_model != null) { - netBuilder.append("\n"); - } - netBuilder.append("\n"); - return netBuilder.toString(); - } - } - - public static class ConsoleDef { - private final String _ttyPath; - private final String _type; - private final String _source; - private short _port = -1; - - public ConsoleDef(String type, String path, String source, short port) { - _type = type; - _ttyPath = path; - _source = source; - _port = port; - } - - @Override - public String toString() { - StringBuilder consoleBuilder = new StringBuilder(); - consoleBuilder.append("\n"); - if (_source != null) { - consoleBuilder.append("\n"); - } - if (_port != -1) { - consoleBuilder.append("\n"); - } - consoleBuilder.append("\n"); - return consoleBuilder.toString(); - } - } - - public static class SerialDef { - private final String _type; - private final String _source; - private short _port = -1; - - public SerialDef(String type, String source, short port) { - _type = type; - _source = source; - _port = port; - } - - @Override - public String toString() { - StringBuilder serialBuidler = new StringBuilder(); - serialBuidler.append("\n"); - if (_source != null) { - serialBuidler.append("\n"); - } - if (_port != -1) { - serialBuidler.append("\n"); - } - serialBuidler.append("\n"); - return serialBuidler.toString(); - } - } - - public static class GraphicDef { - private final String _type; - private short _port = -2; - private boolean _autoPort = false; - private final String _listenAddr; - private final String _passwd; - private final String _keyMap; - - public GraphicDef(String type, short port, boolean autoPort, - String listenAddr, String passwd, String keyMap) { - _type = type; - _port = port; - _autoPort = autoPort; - _listenAddr = listenAddr; - _passwd = passwd; - _keyMap = keyMap; - } - - @Override - public String toString() { - StringBuilder graphicBuilder = new StringBuilder(); - graphicBuilder.append("\n"); - return graphicBuilder.toString(); - } - } - - public static class InputDef { - private final String _type; /* tablet, mouse */ - private final String _bus; /* ps2, usb, xen */ - - public InputDef(String type, String bus) { - _type = type; - _bus = bus; - } - - @Override - public String toString() { - StringBuilder inputBuilder = new StringBuilder(); - inputBuilder.append("\n"); - return inputBuilder.toString(); - } - } - - public void setHvsType(String hvs) { - _hvsType = hvs; - } - - public void setDomainName(String domainName) { - _domName = domainName; - } - - public void setDomUUID(String uuid) { - _domUUID = uuid; - } - - public void setDomDescription(String desc) { - _desc = desc; - } - - public String getGuestOSType() { - return _desc; - } - - public void addComp(Object comp) { - components.put(comp.getClass().toString(), comp); - } - - public DevicesDef getDevices() { - Object o = components.get(DevicesDef.class.toString()); - if (o != null) { - return (DevicesDef) o; - } - return null; - } - - @Override - public String toString() { - StringBuilder vmBuilder = new StringBuilder(); - vmBuilder.append("\n"); - vmBuilder.append("" + _domName + "\n"); - if (_domUUID != null) { - vmBuilder.append("" + _domUUID + "\n"); - } - if (_desc != null) { - vmBuilder.append("" + _desc + "\n"); - } - for (Object o : components.values()) { - vmBuilder.append(o.toString()); - } - vmBuilder.append("\n"); - return vmBuilder.toString(); - } - - public static void main(String[] args) { - System.out.println("testing"); - LibvirtVMDef vm = new LibvirtVMDef(); - vm.setHvsType("kvm"); - vm.setDomainName("testing"); - vm.setDomUUID(UUID.randomUUID().toString()); - - GuestDef guest = new GuestDef(); - guest.setGuestType(GuestDef.guestType.KVM); - guest.setGuestArch("x86_64"); - guest.setMachineType("pc-0.11"); - guest.setBootOrder(GuestDef.bootOrder.HARDISK); - vm.addComp(guest); - - GuestResourceDef grd = new GuestResourceDef(); - grd.setMemorySize(512 * 1024); - grd.setVcpuNum(1); - vm.addComp(grd); - - FeaturesDef features = new FeaturesDef(); - features.addFeatures("pae"); - features.addFeatures("apic"); - features.addFeatures("acpi"); - vm.addComp(features); - - TermPolicy term = new TermPolicy(); - term.setCrashPolicy("destroy"); - term.setPowerOffPolicy("destroy"); - term.setRebootPolicy("destroy"); - vm.addComp(term); - - DevicesDef devices = new DevicesDef(); - devices.setEmulatorPath("/usr/bin/cloud-qemu-system-x86_64"); - - DiskDef hda = new DiskDef(); - hda.defFileBasedDisk("/path/to/hda1", 0, DiskDef.diskBus.VIRTIO, - DiskDef.diskFmtType.QCOW2); - devices.addDevice(hda); - - DiskDef hdb = new DiskDef(); - hdb.defFileBasedDisk("/path/to/hda2", 1, DiskDef.diskBus.VIRTIO, - DiskDef.diskFmtType.QCOW2); - devices.addDevice(hdb); - - InterfaceDef pubNic = new InterfaceDef(); - pubNic.defBridgeNet("cloudbr0", "vnet1", "00:16:3e:77:e2:a1", - InterfaceDef.nicModel.VIRTIO); - devices.addDevice(pubNic); - - InterfaceDef privNic = new InterfaceDef(); - privNic.defPrivateNet("cloud-private", null, "00:16:3e:77:e2:a2", - InterfaceDef.nicModel.VIRTIO); - devices.addDevice(privNic); - - InterfaceDef vlanNic = new InterfaceDef(); - vlanNic.defBridgeNet("vnbr1000", "tap1", "00:16:3e:77:e2:a2", - InterfaceDef.nicModel.VIRTIO); - devices.addDevice(vlanNic); - - SerialDef serial = new SerialDef("pty", null, (short) 0); - devices.addDevice(serial); - - ConsoleDef console = new ConsoleDef("pty", null, null, (short) 0); - devices.addDevice(console); - - GraphicDef grap = new GraphicDef("vnc", (short) 0, true, null, null, - null); - devices.addDevice(grap); - - InputDef input = new InputDef("tablet", "usb"); - devices.addDevice(input); - - vm.addComp(devices); - - System.out.println(vm.toString()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7a0a9231/agent/src/com/cloud/agent/resource/computing/LibvirtXMLParser.java ---------------------------------------------------------------------- diff --git a/agent/src/com/cloud/agent/resource/computing/LibvirtXMLParser.java b/agent/src/com/cloud/agent/resource/computing/LibvirtXMLParser.java deleted file mode 100644 index b73ea0f..0000000 --- a/agent/src/com/cloud/agent/resource/computing/LibvirtXMLParser.java +++ /dev/null @@ -1,72 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.resource.computing; - -import java.io.IOException; -import java.io.StringReader; - -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.apache.log4j.Logger; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -public class LibvirtXMLParser extends DefaultHandler { - private static final Logger s_logger = Logger - .getLogger(LibvirtXMLParser.class); - protected static SAXParserFactory s_spf; - - static { - s_spf = SAXParserFactory.newInstance(); - - } - protected SAXParser _sp; - protected boolean _initialized = false; - - public LibvirtXMLParser() { - - try { - _sp = s_spf.newSAXParser(); - _initialized = true; - } catch (Exception ex) { - } - - } - - public boolean parseDomainXML(String domXML) { - if (!_initialized) { - return false; - } - try { - _sp.parse(new InputSource(new StringReader(domXML)), this); - return true; - } catch (SAXException se) { - s_logger.warn(se.getMessage()); - } catch (IOException ie) { - s_logger.error(ie.getMessage()); - } - return false; - } - - @Override - public void characters(char[] ch, int start, int length) - throws SAXException { - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7a0a9231/agent/src/com/cloud/agent/storage/KVMPhysicalDisk.java ---------------------------------------------------------------------- diff --git a/agent/src/com/cloud/agent/storage/KVMPhysicalDisk.java b/agent/src/com/cloud/agent/storage/KVMPhysicalDisk.java deleted file mode 100644 index cb790d9..0000000 --- a/agent/src/com/cloud/agent/storage/KVMPhysicalDisk.java +++ /dev/null @@ -1,98 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.storage; - -public class KVMPhysicalDisk { - private String path; - private String name; - private KVMStoragePool pool; - - public static enum PhysicalDiskFormat { - RAW("raw"), QCOW2("qcow2"); - String format; - - private PhysicalDiskFormat(String format) { - this.format = format; - } - - public String toString() { - return this.format; - } - } - - public static String RBDStringBuilder(String monHost, int monPort, - String authUserName, String authSecret, String image) { - String rbdOpts; - - rbdOpts = "rbd:" + image; - rbdOpts += ":mon_host=" + monHost + "\\\\:" + monPort; - if (authUserName == null) { - rbdOpts += ":auth_supported=none"; - } else { - rbdOpts += ":auth_supported=cephx"; - rbdOpts += ":id=" + authUserName; - rbdOpts += ":key=" + authSecret; - } - return rbdOpts; - } - - private PhysicalDiskFormat format; - private long size; - private long virtualSize; - - public KVMPhysicalDisk(String path, String name, KVMStoragePool pool) { - this.path = path; - this.name = name; - this.pool = pool; - } - - public void setFormat(PhysicalDiskFormat format) { - this.format = format; - } - - public PhysicalDiskFormat getFormat() { - return this.format; - } - - public void setSize(long size) { - this.size = size; - } - - public long getSize() { - return this.size; - } - - public void setVirtualSize(long size) { - this.virtualSize = size; - } - - public long getVirtualSize() { - return this.virtualSize; - } - - public String getName() { - return this.name; - } - - public String getPath() { - return this.path; - } - - public KVMStoragePool getPool() { - return this.pool; - } -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7a0a9231/agent/src/com/cloud/agent/storage/KVMStoragePool.java ---------------------------------------------------------------------- diff --git a/agent/src/com/cloud/agent/storage/KVMStoragePool.java b/agent/src/com/cloud/agent/storage/KVMStoragePool.java deleted file mode 100644 index f1192ed..0000000 --- a/agent/src/com/cloud/agent/storage/KVMStoragePool.java +++ /dev/null @@ -1,65 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF 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 com.cloud.agent.storage; - -import java.util.List; - -import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat; -import com.cloud.storage.Storage.StoragePoolType; - -public interface KVMStoragePool { - public KVMPhysicalDisk createPhysicalDisk(String name, - PhysicalDiskFormat format, long size); - - public KVMPhysicalDisk createPhysicalDisk(String name, long size); - - public KVMPhysicalDisk getPhysicalDisk(String volumeUuid); - - public boolean deletePhysicalDisk(String uuid); - - public List listPhysicalDisks(); - - public String getUuid(); - - public long getCapacity(); - - public long getUsed(); - - public boolean refresh(); - - public boolean isExternalSnapshot(); - - public String getLocalPath(); - - public String getSourceHost(); - - public String getSourceDir(); - - public int getSourcePort(); - - public String getAuthUserName(); - - public String getAuthSecret(); - - public StoragePoolType getType(); - - public boolean delete(); - - PhysicalDiskFormat getDefaultFormat(); - - public boolean createFolder(String path); -}