[PATCH] [TEST]#2 Move some functions from live.py and utils.py to xm_virt_util.py

# HG changeset patch # User Guolian Yun <yunguol@cn.ibm.com> # Date 1225951428 28800 # Node ID a56da9383d25d808284820338091e2d1cc2fdf0c # Parent 319e2e9509d360334c0e38e17abc9bf2b163e1cb [TEST]#2 Move some functions from live.py and utils.py to xm_virt_util.py Also remove CONSOLE_APP_PATH to lib/XenKvmLib/xm_virt_util.py Signed-off-by: Guolian Yun <yunguol@cn.ibm.com> diff -r 319e2e9509d3 -r a56da9383d25 lib/VirtLib/live.py --- a/lib/VirtLib/live.py Tue Nov 04 05:22:21 2008 -0800 +++ b/lib/VirtLib/live.py Wed Nov 05 22:03:48 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 a56da9383d25 lib/VirtLib/utils.py --- a/lib/VirtLib/utils.py Tue Nov 04 05:22:21 2008 -0800 +++ b/lib/VirtLib/utils.py Wed Nov 05 22:03:48 2008 -0800 @@ -23,8 +23,6 @@ import os import commands - -CONSOLE_APP_PATH = "/tmp/Console.py" # ssh utils @@ -103,11 +101,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 a56da9383d25 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 Wed Nov 05 22:03:48 2008 -0800 @@ -26,6 +26,7 @@ from VirtLib import utils import socket +CONSOLE_APP_PATH = "/tmp/Console.py" def xm_domname(ip, domid): cmd = "xm domname %s" % domid @@ -287,3 +288,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 +
participants (1)
-
yunguol@cn.ibm.com