summaryrefslogtreecommitdiffstats
path: root/testapi/testapi-client/testapiclient/cli
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2018-03-09 16:35:22 +0800
committerSerenaFeng <feng.xiaowei@zte.com.cn>2018-03-09 18:06:09 +0800
commit1a95c1e6b33d9b3efcfd92e1de64feee7e9b5c68 (patch)
tree61488ece232657c6693425eabc07ad6ca4b3af8e /testapi/testapi-client/testapiclient/cli
parentcc29ae1cd41d1f403511730d5ba44dded967fb12 (diff)
restructure testapiclient project
Change-Id: I13d24ce7b436f203a66fe14f4930e58b3ab1193c Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'testapi/testapi-client/testapiclient/cli')
-rw-r--r--testapi/testapi-client/testapiclient/cli/__init__.py0
-rw-r--r--testapi/testapi-client/testapiclient/cli/auth.py14
-rw-r--r--testapi/testapi-client/testapiclient/cli/pods.py78
-rw-r--r--testapi/testapi-client/testapiclient/cli/projects.py95
4 files changed, 187 insertions, 0 deletions
diff --git a/testapi/testapi-client/testapiclient/cli/__init__.py b/testapi/testapi-client/testapiclient/cli/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/cli/__init__.py
diff --git a/testapi/testapi-client/testapiclient/cli/auth.py b/testapi/testapi-client/testapiclient/cli/auth.py
new file mode 100644
index 0000000..434c55a
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/cli/auth.py
@@ -0,0 +1,14 @@
+from testapiclient.utils import command
+from testapiclient.utils import identity
+
+
+class Auth(command.Command):
+ "Handle Authentication for users"
+
+ def get_parser(self, prog_name):
+ parser = super(Auth, self).get_parser(prog_name)
+ return parser
+
+ @identity.authenticate
+ def take_action(self, parsed_args):
+ print "Authentication has been successful!"
diff --git a/testapi/testapi-client/testapiclient/cli/pods.py b/testapi/testapi-client/testapiclient/cli/pods.py
new file mode 100644
index 0000000..cdedc3e
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/cli/pods.py
@@ -0,0 +1,78 @@
+import json
+
+from testapiclient.utils import command
+from testapiclient.utils import http_client as client
+from testapiclient.utils import identity
+from testapiclient.utils import url_parse
+
+
+def pods_url():
+ return url_parse.resource_join('pods')
+
+
+def pod_url(parsed_args):
+ return url_parse.path_join(pods_url(), parsed_args.name)
+
+
+class PodGet(command.Lister):
+ "Handle get request for pods"
+
+ def get_parser(self, prog_name):
+ parser = super(PodGet, self).get_parser(prog_name)
+ parser.add_argument('-name',
+ default='',
+ help='Search pods using name')
+ return parser
+
+ def take_action(self, parsed_args):
+ self.show(client.get(self.filter_by_name(pods_url(), parsed_args)))
+
+
+class PodGetOne(command.ShowOne):
+ "Handle get request for pod by name"
+
+ def get_parser(self, prog_name):
+ parser = super(PodGetOne, self).get_parser(prog_name)
+ parser.add_argument('name',
+ default='',
+ help='Find pod using name')
+ return parser
+
+ def take_action(self, parsed_args):
+ self.show(client.get(pod_url(parsed_args)))
+
+
+class PodCreate(command.Command):
+ "Handle post request for pods"
+
+ def get_parser(self, prog_name):
+ parser = super(PodCreate, self).get_parser(prog_name)
+ parser.add_argument('pod',
+ type=json.loads,
+ help='Pod create request format :\n'
+ '\'{"role": "", "name": "", "details": "", '
+ '"mode": ""}\',\n role should be either '
+ '"community-ci" or "production-ci", and '
+ 'mode should be either "metal" or "virtual.')
+ return parser
+
+ @identity.authenticate
+ def take_action(self, parsed_args):
+ self.show('Create',
+ client.post(pods_url(), parsed_args.pod))
+
+
+class PodDelete(command.Command):
+ "Handle delete request for pods"
+
+ def get_parser(self, prog_name):
+ parser = super(PodDelete, self).get_parser(prog_name)
+ parser.add_argument('name',
+ type=str,
+ help='Delete pods using name')
+ return parser
+
+ @identity.authenticate
+ def take_action(self, parsed_args):
+ self.show('Delete',
+ client.delete(pod_url(parsed_args)))
diff --git a/testapi/testapi-client/testapiclient/cli/projects.py b/testapi/testapi-client/testapiclient/cli/projects.py
new file mode 100644
index 0000000..f847961
--- /dev/null
+++ b/testapi/testapi-client/testapiclient/cli/projects.py
@@ -0,0 +1,95 @@
+import json
+
+from testapiclient.utils import command
+from testapiclient.utils import http_client as client
+from testapiclient.utils import identity
+from testapiclient.utils import url_parse
+
+
+def projects_url():
+ url_parse.resource_join('projects')
+
+
+def project_url(parsed_args):
+ return url_parse.path_join(projects_url(), parsed_args.name)
+
+
+class ProjectGet(command.Lister):
+
+ def get_parser(self, prog_name):
+ parser = super(ProjectGet, self).get_parser(prog_name)
+ parser.add_argument('-name',
+ default='',
+ help='Search projects by name')
+ return parser
+
+ def take_action(self, parsed_args):
+ self.show(client.get(self.filter_name(projects_url(), parsed_args)))
+
+
+class ProjectGetOne(command.ShowOne):
+
+ def get_parser(self, prog_name):
+ parser = super(ProjectGetOne, self).get_parser(prog_name)
+ parser.add_argument('-name',
+ default='',
+ required=True,
+ help='Search project by name')
+ return parser
+
+ def take_action(self, parsed_args):
+ self.show(client.get(project_url(parsed_args)))
+
+
+class ProjectCreate(command.Command):
+
+ def get_parser(self, prog_name):
+ parser = super(ProjectCreate, self).get_parser(prog_name)
+ parser.add_argument('project',
+ type=json.loads,
+ help='Project create request format :{'
+ ' "name": (required)"", '
+ '"description": (optional)""}')
+ return parser
+
+ @identity.authenticate
+ def take_action(self, parsed_args):
+ self.show('Create',
+ client.post(projects_url(), parsed_args.project))
+
+
+class ProjectDelete(command.Command):
+
+ def get_parser(self, prog_name):
+ parser = super(ProjectDelete, self).get_parser(prog_name)
+ parser.add_argument('-name',
+ type=str,
+ required=True,
+ help='Delete project by name')
+ return parser
+
+ @identity.authenticate
+ def take_action(self, parsed_args):
+ self.show('Delete',
+ client.delete(project_url(parsed_args)))
+
+
+class ProjectPut(command.Command):
+
+ def get_parser(self, prog_name):
+ parser = super(ProjectPut, self).get_parser(prog_name)
+ parser.add_argument('-name',
+ type=str,
+ required=True,
+ help='Update project by name')
+ parser.add_argument('project',
+ type=json.loads,
+ help='Project Update request format :{'
+ '"name": (required)"", '
+ '"description": (optional)""}')
+ return parser
+
+ @identity.authenticate
+ def take_action(self, parsed_args):
+ self.show('Update',
+ client.put(project_url(parsed_args), parsed_args.project))