# HG changeset patch
# User Guolian Yun <yunguol(a)cn.ibm.com>
# Date 1225865149 28800
# Node ID 79b321ebebfda4cde38ecb4fe0ea7bd9e4f51539
# Parent 319e2e9509d360334c0e38e17abc9bf2b163e1cb
[TEST] Move some functions from live.py and utils.py to xm_virt_util.py
The moved functions are:
processors_count()
memory_count()
network_macs()
run_remote_guest()
Signed-off-by: Guolian Yun <yunguol(a)cn.ibm.com>
diff -r 319e2e9509d3 -r 79b321ebebfd lib/VirtLib/live.py
--- a/lib/VirtLib/live.py Tue Nov 04 05:22:21 2008 -0800
+++ b/lib/VirtLib/live.py Tue Nov 04 22:05:49 2008 -0800
@@ -25,59 +25,6 @@
import os
import utils
import socket
-
-def processors_count(ip, vs_name):
- """Returns the number of processors of the specified VS
- """
-
- guest_cmd = "grep '^$' /proc/cpuinfo | wc -l"
-
- rc, out = utils.run_remote_guest(ip, vs_name, guest_cmd)
- if rc != 0:
- return -1
-
- try:
- cpus = int(out)
- return cpus
- except ValueError:
- return -1
-
-def memory_count(ip, vs_name):
- """Returns the memory size (in Bytes) of the specified VS.
- """
-
- guest_cmd = "grep MemTotal /proc/meminfo"
-
- rc, out = utils.run_remote_guest(ip, vs_name, guest_cmd)
- if rc != 0:
- return -1
-
- try:
- mem = int( out.split()[1] )
- return mem * 1024
- except (IndexError, ValueError):
- return -1
-
-def network_macs(ip, vs_name):
- """Returns a list of MAC address of the specified VS.
- """
-
- guest_cmd = "ifconfig -a | grep eth"
-
- rc, out = utils.run_remote_guest(ip, vs_name, guest_cmd)
- if rc != 0:
- return []
-
- ret = []
- lines = out.splitlines()
- for l in lines:
- try:
- mac = l.split()[-1]
- ret.append( mac )
- except IndexError:
- pass
-
- return ret
def available_bridges(ip):
"""Return a list of the available bridges in the running dom0.
diff -r 319e2e9509d3 -r 79b321ebebfd lib/VirtLib/utils.py
--- a/lib/VirtLib/utils.py Tue Nov 04 05:22:21 2008 -0800
+++ b/lib/VirtLib/utils.py Tue Nov 04 22:05:49 2008 -0800
@@ -103,11 +103,3 @@
cmd = 'ssh-keygen -y -f %s' % SSH_KEY
pubkey = commands.getoutput(cmd)
write_pubkey(pubkey)
-
-def run_remote_guest(ip, domain, command):
- """ Execute commands on remote guest console.
- """
-
- cmd = 'python %s %s "%s"' % (CONSOLE_APP_PATH, domain, command)
-
- return run_remote(ip, cmd)
diff -r 319e2e9509d3 -r 79b321ebebfd suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Tue Nov 04 05:22:21 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Tue Nov 04 22:05:49 2008 -0800
@@ -287,3 +287,65 @@
if virt == "LXC":
return "lxc:///system"
return ""
+
+def run_remote_guest(ip, domain, command):
+ """ Execute commands on remote guest console.
+ """
+
+ cmd = 'python %s %s "%s"' % (CONSOLE_APP_PATH, domain, command)
+
+ return run_remote(ip, cmd)
+
+def processors_count(ip, vs_name):
+ """Returns the number of processors of the specified VS
+ """
+
+ guest_cmd = "grep '^$' /proc/cpuinfo | wc -l"
+
+ rc, out = run_remote_guest(ip, vs_name, guest_cmd)
+ if rc != 0:
+ return -1
+
+ try:
+ cpus = int(out)
+ return cpus
+ except ValueError:
+ return -1
+
+def memory_count(ip, vs_name):
+ """Returns the memory size (in Bytes) of the specified VS.
+ """
+
+ guest_cmd = "grep MemTotal /proc/meminfo"
+
+ rc, out = run_remote_guest(ip, vs_name, guest_cmd)
+ if rc != 0:
+ return -1
+
+ try:
+ mem = int( out.split()[1] )
+ return mem * 1024
+ except (IndexError, ValueError):
+ return -1
+
+def network_macs(ip, vs_name):
+ """Returns a list of MAC address of the specified VS.
+ """
+
+ guest_cmd = "ifconfig -a | grep eth"
+
+ rc, out = run_remote_guest(ip, vs_name, guest_cmd)
+ if rc != 0:
+ return []
+
+ ret = []
+ lines = out.splitlines()
+ for l in lines:
+ try:
+ mac = l.split()[-1]
+ ret.append( mac )
+ except IndexError:
+ pass
+
+ return ret
+
Show replies by date
diff -r 319e2e9509d3 -r 79b321ebebfd lib/VirtLib/utils.py
--- a/lib/VirtLib/utils.py Tue Nov 04 05:22:21 2008 -0800
+++ b/lib/VirtLib/utils.py Tue Nov 04 22:05:49 2008 -0800
@@ -103,11 +103,3 @@
cmd = 'ssh-keygen -y -f %s' % SSH_KEY
pubkey = commands.getoutput(cmd)
write_pubkey(pubkey)
-
-def run_remote_guest(ip, domain, command):
- """ Execute commands on remote guest console.
- """
-
- cmd = 'python %s %s "%s"' % (CONSOLE_APP_PATH, domain, command)
-
- return run_remote(ip, cmd)
CONSOLE_APP_PATH = "/tmp/Console.py"
This needs to be removed from this file and placed in
lib/XenKvmLib/xm_virt_util.py
--
Kaitlin Rupert
IBM Linux Technology Center
kaitlin(a)linux.vnet.ibm.com