You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by se...@apache.org on 2014/06/20 15:27:39 UTC
[3/7] CLOUDSTACK-6967: Now with module!
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1516b041/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/CloudStackPlugin.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/CloudStackPlugin.java b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/CloudStackPlugin.java
new file mode 100644
index 0000000..94275f4
--- /dev/null
+++ b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/CloudStackPlugin.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.cloud.hypervisor.ovm3.object;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.xmlrpc.XmlRpcException;
+
+public class CloudStackPlugin extends OvmObject {
+
+ public CloudStackPlugin(Connection c) {
+ client = c;
+ }
+
+ public String getVncPort(String vmName) throws XmlRpcException {
+ String x = (String) callWrapper("get_vncport", vmName);
+ return x;
+ }
+
+ public boolean ovsUploadSshKey(String key, String content)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_upload_ssh_key", key, content);
+ if (x==null) {
+ return false;
+ }
+ return true;
+ }
+
+ public class ReturnCode {
+ private Map<String, Object> _rc = new HashMap<String, Object>() {
+ {
+ put("rc", null);
+ put("exit", null);
+ put("err", null);
+ put("out", null);
+ }
+ };
+ public void setValues(Map<String, String> m) {
+ this._rc.putAll(m);
+ }
+ public Boolean getRc() {
+ try {
+ Long rc = (Long) _rc.get("rc");
+ _rc.put("exit", rc);
+ if (rc != 0)
+ return false;
+ return true;
+ } catch (Exception e) {
+
+ }
+ return false;
+ }
+ public String getStdOut() {
+ return (String) _rc.get("out");
+ }
+ public String getStdErr() {
+ return (String) _rc.get("err");
+ }
+ public Integer getExit() {
+ if (_rc.get("exit") == null)
+ _rc.put("exit", _rc.get("rc"));
+ return Integer.valueOf((String) _rc.get("exit"));
+ }
+ }
+ public ReturnCode domrExec(String ip, String cmd) throws XmlRpcException {
+ ReturnCode rc = new ReturnCode();
+ rc.setValues((Map<String, String>) callWrapper("exec_domr", ip, cmd));
+ return rc;
+ }
+
+ public boolean domrCheckPort(String ip, Integer port, Integer retries, Integer interval)
+ throws XmlRpcException, InterruptedException {
+ Boolean x= false;
+ /* should deduct the interval from the timeout and sleep on it */
+ Integer sleep=interval;
+ while(x == false && retries > 0) {
+ x = (Boolean) callWrapper("check_domr_port", ip, port, interval);
+ retries--;
+ Thread.sleep(sleep * 1000);
+ }
+ return x;
+ }
+
+ public Map<String, String> ovsDom0Stats(String bridge) throws XmlRpcException {
+ Map<String, String> stats = (Map<String, String>)
+ callWrapper("ovs_dom0_stats", bridge);
+ return stats;
+ }
+
+
+ public Map<String, String> ovsDomUStats(String domain) throws XmlRpcException {
+ Map<String, String> stats = (Map<String, String>)
+ callWrapper("ovs_domU_stats", domain);
+ return stats;
+ }
+ public boolean domrCheckPort(String ip, Integer port) throws XmlRpcException {
+ Object x = callWrapper("check_domr_port", ip, port);
+ return (Boolean) x;
+ }
+
+ public boolean domrCheckSsh(String ip) throws XmlRpcException {
+ Object x = callWrapper("check_domr_ssh", ip);
+ return (Boolean) x;
+ }
+
+ public boolean ovsControlInterface(String dev, String ipmask) throws XmlRpcException {
+ Object x = callWrapper("ovs_control_interface", dev, ipmask);
+ return (Boolean) x;
+ }
+
+ public boolean ping(String host) throws XmlRpcException {
+ Object x = callWrapper("ping", host);
+ return (Boolean) x;
+ }
+
+ public boolean ovsCheckFile(String file) throws XmlRpcException {
+ Object x = callWrapper("ovs_check_file", file);
+ return (Boolean) x;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1516b041/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Cluster.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Cluster.java b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Cluster.java
new file mode 100644
index 0000000..703f8a2
--- /dev/null
+++ b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Cluster.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.cloud.hypervisor.ovm3.object;
+
+import org.apache.xmlrpc.XmlRpcException;
+
+/*
+ * should become an interface implementation
+ */
+public class Cluster extends OvmObject {
+
+ public Cluster(Connection c) {
+ client = c;
+ }
+
+ /*
+ * leave_cluster, <class 'agent.api.cluster.o2cb.ClusterO2CB'> argument:
+ * self - default: None argument: poolfsUuid - default: None
+ */
+ public Boolean leaveCluster(String poolfsUuid) throws XmlRpcException {
+ Object x = callWrapper("leave_cluster", poolfsUuid);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * configure_server_for_cluster, <class
+ * 'agent.api.cluster.o2cb.ClusterO2CB'> argument: self - default: None <( ?
+ * argument: o2cb_conf - default: None <( ? argument: clusterConf -
+ * default: None <( ? argument: poolfs_type - default: None argument:
+ * poolfs_target - default: None argument: poolfsUuid - default: None
+ * argument: poolfs_nfsbase_uuid - default: None
+ */
+ public Boolean configureServerForCluster(String poolfsUuid)
+ throws XmlRpcException {
+ Object x = callWrapper("configure_server_for_cluster", poolfsUuid);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * deconfigure_server_for_cluster, <class
+ * 'agent.api.cluster.o2cb.ClusterO2CB'> argument: self - default: None
+ * argument: poolfsUuid - default: None
+ */
+ public Boolean deconfigureServerForCluster(String poolfsUuid)
+ throws XmlRpcException {
+ Object x = callWrapper("deconfigure_server_for_cluster", poolfsUuid);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * join_cluster, <class 'agent.api.cluster.o2cb.ClusterO2CB'> argument: self
+ * - default: None argument: poolfsUuid - default: None
+ */
+ public Boolean joinCLuster(String poolfsUuid) throws XmlRpcException {
+ Object x = callWrapper("join_cluster", poolfsUuid);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * discover_cluster, <class 'agent.api.cluster.o2cb.ClusterO2CB'> argument:
+ * self - default: None
+ */
+ /*
+ * <Discover_Cluster_Result>< <O2CB_Config>
+ * <O2CB_HEARTBEAT_THRESHOLD>61</O2CB_HEARTBEAT_THRESHOLD>
+ * <O2CB_RECONNECT_DELAY_MS>2000</O2CB_RECONNECT_DELAY_MS>
+ * <O2CB_KEEPALIVE_DELAY_MS>2000</O2CB_KEEPALIVE_DELAY_MS>
+ * <O2CB_BOOTCLUSTER>ba9aaf00ae5e2d73</O2CB_BOOTCLUSTER>
+ * <O2CB_IDLE_TIMEOUT_MS>60000</O2CB_IDLE_TIMEOUT_MS>
+ * <O2CB_ENABLED>true</O2CB_ENABLED> <O2CB_STACK>o2cb</O2CB_STACK>
+ * </O2CB_Config> <Cluster_Information> <Stored> <Clusters> <Cluster>
+ * <Name>ba9aaf00ae5e2d73</Name> <Node_Count>1</Node_Count>
+ * <Heartbeat_Mode>global</Heartbeat_Mode> </Cluster> </Clusters>
+ * <Heartbeats> <Heartbeat>
+ * <Region>0004FB0000050000E70FBDDEB802208F</Region>
+ * <Cluster>ba9aaf00ae5e2d73</Cluster> </Heartbeat> </Heartbeats> <Nodes>
+ * <Node> <Number>0</Number> <IP_Port>7777</IP_Port>
+ * <IP_Address>192.168.1.64</IP_Address> <Name>ovm-1</Name>
+ * <Cluster_Name>ba9aaf00ae5e2d73</Cluster_Name> </Node> </Nodes> </Stored>
+ * </Cluster_Information> </Discover_Cluster_Result>
+ */
+ /* returns xml - sigh */
+ public Boolean discoverCluster() throws XmlRpcException {
+ Object x = callWrapper("discover_cluster");
+ // System.out.println(x);
+
+ return false;
+ }
+
+ /*
+ * update_clusterConfiguration, <class
+ * 'agent.api.cluster.o2cb.ClusterO2CB'> argument: self - default: None
+ * argument: cluster_conf - default: None <( ? cluster_conf can be a "dict"
+ * or a plain file: print master.update_clusterConfiguration(
+ * "heartbeat:\n\tregion = 0004FB0000050000E70FBDDEB802208F\n\tcluster = ba9aaf00ae5e2d72\n\nnode:\n\tip_port = 7777\n\tip_address = 192.168.1.64\n\tnumber = 0\n\tname = ovm-1\n\tcluster = ba9aaf00ae5e2d72\n\nnode:\n\tip_port = 7777\n\tip_address = 192.168.1.65\n\tnumber = 1\n\tname = ovm-2\n\tcluster = ba9aaf00ae5e2d72\n\ncluster:\n\tnode_count = 2\n\theartbeat_mode = global\n\tname = ba9aaf00ae5e2d72\n"
+ * )
+ */
+ public Boolean updateClusterConfiguration(String clusterConf)
+ throws XmlRpcException {
+ Object x = callWrapper("update_clusterConfiguration", clusterConf);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * destroy_cluster, <class 'agent.api.cluster.o2cb.ClusterO2CB'> argument:
+ * self - default: None argument: poolfsUuid - default: None
+ */
+ public Boolean destroyCluster(String poolfsUuid) throws XmlRpcException {
+ Object x = callWrapper("destroy_cluster", poolfsUuid);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * is_cluster_online, <class 'agent.api.cluster.o2cb.ClusterO2CB'> argument:
+ * self - default: None
+ */
+ public Boolean isClusterOnline() throws XmlRpcException {
+ Object x = callWrapper("is_cluster_online");
+ return Boolean.valueOf(x.toString());
+ }
+
+ /*
+ * create_cluster, <class 'agent.api.cluster.o2cb.ClusterO2CB'> argument:
+ * self - default: None argument: poolfsUuid - default: None
+ */
+ public Boolean createCluster(String poolfsUuid) throws XmlRpcException {
+ Object x = callWrapper("create_cluster", poolfsUuid);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1516b041/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Common.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Common.java b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Common.java
new file mode 100644
index 0000000..ca24748
--- /dev/null
+++ b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Common.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.cloud.hypervisor.ovm3.object;
+
+import org.apache.xmlrpc.XmlRpcException;
+
+/*
+ * should become an interface implementation
+ */
+public class Common extends OvmObject {
+ public String apiVersion;
+
+ public Common(Connection c) {
+ client = c;
+ }
+
+ /*
+ * get_api_version, <class 'agent.api.common.Common'>
+ */
+ public String getApiVersion() throws XmlRpcException {
+ return callString("get_api_version");
+
+ }
+
+ /*
+ * sleep, <class 'agent.api.common.Common'> argument: secs - default: None
+ */
+ public String sleep(int seconds) throws XmlRpcException {
+ return callString("sleep", seconds);
+ }
+
+ /*
+ * dispatch, <class 'agent.api.common.Common'> argument: uri - default: None
+ * argument: func - default: None
+ */
+ /*
+ * normally used to push commands to other hosts in a cluster: *
+ * dispatch function join_server_pool
+ * to server https://oracle:******@192.168.1.67:8899/api/3/
+ */
+ public <T> String dispatch(String url, String function, T... args)
+ throws XmlRpcException {
+ return callString("dispatch", url, function, args);
+ }
+
+ /*
+ * echo, <class 'agent.api.common.Common'> argument: msg - default: None
+ */
+ public String echo(String msg) throws XmlRpcException {
+ return callString("echo", msg);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1516b041/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Connection.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Connection.java b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Connection.java
new file mode 100644
index 0000000..53a8e10
--- /dev/null
+++ b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Connection.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.cloud.hypervisor.ovm3.object;
+import java.net.URL;
+import java.util.TimeZone;
+import java.util.Vector;
+
+import org.apache.log4j.Logger;
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.client.TimingOutCallback;
+import org.apache.xmlrpc.client.XmlRpcClient;
+import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
+
+public class Connection extends XmlRpcClient {
+ private static final Logger s_logger = Logger.getLogger(Connection.class);
+ private final XmlRpcClientConfigImpl _config = new XmlRpcClientConfigImpl();
+ private XmlRpcClient _client;
+ private String _username;
+ private String _password;
+ private String _ip;
+ private Integer _port = 8898;
+ private Boolean _isSsl = false;
+ private String cert = "";
+ private String key = "";
+ private Integer timeout = 1200; /* seconds */
+ private Integer _timeout = timeout * 1000; /* native is ms */
+
+ private XmlRpcClient getXmlClient() throws XmlRpcException {
+ // check ssl boolean
+ final XmlRpcClient client = new XmlRpcClient();
+
+ URL url;
+ try {
+ // here too
+ url = new URL("http://" + _ip + ":" + _port.toString());
+ _config.setTimeZone(TimeZone.getTimeZone("UTC"));
+ _config.setServerURL(url);
+ _config.setReplyTimeout(0); // disable, we use asyncexecute to
+ // control timeout
+ _config.setConnectionTimeout(60000);
+ _config.setReplyTimeout(60 * 15000);
+ _config.setBasicUserName(_username);
+ _config.setBasicPassword(_password);
+ _config.setXmlRpcServer(null);
+ // _config.setEnabledForExtensions(true);
+ client.setConfig(_config);
+ client.setTypeFactory(new RpcTypeFactory(client));
+ } catch (Throwable e) {
+ throw new XmlRpcException(e.getMessage());
+ }
+ return client;
+ }
+
+ public Connection(String ip, Integer port, String username, String password)
+ throws XmlRpcException {
+ _ip = ip;
+ _port = port;
+ _username = username;
+ _password = password;
+ _client = getXmlClient();
+ }
+
+ public Connection(String ip, String username, String password)
+ throws XmlRpcException {
+ _ip = ip;
+ _username = username;
+ _password = password;
+ _client = getXmlClient();
+ }
+
+ public Object call(String method, Vector<?> params) throws XmlRpcException {
+ /* default timeout is 10 mins */
+ return callTimeoutInSec(method, params, this._timeout);
+ }
+
+ public Object call(String method, Vector<?> params, boolean debug)
+ throws XmlRpcException {
+ /* default timeout is 10 mins */
+ return callTimeoutInSec(method, params, this._timeout, debug);
+ }
+
+ public Object callTimeoutInSec(String method, Vector<?> params,
+ int timeout, boolean debug) throws XmlRpcException {
+ TimingOutCallback callback = new TimingOutCallback(timeout * 1000);
+ if (debug) {
+ /*
+ * some parameters including user password should not be printed in
+ * log
+ */
+ s_logger.debug("Call Ovm3 agent: " + method + " with " + params);
+ }
+
+ long startTime = System.currentTimeMillis();
+ _client.executeAsync(method, params, callback);
+ try {
+ return callback.waitForResponse();
+ } catch (TimingOutCallback.TimeoutException to) {
+ throw to;
+ } catch (Throwable e) {
+ throw new XmlRpcException(-2, e.getMessage());
+ } finally {
+ long endTime = System.currentTimeMillis();
+ float during = (endTime - startTime) / 1000; // in secs
+ s_logger.debug("Ovm3 call " + method + " finished in " + during
+ + " secs, on " + _ip + ":" + _port);
+ }
+ }
+
+ public Object callTimeoutInSec(String method, Vector<?> params, int timeout)
+ throws XmlRpcException {
+ return callTimeoutInSec(method, params, timeout, true);
+ }
+
+ public String getIp() {
+ return _ip;
+ }
+
+ public Integer getPort() {
+ return _port;
+ }
+
+ public String getUserName() {
+ return _username;
+ }
+
+ public String getPassword() {
+ return _password;
+ }
+
+ public Boolean getIsSsl() {
+ return _isSsl;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1516b041/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Linux.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Linux.java b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Linux.java
new file mode 100644
index 0000000..3be9feb
--- /dev/null
+++ b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Linux.java
@@ -0,0 +1,612 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.cloud.hypervisor.ovm3.object;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.w3c.dom.Document;
+
+/*
+ * should become an interface implementation
+ */
+public class Linux extends OvmObject {
+ private Integer _init = 0;
+
+ /*
+ * use capabilities to match things later, perhaps also hardware discovery ?
+ * wrap getters and setters.... for Mapps...
+ */
+ public Map<String, String> Capabilities = new HashMap<String, String>();
+ /*
+ * MAX_CONCURRENT_MIGRATION_IN=1, ALL_VM_CPU_OVERSUBSCRIBE=True,
+ * HIGH_AVAILABILITY=True, LOCAL_STORAGE_ELEMENT=True, NFS=True,
+ * MTU_CONFIGURATION=True, CONCURRENT_MIGRATION=False,
+ * VM_MEMORY_ALIGNMENT=1048576, CLUSTERS=True, VM_SUSPEND=True,
+ * BOND_MODE_LINK_AGGREGATION=True, YUM_PACKAGE_MANAGEMENT=True,
+ * VM_VNC_CONSOLE=True, BOND_MODE_ACTIVE_BACKUP=True,
+ * MAX_CONCURRENT_MIGRATION_OUT=1, MIGRATION_SETUP=False,
+ * PER_VM_CPU_OVERSUBSCRIBE=True, POWER_ON_WOL=True, FIBRE_CHANNEL=True,
+ * ISCSI=True, HVM_MAX_VNICS=8}
+ */
+ public Map<String, String> VMM = new HashMap<String, String>();
+ public Map<String, String> VMMc = new HashMap<String, String>();
+ public Map<String, String> NTP = new HashMap<String, String>();
+ public Map<String, String> DateTime = new HashMap<String, String>();
+ public Map<String, String> Generic = new HashMap<String, String>();
+ /*
+ * {OS_Major_Version=5, Statistic=20, Membership_State=Unowned,
+ * OVM_Version=3.2.1-517, OS_Type=Linux, Hypervisor_Name=Xen,
+ * CPU_Type=x86_64, Manager_Core_API_Version=3.2.1.516,
+ * Is_Current_Master=false, OS_Name=Oracle VM Server,
+ * Server_Roles=xen,utility, Pool_Unique_Id=none,
+ * Host_Kernel_Release=2.6.39-300.22.2.el5uek, OS_Minor_Version=7,
+ * Agent_Version=3.2.1-183, Boot_Time=1392366638, RPM_Version=3.2.1-183,
+ * Exports=, Hypervisor_Type=xen, Host_Kernel_Version=#1 SMP Fri Jan 4
+ * 12:40:29 PST 2013,
+ * Unique_Id=1d:d5:e8:91:d9:d0:ed:bd:81:c2:a6:9a:b3:d1:b7:ea,
+ * Manager_Unique_Id=none, Cluster_State=Offline, Hostname=ovm-1}
+ */
+ public Map<String, String> hwVMM = new HashMap<String, String>();
+ public Map<String, String> hwSystem = new HashMap<String, String>();
+ public int localTime;
+ public int lastBootTime;
+ public String timeZone;
+ public String timeUTC;
+ public List<String> _mounts = null;
+
+ // public Map<String, Map> Settings = new HashMap<String, Map>();
+
+ public Linux(Connection c) {
+ client = c;
+ }
+
+ /*
+ * discover_server, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None
+ */
+ public Boolean discoverServer() throws Exception {
+ String cmd = "discover_server";
+ Object result = callWrapper(cmd);
+ if (result == null) {
+ return false;
+ }
+
+ Document xmlDocument = prepParse((String) result);
+ /* System.out.println(result); */
+ /* could be more subtle */
+ String path = "//Discover_Server_Result/Server";
+ Capabilities = xmlToMap(path + "/Capabilities", xmlDocument);
+ VMM = xmlToMap(path + "/VMM/Version", xmlDocument);
+ VMMc = xmlToMap(path + "/VMM", xmlDocument);
+ NTP = xmlToMap(path + "/NTP", xmlDocument);
+ DateTime = xmlToMap(path + "/Date_Time", xmlDocument);
+ Generic = xmlToMap(path, xmlDocument);
+
+ // System.out.println(Get("Agent_Version"));
+
+ // System.out.println(Generic.toString());
+ return true;
+ }
+
+ public String getAgentVersion() throws ParserConfigurationException, IOException, Exception {
+ return this.Get("Agent_Version");
+ }
+ public String getHostKernelRelease() throws ParserConfigurationException, IOException, Exception {
+ return this.Get("Host_Kernel_Release");
+ }
+ public String getHostOs() throws ParserConfigurationException, IOException,
+ Exception {
+ return this.Get("OS_Name");
+ }
+ public String getHostOsVersion() throws ParserConfigurationException,
+ IOException, Exception {
+ String ver = this.Get("OS_Major_Version") + "."
+ + this.Get("OS_Minor_Version");
+ return ver;
+ }
+ public String getHypervisorName() throws ParserConfigurationException, IOException, Exception {
+ return this.Get("Hypervisor_Name");
+ }
+ public String getHypervisorVersion() throws ParserConfigurationException, IOException, Exception {
+ String ver = this.getHypervisorMajor() + "."
+ + this.getHypervisorMinor() + "." + this.getHypervisorExtra();
+ return ver;
+ }
+ public String getCapabilities() throws ParserConfigurationException,
+ IOException, Exception {
+ return this.Get("Capabilities");
+ }
+ public String getHypervisorMajor() throws ParserConfigurationException, IOException, Exception {
+ return this.Get("Major");
+ }
+ public String getHypervisorMinor() throws ParserConfigurationException, IOException, Exception {
+ return this.Get("Minor");
+ }
+ public String getHypervisorExtra() throws ParserConfigurationException,
+ IOException, Exception {
+ return this.Get("Extra").replace(".", "");
+ }
+ public String getManagerUuid() throws ParserConfigurationException, IOException, Exception {
+ return this.Get("Manager_Unique_Id");
+ }
+
+ public String getMembershipState() throws ParserConfigurationException,
+ IOException, Exception {
+ return this.Get("Membership_State");
+ }
+
+ public String getServerRoles() throws ParserConfigurationException,
+ IOException, Exception {
+ return this.Get("Server_Roles");
+ }
+ public boolean getIsMaster() throws ParserConfigurationException,
+ IOException, Exception {
+ return Boolean.parseBoolean(this.Get("Is_Current_Master"));
+ }
+ public String getOvmVersion() throws ParserConfigurationException, IOException, Exception {
+ return this.Get("OVM_Version");
+ }
+ public String getHostName() throws ParserConfigurationException, IOException, Exception {
+ return this.Get("Hostname");
+ }
+ public Integer getCpuKhz() throws NumberFormatException, ParserConfigurationException, IOException, Exception {
+ return Integer.valueOf(this.Get("CPUKHz"));
+ }
+ public Integer getCpuSockets() throws NumberFormatException, ParserConfigurationException, IOException, Exception {
+ return Integer.valueOf(this.Get("SocketsPerNode"));
+ }
+ public Integer getCpuThreads() throws NumberFormatException, ParserConfigurationException, IOException, Exception {
+ return Integer.valueOf(this.Get("ThreadsPerCore"));
+ }
+ public Integer getCpuCores() throws NumberFormatException, ParserConfigurationException, IOException, Exception {
+ return Integer.valueOf(this.Get("CoresPerSocket"));
+ }
+ public Integer getTotalThreads() throws NumberFormatException, ParserConfigurationException, IOException, Exception {
+ return this.getCpuSockets() * this.getCpuCores() * this.getCpuThreads();
+ }
+
+ public Double getMemory() throws NumberFormatException,
+ ParserConfigurationException, IOException, Exception {
+ return Double.valueOf(this.Get("TotalPages")) * 4096;
+ }
+
+ public Double getFreeMemory() throws NumberFormatException,
+ ParserConfigurationException, IOException, Exception {
+ return Double.valueOf(this.Get("FreePages")) * 4096;
+ }
+ public String getUuid() throws NumberFormatException,
+ ParserConfigurationException, IOException, Exception {
+ return this.Get("Unique_Id");
+ }
+
+ public String Get(String element) throws ParserConfigurationException, IOException, Exception {
+ if (this._init == 0) {
+ this.discoverHardware();
+ this.discoverServer();
+ this._init = 1;
+ }
+ if (Generic.containsKey(element))
+ return Generic.get(element);
+ if (VMMc.containsKey(element))
+ return VMMc.get(element);
+ if (VMM.containsKey(element))
+ return VMM.get(element);
+ if (hwVMM.containsKey(element))
+ return hwVMM.get(element);
+ if (hwSystem.containsKey(element))
+ return hwSystem.get(element);
+ if (Capabilities.containsKey(element))
+ return Capabilities.get(element);
+ return "";
+ }
+
+ /*
+ * unexport_fs, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: export_uuid - default: None
+ */
+
+ /*
+ * get_last_boot_time, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None
+ */
+ public Integer getLastBootTime() throws XmlRpcException {
+ HashMap<String, Long> result = callMap("get_last_boot_time");
+ if (result == null)
+ return null;
+ this.lastBootTime = result.get("last_boot_time").intValue();
+ this.localTime = result.get("local_time").intValue();
+ return lastBootTime;
+ }
+
+ /*
+ * delete_yum_repo, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: repo_id - default: None
+ */
+
+ /*
+ * notify_manager, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: notification - default: None argument: data -
+ * default: None
+ */
+
+ /*
+ * update_core_api_bindings, <class 'agent.api.host.linux.Linux'> argument:
+ * self - default: None argument: url - default: None argument: option -
+ * default: None
+ */
+
+ /*
+ * set_datetime, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: year - default: None argument: month - default:
+ * None argument: day - default: None argument: hour - default: None
+ * argument: min - default: None argument: sec - default: None
+ */
+ public Boolean setDateTime(int year, int month, int day, int hour, int min,
+ int sec) throws XmlRpcException {
+ Object x = callWrapper("set_datetime", year, month, day, hour, min, sec);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * list_package, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: name - default: None
+ */
+
+ /*
+ * discover_physical_luns, <class 'agent.api.host.linux.Linux'> argument:
+ * self - default: None argument: args - default: None
+ */
+ public String discoverPhysicalLuns() throws XmlRpcException {
+ String x = (String) callWrapper("discover_physical_luns", "");
+ return x;
+ }
+
+ /*
+ * ovs_download_file, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: url - default: None argument: filename - default:
+ * None argument: option - default: None argument: obj - default: None
+ * argument: obj_current - default: None argument: obj_total - default: None
+ * argument: update_period - default: None
+ */
+
+ /*
+ * install_package, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: pkg_data - default: None argument: option -
+ * default: None
+ */
+
+ /*
+ * get_support_files, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None
+ */
+
+ /*
+ * export_fs, <class 'agent.api.host.linux.Linux'> argument: self - default:
+ * None argument: export_uuid - default: None argument: export_type -
+ * default: None argument: client - default: None argument: path - default:
+ * None argument: options - default: None
+ */
+
+ /*
+ * ovs_async_proc_status, <class 'agent.api.host.linux.Linux'> argument:
+ * self - default: None argument: pid - default: None
+ */
+
+ /*
+ * set_timezone, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: timezone - default: None argument: utc - default:
+ * None
+ */
+ public Boolean setTimeZone(String tz, Boolean utc) throws XmlRpcException {
+ Object x = callWrapper("set_timezone", tz, utc);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * copy_file, <class 'agent.api.host.linux.Linux'> argument: self - default:
+ * None argument: src - default: None argument: dst - default: None
+ * argument: sparse - default: None argument: update_period - default: None
+ */
+ public Boolean copyFile(String src, String dst) throws XmlRpcException {
+ Object x = callWrapper("copy_file", src, dst, false);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ public Boolean copyFile(String src, String dst, Boolean sparse)
+ throws XmlRpcException {
+ Object x = callWrapper("copy_file", src, dst, sparse);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * discover_mounted_file_systems, <class 'agent.api.host.linux.Linux'>
+ * argument: self - default: None argument: args - default: None
+ */
+ /*
+ * <Discover_Mounted_File_Systems_Result> <Filesystem Type="nfs"> <Mount
+ * Dir="/nfsmnt/e080e318-91c2-47e5-a5ab-f3ab53790162">
+ * <Device>cs-mgmt:/volumes/cs-data/secondary/</Device>
+ * <Mount_Options>rw,relatime
+ * ,vers=3,rsize=524288,wsize=524288,namlen=255,hard
+ * ,proto=tcp,port=65535,timeo
+ * =600,retrans=2,sec=sys,local_lock=none,addr=192.168.1.61</Mount_Options>
+ * </Mount> </Filesystem> ... </Discover_Mounted_File_Systems_Result>
+ */
+
+ public Boolean discoverMountedFs() throws XmlRpcException {
+ Object x = callWrapper("discover_mounted_file_systems");
+ // System.out.println(x);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /* Filesystem bits and bobs */
+ private Map<String, FileSystem> fsList = null;
+
+ public Map<String, FileSystem> getFileSystemList(String type)
+ throws ParserConfigurationException, IOException, Exception {
+ if (fsList == null)
+ this.discoverMountedFs(type);
+
+ return fsList;
+ }
+
+ public void setFileSystemList(Map<String, FileSystem> list) {
+ fsList = list;
+ }
+ public class FileSystem {
+ public Map<String, Object> _fs = new HashMap<String, Object>() {
+ {
+ put("Mount_Options", null);
+ put("Name", null);
+ put("Device", null);
+ put("Host", null);
+ put("Dir", null);
+ put("Mount_Point", null);
+ put("Uuid", null);
+ }
+ };
+
+ public String getUuid() {
+ return (String) _fs.get("Uuid");
+ }
+
+ public String setUuid(String uuid) {
+ return (String) _fs.put("Uuid", uuid);
+ }
+ public String getName() {
+ return (String) _fs.get("Name");
+ }
+
+ public String setName(String name) {
+ return (String) _fs.put("Name", name);
+ }
+
+ public String getDevice() {
+ return (String) _fs.get("Device");
+ }
+
+ public String setDevice(String dev) {
+ return (String) _fs.put("Device", dev);
+ }
+
+ public String getHost() {
+ if (getDevice() != null && getDevice().contains(":")) {
+ String spl[] = getDevice().split(":");
+ setHost(spl[0]);
+ setMountPoint(spl[1]);
+ } else {
+ return null;
+ }
+ return (String) _fs.get("Host");
+ }
+
+ public String setHost(String host) {
+ return (String) _fs.put("Host", host);
+ }
+
+ public String getDir() {
+ return (String) _fs.get("Dir");
+ }
+
+ public String setDir(String dir) {
+ return (String) _fs.put("Dir", dir);
+ }
+
+ public String getMountPoint() {
+ if (getHost() != null) {
+ return (String) _fs.get("Mount_Point");
+ }
+ return null;
+ }
+ public String setMountPoint(String pnt) {
+ return (String) _fs.put("Mount_Point", pnt);
+ }
+ };
+
+ /* should actually be called "getMountedsFsDevice" or something */
+ public Map<String, FileSystem> discoverMountedFs(String type)
+ throws ParserConfigurationException, IOException, Exception {
+ // if (postDiscovery == null) {
+ // postDiscovery = callWrapper("discover_network");
+ this.fsList = new HashMap<String, FileSystem>();
+ //}
+ Object x = callWrapper("discover_mounted_file_systems", type);
+ Document xmlDocument = prepParse((String) x);
+ // List<String> list = new ArrayList<String>();
+ String bpath = "//Discover_Mounted_File_Systems_Result/Filesystem";
+ String mpath = bpath + "/Mount/@Dir";
+ _mounts = xmlToList(mpath, xmlDocument);
+ for (String mnt : _mounts) {
+ String dpath = bpath + "/Mount[@Dir='" + mnt + "']";
+ Map<String, Object> fs = xmlToMap(dpath, xmlDocument);
+ FileSystem f = new FileSystem();
+ f._fs = fs;
+ String[] spl = mnt.split("/");
+ String uuid = spl[spl.length - 1];
+ // System.out.println(uuid + " " + mnt);
+ f.setUuid(uuid);
+ f.setDir(mnt);
+ fsList.put(uuid, f);
+ }
+ setFileSystemList(fsList);
+ if (x == null) {
+ return this.fsList;
+ }
+
+ return this.fsList;
+ }
+
+ /*
+ * ovs_async_proc, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: func - default: None
+ */
+
+ /*
+ * get_log, <class 'agent.api.host.linux.Linux'> argument: self - default:
+ * None argument: loglist - default: None
+ */
+
+ /*
+ * update_agent_password, <class 'agent.api.host.linux.Linux'> argument:
+ * self - default: None argument: username - default: None argument:
+ * password - default: None
+ */
+ public Boolean updateAgentPassword(String user, String pass)
+ throws XmlRpcException {
+ Object x = callWrapper("update_agent_password", user, pass);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * yum_update, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: option - default: None
+ */
+
+ /*
+ * discover_hardware, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None
+ */
+ public Boolean discoverHardware()
+ throws ParserConfigurationException, IOException, Exception {
+ Object result = callWrapper("discover_hardware");
+
+ Document xmlDocument = prepParse((String) result);
+ /* could be more subtle */
+ String path = "//Discover_Hardware_Result/NodeInformation";
+ hwVMM = xmlToMap(path + "/VMM/PhysicalInfo", xmlDocument);
+ hwSystem = xmlToMap(path + "/DMTF/System", xmlDocument);
+
+ if (result == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * uninstall_package, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: pkg_list - default: None argument: option -
+ * default: None
+ */
+
+ /*
+ * get_datetime, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None
+ */
+ public Integer getDateTime() throws XmlRpcException {
+ this.getLastBootTime();
+ return this.localTime;
+ }
+
+ /*
+ * configure_yum, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: section - default: None argument: params -
+ * default: None
+ */
+
+ /*
+ * get_yum_config, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None
+ */
+ public Boolean getYumConfig() throws XmlRpcException {
+ Object x = callWrapper("get_yum_config");
+ // System.out.println(x);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_async_proc_stop, <class 'agent.api.host.linux.Linux'> argument: self
+ * - default: None argument: pid - default: None
+ */
+
+ /*
+ * set_statistic_interval, <class 'agent.api.host.linux.Linux'> argument:
+ * interval - default: None
+ */
+ public Boolean setStatisticsInterval(int val) throws XmlRpcException {
+ Object x = callWrapper("set_statistics_interval", val);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * yum_list_package, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None argument: pkgnarrow - default: None argument: patterns -
+ * default: None argument: showdups - default: None argument: ignore_case -
+ * default: None
+ */
+
+ /*
+ * get_timezone, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None
+ */
+ public Boolean getTimeZone() throws XmlRpcException {
+ Object[] result = (Object[]) callWrapper("get_timezone");
+ if (result != null) {
+ this.timeZone = result[0].toString();
+ this.timeUTC = result[1].toString();
+ return true;
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1516b041/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Network.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Network.java b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Network.java
new file mode 100644
index 0000000..0ae9d84
--- /dev/null
+++ b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Network.java
@@ -0,0 +1,628 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.cloud.hypervisor.ovm3.object;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+// import java.util.Map;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.w3c.dom.Document;
+// import java.util.HashMap;
+
+/*
+ * should become an interface implementation
+ */
+public class Network extends OvmObject {
+
+ public Network(Connection c) {
+ client = c;
+ }
+
+ private Map<String, Interface> interfaceList = null;
+
+ public Map<String, Interface> getInterfaceList()
+ throws ParserConfigurationException, IOException, Exception {
+ try {
+ this.discoverNetwork();
+ } catch (Exception e) {
+ throw new Exception(e.getMessage());
+ }
+ return interfaceList;
+ }
+
+ public void setBridgeList(Map<String, Interface> list) {
+ interfaceList = list;
+ }
+
+ public class Interface {
+ private Map<String, String> _interface = new HashMap<String, String>() {
+ {
+ put("Type", null);
+ put("Physical", null);
+ put("Name", null);
+ put("Address", null);
+ put("Broadcast", null);
+ put("MAC", null);
+ put("Vlan", null);
+ }
+ };
+
+ public void setIfType(String t) {
+ this._interface.put("Type", t);
+ }
+ public String getIfType() {
+ return this._interface.get("Type");
+ }
+ public void setInterface(Map<String, String> itf) {
+ this._interface.putAll(itf);
+ }
+
+ public String getName() {
+ return _interface.get("Name");
+ }
+
+ public String getPhysical() {
+ return _interface.get("Physical");
+ }
+
+ public String getAddress() {
+ return _interface.get("Address");
+ }
+
+ public String getBroadcast() {
+ return _interface.get("Broadcast");
+ }
+
+ public String getMac() {
+ return _interface.get("MAC");
+ }
+
+ public String setName(String name) {
+ return _interface.put("Name", name);
+ }
+
+ public String setPhysical(String ph) {
+ return _interface.put("Physical", ph);
+ }
+ public String setAddress(String addr) {
+ return _interface.put("Address", addr);
+ }
+
+ public String setBroadcast(String bcast) {
+ return _interface.put("Broadcast", bcast);
+ }
+
+ public String setMac(String mac) {
+ return _interface.put("MAC", mac);
+ }
+ }
+
+ private Network.Interface _getInterface(String key, String val)
+ throws ParserConfigurationException, IOException, Exception {
+ HashMap<String, Network.Interface> ifaces = new HashMap<String, Network.Interface>();
+ ifaces = (HashMap<String, Interface>) this.getInterfaceList();
+ for (final Entry<String, Interface> iface : ifaces.entrySet()) {
+ String match = "default";
+ if (key.equals("Address"))
+ match = iface.getValue().getAddress();
+ if (key.equals("Name"))
+ match = iface.getKey();
+ // .getName();
+ if (match != null && match.equals(val))
+ return iface.getValue();
+ }
+ return null;
+ }
+
+ public Network.Interface getInterfaceByIp(String ip)
+ throws ParserConfigurationException, IOException, Exception {
+ return _getInterface("Address", ip);
+ }
+
+ public Network.Interface getInterfaceByName(String name)
+ throws ParserConfigurationException, IOException, Exception {
+ return _getInterface("Name", name);
+ }
+ /* check if it is a BRIDGE */
+ public String getPhysicalByBridgeName(String name)
+ throws ParserConfigurationException, IOException, Exception {
+ return getInterfaceByName(name).getPhysical();
+ }
+
+ public Network.Interface getBridgeByName(String name)
+ throws ParserConfigurationException, IOException, Exception {
+ if (_getInterface("Name", name).getIfType().contentEquals("Bridge")) {
+ return _getInterface("Name", name);
+ }
+ return null;
+ }
+ public Network.Interface getBridgeByIp(String ip)
+ throws ParserConfigurationException, IOException, Exception {
+ if (_getInterface("Address", ip).getIfType().contentEquals("Bridge")) {
+ return _getInterface("Address", ip);
+ }
+ return null;
+ }
+ private Object postDiscovery = null;
+
+ private List<String> netInterfaces = new ArrayList<String>();
+
+ /*
+ * ovs_bond_mode, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ Change Bond mode.
+
+ @param bond One of the logical channel bonds (bond0, bond1 ...etc)
+ @mode Current supported bonding modes (1 = active-backup, 4 = 802.3ad
+ 6 = balance-alb).
+ @return If successful, returns bond's names and its new mode
+ Raises an exception on failure
+ Restriction:
+ -bond must be one of the logical channel bonds (bond0, bond1 ...etc)
+
+ */
+ public Boolean ovsBondMode(String bond, String mode) throws XmlRpcException {
+ Object x = callWrapper("ovs_bond_mode", bond, mode);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_change_mtu, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ Changes MTU on a physical,vlan,bond,and bridge interface.
+ Changing a bond MTU will also change the MTU of its slaves.
+ Changing the MTU of an interface that is part of a bridge,
+ will cause the bridge MTU and all of the interfaces change.
+ When a Guest VIF attach to a bridge,the VIF MTU will be set
+ to the bridge MTU
+
+
+ @param interface Physical,bond,vlan, and a bridge
+ @param MTU Values are 1500 to 64000
+
+ @return If successful, returns the interface, and the new MTU
+ Raises an exception on failure
+
+ Restriction:
+ -Can not change the MTU of a bridge without interfaces.
+ -VLAN MTU must less or equal to the MTU of the underlying
+ physical interface.
+ */
+ public Boolean ovsChangeMtu(String net, int mtu) throws XmlRpcException {
+ Object x = callWrapper("ovs_change_mtu", net, mtu);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_async_bridge, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ * argument: self - default: None argument: action - default: None argument:
+ * br_name - default: None argument: net_dev - default: None
+ */
+ public Boolean ovsAsyncBridge(String action, String bridge, String netdev)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_async_bridge", action, bridge, netdev);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_bond_op, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ * argument: self - default: None argument: action - default: None argument:
+ * bond - default: None argument: backup - default: None
+ */
+ public Boolean ovsBondOp(String action, String bond, String backup)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_bond_op", action, bond, backup);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * configure_virtual_ip, <class
+ * 'agent.api.network.linux_network.LinuxNetwork'> argument: self - default:
+ * None argument: virtual_ip - default: None argument: base_ip - default:
+ * None
+ */
+ public Boolean configureVip(String vip, String baseip)
+ throws XmlRpcException {
+ Object x = callWrapper("configure_virtual_ip", vip, baseip);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_ip_config, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ Assigns/flushes IP, netmask address to a physical,VLAN, and bond interfaces.
+
+ @param interface The interface on which to assign
+ @param optype (static|dynamic|flush)
+ static: Assigns the given IP, and netmask to the interface, and
+ saves the config file to /etc/sysconfig/network-scripts.
+ dynamic: Flushes current address, and creats and save the config
+ file to /etc/sysconfig/network-scripts, (BOOTPROTO=dhcp)
+ flush: flushes the interface address,routes, removes the current
+ config file from /etc/sysconfig/network-scripts.
+ Creats a new one with BOOTPROTO=static
+
+ @args Required for the static option, otherwise it is ignored
+ IP address: IPv4 address in decimal notation (101.230.112)
+ netmask: Standard netmask in a decimal notation,NOT CIDR.
+ example(255.255.255.0)
+
+ @return If successful, returns the interface, and addresses added/flushed
+ Raises an exception on failure
+
+ Restriction:
+ -Interface must be physical, VLAN, or a Bond
+ -Interface must not be a bridge port, or slave to a bond
+ -Addresses must be valid in a decimal notation
+
+ */
+ public Boolean ovsIpConfig(String net, String optype, String ip,
+ String netmask)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_ip_config", net, optype, ip, netmask);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_if_meta, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ This function creates meta data file meta-interface, and write the string
+ (METADATA=data) to it. This string is used by the manager to identify
+ networks that interfaces belong to. Dom0 does not make used of this string,
+ it just saves it and returns it during running, saved network discovery.
+
+ - If an interface already has a meta data string, then it gets
+ replace by the new one
+ - An empty meta data string, indicates to remove the existing string
+ (remove the meta-interface) file
+
+ @param interface physical,VLAN, bond ...etc interfaces
+ @param data meta data to save
+
+ @return If successful, returns the interface, and meta data
+ Raises an exception on failure
+
+ Restriction:
+ - data string that starts with leading spaces will be rejected
+ * ovs_if_meta('bond0',
+ * 'ethernet:c0a80100{192.168.1.0}:MANAGEMENT,CLUSTER_HEARTBEAT,LIVE_MIGRATE,VIRTUAL_MACHINE,STORAGE')
+ */
+ public Boolean ovsIfMeta(String net, String data) throws XmlRpcException {
+ Object x = callWrapper("ovs_if_meta", net, data);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+
+ /*
+ * ovs_bond_config, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ * argument: self - default: None argument: action - default: None argument:
+ * bond - default: None
+ */
+ public Boolean ovsBondConfig(String action, String bond)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_bond_config", action, bond);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * discover_network, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ Discover information about the current network configuration.
+ This includes the state of physical NICs, bonds, and bridges. Also return
+ information stored for this server that is needed to configure
+ the network when the OVM Manager is not available.
+
+ Discovery of the current network configuration is handled by invoking
+ a python extension that calls legacy C code from the VI agent.
+
+ @param None
+
+ @return Returns the discovery data as an XML document.
+ Raises an exception on failure.
+ * <?xml version="1.0" ?> <Discover_Network_Result>
+ * <Network><Active><Network> <Device Name="eth0">
+ * <MAC>52:54:00:24:47:70</MAC> <Flags>(0x1843) IFF_UP IFF_BROADCAST
+ * IFF_RUNNING IFF_SLAVE IFF_MULTICAST</Flags> <ETHTOOL> <Autonegotiate>
+ * <State>Complete</State> <Speed>1000baseT-FD</Speed> </Autonegotiate>
+ * <Link>ok</Link> <Capabilities>10baseT-HD 10baseT-FD 100baseT-HD
+ * 100baseT-FD 1000baseT-FD</Capabilities> <Advertising>10baseT-HD
+ * 10baseT-FD 100baseT-HD 100baseT-FD 1000baseT-FD</Advertising> </ETHTOOL>
+ * <WOL> <WakeOnLan>disabled</WakeOnLan> </WOL> <SysFS>
+ * <uevent>INTERFACE=eth0 IFINDEX=2</uevent>
+ * <addr_assign_type>0</addr_assign_type> <addr_len>6</addr_len>
+ * <dev_id>0x0</dev_id> <ifalias/> <iflink>2</iflink> <ifindex>2</ifindex>
+ * <features>0x40014ba9</features> <type>1</type> <link_mode>0</link_mode>
+ * <carrier>1</carrier> <speed>1000</speed> <duplex>full</duplex>
+ * <dormant>0</dormant> <operstate>up</operstate> <mtu>1500</mtu>
+ * <flags>0x1903</flags> <tx_queue_len>1000</tx_queue_len>
+ * <netdev_group>0</netdev_group> <SysFSDev> <vendor>0x8086</vendor>
+ * <device>0x100e</device> <subsystem_vendor>0x1af4</subsystem_vendor>
+ * <subsystem_device>0x1100</subsystem_device> <class>0x020000</class>
+ * </SysFSDev> </SysFS> <BootProto>none</BootProto> </Device> ....
+ * </Network> <Bonding> <Device Name="bond0">
+ * <Bonding_Mode>active-backup</Bonding_Mode> <Primary_Slave>eth0
+ * (primary_reselect always)</Primary_Slave>
+ * <Currently_Active_Slave>eth0</Currently_Active_Slave>
+ * <MII_Status>up</MII_Status>
+ * <MII_Polling_Interval>250</MII_Polling_Interval> <Up_Delay>500</Up_Delay>
+ * <Down_Delay>500</Down_Delay> <Slave_Interface Name="eth0">
+ * <MII_Status>up</MII_Status> <Speed>1000 Mbps</Speed>
+ * <Duplex>full</Duplex> <Link_Failure_Count>0</Link_Failure_Count>
+ * <Permanent_HW_addr>52:54:00:24:47:70</Permanent_HW_addr>
+ * </Slave_Interface> <Family Type="AF_INET"> <MAC>52:54:00:24:47:70</MAC>
+ * <mtu>1500</mtu> </Family> <BootProto>none</BootProto>
+ * <MetaData>ethernet:c0a80100
+ * {192.168.1.0}:MANAGEMENT,CLUSTER_HEARTBEAT,LIVE_MIGRATE
+ * ,VIRTUAL_MACHINE,STORAGE</MetaData> </Device> </Bonding> <Bridges>
+ * <Device Name="c0a80100"> <Family Type="AF_INET">
+ * <MAC>52:54:00:24:47:70</MAC> <Address>192.168.1.64</Address>
+ * <Netmask>255.255.255.0</Netmask> <Broadcast>192.168.1.255</Broadcast>
+ * </Family> <Interfaces> <PhyInterface>bond0</PhyInterface> </Interfaces>
+ * <BootProto>static</BootProto></Device> </Bridges> <Infiniband>
+ * </Infiniband> </Active></Network></Discover_Network_Result>
+ */
+ /* put more in when required, for now ok */
+ public Boolean discoverNetwork() throws ParserConfigurationException,
+ IOException, Exception {
+ // if (postDiscovery == null) {
+ postDiscovery = callWrapper("discover_network");
+ this.interfaceList = new HashMap<String, Interface>();
+ // }
+ // System.out.println(postDiscovery);
+ Document xmlDocument = prepParse((String) postDiscovery);
+ String path = "//Discover_Network_Result/Network/Active";
+ String bpath = path + "/Bridges/Device";
+
+ netInterfaces = new ArrayList<String>();
+ netInterfaces.addAll(xmlToList(bpath + "/@Name",
+ xmlDocument));
+ for (String b : netInterfaces) {
+ Map<String, String> br = xmlToMap(bpath + "[@Name='" + b
+ + "']/Family", xmlDocument);
+ /* vifs are here too */
+ String phyInt = (String) this.xmlToMap(bpath + "[@Name='" + b
+ + "']/Interfaces", xmlDocument).get("PhyInterface");
+ Interface iface = new Interface();
+ iface.setInterface(br);
+ iface.setName(b);
+ iface.setIfType("Bridge");
+ if (phyInt == null) {
+ iface.setIfType("Local");
+ }
+ iface.setPhysical(phyInt);
+ interfaceList.put(b, iface);
+ }
+ /* add "physical" interfaces */
+ bpath = path + "/Network/Device";
+ netInterfaces = new ArrayList<String>();
+ netInterfaces.addAll(xmlToList(bpath + "/@Name", xmlDocument));
+ for (String p : netInterfaces) {
+ Map<String, String> nf = xmlToMap("//Device[@Name='" + p
+ + "']", xmlDocument);
+ Interface iface = new Interface();
+ iface.setPhysical(nf.get("Basename"));
+ iface.setName(p);
+ iface.setMac(nf.get("MAC"));
+ iface.setIfType("Physical");
+ interfaceList.put(p, iface);
+ }
+ /* add virtual interfaces ? */
+ if (postDiscovery == null)
+ return false;
+
+ return true;
+ }
+
+ /*
+ * ovs_local_config, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ Configure a Local Bridge ((NIC-less bridge)
+
+ @param action (start | stop)
+ start: Creates local bridge without a physical interface, and saves bridge config
+ file in /etc/sysconfig/network-scripts
+ stop: Deletes local bridge, removes bridge config file from
+ /etc/sysconfig/network-scripts
+
+ @param br_name The bridge name to add
+
+ @return If successful, returns the name of the bridge
+ Raises an exception on failure
+
+ */
+ public Boolean startOvsLocalConfig(String br)
+ throws XmlRpcException {
+ return ovsLocalConfig("start", br);
+ }
+
+ public Boolean stopOvsLocalConfig(String br)
+ throws XmlRpcException {
+ return ovsLocalConfig("stop", br);
+ }
+
+ public Boolean ovsLocalConfig(String action, String br)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_local_config", action, br);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_vlan_config, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ Creates a VLAN interface on a physical, or a bond interface.
+
+ @param action (add|remove)
+ add: Creates a VLAN on an interface,saves the VLAN config file in
+ /etc/sysconfig/network-scripts
+ remove: Removes a VLAN from an interfacei,removes its config file from
+ /etc/sysconfig/network-scripts
+
+ @param interface The interface on which to create a VLAN
+ @param vlanid VLAN ID (2-4095)
+
+ @return If successful, returns the interface, and VLAN created
+ Raises an exception on failure
+
+ Restriction:
+ -Interface must be physical, or bond
+ -Interface must not be member of a bridge, or slave to a bond
+ -VLAN ID must not exist on the same interface
+
+ */
+ public Boolean startOvsVlanConfig(String dev, int vlan)
+ throws XmlRpcException {
+ return ovsVlanConfig("add", dev, vlan);
+ }
+
+ public Boolean stopOvsVlanConfig(String dev, int vlan)
+ throws XmlRpcException {
+ return ovsVlanConfig("del", dev, vlan);
+ }
+ public Boolean ovsVlanConfig(String action, String net, int vlan)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_vlan_config", action, net, vlan);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_br_config, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ Configure a Standard Bridge.
+
+ @param action (start | stop)
+ start: Creates the bridge, Copies the IP and MAC addresses from netdev to bridge,
+ enslaves net_dev to bridge, and saves bridge config files in
+ /etc/sysconfig/network-scripts
+ stop: Removes net_dev from the bridge,transfers addresses, routes from bridge to
+ net_dev, deletes the bridge, and revomes bridge config files from
+ /etc/sysconfig/network-scripts
+
+ @param br_name The bridge name to add
+ @param net_dev The physical interface to add to the bridge
+
+ @return If successful, returns the names of the bridge and it's physical interface.
+ Raises an exception on failure
+ Restriction:
+ -net_dev must be physical, or bond
+ -net_dev must not be member of a bridge, or slave to a bond
+ */
+ public Boolean startOvsBrConfig(String br, String dev)
+ throws XmlRpcException {
+ return ovsBrConfig("start", br, dev);
+ }
+
+ public Boolean stopOvsBrConfig(String br, String dev)
+ throws XmlRpcException {
+ return ovsBrConfig("stop", br, dev);
+ }
+
+ public Boolean ovsBrConfig(String action, String br, String net)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_br_config", action, br, net);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_vlan_bridge, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ @param action (start | stop)
+ start: Creates the bridge, creats VLAN on net_dev,enslaves
+ the VLAN to the bridge, and saves VLAN bridge config
+ files in /etc/sysconfig/network-scripts
+ stop: Removes the VLAN from the bridge, removes the VLAN,
+ deletes the bridge, and removes VLAN bridge config files
+ from /etc/sysconfig/network-scripts
+
+ @param br_name The bridge name to add
+ @param net_dev The physical interface on which to create a VLAN.
+ @param vlan_id VLAN ID (1-4095). VLAN ID of 1 is the untagged VLAN.
+
+ @return If successful, returns the names of the bridge and it's VLAN interface
+ Raises an exception on failure
+ */
+ public Boolean stopOvsVlanBridge(String br, String net, int vlan) throws XmlRpcException {
+ return ovsVlanBridge("stop", br, net, vlan);
+ }
+
+ public Boolean startOvsVlanBridge(String br, String net, int vlan) throws XmlRpcException {
+ return ovsVlanBridge("start", br, net, vlan);
+ }
+
+ public Boolean ovsVlanBridge(String action, String br, String net, int vlan)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_vlan_bridge", action, br, net, vlan);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * deconfigure_virtual_ip, <class
+ * 'agent.api.network.linux_network.LinuxNetwork'> argument: self - default:
+ * None argument: virtual_ip - default: None
+ */
+ public Boolean deconfigureVip(String vip) throws XmlRpcException {
+ Object x = callWrapper("deconfigure_virtual_ip", vip);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+
+ /*
+ * ovs_async_bond, <class 'agent.api.network.linux_network.LinuxNetwork'>
+ * argument: self - default: None argument: action - default: None argument:
+ * bond - default: None
+ */
+ public Boolean ovsAsyncBond(String action, String bond)
+ throws XmlRpcException {
+ Object x = callWrapper("ovs_async_bond", action, bond);
+ if (x == null)
+ return true;
+
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1516b041/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Ntp.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Ntp.java b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Ntp.java
new file mode 100644
index 0000000..96b1b4e
--- /dev/null
+++ b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/Ntp.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.cloud.hypervisor.ovm3.object;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.xmlrpc.XmlRpcException;
+
+/*
+ * should become an interface implementation
+ */
+public class Ntp extends OvmObject {
+ private List<String> Servers = new ArrayList<String>();
+ private Boolean isServer = null;
+ private Boolean isRunning = null;
+
+ public Ntp(Connection c) {
+ client = c;
+ }
+
+ public List<String> addServer(String server) {
+ if (Servers.contains(server) == false)
+ Servers.add(server);
+
+ return Servers;
+ }
+
+ public List<String> removeServer(String server) {
+ if (Servers.contains(server))
+ Servers.remove(server);
+
+ return Servers;
+ }
+
+ public List<String> servers() {
+ return Servers;
+ }
+
+ public Boolean isRunning() {
+ return isRunning;
+ }
+
+ public Boolean isServer() {
+ return isServer;
+ }
+
+ public Boolean getDetails() throws XmlRpcException {
+ return this.getNtp();
+ }
+
+ /*
+ * get_ntp, <class 'agent.api.host.linux.Linux'> argument: self - default:
+ * None
+ */
+ public Boolean getNtp() throws XmlRpcException {
+ Object[] v = (Object[]) callWrapper("get_ntp");
+ int c = 0;
+ for (Object o : v) {
+ // System.out.println(o.getClass());
+ if (o instanceof java.lang.Boolean) {
+ if (c == 0)
+ this.isServer = (Boolean) o;
+
+ if (c == 1)
+ this.isRunning = (Boolean) o;
+
+ // should not get here
+ if (c > 1)
+ return false;
+
+ c += 1;
+ } else if (o instanceof java.lang.Object) {
+ Object[] S = (Object[]) o;
+ for (Object m : S) {
+ this.addServer((String) m);
+ }
+ }
+ }
+ return true;
+ }
+
+ /*
+ * set_ntp, <class 'agent.api.host.linux.Linux'> argument: self - default:
+ * None argument: servers - default: None argument: local_time_source -
+ * default: None argument: allow_query - default: None // right, can't be
+ * set eh
+ */
+ public Boolean setNtp(List<String> servers, Boolean running)
+ throws XmlRpcException {
+ if (callWrapper("set_ntp", servers, running) == null) {
+ return this.getNtp();
+ } else {
+ return false;
+ }
+ }
+
+ /* also cleans the vector */
+ public Boolean setNtp(String server, Boolean running)
+ throws XmlRpcException {
+ this.Servers = new ArrayList<String>();
+ this.Servers.add(server);
+ return setNtp(this.Servers, running);
+ }
+
+ public Boolean setNtp(Boolean running) throws XmlRpcException {
+ return setNtp(this.Servers, running);
+ }
+
+ /*
+ * disable_ntp, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None
+ */
+ public Boolean disableNtp() throws XmlRpcException {
+ if (callWrapper("disable_ntp") == null)
+ return true;
+ return false;
+ }
+
+ /*
+ * enable_ntp, <class 'agent.api.host.linux.Linux'> argument: self -
+ * default: None
+ */
+ public Boolean enableNtp() throws XmlRpcException {
+ if (callWrapper("enable_ntp") == null)
+ return true;
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1516b041/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/OvmObject.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/OvmObject.java b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/OvmObject.java
new file mode 100644
index 0000000..4dba83c
--- /dev/null
+++ b/plugins/hypervisors/ovm3/src/com/cloud/hypervisor/ovm3/object/OvmObject.java
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.cloud.hypervisor.ovm3.object;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.Vector;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+public class OvmObject {
+ public static Connection client = null;
+ public static Vector<?> emptyParams = new Vector<Object>();
+
+ /* remove dashes from uuids */
+ public String deDash(String str) {
+ final String x = str.replaceAll("-", "");
+ return x;
+ }
+
+ /* generate a uuid */
+ public String newUuid() {
+ final String uuid = UUID.randomUUID().toString();
+ return uuid;
+ }
+
+ /* generate a uuid */
+ public String newUuid(String str) {
+ final String uuid = UUID.nameUUIDFromBytes(str.getBytes()).toString();
+ return uuid;
+ }
+
+ /* capture most of the calls here */
+ public static Object callWrapper(String call) throws XmlRpcException {
+ try {
+ Object res = client.call(call, emptyParams);
+ return res;
+ } catch (XmlRpcException e) {
+ throw new XmlRpcException(e.getMessage());
+ }
+ }
+
+ /* nice try but doesn't work like that .. */
+ @SafeVarargs
+ public static <T> Object callWrapper(String call, T... args)
+ throws XmlRpcException {
+ Vector<T> params = new Vector<T>();
+ for (T param : args) {
+ params.add(param);
+ }
+ // return
+ Object res = client.call(call, params);
+ return res;
+ }
+
+ /* returns a single string */
+ public HashMap<String, Long> callMap(String call) throws XmlRpcException {
+ HashMap<String, Long> result = (HashMap<String, Long>) callWrapper(call);
+ return result;
+ }
+
+ public <T> String callString(String call, T... args) throws XmlRpcException {
+ Object result = callWrapper(call, args);
+ if (result == null) {
+ return null;
+ }
+ if (result instanceof String)
+ return result.toString();
+ if (result instanceof Integer)
+ return result.toString();
+ if (result instanceof Long)
+ return result.toString();
+ if (result instanceof HashMap)
+ return result.toString();
+
+ Object[] results = (Object[]) result;
+
+ if (results.length == 0)
+ // return results[0].toString();
+ return null;
+
+ if (results.length == 1)
+ return results[0].toString();
+
+ return null;
+ }
+
+ /* was String, Object before */
+ public <E> Map<String, E> xmlToMap(String path, Document xmlDocument)
+ throws XPathExpressionException {
+ XPathFactory factory = javax.xml.xpath.XPathFactory.newInstance();
+ XPath xPath = factory.newXPath();
+ // capabilities, date_time etc
+ XPathExpression xPathExpression = xPath.compile(path);
+ NodeList nodeList = (NodeList) xPathExpression.evaluate(xmlDocument,
+ XPathConstants.NODESET);
+
+ Map<String, E> myMap = new HashMap<String, E>();
+ for (int ind = 0; ind < nodeList.getLength(); ind++) {
+ NodeList nodeListFor = nodeList.item(ind).getChildNodes();
+ for (int index = 0; index < nodeListFor.getLength(); index++) {
+ String rnode = nodeListFor.item(index).getNodeName();
+ NodeList nodeListFor2 = nodeListFor.item(index).getChildNodes();
+ if (nodeListFor2.getLength() > 1) {
+ // System.out.println("multiball");
+ /*
+ * for (int i = 0; i < nodeListFor2.getLength(); i++) {
+ * String node = nodeListFor2.item(i).getNodeName(); String
+ * element = nodeListFor2.item(i).getTextContent();
+ * System.out.println("rnode: " + rnode + " -> node " + node
+ * + " ---> " + element); myMap.put(node, element); }
+ */
+ } else {
+ String element = nodeListFor.item(index).getTextContent();
+ // System.out.println("rnode " + rnode + " ---> " +
+ // element);
+ myMap.put(rnode, (E) element);
+ }
+ }
+ }
+ return myMap;
+ }
+
+ public List<String> xmlToList(String path, Document xmlDocument)
+ throws XPathExpressionException {
+ List<String> list = new ArrayList<String>();
+ XPathFactory factory = javax.xml.xpath.XPathFactory.newInstance();
+ XPath xPath = factory.newXPath();
+
+ XPathExpression xPathExpression = xPath.compile(path);
+ NodeList nodeList = (NodeList) xPathExpression.evaluate(xmlDocument,
+ XPathConstants.NODESET);
+
+ for (int ind = 0; ind < nodeList.getLength(); ind++) {
+ // System.out.println(nodeList.item(ind).getTextContent());
+ if (!nodeList.item(ind).getTextContent().isEmpty()) {
+ list.add("" + nodeList.item(ind).getTextContent());
+ } else {
+ list.add("" + nodeList.item(ind).getNodeValue());
+ }
+ }
+ return list;
+ }
+
+ public String xmlToString(String path, Document xmlDocument)
+ throws XPathExpressionException {
+
+ XPathFactory factory = javax.xml.xpath.XPathFactory.newInstance();
+ XPath xPath = factory.newXPath();
+
+ XPathExpression xPathExpression = xPath.compile(path);
+ NodeList nodeList = (NodeList) xPathExpression.evaluate(xmlDocument,
+ XPathConstants.NODESET);
+ // put a try in here too, so we can get the subbies
+ String x = nodeList.item(0).getTextContent();
+ return x;
+ }
+
+ public Document prepParse(String input)
+ throws ParserConfigurationException, Exception, IOException {
+ DocumentBuilderFactory builderfactory = DocumentBuilderFactory
+ .newInstance();
+ builderfactory.setNamespaceAware(true);
+
+ DocumentBuilder builder = builderfactory.newDocumentBuilder();
+ Document xmlDocument = builder.parse(new InputSource(new StringReader(
+ (String) input)));
+ return xmlDocument;
+ }
+ /*
+ * returns a list of strings public <T> ArrayList<String> call(String call,
+ * T... args) throws XmlRpcException { ArrayList<String> data = new
+ * ArrayList<String>(); Object[] result = (Object[]) callWrapper(call,
+ * args);
+ *
+ * if (result[result.length] != null) return null;
+ *
+ * for(Object x : result) { data.add(x.toString()); } return data; }
+ */
+}