Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit a75c45d

Browse files
committed
Merging @agentmilindu's leftover fixes for Python CLI from the later PR #437
1 parent da6b7e4 commit a75c45d

File tree

6 files changed

+40
-30
lines changed

6 files changed

+40
-30
lines changed

components/org.apache.stratos.python.cli/src/main/python/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Install the required Python packages by issuing the following `pip install` comm
88
pip install cmd2
99
pip install texttable
1010

11-
1211
```
13-
12+
13+
#Build
1414
Build and install stratos CLI by,
1515

1616
```
@@ -28,8 +28,19 @@ instead `install` if developing
2828
To start the Python CLI issue,
2929

3030
```
31-
$ stratos
31+
$ stratos-cli
32+
```
33+
34+
Install with Pip
35+
36+
```
37+
pip install stratos
3238
```
39+
40+
or to install a specific version use
3341

42+
```
43+
pip install stratos==1.0
44+
```
3445

3546

components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def do_list_users(self, line , opts=None):
8080
make_option('-e', '--email', type="str", help="Email of the user"),
8181
make_option('-o', '--profile_name', type="str", help="Profile name of the user")
8282
])
83+
@auth
8384
def do_add_user(self, line , opts=None):
8485
"""Add a user."""
8586
try:
@@ -88,8 +89,8 @@ def do_add_user(self, line , opts=None):
8889
" [-l <last name>] [-o <profile name>]")
8990
return
9091
else:
91-
user = Stratos.add_users(opts.username_user, opts.password_user, opts.role_name, opts.first_name, opts.last_name,
92-
opts.email, opts.profile_name)
92+
user = Stratos.add_users(opts.username_user, opts.password_user, opts.role_name, opts.first_name,
93+
opts.last_name, opts.email, opts.profile_name)
9394
if user:
9495
print("User successfully created")
9596
else:
@@ -100,20 +101,20 @@ def do_add_user(self, line , opts=None):
100101
@options([
101102
make_option('-u', '--username', type="str", help="Username of the user"),
102103
make_option('-p', '--password', type="str", help="Password of the user"),
103-
make_option('-s', '--username_user', type="str", help="Username of the user"),
104-
make_option('-a', '--password_user', type="str", help="Password of the user"),
105-
make_option('-r', '--role_name', type="str", help="Role name of the user"),
106-
make_option('-f', '--first_name', type="str", help="First name of the user"),
107-
make_option('-l', '--last_name', type="str", help="Last name of the user"),
108-
make_option('-e', '--email', type="str", help="Email of the user"),
109-
make_option('-o', '--profile_name', type="str", help="Profile name of the user")
104+
make_option('-s', '--username_user', type="str", help="Username of the user to be created"),
105+
make_option('-a', '--password_user', type="str", help="Password of the user to be created"),
106+
make_option('-r', '--role_name', type="str", help="Role name of the user to be created"),
107+
make_option('-f', '--first_name', type="str", help="First name of the user to be created"),
108+
make_option('-l', '--last_name', type="str", help="Last name of the user to be created"),
109+
make_option('-e', '--email', type="str", help="Email of the user to be created"),
110+
make_option('-o', '--profile_name', type="str", help="Profile name of the user to be created")
110111
])
111112
@auth
112113
def do_update_user(self, line , opts=None):
113114
"""Update a specific user."""
114115
try:
115-
user = Stratos.update_user(opts.username_user, opts.password_user, opts.role_name, opts.first_name, opts.last_name,
116-
opts.email, opts.profile_name)
116+
user = Stratos.update_user(opts.username_user, opts.password_user, opts.role_name, opts.first_name,
117+
opts.last_name, opts.email, opts.profile_name)
117118
if user:
118119
print("User successfully updated")
119120
else:
@@ -133,7 +134,6 @@ def do_remove_user(self, name , opts=None):
133134
print("usage: remove-user [username]")
134135
else:
135136
user_removed = Stratos.remove_user(name)
136-
print(user_removed)
137137
if user_removed:
138138
print("You have successfully deleted user: "+name)
139139
else:
@@ -190,7 +190,7 @@ def do_describe_application(self, application_id , opts=None):
190190
print("Application not found in : "+application_id)
191191
else:
192192
print("Application : "+application_id)
193-
PrintableJSON(application).pprint()
193+
PrintableTree(application).print_tree()
194194
except BadResponseError as e:
195195
self.perror(str(e))
196196

@@ -580,7 +580,7 @@ def do_list_cartridges_by_filter(self, filter_text , opts=None):
580580
"""Retrieve details of available cartridges."""
581581
try:
582582
if not filter_text:
583-
print("")
583+
print("usage: describe-cartridge-by-filter [filter]")
584584
else:
585585
cartridges = Stratos.list_cartridges_by_filter(filter_text)
586586
table = PrintableTable()
@@ -1527,4 +1527,4 @@ def do_remove_domain_mappings(self, domain , opts=None):
15271527
print("Could not delete domain: "+domain)
15281528
except BadResponseError as e:
15291529
self.perror(str(e))
1530-
logging.error("HTTP "+e.error_code+" : "+str(e))
1530+

components/org.apache.stratos.python.cli/src/main/python/cli/Stratos.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,11 @@ def update_kubernetes_host(json):
395395

396396
@staticmethod
397397
def remove_kubernetes_cluster(kubernetes_cluster_id):
398-
return Stratos.delete('kubernetesClusters/'+kubernetes_cluster_id,
399-
)
398+
return Stratos.delete('kubernetesClusters/'+kubernetes_cluster_id)
399+
400400
@staticmethod
401401
def remove_kubernetes_host(kubernetes_cluster_id, host_id):
402-
return Stratos.delete('kubernetesClusters/'+kubernetes_cluster_id+"/hosts/"+host_id,
403-
)
402+
return Stratos.delete('kubernetesClusters/'+kubernetes_cluster_id+"/hosts/"+host_id)
404403

405404
"""
406405
# Domain Mapping
@@ -420,8 +419,7 @@ def remove_domain_mappings(application_id):
420419

421420
@staticmethod
422421
def add_domain_mapping(application_id, json):
423-
return Stratos.post('applications/'+application_id+'/domainMappings', json,
424-
)
422+
return Stratos.post('applications/'+application_id+'/domainMappings', json)
425423

426424
"""
427425
# Utils
@@ -465,8 +463,8 @@ def put(resource, data):
465463

466464
@staticmethod
467465
def response(r):
468-
print(r)
469-
print(r.text)
466+
# print(r)
467+
# print(r.text)
470468
if r.status_code == 200:
471469
return r.json()
472470
elif r.status_code == 201:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[wheel]
2-
universal = 1
2+

components/org.apache.stratos.python.cli/src/main/python/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def read(file_name):
2424
return open(os.path.join(os.path.dirname(__file__), file_name)).read()
2525

2626
setup(
27-
name="stratos",
27+
name="stratos-cli",
28+
version="4.1.4",
2829
version="4.1.4",
2930
author="Apache Stratos",
3031
author_email="[email protected]",

components/org.apache.stratos.python.cli/src/main/python/tests/test_stratos_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_http_get_handler_on_200(self):
3131
body='{"keyOne": "valueOne"}', status=200,
3232
content_type='application/json')
3333

34-
r = Stratos.post("")
34+
r = Stratos.get("")
3535

3636
assert r == {"keyOne": "valueOne"}
3737

@@ -94,4 +94,4 @@ def test_http_post_handler_on_500(self):
9494
self.assertRaises(BadResponseError, Stratos.post(""))
9595

9696
if __name__ == '__main__':
97-
unittest.main()
97+
unittest.main()

0 commit comments

Comments
 (0)