Loading ccnode/handlers.py +103 −104 Original line number Diff line number Diff line Loading @@ -303,60 +303,66 @@ class NodeHandler(RpcHandler): mytags[t] = True # add globbing tags for pattern, handler in self.HV_TAG_GLOB.iteritems(): try: # helper is available on the current host if handler[0](self._host_handle): debug('get_tags: host implements `%s`' % pattern) debug('get_tags: host implements `%s`', pattern) # get tags from helper htags = handler[0](self._host_handle, resolve=False) # append all tags for t in htags: mytags[t] = True debug('get_tags: no tag specified, expanded list to `%s`' % mytags.keys()) except Exception as err: warning('get_tags: `%s` -> `%s`', repr(err), err) debug('get_tags: no tag specified, expanded list to `%s`', mytags.keys()) # add mandatory tags if missing in the list, or set noresolve else: for t in self.HV_TAG_MANDATORY: if t not in mytags or not mytags[t]: debug('get_tags: add/correct mandatory tag `%s`' % t) debug('get_tags: add/correct mandatory tag `%s`', t) mytags[t] = True # query host debug('get_tags: query host with tag list `%s`' % mytags.keys()) info('get_tags: query host with tag list `%s`', mytags.keys()) for tag, resolve in mytags.iteritems(): # first, test tag name againts list of plain name if tag in self.HV_TAG_MAP: debug('get_tags: plain mapping found for tag `%s`' % tag) debug('get_tags: plain mapping found for tag `%s`', tag) try: if self.HV_TAG_MAP[tag][0](self._host_handle): debug('get_tags: tag `%s` is available on host' % tag) debug('get_tags: tag `%s` is available on host', tag) result[tag] = {} result[tag]['ttl'] = self.HV_TAG_MAP[tag][2] if resolve: debug('get_tags: resolving now tag `%s`' % tag) debug('get_tags: resolving now tag `%s`', tag) # fetch tag data q = self.HV_TAG_MAP[tag][1](self._host_handle, tag) debug('get_tags: host returned `%s`' % q) debug('get_tags: host returned `%s`', q) if q is not None: # append tag data result[tag]['value'] = str(q) else: debug('get_tags: I wont return `%s`=`None`' % tag) debug('get_tags: I wont return `%s`=`None`',tag) else: debug('get_tags: tag `%s` is NOT implemented' % tag) debug('get_tags: tag `%s` is NOT implemented', tag) except Exception as err: warning('get_tags: `%s` -> `%s`', repr(err), err) # if no direct tag mapping exists, test name against globbing # a list else: debug('get_tags: searching for `%s` in globbing tags' % tag) debug('get_tags: searching for `%s` in globbing tags', tag) # iter on globbing patterns, and get helper references # process the first globbing tag that match then exit bcause # there should not exist two globbing pattern matching # one tag, ideally for pattern, handler in self.HV_TAG_GLOB.iteritems(): try: # helper is available on the current host if handler[0](self._host_handle, tag): debug('get_tags: testing pattern `%s`' % pattern) debug('get_tags: testing pattern `%s`', pattern) if fnmatchcase(tag, pattern): debug('get_tags: processing tag `%s` with ' 'pattern `%s`' % (tag, pattern)) 'pattern `%s`', tag, pattern) # get tags from helper htags = handler[1](self._host_handle, tag) # FIXME intead of extracting one tag, try not Loading @@ -364,14 +370,15 @@ class NodeHandler(RpcHandler): # difficult and not worth to implement if tag in htags: debug('get_tags: found tag in helper result' ' with value `%s`' % htags[tag]) ' with value `%s`', htags[tag]) result[tag] = {} result[tag]['ttl'] = handler[2] if resolve: result[tag]['value'] = str(htags[tag]) break debug("get_tags: released lock") except Exception as err: warning('get_tags: `%s` -> `%s`', repr(err), err) return result def _sub_tag_list(self, sub_obj): Loading Loading @@ -442,49 +449,38 @@ class NodeHandler(RpcHandler): # query the subnode result = {} try: ''' # expand tag list with globbing tags if get_all: for pattern, handler in self.VM_TAG_GLOB.iteritems(): # helper is available on this VM if handler[0](vm): debug('sub_tags: vm implements `%s`' % pattern) # get tags from helper htags = handler[0](vm, resolve=False) # append all tags mytags.extend(htags) ''' # query the VM with each tag for tag, resolve in mytags.iteritems(): # first, search tag in plain mappings if tag in self.VM_TAG_MAP: debug('sub_tags: plain mapping found for tag `%s`' % tag) info('sub_tags: plain mapping found for tag `%s`', tag) # proceed if tag can be resolved on this VM try: if self.VM_TAG_MAP[tag][0](sub): result[tag] = {} # FIXME result[tag]['ttl'] = self.VM_TAG_MAP[tag][2] if resolve: debug('sub_tags: resolving tag %s`' % tag) debug('sub_tags: resolving tag `%s`', tag) # call the wrapper mapping lambda q = self.VM_TAG_MAP[tag][1](sub, tag) debug('sub_tags: tag query returned `%s`' % q) info('sub_tags: tag query returned `%s`', q) if q is not None: if resolve: result[tag]['value'] = str(q) else: debug('sub_tags: I wont return `%s`=`None`' % tag) warning('sub_tags: I wont return `%s`=`None`' , tag) except Exception as err: warning('sub_tags: plain: `%s` -> `%s`', repr(err), err) # no tag mapping exist, test name against the globbing list else: debug('sub_tags: searching for `%s` in globbing tags' % tag) info('sub_tags: searching for `%s` in globbing tags', tag) # iter on globbing patterns, and get helper references # process the first globbing tag that match then exit # because there should not exist two globbing pattern # matching one tag, ideally for pattern, handler in self.VM_TAG_GLOB.iteritems(): try: # helper is available on the current VM if handler[0](sub, tag): if fnmatchcase(tag, pattern): Loading @@ -496,7 +492,7 @@ class NodeHandler(RpcHandler): # not to build the whole list. Maybe it's # too difficult and not worth implementing if tag in htags: debug('sub_tags: found tag in helper ' info('sub_tags: found tag in helper ' 'result with value `%s`' % htags[tag]) result[tag] = {} result[tag]['ttl'] = handler[2] Loading @@ -504,8 +500,11 @@ class NodeHandler(RpcHandler): result[tag]['value'] = str( htags[tag]) break except Exception as e: debug('sub_tags: `%s` --> `%s`' % (repr(e), e)) except Exception as err: warning('sub_tags: glob: `%s` -> `%s`', repr(err), err) except Exception as err: warning('sub_tags: global: `%s` -> `%s`' % (repr(err), err)) return result @pure Loading Loading
ccnode/handlers.py +103 −104 Original line number Diff line number Diff line Loading @@ -303,60 +303,66 @@ class NodeHandler(RpcHandler): mytags[t] = True # add globbing tags for pattern, handler in self.HV_TAG_GLOB.iteritems(): try: # helper is available on the current host if handler[0](self._host_handle): debug('get_tags: host implements `%s`' % pattern) debug('get_tags: host implements `%s`', pattern) # get tags from helper htags = handler[0](self._host_handle, resolve=False) # append all tags for t in htags: mytags[t] = True debug('get_tags: no tag specified, expanded list to `%s`' % mytags.keys()) except Exception as err: warning('get_tags: `%s` -> `%s`', repr(err), err) debug('get_tags: no tag specified, expanded list to `%s`', mytags.keys()) # add mandatory tags if missing in the list, or set noresolve else: for t in self.HV_TAG_MANDATORY: if t not in mytags or not mytags[t]: debug('get_tags: add/correct mandatory tag `%s`' % t) debug('get_tags: add/correct mandatory tag `%s`', t) mytags[t] = True # query host debug('get_tags: query host with tag list `%s`' % mytags.keys()) info('get_tags: query host with tag list `%s`', mytags.keys()) for tag, resolve in mytags.iteritems(): # first, test tag name againts list of plain name if tag in self.HV_TAG_MAP: debug('get_tags: plain mapping found for tag `%s`' % tag) debug('get_tags: plain mapping found for tag `%s`', tag) try: if self.HV_TAG_MAP[tag][0](self._host_handle): debug('get_tags: tag `%s` is available on host' % tag) debug('get_tags: tag `%s` is available on host', tag) result[tag] = {} result[tag]['ttl'] = self.HV_TAG_MAP[tag][2] if resolve: debug('get_tags: resolving now tag `%s`' % tag) debug('get_tags: resolving now tag `%s`', tag) # fetch tag data q = self.HV_TAG_MAP[tag][1](self._host_handle, tag) debug('get_tags: host returned `%s`' % q) debug('get_tags: host returned `%s`', q) if q is not None: # append tag data result[tag]['value'] = str(q) else: debug('get_tags: I wont return `%s`=`None`' % tag) debug('get_tags: I wont return `%s`=`None`',tag) else: debug('get_tags: tag `%s` is NOT implemented' % tag) debug('get_tags: tag `%s` is NOT implemented', tag) except Exception as err: warning('get_tags: `%s` -> `%s`', repr(err), err) # if no direct tag mapping exists, test name against globbing # a list else: debug('get_tags: searching for `%s` in globbing tags' % tag) debug('get_tags: searching for `%s` in globbing tags', tag) # iter on globbing patterns, and get helper references # process the first globbing tag that match then exit bcause # there should not exist two globbing pattern matching # one tag, ideally for pattern, handler in self.HV_TAG_GLOB.iteritems(): try: # helper is available on the current host if handler[0](self._host_handle, tag): debug('get_tags: testing pattern `%s`' % pattern) debug('get_tags: testing pattern `%s`', pattern) if fnmatchcase(tag, pattern): debug('get_tags: processing tag `%s` with ' 'pattern `%s`' % (tag, pattern)) 'pattern `%s`', tag, pattern) # get tags from helper htags = handler[1](self._host_handle, tag) # FIXME intead of extracting one tag, try not Loading @@ -364,14 +370,15 @@ class NodeHandler(RpcHandler): # difficult and not worth to implement if tag in htags: debug('get_tags: found tag in helper result' ' with value `%s`' % htags[tag]) ' with value `%s`', htags[tag]) result[tag] = {} result[tag]['ttl'] = handler[2] if resolve: result[tag]['value'] = str(htags[tag]) break debug("get_tags: released lock") except Exception as err: warning('get_tags: `%s` -> `%s`', repr(err), err) return result def _sub_tag_list(self, sub_obj): Loading Loading @@ -442,49 +449,38 @@ class NodeHandler(RpcHandler): # query the subnode result = {} try: ''' # expand tag list with globbing tags if get_all: for pattern, handler in self.VM_TAG_GLOB.iteritems(): # helper is available on this VM if handler[0](vm): debug('sub_tags: vm implements `%s`' % pattern) # get tags from helper htags = handler[0](vm, resolve=False) # append all tags mytags.extend(htags) ''' # query the VM with each tag for tag, resolve in mytags.iteritems(): # first, search tag in plain mappings if tag in self.VM_TAG_MAP: debug('sub_tags: plain mapping found for tag `%s`' % tag) info('sub_tags: plain mapping found for tag `%s`', tag) # proceed if tag can be resolved on this VM try: if self.VM_TAG_MAP[tag][0](sub): result[tag] = {} # FIXME result[tag]['ttl'] = self.VM_TAG_MAP[tag][2] if resolve: debug('sub_tags: resolving tag %s`' % tag) debug('sub_tags: resolving tag `%s`', tag) # call the wrapper mapping lambda q = self.VM_TAG_MAP[tag][1](sub, tag) debug('sub_tags: tag query returned `%s`' % q) info('sub_tags: tag query returned `%s`', q) if q is not None: if resolve: result[tag]['value'] = str(q) else: debug('sub_tags: I wont return `%s`=`None`' % tag) warning('sub_tags: I wont return `%s`=`None`' , tag) except Exception as err: warning('sub_tags: plain: `%s` -> `%s`', repr(err), err) # no tag mapping exist, test name against the globbing list else: debug('sub_tags: searching for `%s` in globbing tags' % tag) info('sub_tags: searching for `%s` in globbing tags', tag) # iter on globbing patterns, and get helper references # process the first globbing tag that match then exit # because there should not exist two globbing pattern # matching one tag, ideally for pattern, handler in self.VM_TAG_GLOB.iteritems(): try: # helper is available on the current VM if handler[0](sub, tag): if fnmatchcase(tag, pattern): Loading @@ -496,7 +492,7 @@ class NodeHandler(RpcHandler): # not to build the whole list. Maybe it's # too difficult and not worth implementing if tag in htags: debug('sub_tags: found tag in helper ' info('sub_tags: found tag in helper ' 'result with value `%s`' % htags[tag]) result[tag] = {} result[tag]['ttl'] = handler[2] Loading @@ -504,8 +500,11 @@ class NodeHandler(RpcHandler): result[tag]['value'] = str( htags[tag]) break except Exception as e: debug('sub_tags: `%s` --> `%s`' % (repr(e), e)) except Exception as err: warning('sub_tags: glob: `%s` -> `%s`', repr(err), err) except Exception as err: warning('sub_tags: global: `%s` -> `%s`' % (repr(err), err)) return result @pure Loading