def configure(hub_host, user='******', pwd='1q2w3e', use_tls=False, port=8440, aps_host=None, aps_port=6308, use_tls_aps=True): if not aps_host: aps_host = hub_host use_tls = use_tls in ('Yes', 'True', '1') hub = osaapi.OSA(host=hub_host, user=user, password=pwd, ssl=use_tls, port=port) try: hub_version = Hub._get_hub_version(hub) print("Connectivity with Hub RPC API [ok]") Hub._assert_supported_version(hub_version) print("Hub version {}".format(hub_version)) aps_url = '{}://{}:{}'.format('https' if use_tls_aps else 'http', aps_host, aps_port) aps = APS(Hub._get_user_token(hub, 1), aps_url) response = aps.get('aps/2/applications/') response.raise_for_status() print("Connectivity with Hub APS API [ok]") except Exception as e: print("Unable to communicate with hub {}, error: {}".format(hub_host, e)) sys.exit(1) else: with open(CFG_FILE_PATH, 'w+') as cfg: cfg.write(json.dumps({'host': hub_host, 'user': user, 'password': pwd, 'ssl': use_tls, 'port': port, 'aps_port': aps_port, 'aps_host': aps_host, 'use_tls_aps': use_tls_aps}, indent=4)) print("Config saved [{}]".format(CFG_FILE_PATH))
def init_hub(self, hub_host, user='******', pwd='1q2w3e', use_tls=False, port=8440, aps_host=None, aps_port=6308, use_tls_aps=True): """ Connect your Odin Automation Hub""" if not aps_host: aps_host = hub_host use_tls = use_tls in ('Yes', 'True', '1') hub = osaapi.OSA(host=hub_host, user=user, password=pwd, ssl=use_tls, port=port) try: hub_version = _get_hub_version(hub) print("Connectivity with Hub RPC API [ok]") _assert_hub_version(hub_version) print("Hub version {}".format(hub_version)) response = request('GET', '{}/{}'.format( _get_aps_url(aps_host, aps_port, use_tls_aps), 'aps/2/applications/'), headers=_get_user_token(hub, user), verify=False) response.raise_for_status() print("Connectivity with Hub APS API [ok]") except Exception as e: print("Unable to communicate with hub {}, error: {}".format( hub_host, e)) sys.exit(1) with open(CFG_FILE_PATH, 'w+') as cfg: cfg.write( json.dumps( { 'host': hub_host, 'user': user, 'password': pwd, 'ssl': use_tls, 'port': port, 'aps_port': aps_port, 'aps_host': aps_host, 'use_tls_aps': use_tls_aps }, indent=4)) print("Config saved [{}]".format(CFG_FILE_PATH))
def __init__(self): config = get_config() self.osaapi = osaapi.OSA(**{k: config[k] for k in RPC_CONNECT_PARAMS}) self.aps = APS(self.get_admin_token()) self.hub_id = self._get_id()
def _get_hub(): return osaapi.OSA(**{k: _get_cfg()[k] for k in RPC_CONNECT_PARAMS})