client/tools/rhn-virtualization/rhn-virtualization.spec | 10 + client/tools/rhn-virtualization/virtualization/constants.py | 10 + client/tools/rhn-virtualization/virtualization/localvdsm.py | 72 ++++++++++++ client/tools/rhn-virtualization/virtualization/poller.py | 53 ++++++++ client/tools/rhn-virtualization/virtualization/support.py | 38 +++++- 5 files changed, 176 insertions(+), 7 deletions(-)
New commits: commit 41df363e238ffb345f2dce35eb013c9f1a7c2f26 Author: Pradeep Kilambi pkilambi@redhat.com Date: Fri Oct 2 18:44:08 2009 -0400
Feature support for rhn-virt-host to poll guests through VDSM instead of libvirt, if libvirt is disabled.So the guest registration does'nt consume an entitlement following the xen/kvm business rules on server.
diff --git a/client/tools/rhn-virtualization/rhn-virtualization.spec b/client/tools/rhn-virtualization/rhn-virtualization.spec index 6fbc57b..2f2b543 100644 --- a/client/tools/rhn-virtualization/rhn-virtualization.spec +++ b/client/tools/rhn-virtualization/rhn-virtualization.spec @@ -150,6 +150,9 @@ rm -rf $RPM_BUILD_ROOT %{rhn_dir}/virtualization/start_domain.pyo %{rhn_dir}/virtualization/state.pyo %{rhn_dir}/virtualization/support.pyo +%{rhn_dir}/virtualization/localvdsm.py +%{rhn_dir}/virtualization/localvdsm.pyc +%{rhn_dir}/virtualization/localvdsm.pyo %{rhn_dir}/actions/virt.pyo %doc LICENSE
@@ -162,6 +165,7 @@ rm -rf $RPM_BUILD_ROOT %doc LICENSE
%changelog +<<<<<<< Updated upstream:client/tools/rhn-virtualization/rhn-virtualization.spec * Fri Jul 10 2009 Pradeep Kilambi pkilambi@redhat.com 5.4.3-1 - 510606 - Fix rhn-virtualization package to work with kvm guests. This commit includes fixes for > > - Guest start - We assume pygrub for any guest. This @@ -180,6 +184,12 @@ rm -rf $RPM_BUILD_ROOT file. (pkilambi@redhat.com)
* Tue Jun 16 2009 Brad Buckingham bbuckingham@redhat.com 5.4.0-1 +======= +* Fri Oct 02 2009 Pradeep Kilambi pkilambi@redhat.com 5.3.0-5 +- 526371 - Feature support for rhn-virt-host to poll guests through VDSM instead of libvirt.So the guest registration does'nt consume an entitlement following the xen/kvm business rules on server + +* Tue Jun 16 2009 Brad Buckingham bbuckingham@redhat.com 5.3.0-1 +>>>>>>> Stashed changes:client/tools/rhn-virtualization/rhn-virtualization.spec - bumping version (bbuckingham@redhat.com) - 502902 - If xend is not running instead of returning an empty list return an empty dict and let the registration and profile sync warn instead of failing diff --git a/client/tools/rhn-virtualization/virtualization/constants.py b/client/tools/rhn-virtualization/virtualization/constants.py index 5251846..bd45988 100755 --- a/client/tools/rhn-virtualization/virtualization/constants.py +++ b/client/tools/rhn-virtualization/virtualization/constants.py @@ -52,11 +52,17 @@ class PropertyType: # This structure maps the libvirt state enumeration to labels that RHN # understands. # -VIRT_STATE_NAME_MAP = ( StateType.RUNNING, # VIR_DOMAIN_NOSTATE +VIRT_STATE_NAME_MAP = ( StateType.NOSTATE, # VIR_DOMAIN_NOSTATE StateType.RUNNING, # VIR_DOMAIN_RUNNING - StateType.RUNNING, # VIR_DOMAIN_BLOCKED + StateType.BLOCKED, # VIR_DOMAIN_BLOCKED StateType.PAUSED, # VIR_DOMAIN_PAUSED StateType.SHUTDOWN, # VIR_DOMAIN_SHUTDOWN StateType.SHUTOFF, # VIR_DOMAIN_SHUTOFF StateType.CRASHED) # VIR_DOMAIN_CRASHED
+VIRT_VDSM_STATUS_MAP = { + 'Up' : 'running', + 'Down': 'shutdown', + 'Paused' : 'paused', + 'Powering down' : 'shutoff', +} diff --git a/client/tools/rhn-virtualization/virtualization/localvdsm.py b/client/tools/rhn-virtualization/virtualization/localvdsm.py new file mode 100644 index 0000000..843e065 --- /dev/null +++ b/client/tools/rhn-virtualization/virtualization/localvdsm.py @@ -0,0 +1,72 @@ +#!/usr/bin/python +# +# Copyright 2009 Red Hat, Inc. +# +# Contact vdsm running on localhost over xmlrpc (possibly over ssl) +# +# Dan Kenigsberg danken@redhat.com + +import xmlrpclib +import subprocess +import sys + +VDSM_DIR = '/usr/share/vdsm' +VDSM_CONF = '/etc/vdsm/vdsm.conf' + +try: + sys.path.append(VDSM_DIR) + from config import config + sys.path.pop() + config.read(VDSM_CONF) +except: + # VDSM not available + raise ImportError('local vdsm not found') + +def getTrustStorePath(): + tsPath = None + if config.getboolean('vars', 'ssl'): + tsPath = config.get('vars', 'trust_store_path') + return tsPath + +def getLocalVdsName(tsPath): + p = subprocess.Popen(['openssl', 'x509', '-noout', '-subject', '-in', + '%s/certs/vdsmcert.pem' % tsPath], + stdout=subprocess.PIPE, close_fds=True) + out, err = p.communicate() + if p.returncode != 0: + return '0' + return out.split('=')[-1].strip() + +def connect(): + tsPath = getTrustStorePath() + port = config.get('addresses', 'management_port') + addr = getLocalVdsName(tsPath) + if tsPath: + from M2Crypto.m2xmlrpclib import SSL_Transport + from M2Crypto import SSL + + KEYFILE = tsPath + '/keys/vdsmkey.pem' + CERTFILE = tsPath + '/certs/vdsmcert.pem' + CACERT = tsPath + '/certs/cacert.pem' + + ctx = SSL.Context ('sslv3') + + ctx.set_verify(SSL.verify_peer | SSL.verify_fail_if_no_peer_cert, 16) + ctx.load_verify_locations(CACERT) + ctx.load_cert(CERTFILE, KEYFILE) + + server = xmlrpclib.Server('https://%s:%s' % (addr, port), + SSL_Transport(ctx)) + else: + server = xmlrpclib.Server('http://%s:%s' % (server, port)) + return server + +if __name__ == '__main__': + server = connect() + response = server.list(True) + if response['status']['code'] != 0: + print response['status']['message'] + else: + for d in response['vmList']: + print d + diff --git a/client/tools/rhn-virtualization/virtualization/poller.py b/client/tools/rhn-virtualization/virtualization/poller.py index e8d10c6..c918a63 100644 --- a/client/tools/rhn-virtualization/virtualization/poller.py +++ b/client/tools/rhn-virtualization/virtualization/poller.py @@ -32,7 +32,8 @@ from virtualization.errors import VirtualizationException from virtualization.constants import StateType, \ PropertyType, \ VirtualizationType, \ - VIRT_STATE_NAME_MAP + VIRT_STATE_NAME_MAP, \ + VIRT_VDSM_STATUS_MAP from virtualization.notification import Plan, \ EventType, \ TargetType @@ -120,6 +121,56 @@ def poll_hypervisor():
return state
+def poll_through_vdsm(): + """ + This method polls all the virt guests running on a VDSM enabled Host. + Libvirt is disabled by default on RHEV-M managed clients. + * Imports the localvdsm client that talks to the localhost + and fetches the list of vms and their info. + * Extract the data and construct the state to pass it to the + execution plan for guest polling. + * The server should account for business rules similar to + xen/kvm. + """ + import localvdsm + try: + server = localvdsm.connect() + except: + # VDSM raised an exception we're done here + return {} + # Extract list of vm's. True returns full list + domains = server.list(True) + + if not len(domains['vmList']): + # No domains, exit. + return + + state = {} + for domain in domains['vmList']: + #trim uuid + uuid = domain['vmId'].lower().replace('-', '') + # Map the VDSM status to libvirt for server compatibility + status = "Unknown" + if VIRT_VDSM_STATUS_MAP.has_key(domain['status']): + status = VIRT_VDSM_STATUS_MAP[domain['status']] + # This is gonna be fully virt as its managed by VDSM + virt_type = VirtualizationType.FULLY + + properties = { + PropertyType.NAME : domain['vmName'], + PropertyType.UUID : uuid, + PropertyType.TYPE : virt_type, + PropertyType.MEMORY : domain['memSize'], # current memory + PropertyType.VCPUS : domain['smp'], + PropertyType.STATE : status} + + state[uuid] = properties + + if state: _log_debug("Polled state: %s" % repr(state)) + + return state + + def poll_state(uuid): """ Polls just the state of the guest with the provided UUID. This state is diff --git a/client/tools/rhn-virtualization/virtualization/support.py b/client/tools/rhn-virtualization/virtualization/support.py index 2657a71..4cdd95f 100755 --- a/client/tools/rhn-virtualization/virtualization/support.py +++ b/client/tools/rhn-virtualization/virtualization/support.py @@ -39,6 +39,27 @@ except: # be on every system. libvirt = None
+def _check_status(daemon): + """ + Checks to see if daemon is running. + """ + import commands + cmd = "/etc/init.d/%s status" % daemon + status, msg = commands.getstatusoutput(cmd) + if status != 0: + return False + return True + + +vdsm_enabled = None +if not _check_status("libvirtd"): + # Only check for vdsm if libvirt is disabled. + # sometimes due to manual intervention both could be running + # in such case use libvirt as the system is now in + # un supported state. + vdsm_enabled = _check_status("vdsmd") + + ############################################################################### # Public Interface ############################################################################### @@ -67,7 +88,11 @@ def refresh(): PropertyType.UUID : my_uuid })
# Now, crawl each of the domains on this host. - domains = poller.poll_hypervisor() + if vdsm_enabled: + domains = poller.poll_through_vdsm() + else: + domains = poller.poll_hypervisor() + if not len(domains): # Either there were no domains or xend might not be running # dont proceed further. @@ -75,8 +100,10 @@ def refresh(): domain_list = domains.values() domain_uuids = domains.keys()
- domain_dir = DomainDirectory() - domain_dir.save_unknown_domain_configs(domain_uuids) + if not vdsm_enabled: + # We need this only for libvirt + domain_dir = DomainDirectory() + domain_dir.save_unknown_domain_configs(domain_uuids)
plan.add(EventType.CRAWL_BEGAN, TargetType.SYSTEM) for domain_properties in domain_list: @@ -159,6 +186,10 @@ def _is_host_domain():
We can figure out if Xen/Qemu is running by checking for the type """ + if vdsm_enabled: + # since vdsm is enabled, lets move further and + # see what we get + return True if not libvirt: # No libvirt, dont bother with the rest return False @@ -174,7 +205,6 @@ def _fetch_host_uuid(): """ return '0000000000000000'
- ############################################################################### # Test Routine ###############################################################################
spacewalk-commits@lists.fedorahosted.org