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} Thank You for installing App42 PaaS Ruby Client! This is a powerful tool to make your Applications live with-in minutes. App42 PaaS is world's most advanced PaaS solution which supports multiple languages(Java, PHP, Ruby) and services (RDBMS like MySQL and PostgreSQL to NoSQL storage like MongoDB and CouchDB). To Get Started Signup at app42paas.shephertz.com, get your API Key and Secret key after you login and finally use App42 command to push your code to cloud. Enjoy Coding!! $ app42 addKeys 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 either by number of instance(s) OR kontena(s) descale # Descale application either by number of instance(s) OR kontena(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 uploadBackup # Upload file data into a 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 setupBPaaS # Setup App42 BPaaS by choosing required configuration deleteSetup # Delete the setup startBPaaS # Start the BPaaS stopBPaaS # Stop the BPaaS 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 'https://demo.iab.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 | Iaas Provider | Name | Runtime | Instance Count | Framework | Memory | +--------------------------------+------------+-----------------+------+------------+----------------+---------------+--------+ | https://demo.iab.app42paas.com | RUNNING | Amazon (Oregon) | demo | Ruby 2.0.0 | 1 | Ruby on Rack | 256 MB | +--------------------------------+------------+-----------------+------+------------+----------------+---------------+--------+ 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 either by number of instance(s) OR kontena(s) Options: [--app APP] # Name of app, you want to descale Example: $app42 descale Enter App Name: demo 1: Horizontal 2: Vertical Choose Scale Type [Horizontal]: Horizontal descale by instance(s) [1]: 1 Descaling Application demo by instance 1... OK Operation is in progress, Please wait...| Descale completed successfully. DESC end def scale print <<-DESC Usage: app42 scale Scale application either by number of instance(s) OR kontena(s) Options: [--app APP] # Name of app, you want to scale Example: $app42 scale Enter App Name: demo 1: Horizontal 2: Vertical Choose Scale Type [Horizontal]: 2 Vertical descale by kontena power(s) [1]: Scaling Application demo by kontena(s) 1... OK Operation is in progress, Please wait...| Scale completed successfully. DESC end def uploadbackup print <<-DESC Usage: app42 uploadBackup Upload file data into a service Options: [--service SERVICE] # Name of service, you want to scale Example: $app42 uploadBackup Enter Service Name: db Enter Backup File Path: /home/ubuntu/Downloads/demo_production-27Nov2013.sql Do you also want to restore uploaded backup? [Yn]: n Please be patient... This process may take a while to complete. Uploading Service Backup... OK Operation is in progress, Please wait... Backup has been successfully restored. 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 Enter App Name: demo +--------------------------------+------------+-----------------+------+------------+----------------+---------------+--------+ | === demo Info === | +--------------------------------+------------+-----------------+------+------------+----------------+---------------+--------+ | App Url | App Status | Iaas Provider | Name | Runtime | Instance Count | Framework | Memory | +--------------------------------+------------+-----------------+------+------------+----------------+---------------+--------+ | https://demo.iab.app42paas.com | RUNNING | Amazon (Oregon) | demo | Ruby 2.0.0 | 1 | Ruby on Rack | 256 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) | +-----------------------------------------------------------------------------------+ | https://apphq.app42paas.com/app/getInstanceLog?id=eyk3t10hz9nwc12e08f92jxcmz83uo2u | | https://apphq.app42paas.com/app/getInstanceLog?id=zijqty8n5ufna677wgbxwywca5laqkw5 | | https://apphq.app42paas.com/app/getInstanceLog?id=wynv58rt509yj7fqwbkh80zlw6isf6g2 | +-----------------------------------------------------------------------------------+ 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: mysqldb 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 (Oregon) Select IaaS Provider [Amazon (Oregon)]: Specify Kontena Power: 1 Creating Service... OK Operation is in progress, Please wait...| Service created successfully. +---------------+-----------------+----------------------------------+--------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | === mysqldb Details === | +---------------+-----------------+----------------------------------+--------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | Database Name | Iaas Provider | Token | Vm Ip | State | User Name | Vm Port | Service Type | Password | Memory | Service Name | +---------------+-----------------+----------------------------------+--------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | demo_db | Amazon (Oregon) | ytxsq0ov7lf5s4foh2igw01bwy32ydgp | 172.16.2.167 | RUNNING | aoafi8vgczxoftw4 | 12411 | MySQL 5.5.31 | a2rzmvrdr7hpa08a6k1a1r24ixdutyl9 | 256 MB | mysqldb | +---------------+-----------------+----------------------------------+--------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ 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: 1: mysqldb Select Service [mysqldb]: +---------------+-----------------+----------------------------------+--------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | === mysqldb Details === | +---------------+-----------------+----------------------------------+--------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | Database Name | Iaas Provider | Token | Vm Ip | State | User Name | Vm Port | Service Type | Password | Memory | Service Name | +---------------+-----------------+----------------------------------+--------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ | demo_db | Amazon (Oregon) | ytxsq0ov7lf5s4foh2igw01bwy32ydgp | 172.16.2.167 | RUNNING | aoafi8vgczxoftw4 | 12411 | MySQL 5.5.31 | a2rzmvrdr7hpa08a6k1a1r24ixdutyl9 | 256 MB | mysqldb | +---------------+-----------------+----------------------------------+--------------+---------+------------------+---------+--------------+----------------------------------+--------+--------------+ 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-10-25 06:18:42.0 | | scale | COMPLETED | demo | APP | 2013-10-25 06:40:39.0 | | scale | COMPLETED | demo | APP | 2013-10-25 06:41:25.0 | | descale | COMPLETED | demo | APP | 2013-10-25 06:42:12.0 | | descale | COMPLETED | demo | APP | 2013-10-25 06:42:13.0 | | rerstart | COMPLETED | demo | APP | 2013-10-25 06:44:31.0 | | stop | COMPLETED | demo | APP | 2013-10-25 06:45:23.0 | | start | COMPLETED | demo | APP | 2013-10-25 06:45:49.0 | | scale | COMPLETED | demo | APP | 2013-10-25 06:52:56.0 | | scale | COMPLETED | demo | APP | 2013-10-25 06:53:24.0 | | descale | COMPLETED | demo | APP | 2013-10-25 06:58:10.0 | | descale | COMPLETED | demo | APP | 2013-10-25 06:58:10.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 | (Oregon) | +-----------------+-----------------+ 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 setupbpaas print <<-DESC Usage: app42 setupBPaaS Setup App42 BPaaS by choosing required configuration Example: $app42 setupBPaaS 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: 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 deletesetup print <<-DESC Usage: app42 deleteSetup Delete the setup Example: $app42 deleteSetup Enter Setup Name: demo Deleting Setup... 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 | +-----------------------+-------------------------------------+------------+-----------------+------------+---------+---------------+--------------+ | 2013-10-28 15:00:46.0 | https://demoapphq.iab.app42paas.com | demo | Amazon (Oregon) | CLOUDAPI | Shared | light | RUNNING | +-----------------------+-------------------------------------+------------+-----------------+------------+---------+---------------+--------------+ 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 | +-----------------------+-------------------------------------+------------+-----------------+------------+---------+---------------+--------------+ | 2013-10-28 15:00:46.0 | https://demoapphq.iab.app42paas.com | demo | Amazon (Oregon) | CLOUDAPI | Shared | light | RUNNING | +-----------------------+-------------------------------------+------------+-----------------+------------+---------+---------------+--------------+ DESC end def startbpaas print <<-DESC Usage: app42 startBPaaS Start the BPaaS setup Example: $app42 startBPaaS Enter Setup Name: demo Starting BPaaS Setup demo... OK Operation is in progress, Please wait...| BPaaS setup demo started successfully. DESC end def stopbpaas print <<-DESC Usage: app42 stopBPaaS Stop the BPaaS setup Example: $app42 stopBPaaS Enter Setup Name: demo Stopping BPaaS Setup demo... OK Operation is in progress, Please wait...| BPaaS setup demo stopped successfully. 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