def _get_store_snap_info(snap_name): # This logic uses /v2/find returns an array of results, given that # we do a strict search either 1 result or a 404 will be returned. slug = "find?{}".format(parse.urlencode(dict(name=snap_name))) url = get_snapd_socket_path_template().format(slug) snap_info = requests_unixsocket.get(url) snap_info.raise_for_status() return snap_info.json()["result"][0]
def _get_local_snap_info(snap_name): slug = "snaps/{}".format(parse.quote(snap_name, safe="")) url = get_snapd_socket_path_template().format(slug) try: snap_info = requests_unixsocket.get(url) except exceptions.ConnectionError as e: raise errors.SnapdConnectionError(snap_name, url) from e snap_info.raise_for_status() return snap_info.json()["result"]
def _get_local_snap_file_iter(snap_name, *, chunk_size: int): slug = "snaps/{}/file".format(parse.quote(snap_name, safe="")) url = get_snapd_socket_path_template().format(slug) try: snap_file = requests_unixsocket.get(url) except exceptions.ConnectionError as e: raise errors.SnapdConnectionError(snap_name, url) from e snap_file.raise_for_status() return snap_file.iter_content(chunk_size)
def get_installed_snaps(): """Return all the snaps installed in the system. :return: a list of "name=revision" for the snaps installed. """ slug = "snaps" url = get_snapd_socket_path_template().format(slug) try: snap_info = requests_unixsocket.get(url) snap_info.raise_for_status() local_snaps = snap_info.json()["result"] except exceptions.ConnectionError: local_snaps = [] return ["{}={}".format(snap["name"], snap["revision"]) for snap in local_snaps]
def __socket_get(self, path: str): retries = 0 while True: try: res = requests_unixsocket.get( f"http+unix://{quote(self.socket_path, safe='')}/{path}") logger.debug( f"Response from wifi-ap snap API: Status {res.status_code} / {res.text}" ) return res except ConnectionError as e: logger.error( f"Connection error while doing wifi-ap API socket GET request: {e}" ) if retries < SOCKET_RETRY_COUNT: sleep(SOCKET_RETRY_HOLDOFF) retries += 1 logger.info(f"Retrying ({retries}/{SOCKET_RETRY_COUNT})") else: raise (e)
def http_client(): url = 'http+unix://%s/' % quote(unix_socket_tcp.getsockname(), safe='') return requests_unixsocket.get(url).status_code