From 9307fa18848bb4628a2e0f5d8251a9b414f39f21 Mon Sep 17 00:00:00 2001 From: Scott Hussey Date: Mon, 3 Jul 2017 15:03:22 -0500 Subject: [PATCH] WIP - Drydock client and Drydock CLI --- drydock_provisioner/cli/__init__.py | 13 +++ drydock_provisioner/cli/commands.py | 49 ++++++++++ .../drydock_client/.client.py.swp | Bin 0 -> 12288 bytes .../drydock_client/__init__.py | 0 drydock_provisioner/drydock_client/client.py | 88 ++++++++++++++++++ drydock_provisioner/drydock_client/session.py | 26 ++++++ 6 files changed, 176 insertions(+) create mode 100644 drydock_provisioner/cli/__init__.py create mode 100644 drydock_provisioner/cli/commands.py create mode 100644 drydock_provisioner/drydock_client/.client.py.swp create mode 100644 drydock_provisioner/drydock_client/__init__.py create mode 100644 drydock_provisioner/drydock_client/client.py create mode 100644 drydock_provisioner/drydock_client/session.py diff --git a/drydock_provisioner/cli/__init__.py b/drydock_provisioner/cli/__init__.py new file mode 100644 index 00000000..f10bbbf6 --- /dev/null +++ b/drydock_provisioner/cli/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2017 AT&T Intellectual Property. All other rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/drydock_provisioner/cli/commands.py b/drydock_provisioner/cli/commands.py new file mode 100644 index 00000000..482071f1 --- /dev/null +++ b/drydock_provisioner/cli/commands.py @@ -0,0 +1,49 @@ +# Copyright 2017 AT&T Intellectual Property. All other rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import os + +import click + +@click.group() +@click.option('--debug/--no-debug', default=False) +@click.option('--token') +@click.option('--url') +@click.pass_context +def drydock(ctx, debug, token, url): + ctx.obj['DEBUG'] = debug + + if not token: + ctx.obj['TOKEN'] = os.environ['DD_TOKEN'] + else: + ctx.obj['TOKEN'] = token + + if not url: + ctx.obj['URL'] = os.environ['DD_URL'] + else: + ctx.obj['URL'] = url + +@drydock.group() +def create(): + pass + +@drydock.group() +def list() + pass + +@drydock.group() +def show(): + pass + +@create.command() +def design \ No newline at end of file diff --git a/drydock_provisioner/drydock_client/.client.py.swp b/drydock_provisioner/drydock_client/.client.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..9889eefc9c4cba2d436b77617dc5dd2d7f97d22a GIT binary patch literal 12288 zcmeHN&yO2P6|Sr{Ss)3Z<+Pk$9EHp%j_nC60!9Wo$&eVr%xLT+8w6P8?y_Aw?e3;DlId5fXwE5)yo`y4vGRyg|wZ1-hiq z)!p^#y;t9R^{PkHgU0R7m+5ltd4cv(A^vjkmAj|DdqVu?IU&sW(;JsIc;L}3m%Dgd zXLc&1E6Kt8h`*c*)1uwHV>0vuju<}mh5YzlUQYoXF;S@Z0mVfOXu&S zzkFOWP%`i+22P7lUfO7|#M#Oj`q;C#9wl6kl?;>&lnj&%lnj&%lnj&%lnj&%{EsnU z(_`Wltm!Ggt`~fN>`3o#%dTXgWT0fAWT0fAWT0fAWT0fAWT0fAWT0fAWZ(&8K!!s6 z6o33To`&=I|9|oK|1Ulw#LoZ&G=LMp)4*FF7UH+SJ>WX<&(lKu9QYpaZD0-@06m}! zd1)&3ET(13A_q?4frbXdEj%v$ARa7KZD2jfS&+A27Um1AD99Azy{#Begbo) zbou|70YVGaQ23q#e7$2;-%7K$W>hq+V$|qS+}B~1_-S7T7N7A{DNaJwAL_`ethI&j zde)oRW@ykx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ock_client/__init__.py b/drydock_provisioner/drydock_client/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/drydock_provisioner/drydock_client/client.py b/drydock_provisioner/drydock_client/client.py new file mode 100644 index 00000000..d0ddce3b --- /dev/null +++ b/drydock_provisioner/drydock_client/client.py @@ -0,0 +1,88 @@ +# Copyright 2017 AT&T Intellectual Property. All other rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import json +import requests + +from .session import DrydockSession + +class DrydockClient(object): + """" + A client for the Drydock API + + :param string host: Hostname or IP address of Drydock API + :param string port: Port number of Drydock API + :param string version: API version to access + :param string token: Authentication token to use + :param string marker: (optional) External marker to include with requests + """ + + def __init__(self, host=None, port=9000, version='1.0', token=None, marker=None): + self.version = version + self.session = DrydockSession(token=token, ext_marker=marker) + self.base_url = "http://%s:%d/api/%s/" % (host, port, version) + + def send_get(self, api_url, query=None): + """ + Send a GET request to Drydock. + + :param string api_url: The URL string following the hostname and API prefix + :param dict query: A dict of k, v pairs to add to the query string + :return: A requests.Response object + """ + resp = requests.get(self.base_url + api_url, params=query) + + return resp + + def send_post(self, api_url, query=None, body=None, data=None): + """ + Send a POST request to Drydock. If both body and data are specified, + body will will be used. + + :param string api_url: The URL string following the hostname and API prefix + :param dict query: A dict of k, v parameters to add to the query string + :param string body: A string to use as the request body. Will be treated as raw + :param data: Something json.dumps(s) can serialize. Result will be used as the request body + :return: A requests.Response object + """ + + if body is not None: + resp = requests.post(self.base_url + api_url, params=query, data=body) + else: + resp = requests.post(self.base_url + api_url, params=query, json=data) + + return resp + + def get_designs(self): + """ + Get list of Drydock design_ids + + :return: A list of string design_ids + """ + + def get_design(self, design_id): + + def create_design(self): + + def get_parts(self, design_id): + + def get_part(self, design_id, kind, key): + + def load_parts(self, design_id, yaml_string=None): + + def get_tasks(self): + + def get_task(self, task_id): + + def create_task(self, design_id, task_action, node_filter=None): + diff --git a/drydock_provisioner/drydock_client/session.py b/drydock_provisioner/drydock_client/session.py new file mode 100644 index 00000000..a93c2351 --- /dev/null +++ b/drydock_provisioner/drydock_client/session.py @@ -0,0 +1,26 @@ +# Copyright 2017 AT&T Intellectual Property. All other rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +class DrydockSession(object) + """ + A session to the Drydock API maintaining credentials and API options + + :param string token: Auth token + :param string marker: (optional) external context marker + """ + + def __init__(self, token=None, marker=None): + self.token = token + self.marker = marker +