[et-mgmt-tools] [PATCH] Port utility functions to Solaris
john.levon at sun.com
john.levon at sun.com
Wed Dec 10 19:34:12 UTC 2008
# HG changeset patch
# User john.levon at sun.com
# Date 1228937605 28800
# Node ID e9045f3ae5b2243a9ee00f0913c2dcefdddd7c36
# Parent a1b50ecb6ecef44f3a86bd27da53a8f14687dc38
Port utility functions to Solaris
Port the utility functions to Solaris.
Signed-off-by: John Levon <john.levon at sun.com>
diff --git a/virtinst/FullVirtGuest.py b/virtinst/FullVirtGuest.py
--- a/virtinst/FullVirtGuest.py
+++ b/virtinst/FullVirtGuest.py
@@ -38,7 +38,8 @@ class FullVirtGuest(Guest):
installer = DistroManager.DistroInstaller(type = type, os_type = "hvm")
Guest.__init__(self, type, connection, hypervisorURI, installer)
self.disknode = "hd"
- self.features = { "acpi": None, "pae": _util.is_pae_capable(), "apic": None }
+ self.features = { "acpi": None, "pae":
+ _util.is_pae_capable(connection), "apic": None }
if arch is None:
arch = platform.machine()
self.arch = arch
diff --git a/virtinst/util.py b/virtinst/util.py
--- a/virtinst/util.py
+++ b/virtinst/util.py
@@ -33,6 +33,7 @@ import re
import re
import libxml2
import logging
+import subprocess
from sys import stderr
import libvirt
@@ -44,7 +45,19 @@ KEYBOARD_DIR = "/etc/sysconfig/keyboard"
KEYBOARD_DIR = "/etc/sysconfig/keyboard"
XORG_CONF = "/etc/X11/xorg.conf"
-def default_route():
+def default_route(nic = None):
+ if platform.system() == 'SunOS':
+ cmd = [ '/usr/bin/netstat', '-rn' ]
+ if nic:
+ cmd += [ '-I', nic ]
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ for line in proc.stdout.readlines():
+ vals = line.split()
+ if len(vals) > 1 and vals[0] == 'default':
+ return vals[1]
+ return None
+
route_file = "/proc/net/route"
d = file(route_file)
@@ -63,7 +76,29 @@ def default_route():
continue
return None
+def _default_nic():
+ """Return the default NIC to use, if one is specified.
+ This is NOT part of the API and may change at will."""
+
+ dev = ''
+
+ if platform.system() != 'SunOS':
+ return dev
+
+ # XXX: fails without PRIV_XVM_CONTROL
+ proc = subprocess.Popen(['/usr/lib/xen/bin/xenstore-read',
+ 'device-misc/vif/default-nic'], stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ out = proc.stdout.readlines()
+ if len(out) > 0:
+ dev = out[0].rstrip()
+
+ return dev
+
def default_bridge():
+ if platform.system() == 'SunOS':
+ return _default_nic()
+
rt = default_route()
if rt is None:
defn = None
@@ -76,6 +111,9 @@ def default_bridge():
return "xenbr%d"%(defn)
def default_network(conn):
+ if platform.system() == 'SunOS':
+ return ["bridge", _default_nic()]
+
dev = default_route()
if dev is not None and not is_uri_remote(conn.getURI()):
@@ -93,12 +131,16 @@ def default_network(conn):
return ["network", "default"]
def default_connection():
- if os.path.exists("/var/lib/xend") and os.path.exists("/proc/xen"):
- return "xen"
- elif os.path.exists("/usr/bin/qemu") or \
- os.path.exists("/usr/bin/qemu-kvm") or \
- os.path.exists("/usr/bin/kvm") or \
- os.path.exists("/usr/bin/xenner"):
+ if os.path.exists('/var/lib/xend'):
+ if os.path.exists('/dev/xen/evtchn'):
+ return 'xen'
+ if os.path.exists("/proc/xen"):
+ return 'xen'
+
+ if os.path.exists("/usr/bin/qemu") or \
+ os.path.exists("/usr/bin/qemu-kvm") or \
+ os.path.exists("/usr/bin/kvm") or \
+ os.path.exists("/usr/bin/xenner"):
if User.current().has_priv(User.PRIV_QEMU_SYSTEM):
return "qemu:///system"
else:
@@ -106,6 +148,9 @@ def default_connection():
return None
def get_cpu_flags():
+ if platform.system() == 'SunOS':
+ raise OSError('CPU flags not available')
+
f = open("/proc/cpuinfo")
lines = f.readlines()
f.close()
@@ -119,15 +164,16 @@ def get_cpu_flags():
return flst
return []
-def is_pae_capable():
+def is_pae_capable(conn = None):
"""Determine if a machine is PAE capable or not."""
- flags = get_cpu_flags()
- if "pae" in flags:
- return True
- return False
+ if not conn:
+ conn = libvirt.open('')
+ return "pae" in conn.getCapabilities()
def is_hvm_capable():
"""Determine if a machine is HVM capable or not."""
+ if platform.system() == 'SunOS':
+ raise OSError('HVM capability not determinible')
caps = ""
if os.path.exists("/sys/hypervisor/properties/capabilities"):
@@ -143,6 +189,9 @@ def is_kvm_capable():
return os.path.exists("/dev/kvm")
def is_blktap_capable():
+ if platform.system() == 'SunOS':
+ return False
+
#return os.path.exists("/dev/xen/blktapctrl")
f = open("/proc/modules")
lines = f.readlines()
More information about the et-mgmt-tools
mailing list