Пример #1
0
def add_tag(tag):
    try:
        if validate_tag(tag):
            if r_server.sadd('controllers', tag['controller_ip']):
                print('Added a new controller')
            if r_server.sadd('tags:%s' % tag['controller_ip'], tag['name']):
                r_server.hset('tag:%s:%s' % (tag['controller_ip'], tag['name']), 'address', tag['address'])
                r_server.hset('tag:%s:%s' % (tag['controller_ip'], tag['name']), 'type', tag['type'])
                r_server.hset('tag:%s:%s' % (tag['controller_ip'], tag['name']), 'controller_ip', tag['controller_ip'])
                return True
        return False
    except RedisError:
        return False
Пример #2
0
def update_tag(tag):
    try:
        if validate_tag(tag):
            if not r_server.sadd('tags:%s' % tag['controller_ip'], tag['name']):
                r_server.hset('tag:%s:%s' % (tag['controller_ip'], tag['name']), 'address', tag['address'])
                r_server.hset('tag:%s:%s' % (tag['controller_ip'], tag['name']), 'type', tag['type'])
                r_server.hset('tag:%s:%s' % (tag['controller_ip'], tag['name']), 'controller_ip', tag['controller_ip'])
                return True
        return False
    except RedisError:
        return False
Пример #3
0
def create(serial_number, model):
    if r_server.sadd('installations', serial_number):
        return r_server.hset('installation:%s' % serial_number, 'model', model)
    return False