def _join(client, network): """Join the given network. Args: client (two1.server.rest_client.TwentyOneRestClient) an object for sending authenticated requests to the TwentyOne backend network (str): the name of the network being joined. Defaults to 21market Raises: ServerRequestError: if server returns an error code other than 401 """ try: # ensures the zerotier daemon is running zerotier.start_daemon() zt_device_address = zerotier.device_address() response = client.join(network, zt_device_address) if response.ok: network_id = response.json().get("networkid") zerotier.join_network(network_id) logger.info( uxstring.UxString.successful_join.format( click.style(network, fg="magenta"))) return {'joined': True} except exceptions.ServerRequestError as e: if e.status_code == 400: logger.info(uxstring.UxString.invalid_network) return {'joined': False, 'reason': 'invalid network'} else: raise e except subprocess.CalledProcessError as e: logger.info(str(e)) return {'joined': False, 'reason': str(e)}
def _join(client, network): """Join the given network. Args: client (two1.server.rest_client.TwentyOneRestClient) an object for sending authenticated requests to the TwentyOne backend network (str): the name of the network being joined. Defaults to 21market Raises: ServerRequestError: if server returns an error code other than 401 """ try: # ensures the zerotier daemon is running zerotier.start_daemon() zt_device_address = zerotier.device_address() response = client.join(network, zt_device_address) if response.ok: network_id = response.json().get("networkid") zerotier.join_network(network_id) logger.info(uxstring.UxString.successful_join.format(click.style(network, fg="magenta"))) return {'joined': True} except exceptions.ServerRequestError as e: if e.status_code == 400: logger.info(uxstring.UxString.invalid_network) return {'joined': False, 'reason': 'invalid network'} else: raise e except subprocess.CalledProcessError as e: logger.info(str(e)) return {'joined': False, 'reason': str(e)}
def test_join_network(mock_cli, network_id, outcome): """ Ensures that a ValueError is reaised on invalid id """ if isinstance(outcome, str): mock_cli.return_value = outcome assert zerotier.join_network(network_id) == outcome else: with pytest.raises(outcome): zerotier.join_network(network_id)
def connect_market(self, client, network): """ Connect to the 21market network. """ try: zt_device_address = zerotier.device_address() response = client.join(network, zt_device_address) if response.ok: network_id = response.json().get("networkid") zerotier.join_network(network_id) except exceptions.ServerRequestError as e: if e.status_code == 400: logger.info(uxstring.UxString.invalid_network) else: raise e except subprocess.CalledProcessError as e: logger.info(str(e))
def connect_market(self, client, network): """ Connect to the 21market network. Args: client: Client to join network network: Network to join """ try: zt_device_address = zerotier.device_address() response = client.join(network, zt_device_address) if response.ok: network_id = response.json().get("networkid") zerotier.join_network(network_id) except exceptions.ServerRequestError as e: if e.status_code == 400: logger.info(uxstring.UxString.invalid_network) else: raise e except subprocess.CalledProcessError as e: logger.info(str(e))
def connect_market(self, client, network): """ Connect to the 21market network. Args: client: Client to join network network: Network to join """ try: zt_device_address = zerotier.device_address() response = client.join(network, zt_device_address) if response.ok: network_id = response.json().get("networkid") zerotier.join_network(network_id) if self.wait_for_zt_confirmation(): pass except exceptions.ServerRequestError as e: if e.status_code == 400: logger.info(uxstring.UxString.invalid_network) else: raise e except subprocess.CalledProcessError as e: logger.info(str(e)) time.sleep(10) # wait for interface to come up