Loading ccnode/host/__init__.py +4 −4 Original line number Diff line number Diff line Loading @@ -57,19 +57,19 @@ class Handler(DefaultHandler): if reboot: args.append('-r') if gracefull: logger.info(u'Going to reboot the host...') logger.info('Going to reboot the host...') args.append('-f') else: logger.info(u'Going to force the reboot of the host...') logger.info('Going to force the reboot of the host...') args.append('-n') else: # halt args.append('-h -P') if not gracefull: logger.info(u'Going to halt the host...') logger.info('Going to halt the host...') args.append('-n') else: logger.info(u'Going to force the halt of the host...') logger.info('Going to force the halt of the host...') args.append('0') Loading ccnode/hypervisor/__init__.py +4 −10 Original line number Diff line number Diff line import logging import weakref from functools import partial from itertools import chain, imap import libvirt Loading @@ -27,9 +26,6 @@ class Handler(HostHandler): for t in tag_inspector(tags, self): self.tags[t.name] = t # set tag hv # self.tags['hv'] = Tag('hv', ) # initialize hypervisor instance global hypervisor if hypervisor is None: Loading @@ -55,7 +51,7 @@ class Handler(HostHandler): proxy = kwargs.pop('proxy') for dom in hypervisor.domains.itervalues(): name = dom.name logger.debug(u'Registered domain %s' % name) logger.debug('Registered domain %s', name) proxy.register(name, 'vm') def sub_tags(self, sub_id, tags=None, noresolve_tags=None): Loading @@ -65,7 +61,7 @@ class Handler(HostHandler): domain = hypervisor.get_domain_by_name(sub_id) if domain is None: logger.debug(u'Failed to find domain with name %s.' % sub_id) logger.debug('Failed to find domain with name %s.', sub_id) return return get_tags(domain, tags, noresolve_tags) Loading Loading @@ -254,7 +250,7 @@ class Storage(object): self.state = STORAGE_STATES[self.state] self.volumes = map( partial(Volume, storage=self), Volume, (lv_storage.storageVolLookupByName(n) for n in lv_storage.listVolumes()), ) Loading @@ -262,12 +258,10 @@ class Storage(object): class Volume(object): """Volume abstraction.""" def __init__(self, lv_volume, storage): def __init__(self, lv_volume): """ :param lv_volume: Libvirt volume instance :param storage: parent storage instance """ # self.storage = None if storage is None else weakref.proxy(storage) self.storage = lv_volume.storagePoolLookupByVolume().name() self.path = lv_volume.path() self.name = lv_volume.name() Loading ccnode/hypervisor/domains/__init__.py +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class VirtualMachine(object): ): self.tags[t.name] = t logger.debug(self.tags) logger.debug('Virtual Machine tags: %s', self.tags) @property def name(self): Loading ccnode/hypervisor/lib.py +23 −24 Original line number Diff line number Diff line Loading @@ -7,11 +7,15 @@ import select import errno import time import atexit import logging from threading import Thread import libvirt logger = logging.getLogger(__name__) #: connection to the libvirt connection = None # TODO create a watcher thread for this Loading Loading @@ -53,8 +57,8 @@ EVENTS = ( ) # following classes are used only for libvirt eventloop class virEventLoopPureHandle(object): # following event loop implementation was inspired by libvirt python example class LoopHandler(object): """This class contains the data we need to track for a single file handle. """ Loading Loading @@ -85,7 +89,7 @@ class virEventLoopPureHandle(object): self.opaque[1]) class virEventLoopPureTimer(object): class LoopTimer(object): """This class contains the data we need to track for a single periodic timer. Loading Loading @@ -125,8 +129,7 @@ class EventLoop(object): It is a pure python implementation based around the poll() API. """ def __init__(self, debug=False): self.debugOn = debug def __init__(self): self.poll = select.poll() self.pipetrick = os.pipe() self.nextHandleID = 1 Loading @@ -148,13 +151,9 @@ class EventLoop(object): # with the event loop for input events. When we need to force # the main thread out of a poll() sleep, we simple write a # single byte of data to the other end of the pipe. self.debug("Self pipe watch %d write %d" %(self.pipetrick[0], self.pipetrick[1])) logger.debug('Self pipe watch %d write %d', self.pipetrick[0], self.pipetrick[1]) self.poll.register(self.pipetrick[0], select.POLLIN) def debug(self, msg): if self.debugOn: print msg def next_timeout(self): """Calculate when the next timeout is due to occurr, returning the absolute timestamp for the next timeout, or 0 if there is Loading @@ -173,7 +172,7 @@ class EventLoop(object): return next def get_handle_by_fd(self, fd): """Lookup a virEventLoopPureHandle object based on file descriptor. """Lookup a LoopHandler object based on file descriptor. """ for h in self.handles: Loading @@ -182,7 +181,7 @@ class EventLoop(object): return None def get_handle_by_id(self, handleID): """Lookup a virEventLoopPureHandle object based on its event loop ID. """Lookup a LoopHandler object based on its event loop ID. """ for h in self.handles: Loading Loading @@ -215,7 +214,7 @@ class EventLoop(object): """ sleep = -1 next = self.next_timeout() self.debug("Next timeout due at %d" % next) logger.debug('Next timeout due at %d', next) if next > 0: now = int(time.time() * 1000) if now >= next: Loading @@ -223,7 +222,7 @@ class EventLoop(object): else: sleep = next - now self.debug("Poll with a sleep of %d" % sleep) logger.debug('Poll with a sleep of %d', sleep) events = self.poll.poll(sleep) # Dispatch any file handle events that occurred Loading @@ -237,7 +236,7 @@ class EventLoop(object): h = self.get_handle_by_fd(fd) if h: self.debug("Dispatch fd %d handle %d events %d" % (fd, h.get_id(), revents)) logger.debug('Dispatch fd %d handle %d events %d', fd, h.get_id(), revents) h.dispatch(self.events_from_poll(revents)) now = int(time.time() * 1000) Loading @@ -250,7 +249,7 @@ class EventLoop(object): # Deduct 20ms, since schedular timeslice # means we could be ever so slightly early if now >= (want-20): self.debug("Dispatch timer %d now %s want %s" % (t.get_id(), str(now), str(want))) logger.debug('Dispatch timer %d now %s want %s', t.get_id(), str(now), str(want)) t.set_last_fired(now) t.dispatch() Loading @@ -267,13 +266,13 @@ class EventLoop(object): handleID = self.nextHandleID + 1 self.nextHandleID = self.nextHandleID + 1 h = virEventLoopPureHandle(handleID, fd, events, cb, opaque) h = LoopHandler(handleID, fd, events, cb, opaque) self.handles.append(h) self.poll.register(fd, self.events_to_poll(events)) self.interrupt() self.debug("Add handle %d fd %d events %d" % (handleID, fd, events)) logger.debug('Add handle %d fd %d events %d', handleID, fd, events) return handleID Loading @@ -288,11 +287,11 @@ class EventLoop(object): timerID = self.nextTimerID + 1 self.nextTimerID = self.nextTimerID + 1 h = virEventLoopPureTimer(timerID, interval, cb, opaque) h = LoopTimer(timerID, interval, cb, opaque) self.timers.append(h) self.interrupt() self.debug("Add timer %d interval %d" % (timerID, interval)) logger.debug('Add timer %d interval %d', timerID, interval) return timerID Loading @@ -307,7 +306,7 @@ class EventLoop(object): self.poll.register(h.get_fd(), self.events_to_poll(events)) self.interrupt() self.debug("Update handle %d fd %d events %d" % (handleID, h.get_fd(), events)) logger.debug('Update handle %d fd %d events %d', handleID, h.get_fd(), events) def update_timer(self, timerID, interval): """Change the periodic frequency of the timer. Loading @@ -318,7 +317,7 @@ class EventLoop(object): h.set_interval(interval); self.interrupt() self.debug("Update timer %d interval %d" % (timerID, interval)) logger.debug('Update timer %d interval %d', timerID, interval) break def remove_handle(self, handleID): Loading @@ -329,7 +328,7 @@ class EventLoop(object): for h in self.handles: if h.get_id() == handleID: self.poll.unregister(h.get_fd()) self.debug("Remove handle %d fd %d" % (handleID, h.get_fd())) logger.debug('Remove handle %d fd %d', handleID, h.get_fd()) else: handles.append(h) self.handles = handles Loading @@ -343,7 +342,7 @@ class EventLoop(object): for h in self.timers: if h.get_id() != timerID: timers.append(h) self.debug("Remove timer %d" % timerID) logger.debug('Remove timer %d', timerID) self.timers = timers self.interrupt() Loading ccnode/node.py +6 −6 Original line number Diff line number Diff line Loading @@ -93,23 +93,23 @@ class Node(Thread): try: role = self.proxy.authentify(self.user_name, self.user_passwd) except Exception: logger.exception(u'Unknow exception while authentifying.') logger.exception('Unknow exception while authentifying') raise # set handler according to which role was returned by the cc-server if role == u'host': logger.debug(u'Role host affected.') logger.debug('Role host affected') from ccnode.host import Handler as HostHandler self.connection.rpc.set_handler(HostHandler()) self.role = u'host' elif role == u'hv': logger.debug(u'Role hypervisor affected.') logger.debug('Role hypervisor affected') from ccnode.hypervisor import Handler as HypervisorHandler self.connection.rpc.set_handler(HypervisorHandler( proxy=self.proxy, hypervisor_name=self.user_name)) self.role = u'hv' else: logger.debug(u'Wrong role returned: %s', role) logger.debug('Wrong role returned: %s', role) role = None time.sleep(2) Loading @@ -121,7 +121,7 @@ class Node(Thread): try: self.connection.run() except Exception: logger.exception(u'Unknown exception:') logger.exception('Unknown exception:') finally: self.shutdown() Loading @@ -133,7 +133,7 @@ class Node(Thread): try: self.init_rpc() except Exception as e: logger.exception(u'Error in init.') logger.exception('Error in init.') else: break time.sleep(2) Loading Loading
ccnode/host/__init__.py +4 −4 Original line number Diff line number Diff line Loading @@ -57,19 +57,19 @@ class Handler(DefaultHandler): if reboot: args.append('-r') if gracefull: logger.info(u'Going to reboot the host...') logger.info('Going to reboot the host...') args.append('-f') else: logger.info(u'Going to force the reboot of the host...') logger.info('Going to force the reboot of the host...') args.append('-n') else: # halt args.append('-h -P') if not gracefull: logger.info(u'Going to halt the host...') logger.info('Going to halt the host...') args.append('-n') else: logger.info(u'Going to force the halt of the host...') logger.info('Going to force the halt of the host...') args.append('0') Loading
ccnode/hypervisor/__init__.py +4 −10 Original line number Diff line number Diff line import logging import weakref from functools import partial from itertools import chain, imap import libvirt Loading @@ -27,9 +26,6 @@ class Handler(HostHandler): for t in tag_inspector(tags, self): self.tags[t.name] = t # set tag hv # self.tags['hv'] = Tag('hv', ) # initialize hypervisor instance global hypervisor if hypervisor is None: Loading @@ -55,7 +51,7 @@ class Handler(HostHandler): proxy = kwargs.pop('proxy') for dom in hypervisor.domains.itervalues(): name = dom.name logger.debug(u'Registered domain %s' % name) logger.debug('Registered domain %s', name) proxy.register(name, 'vm') def sub_tags(self, sub_id, tags=None, noresolve_tags=None): Loading @@ -65,7 +61,7 @@ class Handler(HostHandler): domain = hypervisor.get_domain_by_name(sub_id) if domain is None: logger.debug(u'Failed to find domain with name %s.' % sub_id) logger.debug('Failed to find domain with name %s.', sub_id) return return get_tags(domain, tags, noresolve_tags) Loading Loading @@ -254,7 +250,7 @@ class Storage(object): self.state = STORAGE_STATES[self.state] self.volumes = map( partial(Volume, storage=self), Volume, (lv_storage.storageVolLookupByName(n) for n in lv_storage.listVolumes()), ) Loading @@ -262,12 +258,10 @@ class Storage(object): class Volume(object): """Volume abstraction.""" def __init__(self, lv_volume, storage): def __init__(self, lv_volume): """ :param lv_volume: Libvirt volume instance :param storage: parent storage instance """ # self.storage = None if storage is None else weakref.proxy(storage) self.storage = lv_volume.storagePoolLookupByVolume().name() self.path = lv_volume.path() self.name = lv_volume.name() Loading
ccnode/hypervisor/domains/__init__.py +1 −1 Original line number Diff line number Diff line Loading @@ -52,7 +52,7 @@ class VirtualMachine(object): ): self.tags[t.name] = t logger.debug(self.tags) logger.debug('Virtual Machine tags: %s', self.tags) @property def name(self): Loading
ccnode/hypervisor/lib.py +23 −24 Original line number Diff line number Diff line Loading @@ -7,11 +7,15 @@ import select import errno import time import atexit import logging from threading import Thread import libvirt logger = logging.getLogger(__name__) #: connection to the libvirt connection = None # TODO create a watcher thread for this Loading Loading @@ -53,8 +57,8 @@ EVENTS = ( ) # following classes are used only for libvirt eventloop class virEventLoopPureHandle(object): # following event loop implementation was inspired by libvirt python example class LoopHandler(object): """This class contains the data we need to track for a single file handle. """ Loading Loading @@ -85,7 +89,7 @@ class virEventLoopPureHandle(object): self.opaque[1]) class virEventLoopPureTimer(object): class LoopTimer(object): """This class contains the data we need to track for a single periodic timer. Loading Loading @@ -125,8 +129,7 @@ class EventLoop(object): It is a pure python implementation based around the poll() API. """ def __init__(self, debug=False): self.debugOn = debug def __init__(self): self.poll = select.poll() self.pipetrick = os.pipe() self.nextHandleID = 1 Loading @@ -148,13 +151,9 @@ class EventLoop(object): # with the event loop for input events. When we need to force # the main thread out of a poll() sleep, we simple write a # single byte of data to the other end of the pipe. self.debug("Self pipe watch %d write %d" %(self.pipetrick[0], self.pipetrick[1])) logger.debug('Self pipe watch %d write %d', self.pipetrick[0], self.pipetrick[1]) self.poll.register(self.pipetrick[0], select.POLLIN) def debug(self, msg): if self.debugOn: print msg def next_timeout(self): """Calculate when the next timeout is due to occurr, returning the absolute timestamp for the next timeout, or 0 if there is Loading @@ -173,7 +172,7 @@ class EventLoop(object): return next def get_handle_by_fd(self, fd): """Lookup a virEventLoopPureHandle object based on file descriptor. """Lookup a LoopHandler object based on file descriptor. """ for h in self.handles: Loading @@ -182,7 +181,7 @@ class EventLoop(object): return None def get_handle_by_id(self, handleID): """Lookup a virEventLoopPureHandle object based on its event loop ID. """Lookup a LoopHandler object based on its event loop ID. """ for h in self.handles: Loading Loading @@ -215,7 +214,7 @@ class EventLoop(object): """ sleep = -1 next = self.next_timeout() self.debug("Next timeout due at %d" % next) logger.debug('Next timeout due at %d', next) if next > 0: now = int(time.time() * 1000) if now >= next: Loading @@ -223,7 +222,7 @@ class EventLoop(object): else: sleep = next - now self.debug("Poll with a sleep of %d" % sleep) logger.debug('Poll with a sleep of %d', sleep) events = self.poll.poll(sleep) # Dispatch any file handle events that occurred Loading @@ -237,7 +236,7 @@ class EventLoop(object): h = self.get_handle_by_fd(fd) if h: self.debug("Dispatch fd %d handle %d events %d" % (fd, h.get_id(), revents)) logger.debug('Dispatch fd %d handle %d events %d', fd, h.get_id(), revents) h.dispatch(self.events_from_poll(revents)) now = int(time.time() * 1000) Loading @@ -250,7 +249,7 @@ class EventLoop(object): # Deduct 20ms, since schedular timeslice # means we could be ever so slightly early if now >= (want-20): self.debug("Dispatch timer %d now %s want %s" % (t.get_id(), str(now), str(want))) logger.debug('Dispatch timer %d now %s want %s', t.get_id(), str(now), str(want)) t.set_last_fired(now) t.dispatch() Loading @@ -267,13 +266,13 @@ class EventLoop(object): handleID = self.nextHandleID + 1 self.nextHandleID = self.nextHandleID + 1 h = virEventLoopPureHandle(handleID, fd, events, cb, opaque) h = LoopHandler(handleID, fd, events, cb, opaque) self.handles.append(h) self.poll.register(fd, self.events_to_poll(events)) self.interrupt() self.debug("Add handle %d fd %d events %d" % (handleID, fd, events)) logger.debug('Add handle %d fd %d events %d', handleID, fd, events) return handleID Loading @@ -288,11 +287,11 @@ class EventLoop(object): timerID = self.nextTimerID + 1 self.nextTimerID = self.nextTimerID + 1 h = virEventLoopPureTimer(timerID, interval, cb, opaque) h = LoopTimer(timerID, interval, cb, opaque) self.timers.append(h) self.interrupt() self.debug("Add timer %d interval %d" % (timerID, interval)) logger.debug('Add timer %d interval %d', timerID, interval) return timerID Loading @@ -307,7 +306,7 @@ class EventLoop(object): self.poll.register(h.get_fd(), self.events_to_poll(events)) self.interrupt() self.debug("Update handle %d fd %d events %d" % (handleID, h.get_fd(), events)) logger.debug('Update handle %d fd %d events %d', handleID, h.get_fd(), events) def update_timer(self, timerID, interval): """Change the periodic frequency of the timer. Loading @@ -318,7 +317,7 @@ class EventLoop(object): h.set_interval(interval); self.interrupt() self.debug("Update timer %d interval %d" % (timerID, interval)) logger.debug('Update timer %d interval %d', timerID, interval) break def remove_handle(self, handleID): Loading @@ -329,7 +328,7 @@ class EventLoop(object): for h in self.handles: if h.get_id() == handleID: self.poll.unregister(h.get_fd()) self.debug("Remove handle %d fd %d" % (handleID, h.get_fd())) logger.debug('Remove handle %d fd %d', handleID, h.get_fd()) else: handles.append(h) self.handles = handles Loading @@ -343,7 +342,7 @@ class EventLoop(object): for h in self.timers: if h.get_id() != timerID: timers.append(h) self.debug("Remove timer %d" % timerID) logger.debug('Remove timer %d', timerID) self.timers = timers self.interrupt() Loading
ccnode/node.py +6 −6 Original line number Diff line number Diff line Loading @@ -93,23 +93,23 @@ class Node(Thread): try: role = self.proxy.authentify(self.user_name, self.user_passwd) except Exception: logger.exception(u'Unknow exception while authentifying.') logger.exception('Unknow exception while authentifying') raise # set handler according to which role was returned by the cc-server if role == u'host': logger.debug(u'Role host affected.') logger.debug('Role host affected') from ccnode.host import Handler as HostHandler self.connection.rpc.set_handler(HostHandler()) self.role = u'host' elif role == u'hv': logger.debug(u'Role hypervisor affected.') logger.debug('Role hypervisor affected') from ccnode.hypervisor import Handler as HypervisorHandler self.connection.rpc.set_handler(HypervisorHandler( proxy=self.proxy, hypervisor_name=self.user_name)) self.role = u'hv' else: logger.debug(u'Wrong role returned: %s', role) logger.debug('Wrong role returned: %s', role) role = None time.sleep(2) Loading @@ -121,7 +121,7 @@ class Node(Thread): try: self.connection.run() except Exception: logger.exception(u'Unknown exception:') logger.exception('Unknown exception:') finally: self.shutdown() Loading @@ -133,7 +133,7 @@ class Node(Thread): try: self.init_rpc() except Exception as e: logger.exception(u'Error in init.') logger.exception('Error in init.') else: break time.sleep(2) Loading