Added set of listing actions

Signed-off-by: Imesh Gunaratne <[email protected]>


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

Branch: refs/heads/stratos-4.1.x
Commit: fee14ff037f961806aeaa8e8a23d16bf43cba6b9
Parents: c8892d9
Author: Milindu Sanoj Kumarage <[email protected]>
Authored: Thu Jul 30 21:39:24 2015 +0530
Committer: Imesh Gunaratne <[email protected]>
Committed: Tue Oct 13 16:32:46 2015 +0530

----------------------------------------------------------------------
 .../src/main/python/cli/CLI.py                  | 61 ++++++++++++++++++--
 .../src/main/python/cli/Stratos.py              | 44 ++++++++++++++
 2 files changed, 100 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/fee14ff0/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 deaf90c..fd33d55 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
@@ -48,7 +48,32 @@ class CLI(Cmd):
         table.add_rows(rows)
         table.print_table()
 
+    """
+    # User Entity
 
+    """
+
+    @options([
+        make_option('-u', '--username', type="str", help="Username of the 
user"),
+        make_option('-p', '--password', type="str", help="Password of the 
user"),
+        make_option('-r', '--role_name', type="str", help="Role name of the 
user"),
+        make_option('-f', '--first_name', type="str", help="First name of the 
user"),
+        make_option('-l', '--last_name', type="str", help="Last name of the 
user"),
+        make_option('-e', '--email', type="str", help="Email of the user"),
+        make_option('-x', '--profile_name', type="str", help="Profile name of 
the user")
+    ])
+    @auth
+    def do_add_user(self, line , opts=None):
+        """Add a new user to the system"""
+        try:
+            user = Stratos.list_users(opts.username, opts.password, 
opts.role_name, opts.first_name, opts.last_name,
+                                       opts.email, opts.profile_name)
+            if user:
+                print("User successfully created")
+            else:
+                print("Error creating the user")
+        except AuthenticationError as e:
+            self.perror("Authentication Error")
 
     @options([
         make_option('-u', '--username', type="str", help="Username of the 
user"),
@@ -58,7 +83,7 @@ class CLI(Cmd):
     def do_list_users(self, line , opts=None):
         """Illustrate the base class method use."""
         try:
-            users = Stratos.list_users()
+            users = Stratos.add_user()
             table = PrintableTable()
             rows = [["Name", "language"]]
             table.set_cols_align(["l", "r"])
@@ -68,7 +93,8 @@ class CLI(Cmd):
             table.add_rows(rows)
             table.print_table()
         except AuthenticationError as e:
-            self.perror("sdc")
+            self.perror("Authentication Error")
+
 
     @options([
         make_option('-u', '--username', type="str", help="Username of the 
user"),
@@ -77,9 +103,13 @@ class CLI(Cmd):
     @auth
     def do_list_network_partitions(self, line , opts=None):
         """Illustrate the base class method use."""
-        repositories = Stratos.list_network_partitions()
-        tree = PrintableTree(repositories)
-        tree.print_tree()
+        network_partitions = Stratos.list_network_partitions()
+        table = PrintableTable()
+        rows = [["Network Partition ID", "Number of Partitions"]]
+        for network_partition in network_partitions:
+            rows.append([network_partition['id'], 
len(network_partition['partitions'])])
+        table.add_rows(rows)
+        table.print_table()
 
     @options([
         make_option('-u', '--username', type="str", help="Username of the 
user"),
@@ -128,6 +158,27 @@ class CLI(Cmd):
                 rows.append([application['type'], application['category'], 
application['displayName'], application['description'], application['version'], 
application['multiTenant']])
             table.add_rows(rows)
             table.print_table()
+    """
+    # Kubernetes Cluster/Host
+
+    """
+    @options([
+        make_option('-u', '--username', type="str", help="Username of the 
user"),
+        make_option('-p', '--password', type="str", help="Password of the 
user")
+    ])
+    @auth
+    def do_list_kubernetes_clusters(self, line , opts=None):
+        """Retrieve detailed information on all Kubernetes-CoreOS Clusters."""
+        kubernetes_clusters = Stratos.list_kubernetes_clusters()
+        if not kubernetes_clusters:
+            print("No Kubernetes-CoreOS clusters found")
+        else:
+            table = PrintableTable()
+            rows = [["Group ID", "Description"]]
+            for kubernetes_cluster in kubernetes_clusters:
+                rows.append([kubernetes_cluster['clusterId'], 
kubernetes_cluster['description']])
+            table.add_rows(rows)
+            table.print_table()
 
     @options([])
     def do_deploy_user(self, line , opts=None):

http://git-wip-us.apache.org/repos/asf/stratos/blob/fee14ff0/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 494bc21..239e806 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
@@ -10,6 +10,10 @@ class Stratos:
     def __init__(self):
         pass
 
+    """
+    # User Entity
+
+    """
     @staticmethod
     def list_users():
         r = requests.get(Configs.stratos_api_url + 'users',
@@ -23,6 +27,12 @@ class Stratos:
             raise AuthenticationError()
 
     @staticmethod
+    def add_users(username, password, role_name, first_name, last_name, email, 
profile_name):
+        data = [username]
+        r = requests.post(Configs.stratos_api_url + 'users', data,
+                         auth=(Configs.stratos_username, 
Configs.stratos_password), verify=False)
+
+    @staticmethod
     def list_network_partitions():
         r = requests.get(Configs.stratos_api_url + 'networkPartitions',
                          auth=(Configs.stratos_username, 
Configs.stratos_password), verify=False)
@@ -68,7 +78,41 @@ class Stratos:
                 raise requests.HTTPError()
 
     @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()
+
+    @staticmethod
     def deploy_user():
         raise ValueError
 
+    @staticmethod
+    def get(resource, errorMessage):
+        r = requests.get(Configs.stratos_api_url + resource,
+                         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'] == errorMessage:
+                return []
+            else:
+                raise requests.HTTPError()
+
+
+
 

Reply via email to