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:07:01 UTC
[38/50] stratos git commit: added describe-* type commands and list-*
type commands
added describe-* type commands and list-* type commands
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/cf49abcc
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/cf49abcc
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/cf49abcc
Branch: refs/heads/stratos-4.1.x
Commit: cf49abcc7c073fe72ea5c8851f98973bb10ce603
Parents: f5e61ea
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Authored: Thu Aug 6 10:17:41 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Tue Oct 13 16:32:48 2015 +0530
----------------------------------------------------------------------
.../src/main/python/cli/CLI.py | 151 ++++++++++++++++++-
.../src/main/python/cli/Stratos.py | 83 ++++++++--
2 files changed, 215 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/cf49abcc/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 b91ba4b..cd9ccb1 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
@@ -38,7 +38,11 @@ class CLI(Cmd):
# resolving the '-' issue
return [a[3:].replace('_', '-') for a in self.get_names() if a.replace('_', '-').startswith('do-'+text)]
+ """
+
+ Stratos CLI specific methods
+ """
@options([
make_option('-u', '--username', type="str", help="Username of the user"),
@@ -153,13 +157,16 @@ class CLI(Cmd):
def do_list_cartridge_groups(self, line , opts=None):
"""Illustrate the base class method use."""
cartridge_groups = Stratos.list_cartridge_groups()
- table = PrintableTable()
- rows = [["Name", "No. of cartridges", "No of groups", "Dependency scaling"]]
- for cartridge_group in cartridge_groups:
- rows.append([cartridge_group['name'], len(cartridge_group['cartridges']),
- len(cartridge_group['cartridges']), cartridge_group['groupScalingEnabled']])
- table.add_rows(rows)
- table.print_table()
+ if not cartridge_groups:
+ print("No cartrige groups found")
+ else:
+ table = PrintableTable()
+ rows = [["Name", "No. of cartridges", "No of groups", "Dependency scaling"]]
+ for cartridge_group in cartridge_groups:
+ rows.append([cartridge_group['name'], len(cartridge_group['cartridges']),
+ len(cartridge_group['cartridges']), len(cartridge_group['dependencies'])])
+ table.add_rows(rows)
+ table.print_table()
@options([
make_option('-u', '--username', type="str", help="Username of the user"),
@@ -246,6 +253,7 @@ class CLI(Cmd):
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."""
@@ -291,3 +299,132 @@ 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_describe_cartridge(self, line , opts=None):
+ """Retrieve details of a specific cartridge."""
+ print(line)
+ cartridge = Stratos.describe_cartridge(line)
+ if not cartridge:
+ print("Cartridge not found")
+ else:
+ print("""
+-------------------------------------
+Cartridge Information:
+-------------------------------------""")
+
+ print("Type: "+cartridge[0]['type'])
+ print("Category: "+cartridge[0]['category'])
+ print("Name: "+cartridge[0]['displayName'])
+ print("Description: "+cartridge[0]['description'])
+ print("Version: "+str(cartridge[0]['version']))
+ print("Multi-Tenant: "+str(cartridge[0]['multiTenant']))
+ print("Host Name: "+cartridge[0]['host'])
+ print("-------------------------------------")
+
+
+ @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_cartridge_group(self, line , opts=None):
+ """Retrieve details of a cartridge group."""
+ if not line.split():
+ print("usage: describe-cartridge-group [cartridge-group-name]")
+ return
+ cartridge_group = Stratos.describe_cartridge_group(line)
+ if not cartridge_group:
+ print("Cartridge group not found")
+ else:
+ PrintableJSON(cartridge_group).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_deployment_policy(self, line , opts=None):
+ """Retrieve details of a specific deployment policy."""
+ if not line.split():
+ print("usage: describe-deployment-policy [deployment-policy-id]")
+ return
+ deployment_policy = Stratos.describe_deployment_policy(line)
+ if not deployment_policy:
+ print("Deployment policy not found")
+ else:
+ PrintableJSON(deployment_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_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():
+ print("usage: describe-application-signup [application-id]")
+ return
+ application_signup = Stratos.describe_application_signup(line)
+ if not application_signup:
+ print("Application signup not found")
+ else:
+ PrintableJSON(application_signup).pprint()
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/stratos/blob/cf49abcc/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 04ff674..f1c2e30 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
@@ -32,7 +32,7 @@ class Stratos:
"""
@staticmethod
def list_users():
- return Stratos.get('users', errorMessage='No applications found')
+ return Stratos.get('users', error_message='No applications found')
@staticmethod
def add_users(username, password, role_name, first_name, last_name, email, profile_name):
@@ -46,7 +46,7 @@ class Stratos:
"""
@staticmethod
def list_network_partitions():
- return Stratos.get('networkPartitions', errorMessage='No network partitions found')
+ return Stratos.get('networkPartitions', error_message='No network partitions found')
"""
# Applications
@@ -74,11 +74,11 @@ class Stratos:
"""
@staticmethod
def list_cartridges():
- return Stratos.get('cartridges', errorMessage='No cartridges found')
+ return Stratos.get('cartridges', error_message='No cartridges found')
@staticmethod
def list_cartridge_groups():
- return Stratos.get('cartridgeGroups', errorMessage='No cartridge groups found')
+ return Stratos.get('cartridgeGroups', error_message='No cartridge groups found')
"""
# Kubernetes Clusters
@@ -86,36 +86,95 @@ class Stratos:
"""
@staticmethod
def list_kubernetes_clusters():
- return Stratos.get('kubernetesClusters', errorMessage='Kubernetes cluster not found')
+ return Stratos.get('kubernetesClusters', error_message='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')
+ error_message='Kubernetes cluster not found')
@staticmethod
def list_deployment_policies():
return Stratos.get('deploymentPolicies',
- errorMessage='Deployment policies not found')
+ error_message='Deployment policies not found')
@staticmethod
def list_cartridge_groups():
return Stratos.get('cartridgeGroups',
- errorMessage='cartridge groups not found')
+ error_message='cartridge groups not found')
@staticmethod
def list_autoscaling_policies():
return Stratos.get('autoscalingPolicies',
- errorMessage='No Autoscaling policies found')
+ error_message='No Autoscaling policies found')
+
+ @staticmethod
+ def describe_cartridge(cartridge_type):
+ return Stratos.get('cartridges/'+cartridge_type,
+ error_message='No Autoscaling policies found')
+
+ @staticmethod
+ def describe_cartridge_group(group_definition_name):
+ return Stratos.get('cartridgeGroups/'+group_definition_name,
+ error_message='No cartridge groups found')
+
+ @staticmethod
+ def describe_deployment_policy(deployment_policy_name):
+ return Stratos.get('deploymentPolicies/'+ deployment_policy_name,
+ error_message='No deployment policies found')
+
+ @staticmethod
+ def describe_kubernetes_cluster(kubernetes_cluster_id):
+ return Stratos.get('kubernetesClusters/'+ kubernetes_cluster_id,
+ error_message='No kubernetes clusters 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_network_partition(network_partition_id):
+ return Stratos.get('networkPartitions/'+ network_partition_id,
+ error_message='No nerwork partitions 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):
+ return Stratos.get('applications/'+ application_id + '/signup',
+ error_message='No signup application found')
+
+
"""
# Utils
"""
@staticmethod
- def get(resource, errorMessage):
+ def get(resource, error_message):
r = requests.get(Configs.stratos_api_url + resource,
auth=(Configs.stratos_username, Configs.stratos_password), verify=False)
- print(r.text)
+ #print(r.text)
+ 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'] == error_message:
+ return []
+ else:
+ raise requests.HTTPError()
+
+ @staticmethod
+ def post(resource, data, error_message):
+ r = requests.post(Configs.stratos_api_url + resource, data,
+ 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:
@@ -123,7 +182,7 @@ class Stratos:
elif r.status_code == 401:
raise AuthenticationError()
elif r.status_code == 404:
- if r.json() and r.json()['errorMessage'] == errorMessage:
+ if r.json() and r.json()['errorMessage'] == error_message:
return []
else:
raise requests.HTTPError()