Actions related to Auto-scaling policies and Kubernetes Clusters updated 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/efd23ec9 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/efd23ec9 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/efd23ec9 Branch: refs/heads/stratos-4.1.x Commit: efd23ec91e78d1456aef77ecb4d36cb0322e65ef Parents: 96d7501 Author: Milindu Sanoj Kumarage <[email protected]> Authored: Sat Aug 8 07:26:23 2015 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Tue Oct 13 16:32:48 2015 +0530 ---------------------------------------------------------------------- .../src/main/python/cli/CLI.py | 182 ++++++++++++------- .../src/main/python/cli/Stratos.py | 50 +++-- 2 files changed, 147 insertions(+), 85 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/efd23ec9/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 b595882..dd9c70a 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 @@ -369,9 +369,11 @@ class CLI(Cmd): """ # Auto-scaling policies - * - """ + * list-autoscaling-policies + * describe-autoscaling-policy + * remove-autoscaling-policy + """ @options([ make_option('-u', '--username', type="str", help="Username of the user"), @@ -390,29 +392,54 @@ class CLI(Cmd): rows.append([autoscaling_policy['id'], "Public" if autoscaling_policy['isPublic'] else "Private"]) 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") ]) @auth - def do_list_applications(self, line , opts=None): - """Illustrate the base class method use.""" - applications = Stratos.list_applications() - if not applications: - print("No applications found") + def do_describe_autoscaling_policy(self, autoscaling_policy_id , opts=None): + """Retrieve details of a specific auto-scaling policy.""" + if not autoscaling_policy_id: + print("usage: describe-autoscaling-policy [autoscaling-policy-id]") + return + autoscaling_policy = Stratos.describe_autoscaling_policy(autoscaling_policy_id) + if not autoscaling_policy: + print("Autoscaling policy not found : "+autoscaling_policy_id) else: - table = PrintableTable() - rows = [["Type", "Category", "Name", "Description", "Version", "Multi-Tenant"]] - for application in applications: - rows.append([application['type'], application['category'], application['displayName'], - application['description'], application['version'], application['multiTenant']]) - table.add_rows(rows) - table.print_table() + print("Autoscaling policy : "+autoscaling_policy_id) + PrintableJSON(autoscaling_policy).pprint() + + @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_remove_autoscaling_policy(self, autoscaling_policy_id , opts=None): + """Delete a cartridge""" + try: + if not autoscaling_policy_id: + print("usage: remove-autoscaling-policy [application-id]") + else: + cartridge_removed = Stratos.remove_autoscaling_policy(autoscaling_policy_id) + if cartridge_removed: + print("Successfully deleted Auto-scaling policy : "+autoscaling_policy_id) + else: + print("Auto-scaling policy not found : "+autoscaling_policy_id) + except AuthenticationError as e: + self.perror("Authentication Error") + """ - # Kubernetes Cluster/Host + # Kubernetes clusters/hosts + * list-kubernetes-clusters + * describe-kubernetes-cluster + * list-kubernetes-hosts + * describe-kubernetes-master + * remove-kubernetes-cluster + * remove-kubernetes-host """ + @options([ make_option('-u', '--username', type="str", help="Username of the user"), make_option('-p', '--password', type="str", help="Password of the user") @@ -433,6 +460,22 @@ class CLI(Cmd): @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_describe_kubernetes_cluster(self, kubernetes_cluster_id, opts=None): + """Retrieve detailed information on a specific Kubernetes-CoreOS group""" + if not kubernetes_cluster_id: + print("usage: describe-kubernetes-cluster [cluster-i]]") + return + kubernetes_cluster = Stratos.describe_kubernetes_cluster(kubernetes_cluster_id) + if not kubernetes_cluster: + print("Kubernetes cluster not found") + else: + PrintableJSON(kubernetes_cluster).pprint() + + @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") ]) @@ -456,6 +499,62 @@ class CLI(Cmd): @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_describe_kubernetes_master(self, kubernetes_cluster_id , opts=None): + """Retrieve detailed information on the master node in a specific Kubernetes-CoreOS group""" + if not kubernetes_cluster_id: + print("usage: describe-kubernetes-master [cluster-id]") + return + kubernetes_master = Stratos.describe_kubernetes_master(kubernetes_cluster_id) + if not kubernetes_master: + print("Kubernetes master not found in : "+kubernetes_cluster_id) + else: + print("Cluster : "+kubernetes_cluster_id) + PrintableJSON(kubernetes_master).pprint() + + @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_remove_kubernetes_cluster(self, kubernetes_cluster_id, opts=None): + """Delete a cartridge""" + try: + if not kubernetes_cluster_id: + print("usage: remove-kubernetes-cluster [cluster-id]") + else: + cartridge_removed = Stratos.remove_autoscaling_policy(kubernetes_cluster_id) + if cartridge_removed: + print("Successfully un-deployed kubernetes cluster : "+kubernetes_cluster_id) + else: + print("Kubernetes cluster not found : "+kubernetes_cluster_id) + except AuthenticationError as e: + self.perror("Authentication Error") + + @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_applications(self, line , opts=None): + """Illustrate the base class method use.""" + applications = Stratos.list_applications() + if not applications: + print("No applications found") + else: + table = PrintableTable() + rows = [["Type", "Category", "Name", "Description", "Version", "Multi-Tenant"]] + for application in applications: + rows.append([application['type'], application['category'], application['displayName'], + application['description'], application['version'], application['multiTenant']]) + 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('-t', '--tenant_domain', type="str", help="Cluster ID") ]) @@ -491,57 +590,6 @@ class CLI(Cmd): make_option('-p', '--password', type="str", help="Password of the user") ]) @auth - def do_describe_kubernetes_cluster(self, line , opts=None): - """Retrieve detailed information on a specific Kubernetes-CoreOS group. -.""" - if not line.split(): - print("usage: describe-kubernetes-cluster [cluster-i]]") - return - kubernetes_cluster= Stratos.describe_kubernetes_cluster(line) - if not kubernetes_cluster: - print("Kubernetes cluster not found") - else: - PrintableJSON(kubernetes_cluster).pprint() - - @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_describe_kubernetes_master(self, line , opts=None): - """Retrieve detailed information on the master node in a specific Kubernetes-CoreOS group""" - if not line.split(): - print("usage: describe-kubernetes-master [cluster-id]") - return - kubernetes_master = Stratos.describe_kubernetes_master(line) - if not kubernetes_master: - print("Kubernetes master not found") - else: - PrintableJSON(kubernetes_master).pprint() - - - - @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_describe_autoscaling_policy(self, line , opts=None): - """Retrieve details of a specific auto-scaling policy.""" - if not line.split(): - print("usage: describe-autoscaling-policy [autoscaling-policy-id]") - return - autoscaling_policy = Stratos.describe_autoscaling_policy(line) - if not autoscaling_policy: - print("Network partition not found") - else: - PrintableJSON(autoscaling_policy).pprint() - - @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_describe_application_signup(self, line , opts=None): """Retrieve details of a specific auto-scaling policy.""" if not line.split(): http://git-wip-us.apache.org/repos/asf/stratos/blob/efd23ec9/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 f753c33..2555d4c 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 @@ -152,37 +152,48 @@ class Stratos: return Stratos.delete('networkPartitions/'+network_partition_id) """ - # Kubernetes Clusters + # Auto-scaling policies + * list-autoscaling-policies + * describe-autoscaling-policy + * remove-autoscaling-policy """ @staticmethod - def list_kubernetes_clusters(): - return Stratos.get('kubernetesClusters', error_message='Kubernetes cluster not found') - + def list_autoscaling_policies(): + return Stratos.get('autoscalingPolicies', + error_message='No Autoscaling policies found') @staticmethod - def list_kubernetes_hosts(kubernetes_cluster_id): - return Stratos.get('kubernetesClusters/'+kubernetes_cluster_id+'/hosts', - error_message='Kubernetes cluster not found') + def describe_autoscaling_policy(autoscaling_policy_id): + return Stratos.get('autoscalingPolicies/'+autoscaling_policy_id, + error_message='No autoscaling policy found') + @staticmethod + def remove_autoscaling_policy(autoscaling_policy_id): + return Stratos.delete('autoscalingPolicies/'+autoscaling_policy_id, error_message="Autoscaling policy not found") + """ + # Kubernetes clusters/hosts + * list-kubernetes-clusters + * describe-kubernetes-cluster + * list-kubernetes-hosts + * describe-kubernetes-master + """ @staticmethod - def list_autoscaling_policies(): - return Stratos.get('autoscalingPolicies', - error_message='No Autoscaling policies found') + def list_kubernetes_clusters(): + return Stratos.get('kubernetesClusters', error_message='Kubernetes cluster not found') @staticmethod def describe_kubernetes_cluster(kubernetes_cluster_id): return Stratos.get('kubernetesClusters/'+ kubernetes_cluster_id, error_message='No kubernetes clusters found') - + @staticmethod + def list_kubernetes_hosts(kubernetes_cluster_id): + return Stratos.get('kubernetesClusters/'+kubernetes_cluster_id+'/hosts', + error_message='Kubernetes cluster not found') @staticmethod def describe_kubernetes_master(kubernetes_cluster_id): return Stratos.get('kubernetesClusters/'+ kubernetes_cluster_id+'/master', error_message='No kubernetes clusters found') - @staticmethod - def describe_autoscaling_policy(autoscaling_policy_id): - return Stratos.get('autoscalingPolicies/'+ autoscaling_policy_id, - error_message='No autoscaling policy found') @staticmethod def describe_application_signup(application_id): @@ -208,12 +219,12 @@ class Stratos: raise AuthenticationError() elif r.status_code == 404: if r.text and r.json() and r.json()['errorMessage'] == error_message: - return [] + return False else: raise requests.HTTPError() @staticmethod - def delete(resource): + def delete(resource, error_message=None): r = requests.delete(Configs.stratos_api_url + resource, auth=(Configs.stratos_username, Configs.stratos_password), verify=False) print(r.text) @@ -224,7 +235,10 @@ class Stratos: elif r.status_code == 401: raise AuthenticationError() elif r.status_code == 404: - raise requests.HTTPError() + if r.text and r.json() and r.json()['errorMessage'] == error_message: + return [] + else: + raise requests.HTTPError() @staticmethod def post(resource, data, error_message):
