Пример #1
0
def append_lm(uri,
              key=None,
              makey=None,
              mqtt_update=None,
              ssl_verify=True,
              timeout=None,
              save=False,
              static=True):
    api = eva.client.coreapiclient.CoreAPIClient()
    api.set_product('lm')
    if key is not None:
        api.set_key(eva.apikey.format_key(key))
    if timeout is not None:
        try:
            t = float(timeout)
        except:
            return False
        api.set_timeout(t)
    else:
        api.set_timeout(eva.core.config.timeout / 2)
    uport = ''
    if uri.startswith('http://') or uri.startswith('https://'):
        if uri.count(':') == 1 and uri.count('/') == 2:
            uport = ':8817'
    else:
        if uri.find(':') == -1 and uri.find('/') == -1:
            uport = ':8817'
    api.set_uri(uri + uport)
    mqu = mqtt_update
    if mqu is None:
        mqu = eva.core.config.mqtt_update_default
    u = eva.client.remote_controller.RemoteLM(None,
                                              api=api,
                                              mqtt_update=mqu,
                                              static=static)
    u._key = key
    if makey:
        u.set_prop('masterkey', makey)
    if not lm_pool.append(u):
        return False
    if not controller_lock.acquire(timeout=eva.core.config.timeout):
        logging.critical('controller_lock locking broken')
        eva.core.critical()
        return
    try:
        remote_lms[u.item_id] = u
    finally:
        controller_lock.release()
    u.config_changed = True
    if save:
        u.save()
    logging.info('controller %s added to pool' % u.full_id)
    return u
Пример #2
0
def append_controller(uri,
                      key=None,
                      mqtt_update=None,
                      ssl_verify=True,
                      timeout=None,
                      save=False,
                      static=True):
    api = eva.client.coreapiclient.CoreAPIClient()
    api.set_product('uc')
    if key is not None: api.set_key(eva.apikey.format_key(key))
    if timeout is not None:
        try:
            t = float(timeout)
        except:
            return False
        api.set_timeout(t)
    else:
        api.set_timeout(eva.core.config.timeout)
    uport = ''
    if uri.startswith('http://') or uri.startswith('https://'):
        if uri.count(':') == 1 and uri.count('/') == 2:
            uport = ':8812'
    else:
        if uri.find(':') == -1 and uri.find('/') == -1:
            uport = ':8812'
    api.set_uri(uri + uport)
    mqu = mqtt_update
    if mqu is None: mqu = eva.core.config.mqtt_update_default
    u = eva.lm.lremote.LRemoteUC(None, api=api, mqtt_update=mqu, static=static)
    u._key = key
    if not uc_pool.append(u): return False
    controller_lock.acquire()
    try:
        remote_ucs[u.item_id] = u
    finally:
        controller_lock.release()
    if save: u.save()
    logging.info('controller %s added to pool' % u.item_id)
    return u