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

Added compatibility with the new tag format.

parent 7c4cf508
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -10,6 +10,28 @@ from client import CCClient
from exceptions import AlreadyRegistered, NotConnectedAccountError
from tql import TqlQuery, TqlCondition, TqlLimit

def conv_node_tags(tags):
    '''
    Convert tag from new format to old format (used for release 8).
    '''

    d = {}
    for k, v in tags.iteritems():
        d[k] = v.get('value')
    return d

def conv_vm_tags(tags):
    '''
    Convert tag from new format to old format (used for release 8).
    '''

    l = []
    for k, v in tags.iteritems():
        t = conv_node_tags(v)
        t['vm'] = k
        l.append(t)
    return l

class CCServer(object):
    '''
    CloudControl server main class.
@@ -143,7 +165,7 @@ class CCServer(object):
            tags['ip'] = client.get_ip()
            rtags = None if requested_tags is None else tuple(requested_tags)
            try:
                tags.update(client.connection.call('get_tags', rtags))
                tags.update(conv_node_tags(client.connection.call('node_tags', rtags)))
            except Exception as err:
                logging.error('Error while calling get_tags on '
                              '%s: %s' % (client.login, err))
@@ -209,7 +231,7 @@ class CCServer(object):
                    tags = tuple(query.tags)
                    for hy_tags in hvs:
                        hy = self.get_connection(hy_tags['a'])
                        cid = hy.connection.async_call('list_vm', tags=query.req_tags)
                        cid = hy.connection.async_call('vm_tags', tags=query.req_tags)
                        async_calls[cid] = hy_tags

                    logging.debug('Waiting for the response of hypervisors...')
@@ -220,7 +242,8 @@ class CCServer(object):
                    for resp in responses:
                        if resp['error'] is None and resp['return']:
                            hy = async_calls[resp['id']]
                            for vm_tags in resp['return']:
                            for vm_tags in conv_vm_tags(resp['return']):
                                print vm_tags
                                vm_tags['role'] = 'vm'
                                vm_tags['id'] = '%s.%s' % (hy['a'], vm_tags['vm'])
                                vm_tags.update(hy['__static_user'])