Added list-kubernetes-hosts command 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/1c366d47 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/1c366d47 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/1c366d47 Branch: refs/heads/stratos-4.1.x Commit: 1c366d47f2fd2a20cebae1f5755c7f9716d102f8 Parents: 90bbb37 Author: Milindu Sanoj Kumarage <[email protected]> Authored: Sat Aug 1 22:35:23 2015 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Tue Oct 13 16:32:47 2015 +0530 ---------------------------------------------------------------------- .../src/main/python/cli/CLI.py | 24 +++++++++++++++++++- .../src/main/python/cli/Stratos.py | 6 +++-- 2 files changed, 27 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/1c366d47/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 3025f6b..6d73df7 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 @@ -188,7 +188,7 @@ class CLI(Cmd): """Retrieve detailed information on all Kubernetes-CoreOS Clusters.""" kubernetes_clusters = Stratos.list_kubernetes_clusters() if not kubernetes_clusters: - print("No Kubernetes-CoreOS clusters found") + print("No Kubernetes clusters found") else: table = PrintableTable() rows = [["Group ID", "Description"]] @@ -197,6 +197,28 @@ class CLI(Cmd): table.add_rows(rows) table.print_table() + @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('-c', '--cluster_id', type="str", help="Cluster ID") + ]) + @auth + def do_list_kubernetes_hosts(self, line , opts=None): + """Retrieve detailed information on all Kubernetes-CoreOS Clusters.""" + if not opts.cluster_id: + print("usage: list-kubernetes-hosts [-c <cluster id>]") + return + kubernetes_cluster_hosts = Stratos.list_kubernetes_hosts(opts.cluster_id) + if not kubernetes_cluster_hosts: + print("No kubernetes hosts found") + else: + table = PrintableTable() + rows = [["Host ID", "Hostname", "Private IP Address", "Public IP Address"]] + for kubernetes_cluster_host in kubernetes_cluster_hosts: + rows.append([kubernetes_cluster_host['hostId'], kubernetes_cluster_host['hostname'], kubernetes_cluster_host['privateIPAddress'], kubernetes_cluster_host['publicIPAddress']]) + table.add_rows(rows) + table.print_table() + @options([]) def do_deploy_user(self, line , opts=None): """Illustrate the base class method use.""" http://git-wip-us.apache.org/repos/asf/stratos/blob/1c366d47/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 72c1c71..af47b50 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 @@ -20,7 +20,6 @@ import Configs from cli.exceptions.AuthenticationError import AuthenticationError - class Stratos: """Apache Stratos Python API""" @@ -103,6 +102,10 @@ class Stratos: def list_kubernetes_clusters(): return Stratos.get('kubernetesClusters', errorMessage='Kubernetes cluster not found') + @staticmethod + def list_kubernetes_hosts(kubernetes_cluster_id): + return Stratos.get('kubernetesClusters/'+kubernetes_cluster_id+'/hosts', errorMessage='Kubernetes cluster not found') + """ # Utils @@ -112,7 +115,6 @@ class Stratos: 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:
