Commit bf42ae59 authored by Antoine Millet's avatar Antoine Millet
Browse files

Implemented catch_all "$" separator (...$*).

parent 3a3d6907
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -136,9 +136,9 @@ class CCServer(object):
        if login in self._connected:
            client = self._connected[login]
            tags['con'] = client.get_uptime()
            rtags = None if requested_tags is None else tuple(requested_tags)
            try:
                tags.update(client.connection.call('get_tags',
                                                   tuple(requested_tags)))
                tags.update(client.connection.call('get_tags', rtags))
            except Exception as err:
                logging.error('Error while calling get_tags on '
                              '%s: %s' % (client.login, err))
+10 −9
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ class ClientHandler(OnlineCCHandler):
                if tag_name in ('a', 'hv', 'h', 'id'):
                    # Append all accounts:
                    for login in self._server.conf.list_accounts():
                        tags = self._server.resolve_tags(login, query.tags)
                        tags = self._server.resolve_tags(login, query.req_tags)
                        objects.append(tags)

                if tag_name in ('vm', 'h', 'id'):
@@ -94,7 +94,7 @@ class ClientHandler(OnlineCCHandler):
                    tags = tuple(query.tags)
                    for hy_tags in hvs:
                        hy = self._server.get_connection(hy_tags['a'])
                        cid = hy.connection.async_call('list_vm', tags=tags)
                        cid = hy.connection.async_call('list_vm', tags=query.req_tags)
                        async_calls[cid] = hy_tags

                    logging.debug('Waiting for the response of hypervisors...')
@@ -118,17 +118,18 @@ class ClientHandler(OnlineCCHandler):
                objects = objects[:condition.number]
                
        # Before to return, filter with the asked tags for each objects:
        tags = query.tags
        tags = query.req_tags
        uniq_objects = {}
        if tags is not None:
            tags.add('id')
            tags.add('role')
        final_objects = {}
        for obj in objects:
            for key in obj.keys():
                if key not in tags:
                if tags is not None and key not in tags:
                    del obj[key]
            final_objects[obj['id']] = obj
            uniq_objects[obj['id']] = obj

        return final_objects.values()
        return uniq_objects.values()

    @pure
    @listed
+16 −2
Original line number Diff line number Diff line
@@ -86,12 +86,13 @@ class TqlQuery(object):
    RE_COND = re.compile(r'^(?P<name>[a-z-A-Z0-9_?*-]+)'
                         r'((?P<operator>[!<>~:=]{1,3})'
                         r'(?P<value>[^&$#]+?))?$')
    RE_TAG = re.compile(r'^(?P<name>[a-z-A-Z0-9_-]+)')
    RE_TAG = re.compile(r'^(?P<name>[a-z-A-Z0-9_-]+|[*])')
    RE_SEPARATOR = re.compile(r'(&|\$|#)')

    def __init__(self, query):
        self._conditions = []
        self._to_show = set()
        self._catchall = False
        self._parse(query)

    def _parse(self, query):
@@ -153,6 +154,9 @@ class TqlQuery(object):
            elif sep == '$':
                # "To show" separator, the token is a tag name:
                if TqlQuery.RE_TAG.match(tok) is not None:
                    if tok == '*':
                        self._catchall = True
                    else:
                        self._to_show.add(tok)
                else:
                    raise TqlParsingError('Error while parsing, invalid tag '
@@ -190,6 +194,16 @@ class TqlQuery(object):

    tags = property(_get_tags)

    def _get_requested_tags(self):
        '''
        Get the set of all tags requested by this query or None if a catchall
        is specified.
        '''

        return None if self._catchall else self.tags

    req_tags = property(_get_requested_tags)

    def op_glob(self, value, pattern):
        if value is None:
            return False