impl import-testapiclient framework 37/56137/4
authorSerenaFeng <feng.xiaowei@zte.com.cn>
Fri, 20 Apr 2018 09:41:19 +0000 (17:41 +0800)
committerSerenaFeng <feng.xiaowei@zte.com.cn>
Mon, 23 Apr 2018 01:46:29 +0000 (09:46 +0800)
the usage:

from testapiclient.client import pods

pod_client = pods.PodsClient(user='test', password='pass')
pod_client.create({'name': 'test-api', 'mode':'metal',
                   'role':'community_ci', 'details':''}

from testapiclient.client import pods
from testapiclient.models import pods as pm

pod_client = pods.PodsClient(user='test', password='pass')
pod = pm.Pods(name='test')
pod_client.create(pod.__dict__)

Change-Id: I6a7770d0b54f5570552a6ebbf1c42a638723997c
Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
testapi/testapi-client/testapiclient/cli/pods.py
testapi/testapi-client/testapiclient/client/__init__.py [new file with mode: 0644]
testapi/testapi-client/testapiclient/client/base.py [new file with mode: 0644]
testapi/testapi-client/testapiclient/client/pods.py [new file with mode: 0644]
testapi/testapi-client/testapiclient/models/__init__.py [new file with mode: 0644]
testapi/testapi-client/testapiclient/models/pods.py [new file with mode: 0644]

index 8d0970b..df63737 100644 (file)
@@ -1,5 +1,6 @@
 import json
 
+from testapiclient.client import pods
 from testapiclient.utils import command
 from testapiclient.utils import urlparse
 
@@ -67,8 +68,8 @@ class PodCreate(command.ShowOne):
         return parser
 
     def take_action(self, parsed_args):
-        return self.format_output(
-            self.app.client_manager.post(pods_url(), parsed_args.pod))
+        client = pods.PodsClient(client_manager=self.app.client_manager)
+        return self.format_output(client.create(parsed_args.pod))
 
 
 class PodDelete(command.Command):
diff --git a/testapi/testapi-client/testapiclient/client/__init__.py b/testapi/testapi-client/testapiclient/client/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/testapi/testapi-client/testapiclient/client/base.py b/testapi/testapi-client/testapiclient/client/base.py
new file mode 100644 (file)
index 0000000..c45c9b7
--- /dev/null
@@ -0,0 +1,23 @@
+from testapiclient.utils import clientmanager
+from testapiclient.utils import urlparse
+
+
+class AuthOption(object):
+    def __init__(self, user=None, password=None):
+        self.u = user
+        self.p = password
+
+
+class Client(object):
+
+    resource = ''
+
+    def __init__(self, user=None, password=None, client_manager=None):
+        self.url = urlparse.resource_join(self.resource)
+        if client_manager:
+            self.clientmanager = client_manager
+        else:
+            self.clientmanager = clientmanager.ClientManager(
+                AuthOption(user, password))
+            if self.clientmanager.auth_required:
+                self.clientmanager.auth()
diff --git a/testapi/testapi-client/testapiclient/client/pods.py b/testapi/testapi-client/testapiclient/client/pods.py
new file mode 100644 (file)
index 0000000..4254da7
--- /dev/null
@@ -0,0 +1,11 @@
+from testapiclient.client import base
+
+
+class PodsClient(base.Client):
+    resource = 'pods'
+
+    def __init__(self, **kwargs):
+        super(PodsClient, self).__init__(**kwargs)
+
+    def create(self, pod_req):
+        return self.clientmanager.post(self.url, pod_req)
diff --git a/testapi/testapi-client/testapiclient/models/__init__.py b/testapi/testapi-client/testapiclient/models/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/testapi/testapi-client/testapiclient/models/pods.py b/testapi/testapi-client/testapiclient/models/pods.py
new file mode 100644 (file)
index 0000000..27ea311
--- /dev/null
@@ -0,0 +1,6 @@
+class PodCreateRequest(object):
+    def __init__(self, name='', mode='', details='', role=""):
+        self.name = name
+        self.mode = mode
+        self.details = details
+        self.role = role