You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stratos.apache.org by agentmilindu <gi...@git.apache.org> on 2015/07/30 18:33:58 UTC
[GitHub] stratos pull request: Python CLI PR1
GitHub user agentmilindu opened a pull request:
https://github.com/apache/stratos/pull/414
Python CLI PR1
Python CLI for Stratos
*( Do not merge )*
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/agentmilindu/stratos python-cli-pr1
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/stratos/pull/414.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #414
----
commit c90fef391274016e14373b42fe01ab1d9bdc5730
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-01T02:38:30Z
Create README.md
commit c22f860d3a146d38f2ad25f33bc83ce1cf78c2e9
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-03T05:23:16Z
Directory structure added
On branch python-cli
new file: components/org.apache.stratos.python.cli/src/main/python/cli/__init__.py
commit 8ccaeb86d44dacb6c4b0fe968027223d73d243e2
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-03T06:41:24Z
Setup file added, setup config added
On branch python-cli
new file: components/org.apache.stratos.python.cli/src/main/python/cli/setup.cfg
new file: components/org.apache.stratos.python.cli/src/main/python/cli/setup.py
commit 0301ea4c0b4c0abc478ffb751c2d5e4c6ef4e073
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-03T10:15:56Z
Directory for Tests added
On branch python-cli
new file: components/org.apache.stratos.python.cli/src/main/python/tests/__init__.py
commit 13bcb5035214e7daf70ee9e9ab01668406384715
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-03T10:17:29Z
Setup file and Setup config file moved to correct location
On branch python-cli
renamed: components/org.apache.stratos.python.cli/src/main/python/cli/setup.cfg -> components/org.apache.stratos.python.cli/src/main/python/setup.cfg
renamed: components/org.apache.stratos.python.cli/src/main/python/cli/setup.py -> components/org.apache.stratos.python.cli/src/main/python/setup.py
Refer https://pythonhosted.org/an_example_pypi_project/setuptools.html#directory-structure
commit 08d10dc3f2bb5778ff22dd119700b86f6ecacd2d
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-03T17:29:52Z
README added
commit 143318f60a89fa221ee792bb2860fec96adbadde
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-03T17:33:55Z
Main file added
On branch python-cli
new file: components/org.apache.stratos.python.cli/src/main/python/cli/Main.py
Main file contains the main() method, the entry point of the CLI
commit 076f5dde0cd3219f112f427e995168e6beb1a02a
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-05T12:39:01Z
Simple code style fixes as of the coding guides
commit fe928e8a00a690573749bd474f3be7ebad35417d
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-05T12:43:08Z
CLI and Stratos scripts added
On branch python-cli
new file: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py
new file: components/org.apache.stratos.python.cli/src/main/python/cli/Stratos.py
commit 3c04078249b596fd93c641df82d7e83af3132d09
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-06T06:33:25Z
Initializing the CMD and started the loop in Main
On branch python-cli
modified: components/org.apache.stratos.python.cli/src/main/python/cli/Main.py
commit d6a85ac15f06fd0377c51b6f43b23e22be913d41
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-06T08:04:47Z
Main and CLI linked
On branch python-cli
modified: cli/CLI.py
modified: cli/Main.py
modified: cli/Stratos.py
modified: setup.py
Now anyone build and install stratos CLI by,
$ python setup.py build
$ python setup.py install
or use
$ python setup.py develop
instead `install` if developing
commit e02264d749990dccd8273852c3af8a0ef89fc841
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-07T12:39:53Z
Made the README a rst file
On branch python-cli
renamed: README.md -> README.rst
Using rst(reStructuredText) file as setup.py's description, this will become the description of stratos on Pip.
Therefor adding the default Stratos CLI guide there.
Python CLI specific details would reside on README.md
commit dee2998b57fff9dd08dd5349eb5c15c7c8582d30
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-07T12:46:54Z
Git Ignore file updated
On branch python-cli
new file: .gitignore
Ignoring
build/
dist/
stratos.egg-info/
commit e7e29de764290f41f29cec9212daa6e1e3a7840b
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-07T12:48:14Z
new README.md added
On branch python-cli
new file: README.md
Python CLI specific README
commit 5f2b673edff89bf9656a1ce5cb3d889c737c937d
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-07T12:54:05Z
Setup.py now use README.rst as description
commit 93c4bd38770f7ebbc510cb2c51e230d193b097de
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-13T18:35:01Z
Added Apache details to the Setup.py
On branch python-cli
modified: setup.py
commit 4ad55d444ca22e5e3fad34335cf49257276d361c
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-14T03:32:01Z
Utilities to print tables, trees added
On branch python-cli
new file: cli/Utils.py
commit c1151b1ebf890f5e6344a27c6dc8b6d29f4443cd
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-14T03:33:21Z
Seperate py to handle Logging related stuffs
On branch python-cli
new file: cli/Logging.py
commit aa17a47c9a6e1e731115e25f905b82c548b3c13a
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-16T05:59:42Z
Creating stratos folder for logging( if not exists ), logging in to stratos-cli.log
commit d2f6a8dd04fc268206e07bef19f6843f0ac7f73c
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-16T06:01:28Z
Logging added to the Main py
commit 8ff72c6bc242faf8762e1f0dd24ff50f7667c086
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-22T11:46:11Z
Configs.py added, Using the constants in Configs.py
On branch python-cli
modified: cli/CLI.py
new file: cli/Configs.py
modified: cli/Logging.py
commit 4170cd584bbc752b90258603ad6dfe9c89077fab
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-05-22T12:09:16Z
Resolving the '-' issue
commit 53c8330b979c74fa92caaa4eeae1bf1fd5788a2f
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-06-13T11:41:58Z
Log file location moved to COnfigs.py from Logger.py
On branch python-cli
modified: components/org.apache.stratos.python.cli/src/main/python/cli/Configs.py
modified: components/org.apache.stratos.python.cli/src/main/python/cli/Logging.py
commit 3d824eb506083fcb4630a663aedffff9b340d335
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-06-14T07:45:33Z
Some quick fixes
Using python os.path.join() to avoid forward/back slash problems
Setting empty strings as defaults for username and password evn vars instead of None
commit db530d8897be2fc12b84ae87420266b0237f8f38
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-06-14T09:41:25Z
Pre Authentication decorator added
commit 6ce72d58e9325bc7a3e96c100982d7cee18c5971
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-06-18T01:40:06Z
Default stratos URL added
commit d7772d7a70e42ee1c1410fb752aa07d678a44c68
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-06-18T16:37:56Z
Auth and Print tree improved
commit 2e68712bb107553907152ba3e917bcde6273e765
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-06-18T16:39:09Z
Prompting for user credentials when starting the interactive mode
commit c9d72884fc700b7cf889ebc2b45fe147890a3996
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-06-18T16:41:09Z
Stratos API URL added
commit 5b6440282d4039936409a61a784f5c0be4af8422
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date: 2015-07-25T06:59:13Z
Passowrd and username checking now happens in @auth decorator. do_list_users and do_network_partitions added
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by agentmilindu <gi...@git.apache.org>.
Github user agentmilindu commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r36040497
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
@@ -0,0 +1,190 @@
+from cmd2 import *
+from Utils import *
+from Stratos import *
+import Configs
+from cli.exceptions import AuthenticationError
+
+
+class CLI(Cmd):
+ """Apache Stratos CLI"""
+
+ prompt = Configs.stratos_prompt
+ # resolving the '-' issue
+ Cmd.legalChars = '-' + Cmd.legalChars
+
+ def __init__(self):
+ # resolving the '-' issue
+ [Cmd.shortcuts.update({a[3:].replace('_', '-'): a[3:]}) for a in self.get_names() if a.startswith('do_')]
+ Cmd.__init__(self)
+
+ def completenames(self, text, *ignored):
+ # resolving the '-' issue
+ return [a[3:].replace('_', '-') for a in self.get_names() if a.replace('_', '-').startswith('do-'+text)]
+
+
+
+ @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_repositories(self, line, opts=None):
+ """ Shows the git repositories of the user identified by given the username and password
+ eg: repositories -u agentmilindu -p agentmilindu123 """
+
+ r = requests.get('https://api.github.com/users/' + Configs.stratos_username + '/repos?per_page=5',
+ auth=(Configs.stratos_username, Configs.stratos_password))
+ repositories = r.json()
+ print(r)
+ print(repositories)
+ table = PrintableTable()
+ rows = [["Name", "language"]]
+ table.set_cols_align(["l", "r"])
+ table.set_cols_valign(["t", "m"])
+
+ for repo in repositories:
+ rows.append([repo['name'], repo['language']])
+ print(rows)
+ 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"),
+ make_option('-p', '--password', type="str", help="Password of the user")
+ ])
+ @auth
+ def do_list_users(self, line , opts=None):
+ """Illustrate the base class method use."""
+ try:
+ users = Stratos.list_users()
+ table = PrintableTable()
+ rows = [["Name", "language"]]
+ table.set_cols_align(["l", "r"])
+ table.set_cols_valign(["t", "m"])
+ for user in users:
+ rows.append([user['role'], user['userName']])
+ table.add_rows(rows)
+ table.print_table()
+ 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_network_partitions(self, line , opts=None):
+ """Illustrate the base class method use."""
+ 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"),
+ make_option('-p', '--password', type="str", help="Password of the user")
+ ])
+ @auth
+ def do_list_cartridges(self, line , opts=None):
+ """Illustrate the base class method use."""
+ cartridges = Stratos.list_cartridges()
+ table = PrintableTable()
+ rows = [["Type", "Category", "Name", "Description", "Version", "Multi-Tenant"]]
+ for cartridge in cartridges:
+ rows.append([cartridge['type'], cartridge['category'], cartridge['displayName'], cartridge['description'], cartridge['version'], cartridge['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")
+ ])
+ @auth
+ def do_list_cartridges_group(self, line , opts=None):
+ """Illustrate the base class method use."""
+ cartridges_groups = Stratos.list_cartridges_group()
+ table = PrintableTable()
+ rows = [["Name", "No. of cartridges", "No of groups", "Dependency scaling"]]
+ for cartridges_group in cartridges_groups:
+ rows.append([cartridges_group['name'], cartridges_group['category'], cartridges_group['displayName'], cartridge['description'], cartridge['version'], cartridge['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")
+ ])
+ @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']])
--- End diff --
Fixed :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by agentmilindu <gi...@git.apache.org>.
Github user agentmilindu commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r36040500
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
@@ -0,0 +1,190 @@
+from cmd2 import *
+from Utils import *
+from Stratos import *
+import Configs
+from cli.exceptions import AuthenticationError
+
+
+class CLI(Cmd):
+ """Apache Stratos CLI"""
+
+ prompt = Configs.stratos_prompt
+ # resolving the '-' issue
+ Cmd.legalChars = '-' + Cmd.legalChars
+
+ def __init__(self):
+ # resolving the '-' issue
+ [Cmd.shortcuts.update({a[3:].replace('_', '-'): a[3:]}) for a in self.get_names() if a.startswith('do_')]
+ Cmd.__init__(self)
+
+ def completenames(self, text, *ignored):
+ # resolving the '-' issue
+ return [a[3:].replace('_', '-') for a in self.get_names() if a.replace('_', '-').startswith('do-'+text)]
+
+
+
+ @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_repositories(self, line, opts=None):
+ """ Shows the git repositories of the user identified by given the username and password
+ eg: repositories -u agentmilindu -p agentmilindu123 """
+
+ r = requests.get('https://api.github.com/users/' + Configs.stratos_username + '/repos?per_page=5',
+ auth=(Configs.stratos_username, Configs.stratos_password))
+ repositories = r.json()
+ print(r)
+ print(repositories)
+ table = PrintableTable()
+ rows = [["Name", "language"]]
+ table.set_cols_align(["l", "r"])
+ table.set_cols_valign(["t", "m"])
+
+ for repo in repositories:
+ rows.append([repo['name'], repo['language']])
+ print(rows)
+ 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"),
+ make_option('-p', '--password', type="str", help="Password of the user")
+ ])
+ @auth
+ def do_list_users(self, line , opts=None):
+ """Illustrate the base class method use."""
+ try:
+ users = Stratos.list_users()
+ table = PrintableTable()
+ rows = [["Name", "language"]]
+ table.set_cols_align(["l", "r"])
+ table.set_cols_valign(["t", "m"])
+ for user in users:
+ rows.append([user['role'], user['userName']])
+ table.add_rows(rows)
+ table.print_table()
+ 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_network_partitions(self, line , opts=None):
+ """Illustrate the base class method use."""
+ 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"),
+ make_option('-p', '--password', type="str", help="Password of the user")
+ ])
+ @auth
+ def do_list_cartridges(self, line , opts=None):
+ """Illustrate the base class method use."""
+ cartridges = Stratos.list_cartridges()
+ table = PrintableTable()
+ rows = [["Type", "Category", "Name", "Description", "Version", "Multi-Tenant"]]
+ for cartridge in cartridges:
+ rows.append([cartridge['type'], cartridge['category'], cartridge['displayName'], cartridge['description'], cartridge['version'], cartridge['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")
+ ])
+ @auth
+ def do_list_cartridges_group(self, line , opts=None):
+ """Illustrate the base class method use."""
+ cartridges_groups = Stratos.list_cartridges_group()
+ table = PrintableTable()
+ rows = [["Name", "No. of cartridges", "No of groups", "Dependency scaling"]]
+ for cartridges_group in cartridges_groups:
+ rows.append([cartridges_group['name'], cartridges_group['category'], cartridges_group['displayName'], cartridge['description'], cartridge['version'], cartridge['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")
+ ])
+ @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()
+ """
+ # 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):
+ """Illustrate the base class method use."""
+ print("hello User")
+ try:
+ Stratos.deploy_user()
+ except ValueError as e:
+ self.perror("sdc")
--- End diff --
Fixed :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by chamilad <gi...@git.apache.org>.
Github user chamilad commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r35941633
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/Main.py ---
@@ -0,0 +1,38 @@
+import sys
--- End diff --
License statement missing. You can configure most IDEs to automatically insert the statement to a new file.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by chamilad <gi...@git.apache.org>.
Github user chamilad commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r35941736
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
@@ -0,0 +1,190 @@
+from cmd2 import *
+from Utils import *
+from Stratos import *
+import Configs
+from cli.exceptions import AuthenticationError
+
+
+class CLI(Cmd):
+ """Apache Stratos CLI"""
+
+ prompt = Configs.stratos_prompt
+ # resolving the '-' issue
+ Cmd.legalChars = '-' + Cmd.legalChars
+
+ def __init__(self):
+ # resolving the '-' issue
+ [Cmd.shortcuts.update({a[3:].replace('_', '-'): a[3:]}) for a in self.get_names() if a.startswith('do_')]
+ Cmd.__init__(self)
+
+ def completenames(self, text, *ignored):
+ # resolving the '-' issue
+ return [a[3:].replace('_', '-') for a in self.get_names() if a.replace('_', '-').startswith('do-'+text)]
+
+
+
+ @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_repositories(self, line, opts=None):
+ """ Shows the git repositories of the user identified by given the username and password
+ eg: repositories -u agentmilindu -p agentmilindu123 """
+
+ r = requests.get('https://api.github.com/users/' + Configs.stratos_username + '/repos?per_page=5',
+ auth=(Configs.stratos_username, Configs.stratos_password))
+ repositories = r.json()
+ print(r)
+ print(repositories)
+ table = PrintableTable()
+ rows = [["Name", "language"]]
+ table.set_cols_align(["l", "r"])
+ table.set_cols_valign(["t", "m"])
+
+ for repo in repositories:
+ rows.append([repo['name'], repo['language']])
+ print(rows)
+ 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"),
+ make_option('-p', '--password', type="str", help="Password of the user")
+ ])
+ @auth
+ def do_list_users(self, line , opts=None):
+ """Illustrate the base class method use."""
+ try:
+ users = Stratos.list_users()
+ table = PrintableTable()
+ rows = [["Name", "language"]]
+ table.set_cols_align(["l", "r"])
+ table.set_cols_valign(["t", "m"])
+ for user in users:
+ rows.append([user['role'], user['userName']])
+ table.add_rows(rows)
+ table.print_table()
+ 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_network_partitions(self, line , opts=None):
+ """Illustrate the base class method use."""
+ 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"),
+ make_option('-p', '--password', type="str", help="Password of the user")
+ ])
+ @auth
+ def do_list_cartridges(self, line , opts=None):
+ """Illustrate the base class method use."""
+ cartridges = Stratos.list_cartridges()
+ table = PrintableTable()
+ rows = [["Type", "Category", "Name", "Description", "Version", "Multi-Tenant"]]
+ for cartridge in cartridges:
+ rows.append([cartridge['type'], cartridge['category'], cartridge['displayName'], cartridge['description'], cartridge['version'], cartridge['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")
+ ])
+ @auth
+ def do_list_cartridges_group(self, line , opts=None):
+ """Illustrate the base class method use."""
+ cartridges_groups = Stratos.list_cartridges_group()
+ table = PrintableTable()
+ rows = [["Name", "No. of cartridges", "No of groups", "Dependency scaling"]]
+ for cartridges_group in cartridges_groups:
+ rows.append([cartridges_group['name'], cartridges_group['category'], cartridges_group['displayName'], cartridge['description'], cartridge['version'], cartridge['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")
+ ])
+ @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']])
--- End diff --
check 180 char limit
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on the pull request:
https://github.com/apache/stratos/pull/414#issuecomment-147689832
Thanks Milindu for your contribution! This pull request is now merged to stratos-4.1.x branch. It will be released with 4.1.4.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/stratos/pull/414
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by chamilad <gi...@git.apache.org>.
Github user chamilad commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r35941444
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/Configs.py ---
@@ -0,0 +1,14 @@
+import os
+
+stratos_prompt = "stratos> "
+
+stratos_dir = "~/.stratos"
+log_file_name = "stratos-cli.log"
+
+stratos_dir_path = os.path.expanduser(stratos_dir)
+log_file_path = os.path.join(stratos_dir_path, log_file_name)
+
+stratos_url = os.getenv('STRATOS_URL', "https://localhost:9443/")
--- End diff --
Are these configurable options by the user? If they are there shouldn't be code here. Better go for a config file such as an *.ini file and read from it.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by agentmilindu <gi...@git.apache.org>.
Github user agentmilindu commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r36039838
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/Main.py ---
@@ -0,0 +1,38 @@
+import sys
--- End diff --
Fixed :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by chamilad <gi...@git.apache.org>.
Github user chamilad commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r35942295
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/Utils.py ---
@@ -0,0 +1,69 @@
+from __future__ import print_function
+import sys
+from texttable import *
+import Configs
+from Logging import logging
+
+
+class PrintableTree:
+
+ def __init__(self, tree_data):
+ self.tree_data = tree_data
+ pass
+
+ def print_tree(self):
+ def _print_tree(t, level=0, ups=""):
+ if isinstance(t, list):
+ print('|')
+ for element in t[:-1]:
+ print(ups + "+-", end='')
+ _print_tree(element, level + 1, ups + "| ")
+ else:
+ print(ups + "+-", end='')
+ _print_tree(t[-1], level + 1, ups + " ")
+ elif isinstance(t, dict):
+ print('|')
+ l = []
+ for k, v in t.items():
+ if isinstance(v, list) or isinstance(v, dict):
+ l.extend([k, v])
+ else:
+ l.extend([str(k) + ":" + str(v)])
+ t = l
+ for element in t[:-1]:
+ print(ups + "+-", end='')
+ _print_tree(element, level + 1, ups + "| ")
+ else:
+ print(ups + "+-", end='')
+ _print_tree(t[-1], level + 1, ups + " ")
+ else:
+ print(str(t))
+ print("_")
+ _print_tree(self.tree_data)
+
+
+class PrintableTable(Texttable):
+
+ def __init__(self):
+ Texttable.__init__(self)
+ self.set_deco(Texttable.BORDER | Texttable.HEADER | Texttable.VLINES)
+
+ def print_table(self):
+ print(self.draw())
+
+def auth(func):
+ """Authenticate"""
+ def auth_inner(self, *args, **kwargs):
--- End diff --
Why an inner function here?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by agentmilindu <gi...@git.apache.org>.
Github user agentmilindu commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r36039837
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/Configs.py ---
@@ -0,0 +1,14 @@
+import os
+
+stratos_prompt = "stratos> "
+
+stratos_dir = "~/.stratos"
+log_file_name = "stratos-cli.log"
+
+stratos_dir_path = os.path.expanduser(stratos_dir)
+log_file_path = os.path.join(stratos_dir_path, log_file_name)
+
+stratos_url = os.getenv('STRATOS_URL', "https://localhost:9443/")
--- End diff --
At the moment they are not configurable by the user, but let's try to go for a config file such as an *.ini as you suggest, once we are done with the rest.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by chamilad <gi...@git.apache.org>.
Github user chamilad commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r35941807
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/Stratos.py ---
@@ -0,0 +1,113 @@
+import requests
+import Configs
+from cli.exceptions.AuthenticationError import AuthenticationError
+
+
+
+class Stratos:
+ """Apache Stratos Python API"""
+
+ def __init__(self):
+ pass
+
+ """
+ # Users
--- End diff --
Include more descriptive comments for both methods and modules/classes.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by chamilad <gi...@git.apache.org>.
Github user chamilad commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r35940678
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
@@ -0,0 +1,190 @@
+from cmd2 import *
+from Utils import *
+from Stratos import *
+import Configs
+from cli.exceptions import AuthenticationError
+
+
+class CLI(Cmd):
+ """Apache Stratos CLI"""
+
+ prompt = Configs.stratos_prompt
+ # resolving the '-' issue
+ Cmd.legalChars = '-' + Cmd.legalChars
+
+ def __init__(self):
+ # resolving the '-' issue
+ [Cmd.shortcuts.update({a[3:].replace('_', '-'): a[3:]}) for a in self.get_names() if a.startswith('do_')]
--- End diff --
Code readability is lesser here. IMO we should go for a cleaner approach with self describing code.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] stratos pull request: Python CLI PR1
Posted by chamilad <gi...@git.apache.org>.
Github user chamilad commented on a diff in the pull request:
https://github.com/apache/stratos/pull/414#discussion_r35941086
--- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
@@ -0,0 +1,190 @@
+from cmd2 import *
+from Utils import *
+from Stratos import *
+import Configs
+from cli.exceptions import AuthenticationError
+
+
+class CLI(Cmd):
+ """Apache Stratos CLI"""
+
+ prompt = Configs.stratos_prompt
+ # resolving the '-' issue
+ Cmd.legalChars = '-' + Cmd.legalChars
+
+ def __init__(self):
+ # resolving the '-' issue
+ [Cmd.shortcuts.update({a[3:].replace('_', '-'): a[3:]}) for a in self.get_names() if a.startswith('do_')]
+ Cmd.__init__(self)
+
+ def completenames(self, text, *ignored):
+ # resolving the '-' issue
+ return [a[3:].replace('_', '-') for a in self.get_names() if a.replace('_', '-').startswith('do-'+text)]
+
+
+
+ @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_repositories(self, line, opts=None):
+ """ Shows the git repositories of the user identified by given the username and password
+ eg: repositories -u agentmilindu -p agentmilindu123 """
+
+ r = requests.get('https://api.github.com/users/' + Configs.stratos_username + '/repos?per_page=5',
+ auth=(Configs.stratos_username, Configs.stratos_password))
+ repositories = r.json()
+ print(r)
+ print(repositories)
+ table = PrintableTable()
+ rows = [["Name", "language"]]
+ table.set_cols_align(["l", "r"])
+ table.set_cols_valign(["t", "m"])
+
+ for repo in repositories:
+ rows.append([repo['name'], repo['language']])
+ print(rows)
+ 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"),
+ make_option('-p', '--password', type="str", help="Password of the user")
+ ])
+ @auth
+ def do_list_users(self, line , opts=None):
+ """Illustrate the base class method use."""
+ try:
+ users = Stratos.list_users()
+ table = PrintableTable()
+ rows = [["Name", "language"]]
+ table.set_cols_align(["l", "r"])
+ table.set_cols_valign(["t", "m"])
+ for user in users:
+ rows.append([user['role'], user['userName']])
+ table.add_rows(rows)
+ table.print_table()
+ 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_network_partitions(self, line , opts=None):
+ """Illustrate the base class method use."""
+ 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"),
+ make_option('-p', '--password', type="str", help="Password of the user")
+ ])
+ @auth
+ def do_list_cartridges(self, line , opts=None):
+ """Illustrate the base class method use."""
+ cartridges = Stratos.list_cartridges()
+ table = PrintableTable()
+ rows = [["Type", "Category", "Name", "Description", "Version", "Multi-Tenant"]]
+ for cartridge in cartridges:
+ rows.append([cartridge['type'], cartridge['category'], cartridge['displayName'], cartridge['description'], cartridge['version'], cartridge['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")
+ ])
+ @auth
+ def do_list_cartridges_group(self, line , opts=None):
+ """Illustrate the base class method use."""
+ cartridges_groups = Stratos.list_cartridges_group()
+ table = PrintableTable()
+ rows = [["Name", "No. of cartridges", "No of groups", "Dependency scaling"]]
+ for cartridges_group in cartridges_groups:
+ rows.append([cartridges_group['name'], cartridges_group['category'], cartridges_group['displayName'], cartridge['description'], cartridge['version'], cartridge['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")
+ ])
+ @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()
+ """
+ # 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):
+ """Illustrate the base class method use."""
+ print("hello User")
+ try:
+ Stratos.deploy_user()
+ except ValueError as e:
+ self.perror("sdc")
--- End diff --
New line at the end of file - PEP8
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---