require 'paint' # list commands and display help # module App42 module Base class Help # details, how to use app42 commands def self.how_to Paint["Usage: app42 COMMAND [command-specific-options]", :blue] end # list available commands or display help for a specific command def self.commands print <<-USAGE #{how_to} Key keys # List API key and Secret key addKeys # Add API key and Secret key clearKeys # Clear API key and Secret key Applications setupInfra # Setup your deployment and runtime environment i.e. Instance(Memory, CPU) and Technology Stack deploy # Deploy the application over your runtime environment update # Update the application over your runtime environment scale # Scale application by number of instance(s) descale # Descale application by number of instance(s) start # Start the application stop # Stop the application restart # Restart the application deleteInfra # Delete the Infrastructure environment apps # List all the deployed applications with their meta details appInfo # Show meta information of the application appState # Show current state of the application logs # Returns the log file URL(s) for the application Services createService # Creates a new service e.g. MySQL, MongoDB, CouchDB, PostgreSQL etc. deleteService # Delete provisioned service startService # Start the service restartService # Restart the service stopService # Stop the service services # List all the provisioned services with their meta details serviceInfo # Show meta information of the provisioned service resetServicePassword # Reset password of provisioned service bindIP # Bind IP to provisioned service unbindIP # Unbind IP from provisioned service bindInfo # Show IP bind information related to provisioned service Misc supportedServices # List supported services by App42 iaasProviders # List supported IaaS providers by App42 runtimes # List supported runtimes by App42 activities # List all activities with their status Setup setupCloudAPI # Setup App42 cloud API by choosing required configuration deleteCloudAPI # Delete App42 cloud API setup setupInfo # Show setup information setups # List all the setups Help version # Show Ruby client gem version help # List available commands and their description COMMAND --help # Display detailed help of a specific command USAGE end def self.keys_help print <<-USAGE #{how_to} app42 api_key:add [KEY] # add a api key for the current user app42 secret_key:add [KEY] # add a Secret Key for the current user app42 keys:clear # remove all authentication keys from the current user USAGE end # call help methods def Help.usage command if self.respond_to?(command) send command elsif self.respond_to?(command.split(':').last) send command.split(':').last elsif self.respond_to?(command.split('-').join('_')) send command.split('-').join('_') else Paint["Sorry..!!, Help is not available.\n", :red] end end class << self def keys print <<-DESC Usage: app42 keys List API key and Secret key Example: === API/Secret Key === API Key = Secret Key = DESC end def addkeys print <<-DESC Usage: app42 addKeys Add API key and Secret key Options: [--apiKey=API_KEY] # API Key to add. [--secretKey=SECRET_KEY] # Secret Key to add. Example: $app42 addKeys == Enter your App42PaaS keys == Enter API Key:: Enter Secret Key:: Adding keys...done DESC end def clearkeys print <<-DESC Usage: app42 clearKeys Clear API key and Secret key Example: app42 clearKeys Do you want to delete existing keys? [Yn]: y === API key and Secret key have been deleted. === DESC end def setupinfra print <<-DESC Usage: app42 setupInfra Setup your deployment and runtime environment i.e. Instance(Memory, CPU) and Technology Stack Example: $app42 setupInfra Application Name: demo Checking App Name Availability... OK 1: Shared Select Instance Type [Shared]: 1: Amazon us-west-2 Select IaaS Provider [Amazon us-west-2]: 1: Ruby 2.0.0 2: Java 6 3: Java 7 4: PHP 5.3 5: PHP 5.5 Select Runtime [Ruby 2.0.0]: 1: Ruby on Rack 2: Rails 4.0 3: Sinatra 1.4 Select Framework [Ruby on Rack ]: 1: Nginx 1.4.1 Select Web Server [Nginx 1.4.1]: Specify Kontena Power: 5 Setting up the infrastructure... OK Operation is in progress, Please wait.../ Setup Infra completed successfully. Default application has been deployed. You can visit 'demo.aws.app42paas.com' to see the default application. DESC end def apps print <<-DESC Usage: app42 apps List all the deployed applications with their meta details Example: $app42 apps +------------------------+------------+-----------------+---------------+---------+------+ | === My Apps === | +------------------------+------------+-----------------+---------------+---------+------+ | App Url | App Status | Container Count | Iaas Provider | Vm Type | Name | +------------------------+------------+-----------------+---------------+---------+------+ | demo.aws.app42paas.com | RUNNING | 1 | Amazon | Shared | demo | +------------------------+------------+-----------------+---------------+---------+------+ DESC end def deploy print <<-DESC Usage: app42 deploy Deploy the application over your runtime environment Options: [--app APP] # Name of app, you want to update Example: $app42 deploy Enter App Name: demo 1: Binary 2: Source Choose Upload Type [Binary]: 2 Enter Git URL?: https://github.com/shepHertz/demo.git Deploying Application... OK Operation is in progress, Please wait...| App deployed successfully. DESC end def update print <<-DESC Usage: app42 update Update the application over your runtime environment Options: [--app APP] # Name of app, you want to update Example: $app42 update Enter App Name: demo 1: Binary 2: Source Choose Upload Type [Binary]: 2 Updating Application... OK Operation is in progress, Please wait...- App deployed successfully. DESC end def start print <<-DESC Usage: app42 start Start the application Options: [--app APP] # Name of app, you want to start Example: $app42 start --app demo Starting Application demo... OK Operation is in progress, Please wait... 1 out of 3 started - 2 out of 3 started | App started successfully. DESC end def stop print <<-DESC Usage: app42 stop Stop the application Options: [--app APP] # Name of app, you want to stop Example: $app42 stop --app demo Stopping Application demo... OK Operation is in progress, Please wait...- 1 out of 3 stopped - 2 out of 3 stopped - App stopped successfully. DESC end def restart print <<-DESC Usage: app42 restart Restart the application Options: [--app APP] # Name of app, you want to restart Example: $app42 start --app demo Restarting Application demo... OK Operation is in progress, Please wait... 1 out of 3 restarted - 2 out of 3 restarted | App restarted successfully. DESC end def deleteinfra print <<-DESC Usage: app42 deleteInfra Delete the Infrastructure environment Options: [--app APP] # Name of app, you want to delete Example: $app42 deleteInfra --app demo Deleting Application demo... OK Operation is in progress, Please wait... 1 out of 3 deleted - 2 out of 3 deleted | App deleted successfully. DESC end def descale print <<-DESC Usage: app42 descale Descale application by number of instance(s) Options: [--app APP] # Name of app, you want to descale Example: $app42 descale Enter App Name: demo Descale by instance(s) [1]: 2 Descaling Application demo by instance 2... OK Operation is in progress, Please wait...| 1 out of 2 descaled - Descale completed successfully. DESC end def scale print <<-DESC Usage: app42 scale Scale application by number of instance(s) Options: [--app APP] # Name of app, you want to scale Example: $app42 scale Enter App Name: demo Scale by instance(s) [1]: 2 Scaling Application demo by instance 2... OK Operation is in progress, Please wait...- 1 out of 2 scaled | Scale completed successfully. DESC end def appinfo print <<-DESC Usage: app42 appInfo Show the meta information of the application Options: [--app APP] # Name of app, you want to info Example: $app42 appInfo --app demo Application Name: demo +------------------------+------------+---------------+------+----------+----------------+--------+ | === demo Info === | +------------------------+------------+---------------+------+----------+----------------+--------+ | App Url | App Status | Iaas Provider | Name | Runtime | Instance Count | Memory | +------------------------+------------+---------------+------+----------+----------------+--------+ | demo.aws.app42paas.com | RUNNING | Amazon | demo | Ruby 2.0 | 1 | 512 MB | +------------------------+------------+---------------+------+----------+----------------+--------+ DESC end def appstate print <<-DESC Usage: app42 appState Show current state of the application Options: [--app APP] # Name of app Example: $app42 appState --app demo +--------------------+ | === demo State === | +--------------------+ | RUNNING | +--------------------+ DESC end def logs print <<-DESC Usage: app42 logs Returns the log URL(s) for the application Example: $app42 logs Enter App Name: demo Please visit below URL(s) to access app logs +----------------------------------------------------------------------------+ | Log URL(s) | +----------------------------------------------------------------------------+ | demo.aws.app42paas.com/getInstanceLog?id=fi1nyi7bh68nvz0riyqrfup8lkm57qiu | | demo.aws.app42paas.com/getInstanceLog?id=v1bta5rg2tsycat31r3pzc28sa7d1bjy | +----------------------------------------------------------------------------+ DESC end def createservice print <<-DESC Usage: app42 createService Creates a new service e.g. MySQL, MongoDB, CouchDB, PostgreSQL etc. Example: $app42 createService Enter Service Name: mysqldemo Checking Service Name Availability... OK 1: MySQL 5.5.31 2: Mongodb 2.4.4 3: Couchdb 1.0.1 4: PostgreSQL 9.1.9 Select Service [MySQL 5.5.31]: Enter Database Name: demo_db 1: Shared Select Instance Type [Shared]: 1: Amazon us-west-2 Select IaaS Provider [Amazon us-west-2]: Specify Kontena Power: 5 Creating Service... OK Operation is in progress, Please wait...| Service created successfully. +---------------+---------------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | === mysqldemo Details === | +---------------+---------------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | Database Name | Iaas Provider | Vm Ip | State | User Name | Vm Port | Service Type | Password | Memory | Service Name | +---------------+---------------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | demodb | Amazon | 10.0.0.52 | RUNNING | j7zz1jsx1bb4eiz1 | 49695 | MySQL 5.5.1 | teh77o4b6kpb22ab6oogfu9lwru9vrlj | 512 MB | mysqldemo | +---------------+---------------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ DESC end def deleteservice print <<-DESC Usage: app42 deleteService Delete the provisioned service Options: [--service SERVICE] # Name of service Example: $app42 deleteService Enter Service Name: mysqldemo Deleting Service... OK Operation is in progress, Please wait...| Service deleted successfully. DESC end def startservice print <<-DESC Usage: app42 startService Start the service Options: [--app Service] # Name of service, you want to start Example: $app42 startService Enter Service Name: mysql Starting Service mysql... OK Operation is in progress, Please wait...| Service started successfully. DESC end def stopservice print <<-DESC Usage: app42 stopService Stop the service Options: [--app Service] # Name of service, you want to start Example: $app42 stopService Enter Service Name: mysql Stopping Service mysql... OK Operation is in progress, Please wait...| Service stopped successfully. DESC end def restartservice print <<-DESC Usage: app42 restartService Restart the service Options: [--app Service] # Name of service, you want to start Example: $app42 restartService Enter Service Name: mysql Restarting Service mysql... OK Operation is in progress, Please wait...| Service restarted successfully. DESC end def services print <<-DESC Usage: app42 services List the all provisioned services with their meta details Example: $app42 services +---------------+---------------+-----------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+ | === Service List === | +---------------+---------------+-----------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+ | Database Name | Iaas Provider | Name | Vm Ip | State | User Name | Vm Port | Service Type | Password | Memory | +---------------+---------------+-----------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+ | demodb | Amazon | mysqldemo | 10.0.0.52 | RUNNING | j7zz1jsx1bb4eiz1 | 49695 | MySQL 5.5.1 | teh77o4b6kpb22ab6oogfu9lwru9vrlj | 512 MB | +---------------+---------------+-----------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+ DESC end def serviceinfo print <<-DESC Usage: app42 serviceInfo Show meta information of the provisioned service Options: [--service SERVICE] # Name of service Example: $app42 serviceInfo 1: mysqldemo Select Service: 1 +---------------+---------------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | === mysqldemo Details === | +---------------+---------------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | Database Name | Iaas Provider | Vm Ip | State | User Name | Vm Port | Service Type | Password | Memory | Service Name | +---------------+---------------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | demodb | Amazon | 10.0.0.52 | RUNNING | 5hk1tmdmkr16b94f | 52108 | MySQL 5.5.1 | 2otwxwpu8mskmmvwt7bx4r2fzw4ytls0 | 512 MB | mysqldemo | +---------------+---------------+-----------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ DESC end def supportedservices print <<-DESC Usage: app42 supportedServices List the supported services by App42 Example: $app42 supportedServices +--------------+--------------+ | === App42 PaaS Services === | +--------------+--------------+ | Name | Version | +--------------+--------------+ | MySQL | 5.5.1 | | Mongodb | 2.4 | | Couchdb | 10.1 | | PostgreSQL | 9.1 | +--------------+--------------+ DESC end def activities print <<-DESC Usage: app42 activities List all activities with their status Example: $app42 activities +---------------+-----------+---------+---------+-----------------------+ | === User Activities === | +---------------+-----------+---------+---------+-----------------------+ | Operation | Status | Name | Type | Date | +---------------+-----------+---------+---------+-----------------------+ | setupInfra | COMPLETED | demo | APP | 2013-08-27 06:24:03.0 | | scale | COMPLETED | demo | APP | 2013-08-27 06:32:15.0 | | createService | COMPLETED | couchdb | SERVICE | 2013-08-27 06:33:56.0 | | setupInfra | COMPLETED | demo1 | APP | 2013-08-27 07:00:47.0 | +---------------+-----------+---------+---------+-----------------------+ DESC end def runtimes print <<-DESC Usage: app42 runtimes List the supported runtimes Example: $app42 runtimes +--------------+--------------+ | === Available Runtimes === | +--------------+--------------+ | Name | Version | +--------------+--------------+ | Ruby | 2.0 | | Java | 6.0 | | Java | 7.0 | | Php | 5.3 | | Php | 5.5 | +--------------+--------------+ DESC end def iaasproviders print <<-DESC Usage: app42 iaasProviders List the supported IaaS providers by App42 Example: $app42 iaasProviders +-----------------+-----------------+ | === Available IaaS Providers === | +-----------------+-----------------+ | Name | Zone | +-----------------+-----------------+ | Amazon | US West-2a | +-----------------+-----------------+ DESC end def app42_update print <<-DESC Usage: app42 app42-update Update App42PaaS client(app42) -> Download app42 client, In a terminal, go to the folder where you have downloaded the client and run client update command. Example: $app42 app42-update Uninstalling current app42 client Remove executables: app42 in addition to the gem? [Yn] y Removing app42 Successfully uninstalled app42-0.5.0 Installing latest app42 client Successfully installed app42-0.5.0 1 gem installed Installing ri documentation for app42-0.5.0... Installing RDoc documentation for app42-0.5.0... DESC end def resetservicepassword print <<-DESC Usage: resetServicePassword Reset the password of provisioned service Example: $resetServicePassword Enter Service Name: mysqldemo Enter Old Password: teh77o4b6kpb22ab6oogfu9lwru9vrlj Resetting Password... OK Operation is in progress, Please wait.../ Service Password has been reset successfully. Your new password is: z2qo1vxeadak6jsmt9upobytwptc5eo0 DESC end def bindip print <<-DESC Usage: app42 bindIP Bind IP to provisioned service Example: $app42 bindIP Enter Service Name: mysqldemo Please Provide Source IP (For public access, use '0.0.0.0'): Binding IP to service... OK Operation is in progress, Please wait...- Service bind with IP successfully. +---------------+---------------+----------------+-----------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | === mysqldemo Details === | +---------------+---------------+----------------+-----------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | Database Name | Iaas Provider | Vm Ip | Source Ip | State | User Name | Vm Port | Service Type | Password | Memory | Service Name | +---------------+---------------+----------------+-----------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | demodb | Amazon | 54.218.127.245 | 122.162.124.222 | RUNNING | j7zz1jsx1bb4eiz1 | 49695 | MySQL 5.5.1 | z2qo1vxeadak6jsmt9upobytwptc5eo0 | 512 MB | mysqldemo | +---------------+---------------+----------------+-----------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ DESC end def unbindip print <<-DESC Usage: app42 unbindIP Unbind IP from provisioned service Example: $app42 unbindIP Enter Service Name: mysqldemo Please Provide Source IP: Unbinding IP to service... OK Operation is in progress, Please wait...| Service unbind with IP successfully. DESC end def bindinfo print <<-DESC Usage: app42 bindInfo Show IP bind information related to provisioned service Example: $app42 bindInfo 1: mysqldemo Select Service [mysqldemo]: +---------------+---------------+----------------+-----------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | === mysqldemo Details === | +---------------+---------------+----------------+-----------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | Database Name | Iaas Provider | Vm Ip | Source Ip | State | User Name | Vm Port | Service Type | Password | Memory | Service Name | +---------------+---------------+----------------+-----------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | demodb | Amazon | 54.218.127.245 | 122.162.124.222 | RUNNING | j7zz1jsx1bb4eiz1 | 49695 | MySQL 5.5.1 | z2qo1vxeadak6jsmt9upobytwptc5eo0 | 512 MB | mysqldemo | +---------------+---------------+----------------+-----------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ DESC end def setupcloudapi print <<-DESC Usage: app42 setupCloudAPI Setup App42 cloud API by choosing required configuration Example: $app42 setupCloudAPI Enter Setup Name: railsdemo Checking Setup Name Availability... OK 1: Shared Select Instance Type [Shared]: 1: Amazon us-west-2 Select IaaS Provider [Amazon us-west-2]: 1: App42CloudAPI Select Setup Type [App42CloudAPI]: 1: Light 2: Medium 3: Heavy Select Flavour [Light]: 1 Setting up the infrastructure... OK Operation is in progress, Please wait...| Your setup has been completed successfully, For details, Login to your AppHQ console. DESC end def deletecloudapi print <<-DESC Usage: app42 deleteCloudAPI Delete App42 cloud API setup Example: $app42 deleteCloudAPI Enter Setup Name: demo Deleting Cloud API... OK Operation is in progress, Please wait...- Setup deleted successfully. DESC end def setupinfo print <<-DESC Usage: app42 setupInfo Show setup information Example: $app42 setupInfo Enter Setup Name: demo +-----------------------+--------------------------------+------------+------------------+------------+---------+---------------+--------------+-----------------------------+ | === demo Details === | +-----------------------+--------------------------------+------------+------------------+------------+---------+---------------+--------------+-----------------------------+ | Created On | Api Server Url | Setup Name | Iaas Provider | Setup Type | Vm Type | Setup Flavour | Setup Status | App Hq Url | +-----------------------+--------------------------------+------------+------------------+------------+---------+---------------+--------------+-----------------------------+ | 2013-10-16 13:05:12.0 | democloudapi.aws.app42paas.com | demo | Amazon us-west-2 | CLOUDAPI | Shared | light | RUNNING | demoapphq.aws.app42paas.com | +-----------------------+--------------------------------+------------+------------------+------------+---------+---------------+--------------+-----------------------------+ DESC end def setups print <<-DESC Usage: app42 setups List all the setups Example: $app42 setups +-----------------------+--------------------------------+------------+------------------+------------+---------+---------------+--------------+-----------------------------+ | === Setups List === | +-----------------------+--------------------------------+------------+------------------+------------+---------+---------------+--------------+-----------------------------+ | Created On | Api Server Url | Setup Name | Iaas Provider | Setup Type | Vm Type | Setup Flavour | Setup Status | App Hq Url | +-----------------------+--------------------------------+------------+------------------+------------+---------+---------------+--------------+-----------------------------+ | 2013-10-16 13:05:12.0 | democloudapi.aws.app42paas.com | demo | Amazon us-west-2 | CLOUDAPI | Shared | light | RUNNING | demoapphq.aws.app42paas.com | +-----------------------+--------------------------------+------------+------------------+------------+---------+---------------+--------------+-----------------------------+ DESC end def version print <<-DESC Usage: app42 version Show Ruby client gem version Example: $app42 version App42 current version: 0.5.3 DESC end end end end end