diff --git a/riocli/v2client/client.py b/riocli/v2client/client.py index 44d5ac39..dfbf1ced 100644 --- a/riocli/v2client/client.py +++ b/riocli/v2client/client.py @@ -20,20 +20,14 @@ from hashlib import md5 from typing import List, Optional, Dict, Any -import click import magic import requests from munch import munchify, Munch from rapyuta_io.utils.rest_client import HttpMethod, RestClient from riocli.v2client.enums import DeploymentPhaseConstants -from riocli.v2client.error import RetriesExhausted, DeploymentNotRunning, ImagePullError - - -class DeploymentNotFound(Exception): - def __init__(self, message='deployment not found!'): - self.message = message - super().__init__(self.message) +from riocli.v2client.error import (RetriesExhausted, DeploymentNotRunning, ImagePullError, + NetworkNotFound) def handle_server_errors(response: requests.Response): @@ -58,12 +52,6 @@ def handle_server_errors(response: requests.Response): raise Exception('unknown server error') -class NetworkNotFound(Exception): - def __init__(self, message='network not found!'): - self.message = message - super().__init__(self.message) - - class Client(object): """ v2 API Client @@ -738,7 +726,7 @@ def list_packages( List all packages in a project """ url = "{}/v2/packages/".format(self._host) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = {} params.update(query or {}) @@ -766,7 +754,7 @@ def create_package(self, payload: dict) -> Munch: Create a new package """ url = "{}/v2/packages/".format(self._host) - headers = self._config.get_auth_header() + headers = self._get_auth_header() response = RestClient(url).method(HttpMethod.POST).headers( headers).execute(payload=payload) handle_server_errors(response) @@ -787,7 +775,7 @@ def get_package( List all packages in a project """ url = "{}/v2/packages/{}/".format(self._host, name) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = {} params.update(query or {}) @@ -807,7 +795,7 @@ def delete_package(self, package_name: str, Delete a secret """ url = "{}/v2/packages/{}/".format(self._host, package_name) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = {} params.update(query or {}) @@ -831,7 +819,7 @@ def list_networks( List all networks in a project """ url = "{}/v2/networks/".format(self._host) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = {} params.update(query or {}) @@ -859,7 +847,7 @@ def create_network(self, payload: dict) -> Munch: Create a new network """ url = "{}/v2/networks/".format(self._host) - headers = self._config.get_auth_header() + headers = self._get_auth_header() response = RestClient(url).method(HttpMethod.POST).headers( headers).execute(payload=payload) handle_server_errors(response) @@ -880,7 +868,7 @@ def get_network( get a network in a project """ url = "{}/v2/networks/{}/".format(self._host, name) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = {} params.update(query or {}) @@ -904,7 +892,7 @@ def delete_network(self, network_name: str, Delete a secret """ url = "{}/v2/networks/{}/".format(self._host, network_name) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = {} params.update(query or {}) @@ -928,7 +916,7 @@ def list_deployments( List all deployments in a project """ url = "{}/v2/deployments/".format(self._host) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = { "continue": 0, @@ -957,7 +945,7 @@ def create_deployment(self, deployment: dict) -> Munch: Create a new deployment """ url = "{}/v2/deployments/".format(self._host) - headers = self._config.get_auth_header() + headers = self._get_auth_header() deployment["metadata"]["projectGUID"] = headers["project"] response = RestClient(url).method(HttpMethod.POST).headers( @@ -976,7 +964,7 @@ def get_deployment( query: dict = None ): url = "{}/v2/deployments/{}/".format(self._host, name) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = {} params.update(query or {}) @@ -999,7 +987,7 @@ def update_deployment(self, name: str, dep: dict) -> Munch: Update a deployment """ url = "{}/v2/deployments/{}/".format(self._host, name) - headers = self._config.get_auth_header() + headers = self._get_auth_header() response = RestClient(url).method(HttpMethod.PATCH).headers( headers).execute(payload=dep) handle_server_errors(response) @@ -1015,7 +1003,7 @@ def delete_deployment(self, name: str, query: dict = None) -> Munch: Delete a deployment """ url = "{}/v2/deployments/{}/".format(self._host, name) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = {} params.update(query or {}) response = RestClient(url).method( @@ -1070,7 +1058,7 @@ def list_disks( List all disks in a project """ url = "{}/v2/disks/".format(self._host) - headers = self._config.get_auth_header() + headers = self._get_auth_header() params = {} params.update(query or {}) @@ -1098,7 +1086,7 @@ def get_disk(self, name: str) -> Munch: Get a Disk by its name """ url = "{}/v2/disks/{}/".format(self._host, name) - headers = self._config.get_auth_header() + headers = self._get_auth_header() response = RestClient(url).method( HttpMethod.GET).headers(headers).execute() @@ -1116,7 +1104,7 @@ def create_disk(self, disk: dict) -> Munch: Create a new disk """ url = "{}/v2/disks/".format(self._host) - headers = self._config.get_auth_header() + headers = self._get_auth_header() response = RestClient(url).method(HttpMethod.POST).headers( headers).execute(payload=disk) @@ -1134,7 +1122,7 @@ def delete_disk(self, name: str) -> Munch: Delete a disk by its name """ url = "{}/v2/disks/{}/".format(self._host, name) - headers = self._config.get_auth_header() + headers = self._get_auth_header() response = RestClient(url).method( HttpMethod.DELETE).headers(headers).execute() diff --git a/riocli/v2client/error.py b/riocli/v2client/error.py index bef94764..145b9214 100644 --- a/riocli/v2client/error.py +++ b/riocli/v2client/error.py @@ -1,4 +1,3 @@ - class RetriesExhausted(Exception): def __init__(self, msg=None): Exception.__init__(self, msg) @@ -8,6 +7,19 @@ class DeploymentNotRunning(Exception): def __init__(self, msg=None): Exception.__init__(self, msg) + class ImagePullError(Exception): def __init__(self, msg=None): - Exception.__init__(self, msg) \ No newline at end of file + Exception.__init__(self, msg) + + +class NetworkNotFound(Exception): + def __init__(self, message='network not found!'): + self.message = message + super().__init__(self.message) + + +class DeploymentNotFound(Exception): + def __init__(self, message='deployment not found!'): + self.message = message + super().__init__(self.message)