You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/10/13 13:06:40 UTC

[17/50] stratos git commit: Using generalized get method

Using generalized get method

Signed-off-by: Imesh Gunaratne <im...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/105ecbf7
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/105ecbf7
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/105ecbf7

Branch: refs/heads/stratos-4.1.x
Commit: 105ecbf7cbb0f6ec1919e283f6efc127f170609e
Parents: fee14ff
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Authored: Thu Jul 30 21:53:30 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Tue Oct 13 16:32:46 2015 +0530

----------------------------------------------------------------------
 .../src/main/python/cli/CLI.py                  |  2 +-
 .../src/main/python/cli/Stratos.py              | 53 +++++++++-----------
 2 files changed, 25 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/105ecbf7/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py b/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py
index fd33d55..821e47f 100755
--- a/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py
+++ b/components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py
@@ -83,7 +83,7 @@ class CLI(Cmd):
     def do_list_users(self, line , opts=None):
         """Illustrate the base class method use."""
         try:
-            users = Stratos.add_user()
+            users = Stratos.list_users()
             table = PrintableTable()
             rows = [["Name", "language"]]
             table.set_cols_align(["l", "r"])

http://git-wip-us.apache.org/repos/asf/stratos/blob/105ecbf7/components/org.apache.stratos.python.cli/src/main/python/cli/Stratos.py
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.python.cli/src/main/python/cli/Stratos.py b/components/org.apache.stratos.python.cli/src/main/python/cli/Stratos.py
index 239e806..a063f1c 100755
--- a/components/org.apache.stratos.python.cli/src/main/python/cli/Stratos.py
+++ b/components/org.apache.stratos.python.cli/src/main/python/cli/Stratos.py
@@ -11,20 +11,12 @@ class Stratos:
         pass
 
     """
-    # User Entity
+    # Users
 
     """
     @staticmethod
     def list_users():
-        r = requests.get(Configs.stratos_api_url + 'users',
-                         auth=(Configs.stratos_username, Configs.stratos_password), verify=False)
-
-        if r.status_code == 200:
-            return r.json()
-        elif r.status_code == 400:
-            raise requests.HTTPError()
-        elif r.status_code == 401:
-            raise AuthenticationError()
+        return Stratos.get('users', errorMessage='No applications found')
 
     @staticmethod
     def add_users(username, password, role_name, first_name, last_name, email, profile_name):
@@ -32,12 +24,18 @@ class Stratos:
         r = requests.post(Configs.stratos_api_url + 'users', data,
                          auth=(Configs.stratos_username, Configs.stratos_password), verify=False)
 
+    """
+    # Network Partitions
+
+    """
     @staticmethod
     def list_network_partitions():
-        r = requests.get(Configs.stratos_api_url + 'networkPartitions',
-                         auth=(Configs.stratos_username, Configs.stratos_password), verify=False)
-        return r.json()
+        return Stratos.get('networkPartitions', errorMessage='No network partitions found')
+
+    """
+    # Applications
 
+    """
     @staticmethod
     def list_applications():
         r = requests.get(Configs.stratos_api_url + 'applications',
@@ -54,7 +52,10 @@ class Stratos:
             else:
                 raise requests.HTTPError()
 
+    """
+    # Cartridges
 
+    """
     @staticmethod
     def list_cartridges():
         r = requests.get(Configs.stratos_api_url + 'cartridges',
@@ -77,30 +78,24 @@ class Stratos:
             else:
                 raise requests.HTTPError()
 
+    """
+    # Kubernetes Clusters
+
+    """
     @staticmethod
     def list_kubernetes_clusters():
-        r = requests.get(Configs.stratos_api_url + 'kubernetesClusters',
-                         auth=(Configs.stratos_username, Configs.stratos_password), verify=False)
-        if r.status_code == 200:
-            return r.json()
-        elif r.status_code == 400:
-            raise requests.HTTPError()
-        elif r.status_code == 401:
-            raise AuthenticationError()
-        elif r.status_code == 404:
-            if r.json() and r.json()['errorMessage'] == "No cartridges found":
-                return []
-            else:
-                raise requests.HTTPError()
+        return Stratos.get('kubernetesClusters', errorMessage='Kubernetes cluster not found')
 
-    @staticmethod
-    def deploy_user():
-        raise ValueError
 
+    """
+    # Utils
+
+    """
     @staticmethod
     def get(resource, errorMessage):
         r = requests.get(Configs.stratos_api_url + resource,
                          auth=(Configs.stratos_username, Configs.stratos_password), verify=False)
+        print(r.text)
         if r.status_code == 200:
             return r.json()
         elif r.status_code == 400: