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/08/17 20:41:17 UTC

[GitHub] stratos pull request: Python CLI GSoC15

GitHub user agentmilindu opened a pull request:

    https://github.com/apache/stratos/pull/437

    Python CLI GSoC15

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/agentmilindu/stratos python-cli-gsoc15

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/stratos/pull/437.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 #437
    
----
commit 33c66410b0c6e7dcb2a183b1d44cd6598b5cc083
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-05-01T02:38:30Z

    Create README.md

commit 758555cdb874671bbae639c58c3bb6d6a3ec96ac
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 3020d25b53e800c98ece368dd6de0a30b13502e8
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 4ef19f9bae3c4d79a80f024d86d371732b18af3b
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 6553b4604ea0de89eba936519c041337616bbd5d
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 3b9067d05a9e001a714606c4689b15b71aef5193
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-05-03T17:29:52Z

    README added

commit 867c9a8645c26fd82909604af87512c77f1bbb93
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 e8c46899aa5f0bef511b20358a6be50819cd5313
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-05-05T12:39:01Z

    Simple code style fixes as of the coding guides

commit ea0987681884a9a13dbc80b1a05eb83c48e5f9d7
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 cc0e57c5186922f45313caaa032f8f64ebf2f06f
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 0e8c1377e9c280b7b9a62aaa77f6775f5bc3efb4
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 f67802be3adfd42574dd746dfe16465eb73c520d
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 a04004568a8a937676e09635e94f5066eb84bcb4
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 4f5740772cf97daa7dbb0e10fce3a3b854e9795c
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 eeb5e1fb9547e7dffca295661e077886df053278
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-05-07T12:54:05Z

    Setup.py now use README.rst as description

commit a8b65235cb4ce80d0b312e8e28b2d6a63ce50042
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 979c0ef7f68a2ab25f466b30f1dd979db04f38e0
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 c3dbb1756160fa3a268dc3f1d04aa36e1f8f0a18
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 05e3a721808f2c9bc11e944a2574365d2fe60ec9
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 999500c897b677ce1d683ab828047e2ebb0e01f0
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-05-16T06:01:28Z

    Logging added to the Main py

commit d1ab83c5df4a83217d62f83a7e67d66880bff7c3
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 4502eb63b881ed9f65d9dd3dbac29c34f80c6b4a
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-05-22T12:09:16Z

    Resolving the '-' issue

commit ef36b7a0aa683fb3f91cf909244d90e39c432235
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 72dd3a4b8753501b63241287dca07065e1742298
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 28a72d39bf321cbfc6baf524b91930449f504cbd
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-06-14T09:41:25Z

    Pre Authentication decorator added

commit f9f246f6bf61a9a767cee7cb9e314052b3bad91c
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-06-18T01:40:06Z

    Default stratos URL added

commit bf053e092e23f1d76bdc980048f78c4036ce2982
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-06-18T16:37:56Z

    Auth and Print tree improved

commit 347010278fa50ec90cdacc6ab830be6fe58cfc70
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-06-18T16:39:09Z

    Prompting for user credentials when starting the interactive mode

commit 23d9785dd95bb38c96f76647b7283069cef169b6
Author: Milindu Sanoj Kumarage <ag...@gmail.com>
Date:   2015-06-18T16:41:09Z

    Stratos API URL added

commit e66a7ee147467e7f9f286c0447f718f3baaf03ff
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 GSoC15

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/437#discussion_r37261901
  
    --- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
    @@ -0,0 +1,1530 @@
    +# Licensed to the Apache Software Foundation (ASF) under one
    +# or more contributor license agreements.  See the NOTICE file
    +# distributed with this work for additional information
    +# regarding copyright ownership.  The ASF licenses this file
    +# to you under the Apache License, Version 2.0 (the
    +# "License"); you may not use this file except in compliance
    +# with the License.  You may obtain a copy of the License at
    +#
    +# http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing,
    +# software distributed under the License is distributed on an
    +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +# KIND, either express or implied.  See the License for the
    +# specific language governing permissions and limitations
    +# under the License.
    +
    +from cmd2 import *
    +from Utils import *
    +from Stratos import *
    +import Configs
    +from cli.exceptions import BadResponseError
    +
    +
    +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)]
    +
    +    """
    +
    +    Stratos CLI specific methods
    +    ====================================================================================================================
    +
    +    # User
    +     * list-users
    +     * add-user
    +     * update-user
    +     * remove-user
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all users."""
    +        try:
    +            users = Stratos.list_users()
    +            table = PrintableTable()
    +            rows = [["Username", "Role"]]
    +            for user in users:
    +                rows.append([user['userName'], user['role']])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    def do_add_user(self, line , opts=None):
    +        """Add a user."""
    +        try:
    +            if not opts.username_user or not opts.password_user:
    +                print("usage: add-user [-s <username>] [-a <credential>] [-r <role>] [-e <email>] [-f <first name>]" +
    +                      " [-l <last name>] [-o <profile name>]")
    +                return
    +            else:
    +                user = Stratos.add_users(opts.username_user, opts.password_user, 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 BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    @auth
    +    def do_update_user(self, line , opts=None):
    +        """Update a specific user."""
    +        try:
    +            user = Stratos.update_user(opts.username_user, opts.password_user, opts.role_name, opts.first_name, opts.last_name,
    +                                       opts.email, opts.profile_name)
    +            if user:
    +                print("User successfully updated")
    +            else:
    +                print("Error updating the user")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_user(self, name , opts=None):
    +        """Delete a user."""
    +        try:
    +            if not name:
    +                print("usage: remove-user [username]")
    +            else:
    +                user_removed = Stratos.remove_user(name)
    +                print(user_removed)
    +                if user_removed:
    +                    print("You have successfully deleted user: "+name)
    +                else:
    +                    print("Could not delete user: "+name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Applications
    +     * list-applications
    +     * describe-application
    +     * add-application
    +     * update-application
    +     * remove-application
    +     * describe-application-runtime
    +     * deploy-application
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all the applications."""
    +        try:
    +            applications = Stratos.list_applications()
    +            if not applications:
    +                print("No applications found")
    +            else:
    +                table = PrintableTable()
    +                rows = [["Application ID", "Alias", "Status"]]
    +                for application in applications:
    +                    rows.append([application['applicationId'], application['alias'], application['status']])
    +                table.add_rows(rows)
    +                table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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(self, application_id , opts=None):
    +        """Describe an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application [cluster-id]")
    +                return
    +            application = Stratos.describe_application(application_id)
    +            if not application:
    +                print("Application not found in : "+application_id)
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application(self, line , opts=None):
    +        """Add an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application [-f <resource path>]")
    +            else:
    +                add_application = Stratos.add_application(open(opts.json_file_path, 'r').read())
    +                if add_application:
    +                    print("Application added successfully")
    +                else:
    +                    print("Error adding application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_update_application(self, application , opts=None):
    +        """Update an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: update-application [-f <resource path>] [application]")
    +            else:
    +                update_application = Stratos.update_application(application, open(opts.json_file_path, 'r').read())
    +                if update_application:
    +                    print("Application updated successfully")
    +                else:
    +                    print("Error updating application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +
    +    @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_application(self, application , opts=None):
    +        """Delete an application."""
    +        try:
    +            if not application:
    +                print("usage: remove-application [application]")
    +            else:
    +                application_removed = Stratos.remove_application(application)
    +                if application_removed:
    +                    print("You have successfully removed application: "+application)
    +                else:
    +                    print("Could not delete application : "+application)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_deploy_application(self, line , opts=None):
    +        """Deploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: deploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.deploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully deployed application: "+opts.application_id)
    +                else:
    +                    print("Could not deployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_undeploy_application(self, line , opts=None):
    +        """Undeploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: undeploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.undeploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully undeployed application: "+opts.application_id)
    +                else:
    +                    print("Could not undeployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_runtime(self, application_id , opts=None):
    +        """Describe the runtime topology of an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-runtime [application-id]")
    +                return
    +            application_runtime = Stratos.describe_application_runtime(application_id)
    +            if not application_runtime:
    +                print("Application runtime not found")
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application_runtime).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Application signup
    +     * describe-application-signup
    +     * add-application-signup
    +     * remove-application-signup
    +
    +    """
    +    @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, application_id , opts=None):
    +        """Retrieve details of a specific application signup."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-signup [application-id]")
    +                return
    +            application_signup = Stratos.describe_application_signup(application_id)
    +            if not application_signup:
    +                print("Application signup not found")
    +            else:
    +                PrintableJSON(application_signup).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application_signup(self, application_id, opts=None):
    +        """Add a new application signup to the system"""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application-signup [-f <resource path>] [application_id]")
    +            else:
    +                application_signup = Stratos.add_application_signup(application_id, open(opts.json_file_path, 'r').read())
    +                if application_signup:
    +                    print("Application signup added successfully")
    +                else:
    +                    print("Error creating application signup")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_application_signup(self, signup , opts=None):
    +        """Delete an application sign up."""
    +        try:
    +            if not signup:
    +                print("usage: remove-application-signup [signup]")
    +            else:
    +                signup_removed = Stratos.remove_application_signup(signup)
    +                if signup_removed:
    +                    print("You have successfully remove signup: "+signup)
    +                else:
    +                    print("Could not delete application signup: "+signup)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Tenants
    +     * list-tenants
    +     * list-tenants-by-partial-domain
    +     * describe-tenant
    +     * add-tenant
    +     * activate-tenant
    +     * deactivate-tenant
    +
    +    """
    +
    +    @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_tenants(self, line , opts=None):
    +        """Retrieve details of all tenants."""
    +        try:
    +            tenants = Stratos.list_tenants()
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenants_by_partial_domain(self, partial_domain , opts=None):
    +        """Search for tenants based on the partial domain value entered."""
    +        try:
    +            tenants = Stratos.list_tenants_by_partial_domain(partial_domain)
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenant(self, tenant_domain_name, opts=None):
    +        """Retrieve details of a specific tenant."""
    +        if not tenant_domain_name:
    +            print("usage: describe-tenant [Domain-Name]")
    +        else:
    +            try:
    +                tenant = Stratos.describe_tenant(tenant_domain_name)
    +                if not tenant:
    +                    print("Tenant not found")
    +                else:
    +                    print("-------------------------------------")
    +                    print("Tenant Information:")
    +                    print("-------------------------------------")
    +                    print("Tenant domain: "+tenant['tenantDomain'])
    +                    print("ID: "+str(tenant['tenantId']))
    +                    print("Active: "+str(tenant['active']))
    +                    print("Email: "+tenant['email'])
    +                    print("Created date: "+datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S'))
    +                    print("-------------------------------------")
    +            except BadResponseError as e:
    +                self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant")
    +    ])
    +    @auth
    +    def do_add_tenant(self, line , opts=None):
    +        """Add a tenant."""
    +        try:
    +            tenant = Stratos.add_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                        opts.domain_name, opts.email)
    +            if tenant:
    +                print("Tenant added successfully : "+opts.domain_name)
    +            else:
    +                print("Error creating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant"),
    +        make_option('-i', '--tenant_id', type="str", help="ID of the tenant")
    +    ])
    +    @auth
    +    def do_update_tenant(self, line , opts=None):
    +        """Update a specific tenant."""
    +        try:
    +            tenant = Stratos.update_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                           opts.domain_name, opts.email, opts.tenant_id)
    +            if tenant:
    +                print("Tenant updated successfully : "+opts.domain_name)
    +            else:
    +                print("Error updating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_activate_tenant(self, tenant_domain, opts=None):
    +        """Activate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: activate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.activate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully activated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not activate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_deactivate_tenant(self, tenant_domain, opts=None):
    +        """Deactivate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: deactivate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.deactivate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully deactivated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not deactivate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Cartridges
    +     * list-cartridges
    +     * list-cartridges-by-filter
    +     * describe-cartridge
    +     * add-cartridge
    +     * remove-cartridge
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of available cartridges."""
    --- End diff --
    
    Looks like parameters are missing in the method comment.


---
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 GSoC15

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/437#discussion_r37261949
  
    --- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
    @@ -0,0 +1,1530 @@
    +# Licensed to the Apache Software Foundation (ASF) under one
    +# or more contributor license agreements.  See the NOTICE file
    +# distributed with this work for additional information
    +# regarding copyright ownership.  The ASF licenses this file
    +# to you under the Apache License, Version 2.0 (the
    +# "License"); you may not use this file except in compliance
    +# with the License.  You may obtain a copy of the License at
    +#
    +# http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing,
    +# software distributed under the License is distributed on an
    +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +# KIND, either express or implied.  See the License for the
    +# specific language governing permissions and limitations
    +# under the License.
    +
    +from cmd2 import *
    +from Utils import *
    +from Stratos import *
    +import Configs
    +from cli.exceptions import BadResponseError
    +
    +
    +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)]
    +
    +    """
    +
    +    Stratos CLI specific methods
    +    ====================================================================================================================
    +
    +    # User
    +     * list-users
    +     * add-user
    +     * update-user
    +     * remove-user
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all users."""
    +        try:
    +            users = Stratos.list_users()
    +            table = PrintableTable()
    +            rows = [["Username", "Role"]]
    +            for user in users:
    +                rows.append([user['userName'], user['role']])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    def do_add_user(self, line , opts=None):
    +        """Add a user."""
    +        try:
    +            if not opts.username_user or not opts.password_user:
    +                print("usage: add-user [-s <username>] [-a <credential>] [-r <role>] [-e <email>] [-f <first name>]" +
    +                      " [-l <last name>] [-o <profile name>]")
    +                return
    +            else:
    +                user = Stratos.add_users(opts.username_user, opts.password_user, 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 BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    @auth
    +    def do_update_user(self, line , opts=None):
    +        """Update a specific user."""
    +        try:
    +            user = Stratos.update_user(opts.username_user, opts.password_user, opts.role_name, opts.first_name, opts.last_name,
    +                                       opts.email, opts.profile_name)
    +            if user:
    +                print("User successfully updated")
    +            else:
    +                print("Error updating the user")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_user(self, name , opts=None):
    +        """Delete a user."""
    +        try:
    +            if not name:
    +                print("usage: remove-user [username]")
    +            else:
    +                user_removed = Stratos.remove_user(name)
    +                print(user_removed)
    +                if user_removed:
    +                    print("You have successfully deleted user: "+name)
    +                else:
    +                    print("Could not delete user: "+name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Applications
    +     * list-applications
    +     * describe-application
    +     * add-application
    +     * update-application
    +     * remove-application
    +     * describe-application-runtime
    +     * deploy-application
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all the applications."""
    +        try:
    +            applications = Stratos.list_applications()
    +            if not applications:
    +                print("No applications found")
    +            else:
    +                table = PrintableTable()
    +                rows = [["Application ID", "Alias", "Status"]]
    +                for application in applications:
    +                    rows.append([application['applicationId'], application['alias'], application['status']])
    +                table.add_rows(rows)
    +                table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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(self, application_id , opts=None):
    +        """Describe an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application [cluster-id]")
    +                return
    +            application = Stratos.describe_application(application_id)
    +            if not application:
    +                print("Application not found in : "+application_id)
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application(self, line , opts=None):
    +        """Add an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application [-f <resource path>]")
    +            else:
    +                add_application = Stratos.add_application(open(opts.json_file_path, 'r').read())
    +                if add_application:
    +                    print("Application added successfully")
    +                else:
    +                    print("Error adding application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_update_application(self, application , opts=None):
    +        """Update an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: update-application [-f <resource path>] [application]")
    +            else:
    +                update_application = Stratos.update_application(application, open(opts.json_file_path, 'r').read())
    +                if update_application:
    +                    print("Application updated successfully")
    +                else:
    +                    print("Error updating application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +
    +    @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_application(self, application , opts=None):
    +        """Delete an application."""
    +        try:
    +            if not application:
    +                print("usage: remove-application [application]")
    +            else:
    +                application_removed = Stratos.remove_application(application)
    +                if application_removed:
    +                    print("You have successfully removed application: "+application)
    +                else:
    +                    print("Could not delete application : "+application)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_deploy_application(self, line , opts=None):
    +        """Deploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: deploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.deploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully deployed application: "+opts.application_id)
    +                else:
    +                    print("Could not deployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_undeploy_application(self, line , opts=None):
    +        """Undeploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: undeploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.undeploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully undeployed application: "+opts.application_id)
    +                else:
    +                    print("Could not undeployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_runtime(self, application_id , opts=None):
    +        """Describe the runtime topology of an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-runtime [application-id]")
    +                return
    +            application_runtime = Stratos.describe_application_runtime(application_id)
    +            if not application_runtime:
    +                print("Application runtime not found")
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application_runtime).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Application signup
    +     * describe-application-signup
    +     * add-application-signup
    +     * remove-application-signup
    +
    +    """
    +    @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, application_id , opts=None):
    +        """Retrieve details of a specific application signup."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-signup [application-id]")
    +                return
    +            application_signup = Stratos.describe_application_signup(application_id)
    +            if not application_signup:
    +                print("Application signup not found")
    +            else:
    +                PrintableJSON(application_signup).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application_signup(self, application_id, opts=None):
    +        """Add a new application signup to the system"""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application-signup [-f <resource path>] [application_id]")
    +            else:
    +                application_signup = Stratos.add_application_signup(application_id, open(opts.json_file_path, 'r').read())
    +                if application_signup:
    +                    print("Application signup added successfully")
    +                else:
    +                    print("Error creating application signup")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_application_signup(self, signup , opts=None):
    +        """Delete an application sign up."""
    +        try:
    +            if not signup:
    +                print("usage: remove-application-signup [signup]")
    +            else:
    +                signup_removed = Stratos.remove_application_signup(signup)
    +                if signup_removed:
    +                    print("You have successfully remove signup: "+signup)
    +                else:
    +                    print("Could not delete application signup: "+signup)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Tenants
    +     * list-tenants
    +     * list-tenants-by-partial-domain
    +     * describe-tenant
    +     * add-tenant
    +     * activate-tenant
    +     * deactivate-tenant
    +
    +    """
    +
    +    @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_tenants(self, line , opts=None):
    +        """Retrieve details of all tenants."""
    +        try:
    +            tenants = Stratos.list_tenants()
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenants_by_partial_domain(self, partial_domain , opts=None):
    +        """Search for tenants based on the partial domain value entered."""
    +        try:
    +            tenants = Stratos.list_tenants_by_partial_domain(partial_domain)
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenant(self, tenant_domain_name, opts=None):
    +        """Retrieve details of a specific tenant."""
    +        if not tenant_domain_name:
    +            print("usage: describe-tenant [Domain-Name]")
    +        else:
    +            try:
    +                tenant = Stratos.describe_tenant(tenant_domain_name)
    +                if not tenant:
    +                    print("Tenant not found")
    +                else:
    +                    print("-------------------------------------")
    +                    print("Tenant Information:")
    +                    print("-------------------------------------")
    +                    print("Tenant domain: "+tenant['tenantDomain'])
    +                    print("ID: "+str(tenant['tenantId']))
    +                    print("Active: "+str(tenant['active']))
    +                    print("Email: "+tenant['email'])
    +                    print("Created date: "+datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S'))
    +                    print("-------------------------------------")
    +            except BadResponseError as e:
    +                self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant")
    +    ])
    +    @auth
    +    def do_add_tenant(self, line , opts=None):
    +        """Add a tenant."""
    +        try:
    +            tenant = Stratos.add_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                        opts.domain_name, opts.email)
    +            if tenant:
    +                print("Tenant added successfully : "+opts.domain_name)
    +            else:
    +                print("Error creating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant"),
    +        make_option('-i', '--tenant_id', type="str", help="ID of the tenant")
    +    ])
    +    @auth
    +    def do_update_tenant(self, line , opts=None):
    +        """Update a specific tenant."""
    +        try:
    +            tenant = Stratos.update_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                           opts.domain_name, opts.email, opts.tenant_id)
    +            if tenant:
    +                print("Tenant updated successfully : "+opts.domain_name)
    +            else:
    +                print("Error updating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_activate_tenant(self, tenant_domain, opts=None):
    +        """Activate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: activate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.activate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully activated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not activate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_deactivate_tenant(self, tenant_domain, opts=None):
    +        """Deactivate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: deactivate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.deactivate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully deactivated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not deactivate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Cartridges
    +     * list-cartridges
    +     * list-cartridges-by-filter
    +     * describe-cartridge
    +     * add-cartridge
    +     * remove-cartridge
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of available cartridges."""
    +        try:
    +            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'], "True" if cartridge['multiTenant'] == 1 else "False"])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_by_filter(self, filter_text , opts=None):
    +        """Retrieve details of available cartridges."""
    +        try:
    +            if not filter_text:
    +                print("")
    +            else:
    +                cartridges = Stratos.list_cartridges_by_filter(filter_text)
    +                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'], "True" if cartridge['multiTenant'] == 1 else "False"])
    +                table.add_rows(rows)
    +                table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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, cartridge_type, opts=None):
    +        """Retrieve details of a specific cartridge."""
    +        if not cartridge_type:
    +            print("usage: describe-cartridge [cartridge-type]")
    +        else:
    +            try:
    +                cartridge = Stratos.describe_cartridge(cartridge_type)
    +                if not cartridge:
    +                    print("Cartridge not found")
    +                else:
    +                    print("-------------------------------------")
    +                    print("Cartridge Information:")
    +                    print("-------------------------------------")
    +                    print("Type: "+cartridge['type'])
    +                    print("Category: "+cartridge['category'])
    +                    print("Name: "+cartridge['displayName'])
    +                    print("Description: "+cartridge['description'])
    +                    print("Version: "+str(cartridge['version']))
    +                    print("Multi-Tenant: "+str(cartridge['multiTenant']))
    +                    print("Host Name: "+cartridge['host'])
    +                    print("-------------------------------------")
    +            except requests.HTTPError as e:
    +                self.perror(str(e))
    +    
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_cartridge(self, line , opts=None):
    +        """Add a cartridge definition."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-cartridge [-f <resource path>]")
    +            else:
    +                cartridge = Stratos.add_cartridge(open(opts.json_file_path, 'r').read())
    +                if cartridge:
    +                    print("Cartridge added successfully")
    +                else:
    +                    print("Error adding Cartridge")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_update_cartridge(self, line , opts=None):
    +        """Update a cartridge"""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: update-cartridge [-f <resource path>]")
    +            else:
    +                cartridge = Stratos.update_cartridge(open(opts.json_file_path, 'r').read())
    +                if cartridge:
    +                    print("Cartridge updated successfully")
    +                else:
    +                    print("Error updating Cartridge")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +
    +    @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_cartridge(self, cartridge_type , opts=None):
    +        """Delete a cartridge"""
    +        try:
    +            if not cartridge_type:
    +                print("usage: remove-cartridge [cartridge-type]")
    +            else:
    +                cartridge_removed = Stratos.remove_cartridge(cartridge_type)
    +                if cartridge_removed:
    +                    print("Successfully un-deployed cartridge : "+cartridge_type)
    +                else:
    +                    print("Could not un-deployed cartridge : "+cartridge_type)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Cartridge groups
    +     * list-cartridge-groups
    +     * describe-cartridge-group
    +     * add-cartridge-group
    +     * remove-cartridge-group
    +
    +    """
    +
    +    @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_cartridge_groups(self, line , opts=None):
    +        """Retrieve details of all the cartridge groups."""
    --- End diff --
    
    Same as above, shall we add parameter descriptions to the method comment?


---
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 GSoC15

Posted by agentmilindu <gi...@git.apache.org>.
Github user agentmilindu commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/437#discussion_r37264199
  
    --- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
    @@ -0,0 +1,1530 @@
    +# Licensed to the Apache Software Foundation (ASF) under one
    +# or more contributor license agreements.  See the NOTICE file
    +# distributed with this work for additional information
    +# regarding copyright ownership.  The ASF licenses this file
    +# to you under the Apache License, Version 2.0 (the
    +# "License"); you may not use this file except in compliance
    +# with the License.  You may obtain a copy of the License at
    +#
    +# http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing,
    +# software distributed under the License is distributed on an
    +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +# KIND, either express or implied.  See the License for the
    +# specific language governing permissions and limitations
    +# under the License.
    +
    +from cmd2 import *
    +from Utils import *
    +from Stratos import *
    +import Configs
    +from cli.exceptions import BadResponseError
    +
    +
    +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)]
    +
    +    """
    +
    +    Stratos CLI specific methods
    +    ====================================================================================================================
    +
    +    # User
    +     * list-users
    +     * add-user
    +     * update-user
    +     * remove-user
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all users."""
    +        try:
    +            users = Stratos.list_users()
    +            table = PrintableTable()
    +            rows = [["Username", "Role"]]
    +            for user in users:
    +                rows.append([user['userName'], user['role']])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    def do_add_user(self, line , opts=None):
    +        """Add a user."""
    +        try:
    +            if not opts.username_user or not opts.password_user:
    +                print("usage: add-user [-s <username>] [-a <credential>] [-r <role>] [-e <email>] [-f <first name>]" +
    +                      " [-l <last name>] [-o <profile name>]")
    +                return
    +            else:
    +                user = Stratos.add_users(opts.username_user, opts.password_user, 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 BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    @auth
    +    def do_update_user(self, line , opts=None):
    +        """Update a specific user."""
    +        try:
    +            user = Stratos.update_user(opts.username_user, opts.password_user, opts.role_name, opts.first_name, opts.last_name,
    +                                       opts.email, opts.profile_name)
    +            if user:
    +                print("User successfully updated")
    +            else:
    +                print("Error updating the user")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_user(self, name , opts=None):
    +        """Delete a user."""
    +        try:
    +            if not name:
    +                print("usage: remove-user [username]")
    +            else:
    +                user_removed = Stratos.remove_user(name)
    +                print(user_removed)
    +                if user_removed:
    +                    print("You have successfully deleted user: "+name)
    +                else:
    +                    print("Could not delete user: "+name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Applications
    +     * list-applications
    +     * describe-application
    +     * add-application
    +     * update-application
    +     * remove-application
    +     * describe-application-runtime
    +     * deploy-application
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all the applications."""
    +        try:
    +            applications = Stratos.list_applications()
    +            if not applications:
    +                print("No applications found")
    +            else:
    +                table = PrintableTable()
    +                rows = [["Application ID", "Alias", "Status"]]
    +                for application in applications:
    +                    rows.append([application['applicationId'], application['alias'], application['status']])
    +                table.add_rows(rows)
    +                table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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(self, application_id , opts=None):
    +        """Describe an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application [cluster-id]")
    +                return
    +            application = Stratos.describe_application(application_id)
    +            if not application:
    +                print("Application not found in : "+application_id)
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application(self, line , opts=None):
    +        """Add an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application [-f <resource path>]")
    +            else:
    +                add_application = Stratos.add_application(open(opts.json_file_path, 'r').read())
    +                if add_application:
    +                    print("Application added successfully")
    +                else:
    +                    print("Error adding application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_update_application(self, application , opts=None):
    +        """Update an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: update-application [-f <resource path>] [application]")
    +            else:
    +                update_application = Stratos.update_application(application, open(opts.json_file_path, 'r').read())
    +                if update_application:
    +                    print("Application updated successfully")
    +                else:
    +                    print("Error updating application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +
    +    @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_application(self, application , opts=None):
    +        """Delete an application."""
    +        try:
    +            if not application:
    +                print("usage: remove-application [application]")
    +            else:
    +                application_removed = Stratos.remove_application(application)
    +                if application_removed:
    +                    print("You have successfully removed application: "+application)
    +                else:
    +                    print("Could not delete application : "+application)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_deploy_application(self, line , opts=None):
    +        """Deploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: deploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.deploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully deployed application: "+opts.application_id)
    +                else:
    +                    print("Could not deployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_undeploy_application(self, line , opts=None):
    +        """Undeploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: undeploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.undeploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully undeployed application: "+opts.application_id)
    +                else:
    +                    print("Could not undeployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_runtime(self, application_id , opts=None):
    +        """Describe the runtime topology of an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-runtime [application-id]")
    +                return
    +            application_runtime = Stratos.describe_application_runtime(application_id)
    +            if not application_runtime:
    +                print("Application runtime not found")
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application_runtime).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Application signup
    +     * describe-application-signup
    +     * add-application-signup
    +     * remove-application-signup
    +
    +    """
    +    @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, application_id , opts=None):
    +        """Retrieve details of a specific application signup."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-signup [application-id]")
    +                return
    +            application_signup = Stratos.describe_application_signup(application_id)
    +            if not application_signup:
    +                print("Application signup not found")
    +            else:
    +                PrintableJSON(application_signup).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application_signup(self, application_id, opts=None):
    +        """Add a new application signup to the system"""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application-signup [-f <resource path>] [application_id]")
    +            else:
    +                application_signup = Stratos.add_application_signup(application_id, open(opts.json_file_path, 'r').read())
    +                if application_signup:
    +                    print("Application signup added successfully")
    +                else:
    +                    print("Error creating application signup")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_application_signup(self, signup , opts=None):
    +        """Delete an application sign up."""
    +        try:
    +            if not signup:
    +                print("usage: remove-application-signup [signup]")
    +            else:
    +                signup_removed = Stratos.remove_application_signup(signup)
    +                if signup_removed:
    +                    print("You have successfully remove signup: "+signup)
    +                else:
    +                    print("Could not delete application signup: "+signup)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Tenants
    +     * list-tenants
    +     * list-tenants-by-partial-domain
    +     * describe-tenant
    +     * add-tenant
    +     * activate-tenant
    +     * deactivate-tenant
    +
    +    """
    +
    +    @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_tenants(self, line , opts=None):
    +        """Retrieve details of all tenants."""
    +        try:
    +            tenants = Stratos.list_tenants()
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenants_by_partial_domain(self, partial_domain , opts=None):
    +        """Search for tenants based on the partial domain value entered."""
    +        try:
    +            tenants = Stratos.list_tenants_by_partial_domain(partial_domain)
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenant(self, tenant_domain_name, opts=None):
    +        """Retrieve details of a specific tenant."""
    +        if not tenant_domain_name:
    +            print("usage: describe-tenant [Domain-Name]")
    +        else:
    +            try:
    +                tenant = Stratos.describe_tenant(tenant_domain_name)
    +                if not tenant:
    +                    print("Tenant not found")
    +                else:
    +                    print("-------------------------------------")
    +                    print("Tenant Information:")
    +                    print("-------------------------------------")
    +                    print("Tenant domain: "+tenant['tenantDomain'])
    +                    print("ID: "+str(tenant['tenantId']))
    +                    print("Active: "+str(tenant['active']))
    +                    print("Email: "+tenant['email'])
    +                    print("Created date: "+datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S'))
    +                    print("-------------------------------------")
    +            except BadResponseError as e:
    +                self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant")
    +    ])
    +    @auth
    +    def do_add_tenant(self, line , opts=None):
    +        """Add a tenant."""
    +        try:
    +            tenant = Stratos.add_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                        opts.domain_name, opts.email)
    +            if tenant:
    +                print("Tenant added successfully : "+opts.domain_name)
    +            else:
    +                print("Error creating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant"),
    +        make_option('-i', '--tenant_id', type="str", help="ID of the tenant")
    +    ])
    +    @auth
    +    def do_update_tenant(self, line , opts=None):
    +        """Update a specific tenant."""
    +        try:
    +            tenant = Stratos.update_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                           opts.domain_name, opts.email, opts.tenant_id)
    +            if tenant:
    +                print("Tenant updated successfully : "+opts.domain_name)
    +            else:
    +                print("Error updating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_activate_tenant(self, tenant_domain, opts=None):
    +        """Activate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: activate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.activate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully activated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not activate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_deactivate_tenant(self, tenant_domain, opts=None):
    +        """Deactivate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: deactivate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.deactivate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully deactivated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not deactivate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Cartridges
    +     * list-cartridges
    +     * list-cartridges-by-filter
    +     * describe-cartridge
    +     * add-cartridge
    +     * remove-cartridge
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of available cartridges."""
    +        try:
    +            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'], "True" if cartridge['multiTenant'] == 1 else "False"])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_by_filter(self, filter_text , opts=None):
    +        """Retrieve details of available cartridges."""
    +        try:
    +            if not filter_text:
    +                print("")
    --- End diff --
    
    Ah, my mistake :O 


---
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 GSoC15

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on the pull request:

    https://github.com/apache/stratos/pull/437#issuecomment-160507178
  
    I think we have merged this PR (Python CLI) to master branch. If so shall we close this?
    Thanks


---
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 GSoC15

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/437#discussion_r37261932
  
    --- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
    @@ -0,0 +1,1530 @@
    +# Licensed to the Apache Software Foundation (ASF) under one
    +# or more contributor license agreements.  See the NOTICE file
    +# distributed with this work for additional information
    +# regarding copyright ownership.  The ASF licenses this file
    +# to you under the Apache License, Version 2.0 (the
    +# "License"); you may not use this file except in compliance
    +# with the License.  You may obtain a copy of the License at
    +#
    +# http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing,
    +# software distributed under the License is distributed on an
    +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +# KIND, either express or implied.  See the License for the
    +# specific language governing permissions and limitations
    +# under the License.
    +
    +from cmd2 import *
    +from Utils import *
    +from Stratos import *
    +import Configs
    +from cli.exceptions import BadResponseError
    +
    +
    +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)]
    +
    +    """
    +
    +    Stratos CLI specific methods
    +    ====================================================================================================================
    +
    +    # User
    +     * list-users
    +     * add-user
    +     * update-user
    +     * remove-user
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all users."""
    +        try:
    +            users = Stratos.list_users()
    +            table = PrintableTable()
    +            rows = [["Username", "Role"]]
    +            for user in users:
    +                rows.append([user['userName'], user['role']])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    def do_add_user(self, line , opts=None):
    +        """Add a user."""
    +        try:
    +            if not opts.username_user or not opts.password_user:
    +                print("usage: add-user [-s <username>] [-a <credential>] [-r <role>] [-e <email>] [-f <first name>]" +
    +                      " [-l <last name>] [-o <profile name>]")
    +                return
    +            else:
    +                user = Stratos.add_users(opts.username_user, opts.password_user, 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 BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    @auth
    +    def do_update_user(self, line , opts=None):
    +        """Update a specific user."""
    +        try:
    +            user = Stratos.update_user(opts.username_user, opts.password_user, opts.role_name, opts.first_name, opts.last_name,
    +                                       opts.email, opts.profile_name)
    +            if user:
    +                print("User successfully updated")
    +            else:
    +                print("Error updating the user")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_user(self, name , opts=None):
    +        """Delete a user."""
    +        try:
    +            if not name:
    +                print("usage: remove-user [username]")
    +            else:
    +                user_removed = Stratos.remove_user(name)
    +                print(user_removed)
    +                if user_removed:
    +                    print("You have successfully deleted user: "+name)
    +                else:
    +                    print("Could not delete user: "+name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Applications
    +     * list-applications
    +     * describe-application
    +     * add-application
    +     * update-application
    +     * remove-application
    +     * describe-application-runtime
    +     * deploy-application
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all the applications."""
    +        try:
    +            applications = Stratos.list_applications()
    +            if not applications:
    +                print("No applications found")
    +            else:
    +                table = PrintableTable()
    +                rows = [["Application ID", "Alias", "Status"]]
    +                for application in applications:
    +                    rows.append([application['applicationId'], application['alias'], application['status']])
    +                table.add_rows(rows)
    +                table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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(self, application_id , opts=None):
    +        """Describe an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application [cluster-id]")
    +                return
    +            application = Stratos.describe_application(application_id)
    +            if not application:
    +                print("Application not found in : "+application_id)
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application(self, line , opts=None):
    +        """Add an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application [-f <resource path>]")
    +            else:
    +                add_application = Stratos.add_application(open(opts.json_file_path, 'r').read())
    +                if add_application:
    +                    print("Application added successfully")
    +                else:
    +                    print("Error adding application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_update_application(self, application , opts=None):
    +        """Update an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: update-application [-f <resource path>] [application]")
    +            else:
    +                update_application = Stratos.update_application(application, open(opts.json_file_path, 'r').read())
    +                if update_application:
    +                    print("Application updated successfully")
    +                else:
    +                    print("Error updating application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +
    +    @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_application(self, application , opts=None):
    +        """Delete an application."""
    +        try:
    +            if not application:
    +                print("usage: remove-application [application]")
    +            else:
    +                application_removed = Stratos.remove_application(application)
    +                if application_removed:
    +                    print("You have successfully removed application: "+application)
    +                else:
    +                    print("Could not delete application : "+application)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_deploy_application(self, line , opts=None):
    +        """Deploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: deploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.deploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully deployed application: "+opts.application_id)
    +                else:
    +                    print("Could not deployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_undeploy_application(self, line , opts=None):
    +        """Undeploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: undeploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.undeploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully undeployed application: "+opts.application_id)
    +                else:
    +                    print("Could not undeployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_runtime(self, application_id , opts=None):
    +        """Describe the runtime topology of an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-runtime [application-id]")
    +                return
    +            application_runtime = Stratos.describe_application_runtime(application_id)
    +            if not application_runtime:
    +                print("Application runtime not found")
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application_runtime).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Application signup
    +     * describe-application-signup
    +     * add-application-signup
    +     * remove-application-signup
    +
    +    """
    +    @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, application_id , opts=None):
    +        """Retrieve details of a specific application signup."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-signup [application-id]")
    +                return
    +            application_signup = Stratos.describe_application_signup(application_id)
    +            if not application_signup:
    +                print("Application signup not found")
    +            else:
    +                PrintableJSON(application_signup).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application_signup(self, application_id, opts=None):
    +        """Add a new application signup to the system"""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application-signup [-f <resource path>] [application_id]")
    +            else:
    +                application_signup = Stratos.add_application_signup(application_id, open(opts.json_file_path, 'r').read())
    +                if application_signup:
    +                    print("Application signup added successfully")
    +                else:
    +                    print("Error creating application signup")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_application_signup(self, signup , opts=None):
    +        """Delete an application sign up."""
    +        try:
    +            if not signup:
    +                print("usage: remove-application-signup [signup]")
    +            else:
    +                signup_removed = Stratos.remove_application_signup(signup)
    +                if signup_removed:
    +                    print("You have successfully remove signup: "+signup)
    +                else:
    +                    print("Could not delete application signup: "+signup)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Tenants
    +     * list-tenants
    +     * list-tenants-by-partial-domain
    +     * describe-tenant
    +     * add-tenant
    +     * activate-tenant
    +     * deactivate-tenant
    +
    +    """
    +
    +    @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_tenants(self, line , opts=None):
    +        """Retrieve details of all tenants."""
    +        try:
    +            tenants = Stratos.list_tenants()
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenants_by_partial_domain(self, partial_domain , opts=None):
    +        """Search for tenants based on the partial domain value entered."""
    +        try:
    +            tenants = Stratos.list_tenants_by_partial_domain(partial_domain)
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenant(self, tenant_domain_name, opts=None):
    +        """Retrieve details of a specific tenant."""
    +        if not tenant_domain_name:
    +            print("usage: describe-tenant [Domain-Name]")
    +        else:
    +            try:
    +                tenant = Stratos.describe_tenant(tenant_domain_name)
    +                if not tenant:
    +                    print("Tenant not found")
    +                else:
    +                    print("-------------------------------------")
    +                    print("Tenant Information:")
    +                    print("-------------------------------------")
    +                    print("Tenant domain: "+tenant['tenantDomain'])
    +                    print("ID: "+str(tenant['tenantId']))
    +                    print("Active: "+str(tenant['active']))
    +                    print("Email: "+tenant['email'])
    +                    print("Created date: "+datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S'))
    +                    print("-------------------------------------")
    +            except BadResponseError as e:
    +                self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant")
    +    ])
    +    @auth
    +    def do_add_tenant(self, line , opts=None):
    +        """Add a tenant."""
    +        try:
    +            tenant = Stratos.add_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                        opts.domain_name, opts.email)
    +            if tenant:
    +                print("Tenant added successfully : "+opts.domain_name)
    +            else:
    +                print("Error creating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant"),
    +        make_option('-i', '--tenant_id', type="str", help="ID of the tenant")
    +    ])
    +    @auth
    +    def do_update_tenant(self, line , opts=None):
    +        """Update a specific tenant."""
    +        try:
    +            tenant = Stratos.update_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                           opts.domain_name, opts.email, opts.tenant_id)
    +            if tenant:
    +                print("Tenant updated successfully : "+opts.domain_name)
    +            else:
    +                print("Error updating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_activate_tenant(self, tenant_domain, opts=None):
    +        """Activate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: activate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.activate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully activated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not activate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_deactivate_tenant(self, tenant_domain, opts=None):
    +        """Deactivate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: deactivate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.deactivate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully deactivated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not deactivate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Cartridges
    +     * list-cartridges
    +     * list-cartridges-by-filter
    +     * describe-cartridge
    +     * add-cartridge
    +     * remove-cartridge
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of available cartridges."""
    +        try:
    +            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'], "True" if cartridge['multiTenant'] == 1 else "False"])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_by_filter(self, filter_text , opts=None):
    +        """Retrieve details of available cartridges."""
    +        try:
    +            if not filter_text:
    +                print("")
    --- End diff --
    
    Why do we print a blank line 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 GSoC15

Posted by agentmilindu <gi...@git.apache.org>.
Github user agentmilindu commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/437#discussion_r37264177
  
    --- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
    @@ -0,0 +1,1530 @@
    +# Licensed to the Apache Software Foundation (ASF) under one
    +# or more contributor license agreements.  See the NOTICE file
    +# distributed with this work for additional information
    +# regarding copyright ownership.  The ASF licenses this file
    +# to you under the Apache License, Version 2.0 (the
    +# "License"); you may not use this file except in compliance
    +# with the License.  You may obtain a copy of the License at
    +#
    +# http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing,
    +# software distributed under the License is distributed on an
    +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +# KIND, either express or implied.  See the License for the
    +# specific language governing permissions and limitations
    +# under the License.
    +
    +from cmd2 import *
    +from Utils import *
    +from Stratos import *
    +import Configs
    +from cli.exceptions import BadResponseError
    +
    +
    +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)]
    +
    +    """
    +
    +    Stratos CLI specific methods
    +    ====================================================================================================================
    +
    +    # User
    +     * list-users
    +     * add-user
    +     * update-user
    +     * remove-user
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all users."""
    +        try:
    +            users = Stratos.list_users()
    +            table = PrintableTable()
    +            rows = [["Username", "Role"]]
    +            for user in users:
    +                rows.append([user['userName'], user['role']])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    def do_add_user(self, line , opts=None):
    +        """Add a user."""
    +        try:
    +            if not opts.username_user or not opts.password_user:
    +                print("usage: add-user [-s <username>] [-a <credential>] [-r <role>] [-e <email>] [-f <first name>]" +
    +                      " [-l <last name>] [-o <profile name>]")
    +                return
    +            else:
    +                user = Stratos.add_users(opts.username_user, opts.password_user, 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 BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    @auth
    +    def do_update_user(self, line , opts=None):
    +        """Update a specific user."""
    +        try:
    +            user = Stratos.update_user(opts.username_user, opts.password_user, opts.role_name, opts.first_name, opts.last_name,
    +                                       opts.email, opts.profile_name)
    +            if user:
    +                print("User successfully updated")
    +            else:
    +                print("Error updating the user")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_user(self, name , opts=None):
    +        """Delete a user."""
    +        try:
    +            if not name:
    +                print("usage: remove-user [username]")
    +            else:
    +                user_removed = Stratos.remove_user(name)
    +                print(user_removed)
    +                if user_removed:
    +                    print("You have successfully deleted user: "+name)
    +                else:
    +                    print("Could not delete user: "+name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Applications
    +     * list-applications
    +     * describe-application
    +     * add-application
    +     * update-application
    +     * remove-application
    +     * describe-application-runtime
    +     * deploy-application
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all the applications."""
    +        try:
    +            applications = Stratos.list_applications()
    +            if not applications:
    +                print("No applications found")
    +            else:
    +                table = PrintableTable()
    +                rows = [["Application ID", "Alias", "Status"]]
    +                for application in applications:
    +                    rows.append([application['applicationId'], application['alias'], application['status']])
    +                table.add_rows(rows)
    +                table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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(self, application_id , opts=None):
    +        """Describe an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application [cluster-id]")
    +                return
    +            application = Stratos.describe_application(application_id)
    +            if not application:
    +                print("Application not found in : "+application_id)
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application(self, line , opts=None):
    +        """Add an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application [-f <resource path>]")
    +            else:
    +                add_application = Stratos.add_application(open(opts.json_file_path, 'r').read())
    +                if add_application:
    +                    print("Application added successfully")
    +                else:
    +                    print("Error adding application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_update_application(self, application , opts=None):
    +        """Update an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: update-application [-f <resource path>] [application]")
    +            else:
    +                update_application = Stratos.update_application(application, open(opts.json_file_path, 'r').read())
    +                if update_application:
    +                    print("Application updated successfully")
    +                else:
    +                    print("Error updating application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +
    +    @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_application(self, application , opts=None):
    +        """Delete an application."""
    +        try:
    +            if not application:
    +                print("usage: remove-application [application]")
    +            else:
    +                application_removed = Stratos.remove_application(application)
    +                if application_removed:
    +                    print("You have successfully removed application: "+application)
    +                else:
    +                    print("Could not delete application : "+application)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_deploy_application(self, line , opts=None):
    +        """Deploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: deploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.deploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully deployed application: "+opts.application_id)
    +                else:
    +                    print("Could not deployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_undeploy_application(self, line , opts=None):
    +        """Undeploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: undeploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.undeploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully undeployed application: "+opts.application_id)
    +                else:
    +                    print("Could not undeployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_runtime(self, application_id , opts=None):
    +        """Describe the runtime topology of an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-runtime [application-id]")
    +                return
    +            application_runtime = Stratos.describe_application_runtime(application_id)
    +            if not application_runtime:
    +                print("Application runtime not found")
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application_runtime).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Application signup
    +     * describe-application-signup
    +     * add-application-signup
    +     * remove-application-signup
    +
    +    """
    +    @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, application_id , opts=None):
    +        """Retrieve details of a specific application signup."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-signup [application-id]")
    +                return
    +            application_signup = Stratos.describe_application_signup(application_id)
    +            if not application_signup:
    +                print("Application signup not found")
    +            else:
    +                PrintableJSON(application_signup).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application_signup(self, application_id, opts=None):
    +        """Add a new application signup to the system"""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application-signup [-f <resource path>] [application_id]")
    +            else:
    +                application_signup = Stratos.add_application_signup(application_id, open(opts.json_file_path, 'r').read())
    +                if application_signup:
    +                    print("Application signup added successfully")
    +                else:
    +                    print("Error creating application signup")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_application_signup(self, signup , opts=None):
    +        """Delete an application sign up."""
    +        try:
    +            if not signup:
    +                print("usage: remove-application-signup [signup]")
    +            else:
    +                signup_removed = Stratos.remove_application_signup(signup)
    +                if signup_removed:
    +                    print("You have successfully remove signup: "+signup)
    +                else:
    +                    print("Could not delete application signup: "+signup)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Tenants
    +     * list-tenants
    +     * list-tenants-by-partial-domain
    +     * describe-tenant
    +     * add-tenant
    +     * activate-tenant
    +     * deactivate-tenant
    +
    +    """
    +
    +    @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_tenants(self, line , opts=None):
    +        """Retrieve details of all tenants."""
    +        try:
    +            tenants = Stratos.list_tenants()
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenants_by_partial_domain(self, partial_domain , opts=None):
    +        """Search for tenants based on the partial domain value entered."""
    +        try:
    +            tenants = Stratos.list_tenants_by_partial_domain(partial_domain)
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenant(self, tenant_domain_name, opts=None):
    +        """Retrieve details of a specific tenant."""
    +        if not tenant_domain_name:
    +            print("usage: describe-tenant [Domain-Name]")
    +        else:
    +            try:
    +                tenant = Stratos.describe_tenant(tenant_domain_name)
    +                if not tenant:
    +                    print("Tenant not found")
    +                else:
    +                    print("-------------------------------------")
    +                    print("Tenant Information:")
    +                    print("-------------------------------------")
    +                    print("Tenant domain: "+tenant['tenantDomain'])
    +                    print("ID: "+str(tenant['tenantId']))
    +                    print("Active: "+str(tenant['active']))
    +                    print("Email: "+tenant['email'])
    +                    print("Created date: "+datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S'))
    +                    print("-------------------------------------")
    +            except BadResponseError as e:
    +                self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant")
    +    ])
    +    @auth
    +    def do_add_tenant(self, line , opts=None):
    +        """Add a tenant."""
    +        try:
    +            tenant = Stratos.add_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                        opts.domain_name, opts.email)
    +            if tenant:
    +                print("Tenant added successfully : "+opts.domain_name)
    +            else:
    +                print("Error creating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant"),
    +        make_option('-i', '--tenant_id', type="str", help="ID of the tenant")
    +    ])
    +    @auth
    +    def do_update_tenant(self, line , opts=None):
    +        """Update a specific tenant."""
    +        try:
    +            tenant = Stratos.update_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                           opts.domain_name, opts.email, opts.tenant_id)
    +            if tenant:
    +                print("Tenant updated successfully : "+opts.domain_name)
    +            else:
    +                print("Error updating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_activate_tenant(self, tenant_domain, opts=None):
    +        """Activate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: activate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.activate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully activated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not activate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_deactivate_tenant(self, tenant_domain, opts=None):
    +        """Deactivate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: deactivate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.deactivate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully deactivated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not deactivate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Cartridges
    +     * list-cartridges
    +     * list-cartridges-by-filter
    +     * describe-cartridge
    +     * add-cartridge
    +     * remove-cartridge
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of available cartridges."""
    +        try:
    +            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'], "True" if cartridge['multiTenant'] == 1 else "False"])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_by_filter(self, filter_text , opts=None):
    +        """Retrieve details of available cartridges."""
    +        try:
    +            if not filter_text:
    +                print("")
    +            else:
    +                cartridges = Stratos.list_cartridges_by_filter(filter_text)
    +                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'], "True" if cartridge['multiTenant'] == 1 else "False"])
    +                table.add_rows(rows)
    +                table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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, cartridge_type, opts=None):
    +        """Retrieve details of a specific cartridge."""
    +        if not cartridge_type:
    +            print("usage: describe-cartridge [cartridge-type]")
    +        else:
    +            try:
    +                cartridge = Stratos.describe_cartridge(cartridge_type)
    +                if not cartridge:
    +                    print("Cartridge not found")
    +                else:
    +                    print("-------------------------------------")
    +                    print("Cartridge Information:")
    +                    print("-------------------------------------")
    +                    print("Type: "+cartridge['type'])
    +                    print("Category: "+cartridge['category'])
    +                    print("Name: "+cartridge['displayName'])
    +                    print("Description: "+cartridge['description'])
    +                    print("Version: "+str(cartridge['version']))
    +                    print("Multi-Tenant: "+str(cartridge['multiTenant']))
    +                    print("Host Name: "+cartridge['host'])
    +                    print("-------------------------------------")
    +            except requests.HTTPError as e:
    +                self.perror(str(e))
    +    
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_cartridge(self, line , opts=None):
    +        """Add a cartridge definition."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-cartridge [-f <resource path>]")
    +            else:
    +                cartridge = Stratos.add_cartridge(open(opts.json_file_path, 'r').read())
    +                if cartridge:
    +                    print("Cartridge added successfully")
    +                else:
    +                    print("Error adding Cartridge")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_update_cartridge(self, line , opts=None):
    +        """Update a cartridge"""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: update-cartridge [-f <resource path>]")
    +            else:
    +                cartridge = Stratos.update_cartridge(open(opts.json_file_path, 'r').read())
    +                if cartridge:
    +                    print("Cartridge updated successfully")
    +                else:
    +                    print("Error updating Cartridge")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +
    +    @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_cartridge(self, cartridge_type , opts=None):
    +        """Delete a cartridge"""
    +        try:
    +            if not cartridge_type:
    +                print("usage: remove-cartridge [cartridge-type]")
    +            else:
    +                cartridge_removed = Stratos.remove_cartridge(cartridge_type)
    +                if cartridge_removed:
    +                    print("Successfully un-deployed cartridge : "+cartridge_type)
    +                else:
    +                    print("Could not un-deployed cartridge : "+cartridge_type)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Cartridge groups
    +     * list-cartridge-groups
    +     * describe-cartridge-group
    +     * add-cartridge-group
    +     * remove-cartridge-group
    +
    +    """
    +
    +    @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_cartridge_groups(self, line , opts=None):
    +        """Retrieve details of all the cartridge groups."""
    --- End diff --
    
    This Doc string is used as the help text of the command and the parameter descriptions are automatically added by the framework.  `help` attribute of the `make_option` function in `@options` decorator is used as parameter description :) 
     
    ![stratos-cli](https://cloud.githubusercontent.com/assets/1391468/9322605/2cfe8878-4593-11e5-8e97-b7e02e1a085b.png)



---
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 GSoC15

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/437#discussion_r37261916
  
    --- Diff: components/org.apache.stratos.python.cli/src/main/python/cli/CLI.py ---
    @@ -0,0 +1,1530 @@
    +# Licensed to the Apache Software Foundation (ASF) under one
    +# or more contributor license agreements.  See the NOTICE file
    +# distributed with this work for additional information
    +# regarding copyright ownership.  The ASF licenses this file
    +# to you under the Apache License, Version 2.0 (the
    +# "License"); you may not use this file except in compliance
    +# with the License.  You may obtain a copy of the License at
    +#
    +# http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing,
    +# software distributed under the License is distributed on an
    +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +# KIND, either express or implied.  See the License for the
    +# specific language governing permissions and limitations
    +# under the License.
    +
    +from cmd2 import *
    +from Utils import *
    +from Stratos import *
    +import Configs
    +from cli.exceptions import BadResponseError
    +
    +
    +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)]
    +
    +    """
    +
    +    Stratos CLI specific methods
    +    ====================================================================================================================
    +
    +    # User
    +     * list-users
    +     * add-user
    +     * update-user
    +     * remove-user
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all users."""
    +        try:
    +            users = Stratos.list_users()
    +            table = PrintableTable()
    +            rows = [["Username", "Role"]]
    +            for user in users:
    +                rows.append([user['userName'], user['role']])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    def do_add_user(self, line , opts=None):
    +        """Add a user."""
    +        try:
    +            if not opts.username_user or not opts.password_user:
    +                print("usage: add-user [-s <username>] [-a <credential>] [-r <role>] [-e <email>] [-f <first name>]" +
    +                      " [-l <last name>] [-o <profile name>]")
    +                return
    +            else:
    +                user = Stratos.add_users(opts.username_user, opts.password_user, 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 BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the user"),
    +        make_option('-a', '--password_user', 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('-o', '--profile_name', type="str", help="Profile name of the user")
    +    ])
    +    @auth
    +    def do_update_user(self, line , opts=None):
    +        """Update a specific user."""
    +        try:
    +            user = Stratos.update_user(opts.username_user, opts.password_user, opts.role_name, opts.first_name, opts.last_name,
    +                                       opts.email, opts.profile_name)
    +            if user:
    +                print("User successfully updated")
    +            else:
    +                print("Error updating the user")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_user(self, name , opts=None):
    +        """Delete a user."""
    +        try:
    +            if not name:
    +                print("usage: remove-user [username]")
    +            else:
    +                user_removed = Stratos.remove_user(name)
    +                print(user_removed)
    +                if user_removed:
    +                    print("You have successfully deleted user: "+name)
    +                else:
    +                    print("Could not delete user: "+name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Applications
    +     * list-applications
    +     * describe-application
    +     * add-application
    +     * update-application
    +     * remove-application
    +     * describe-application-runtime
    +     * deploy-application
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of all the applications."""
    +        try:
    +            applications = Stratos.list_applications()
    +            if not applications:
    +                print("No applications found")
    +            else:
    +                table = PrintableTable()
    +                rows = [["Application ID", "Alias", "Status"]]
    +                for application in applications:
    +                    rows.append([application['applicationId'], application['alias'], application['status']])
    +                table.add_rows(rows)
    +                table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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(self, application_id , opts=None):
    +        """Describe an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application [cluster-id]")
    +                return
    +            application = Stratos.describe_application(application_id)
    +            if not application:
    +                print("Application not found in : "+application_id)
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application(self, line , opts=None):
    +        """Add an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application [-f <resource path>]")
    +            else:
    +                add_application = Stratos.add_application(open(opts.json_file_path, 'r').read())
    +                if add_application:
    +                    print("Application added successfully")
    +                else:
    +                    print("Error adding application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_update_application(self, application , opts=None):
    +        """Update an application."""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: update-application [-f <resource path>] [application]")
    +            else:
    +                update_application = Stratos.update_application(application, open(opts.json_file_path, 'r').read())
    +                if update_application:
    +                    print("Application updated successfully")
    +                else:
    +                    print("Error updating application")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +
    +    @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_application(self, application , opts=None):
    +        """Delete an application."""
    +        try:
    +            if not application:
    +                print("usage: remove-application [application]")
    +            else:
    +                application_removed = Stratos.remove_application(application)
    +                if application_removed:
    +                    print("You have successfully removed application: "+application)
    +                else:
    +                    print("Could not delete application : "+application)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_deploy_application(self, line , opts=None):
    +        """Deploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: deploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.deploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully deployed application: "+opts.application_id)
    +                else:
    +                    print("Could not deployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-a', '--application_id', type="str", help="Unique ID of the application"),
    +        make_option('-o', '--application_policy_id', type="str", help="Unique ID of the application policy")
    +    ])
    +    @auth
    +    def do_undeploy_application(self, line , opts=None):
    +        """Undeploy an application."""
    +        try:
    +            if not opts.application_id or not opts.application_policy_id:
    +                print("usage: undeploy-application [-a <applicationId>] [-o <applicationPolicyId>]")
    +            else:
    +                application_removed = Stratos.undeploy_application(opts.application_id, opts.application_policy_id)
    +                if application_removed:
    +                    print("You have successfully undeployed application: "+opts.application_id)
    +                else:
    +                    print("Could not undeployed application : "+opts.application_id)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_runtime(self, application_id , opts=None):
    +        """Describe the runtime topology of an application."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-runtime [application-id]")
    +                return
    +            application_runtime = Stratos.describe_application_runtime(application_id)
    +            if not application_runtime:
    +                print("Application runtime not found")
    +            else:
    +                print("Application : "+application_id)
    +                PrintableJSON(application_runtime).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Application signup
    +     * describe-application-signup
    +     * add-application-signup
    +     * remove-application-signup
    +
    +    """
    +    @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, application_id , opts=None):
    +        """Retrieve details of a specific application signup."""
    +        try:
    +            if not application_id:
    +                print("usage: describe-application-signup [application-id]")
    +                return
    +            application_signup = Stratos.describe_application_signup(application_id)
    +            if not application_signup:
    +                print("Application signup not found")
    +            else:
    +                PrintableJSON(application_signup).pprint()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-f', '--json_file_path', type="str", help="Path of the JSON file")
    +    ])
    +    @auth
    +    def do_add_application_signup(self, application_id, opts=None):
    +        """Add a new application signup to the system"""
    +        try:
    +            if not opts.json_file_path:
    +                print("usage: add-application-signup [-f <resource path>] [application_id]")
    +            else:
    +                application_signup = Stratos.add_application_signup(application_id, open(opts.json_file_path, 'r').read())
    +                if application_signup:
    +                    print("Application signup added successfully")
    +                else:
    +                    print("Error creating application signup")
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_application_signup(self, signup , opts=None):
    +        """Delete an application sign up."""
    +        try:
    +            if not signup:
    +                print("usage: remove-application-signup [signup]")
    +            else:
    +                signup_removed = Stratos.remove_application_signup(signup)
    +                if signup_removed:
    +                    print("You have successfully remove signup: "+signup)
    +                else:
    +                    print("Could not delete application signup: "+signup)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Tenants
    +     * list-tenants
    +     * list-tenants-by-partial-domain
    +     * describe-tenant
    +     * add-tenant
    +     * activate-tenant
    +     * deactivate-tenant
    +
    +    """
    +
    +    @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_tenants(self, line , opts=None):
    +        """Retrieve details of all tenants."""
    +        try:
    +            tenants = Stratos.list_tenants()
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenants_by_partial_domain(self, partial_domain , opts=None):
    +        """Search for tenants based on the partial domain value entered."""
    +        try:
    +            tenants = Stratos.list_tenants_by_partial_domain(partial_domain)
    +            table = PrintableTable()
    +            rows = [["Domain", "Tenant ID", "Email", " State", "Created Date"]]
    +            for tenant in tenants:
    +                rows.append([tenant['tenantDomain'], tenant['tenantId'], tenant['email'],
    +                             "Active" if tenant['active'] else "De-Active", datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S')])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_tenant(self, tenant_domain_name, opts=None):
    +        """Retrieve details of a specific tenant."""
    +        if not tenant_domain_name:
    +            print("usage: describe-tenant [Domain-Name]")
    +        else:
    +            try:
    +                tenant = Stratos.describe_tenant(tenant_domain_name)
    +                if not tenant:
    +                    print("Tenant not found")
    +                else:
    +                    print("-------------------------------------")
    +                    print("Tenant Information:")
    +                    print("-------------------------------------")
    +                    print("Tenant domain: "+tenant['tenantDomain'])
    +                    print("ID: "+str(tenant['tenantId']))
    +                    print("Active: "+str(tenant['active']))
    +                    print("Email: "+tenant['email'])
    +                    print("Created date: "+datetime.datetime.fromtimestamp(tenant['createdDate']/1000).strftime('%Y-%m-%d %H:%M:%S'))
    +                    print("-------------------------------------")
    +            except BadResponseError as e:
    +                self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant")
    +    ])
    +    @auth
    +    def do_add_tenant(self, line , opts=None):
    +        """Add a tenant."""
    +        try:
    +            tenant = Stratos.add_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                        opts.domain_name, opts.email)
    +            if tenant:
    +                print("Tenant added successfully : "+opts.domain_name)
    +            else:
    +                print("Error creating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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('-s', '--username_user', type="str", help="Username of the tenant"),
    +        make_option('-a', '--password_user', type="str", help="Password of the tenant"),
    +        make_option('-d', '--domain_name', type="str", help="domain name of the tenant"),
    +        make_option('-f', '--first_name', type="str", help="First name of the tenant"),
    +        make_option('-l', '--last_name', type="str", help="Last name of the tenant"),
    +        make_option('-e', '--email', type="str", help="Email of the tenant"),
    +        make_option('-i', '--tenant_id', type="str", help="ID of the tenant")
    +    ])
    +    @auth
    +    def do_update_tenant(self, line , opts=None):
    +        """Update a specific tenant."""
    +        try:
    +            tenant = Stratos.update_tenant(opts.username_user, opts.first_name, opts.last_name, opts.password_user,
    +                                           opts.domain_name, opts.email, opts.tenant_id)
    +            if tenant:
    +                print("Tenant updated successfully : "+opts.domain_name)
    +            else:
    +                print("Error updating the tenant : "+opts.domain_name)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_activate_tenant(self, tenant_domain, opts=None):
    +        """Activate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: activate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.activate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully activated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not activate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_deactivate_tenant(self, tenant_domain, opts=None):
    +        """Deactivate a tenant."""
    +        try:
    +            if not tenant_domain:
    +                print("usage: deactivate-tenant <TENANT_DOMAIN> ")
    +            else:
    +                activate_tenant = Stratos.deactivate_tenant(tenant_domain)
    +                if activate_tenant:
    +                    print("You have successfully deactivated the tenant : "+tenant_domain)
    +                else:
    +                    print("Could not deactivate tenant : "+tenant_domain)
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    """
    +    # Cartridges
    +     * list-cartridges
    +     * list-cartridges-by-filter
    +     * describe-cartridge
    +     * add-cartridge
    +     * remove-cartridge
    +
    +    """
    +
    +    @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):
    +        """Retrieve details of available cartridges."""
    +        try:
    +            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'], "True" if cartridge['multiTenant'] == 1 else "False"])
    +            table.add_rows(rows)
    +            table.print_table()
    +        except BadResponseError as e:
    +            self.perror(str(e))
    +
    +    @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_by_filter(self, filter_text , opts=None):
    +        """Retrieve details of available cartridges."""
    --- End diff --
    
    Might be better to auto-generate method comments and include parameter descriptions.


---
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.
---