Class: App42::Command::Service
- Defined in:
- lib/app42/command/service.rb
Instance Method Summary collapse
-
#app42pass_services ⇒ Object
list all available service on app42pass.
-
#ask_database_name ⇒ Object
ask database name to user.
-
#ask_service_name ⇒ Object
ask service name to user.
-
#ask_service_token ⇒ Object
ask old password to user.
-
#ask_source_ip(what) ⇒ Object
ask source id to user which he want to bind to service.
-
#ask_user_service_name ⇒ Object
ask users service name to user.
-
#create ⇒ Object
collect all required data from user to create new service.
-
#delete ⇒ Object
collect service name from user and proceed service delete request.
-
#get_service ⇒ Object
ask service name to user.
-
#get_service_name ⇒ Object
ask service name to user.
-
#get_services ⇒ Object
list all available service of requested user.
-
#get_uploadbackup_path ⇒ Object
:nodoc:.
-
#get_user_services ⇒ Object
:nodoc:.
-
#info ⇒ Object
list details of specific service.
-
#reset_pass ⇒ Object
collect service name from user and proceed service resetPassword request.
-
#restart ⇒ Object
collect service name from user and proceed service restart request.
-
#service_bind ⇒ Object
collect service name,source IP and access time from user and proceed service resetPassword request.
-
#service_bindInfo ⇒ Object
list details of specific service.
-
#service_unbind ⇒ Object
collect service name and source IP from user and proceed service unbind request.
-
#services ⇒ Object
list all available service on app42pass.
-
#start ⇒ Object
collect service name from user and proceed service start request.
-
#stop ⇒ Object
collect service name from user and proceed service stop request.
-
#uploadbackup ⇒ Object
read app name and number of
instance
from user then vertically descale app by no of instance. -
#vdescale ⇒ Object
read app name and number of
instance
from user then vertically descale app by no of instance. -
#vscale ⇒ Object
read service name and number of
instance
from user then vertically scale service by no of instance.
Methods inherited from Base
#app_information, #app_operation, #app_url_availability, #assign_release_static_ip, #cloudapi_operation, #collect_app_source, #create_cloud_setup, #create_gpaas_setup, #create_infrastructure, #create_service, #create_service_tunnel, #create_wordpress_setup, #custom_url_information, #custom_url_operation, #delete_cloudapi, #delete_gpaas, #delete_service, #delete_service_tunnel, #delete_wordpress, #get_app_name, #get_app_name_and_check_app_url_availability, #get_app_source, #get_custom_url, #get_framework, #get_iaas_providers, #get_instance, #get_kontena, #get_os_for_app, #get_os_for_service, #get_runtime, #get_setup_name, #get_setup_name_and_check_setup_url_availability, #get_subscription, #get_vm_types, #get_vmconfig, #get_webserver, #get_wordpress_name, #get_wordpress_name_and_check_wordpress_url_availability, #gpaas_operation, #initialize, #interactive_get, #reset_password, #scale_or_descale_app, #service_name_availability, #service_operation, #setup_url_availability, #update_binary, #update_gpaas_dashboard, #upgrade_or_downgrade_cloudapi, #upgrade_or_downgrade_gpaas, #upgrade_or_downgrade_wordpress, #upload_binary, #upload_service_backup, #vscale_or_vdescale_app, #vscale_or_vdescale_service, #wordpress_operation, #wordpress_url_availability
Methods included from Base::HttpHelper
#build_delete_request, #build_get_request, #build_post_request, #build_put_request, #delete_request, #get_request, #post_request, #put_request
Methods included from Base::Util
#app42_client_info, #ask_app_name, #camel_case_to_whitespace, #check_transaction_status, #check_transaction_status_of_setup, #escape_path, #get_flavour_for_upgrade_or_downgrade, #get_instance_config_for_upgrade_or_downgrade, #input, #ip_address_valid?, #is_app_exist?, #is_service_exist?, #is_setup_name_exist?, #is_static_ip_assigned?, #json_parse, #message, #number_valid?, #numeric?, #numeric_including_zero?, #params, #parse_error_message, #print_new_line, #request_failed?, #resource_url, #show_wait_spinner, #signature, #status_call, #time_valid?, #util_base, #validate_app_and_service_name, #validate_database_name, #validate_git_url, #validate_setup_name, #validate_upload_backup_path, #validate_url, #validate_vm_config
Methods included from UserToken
#check_key_file?, #config_path, #ensure_config_dir, #ensure_key_file, #get_keys, #key_path, #local_app42_key, #remove_key_file
Constructor Details
This class inherits a constructor from App42::Command::Base
Instance Method Details
#app42pass_services ⇒ Object
list all available service on app42pass
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/app42/command/service.rb', line 205 def app42pass_services rows, rows_header_final, rows_header = [], [], nil services = get_services if services && services['services'] services['services'].each do |e| e.delete('id') rows_header = e.keys rows << e.values end #unless services.nil? rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== App42 PaaS Services ===", :green], :headings => rows_header_final, :rows => rows puts table end end |
#ask_database_name ⇒ Object
ask database name to user
59 60 61 62 63 |
# File 'lib/app42/command/service.rb', line 59 def ask_database_name database_name = input "Enter Database Name", [], true valid_database_name = validate_database_name "Database name", database_name valid_database_name ? (return valid_database_name) : ask_database_name end |
#ask_service_name ⇒ Object
ask service name to user
33 34 35 36 37 38 |
# File 'lib/app42/command/service.rb', line 33 def ask_service_name service_name = ask Paint["Enter Service Name", :cyan] print_new_line valid_service_name = validate_app_and_service_name "Service name", service_name.strip valid_service_name ? (return valid_service_name) : ask_service_name end |
#ask_service_token ⇒ Object
ask old password to user
41 42 43 |
# File 'lib/app42/command/service.rb', line 41 def ask_service_token input "Enter Service Token", [], true end |
#ask_source_ip(what) ⇒ Object
ask source id to user which he want to bind to service
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/app42/command/service.rb', line 46 def ask_source_ip what ip = input "#{Message::BIND_NOTE}", [], true if what.to_s == 'bind' ip = input "#{Message::UNBIND_NOTE}", [], true if what.to_s == 'unbind' ip_address = ip.strip if ip_address_valid? ip_address return ip_address else "#{Message::IP_NOT_VALID}", true, 'red' ask_source_ip what end end |
#ask_user_service_name ⇒ Object
ask users service name to user
66 67 68 69 70 |
# File 'lib/app42/command/service.rb', line 66 def ask_user_service_name service_list = [] get_user_services['services'].select {|service| service_list << service['name'] } input "Select Service", service_list, true end |
#create ⇒ Object
collect all required data from user to create new service
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/app42/command/service.rb', line 81 def create service_name = get_service_name service = get_service database = ask_database_name unless service == 'redis283' database = '0' if service == 'redis283' vm_type = get_vm_types "service" iaas = get_iaas_providers vm_type os = get_os_for_service iaas, vm_type, service kontena = get_vmconfig create_service service, service_name , database, vm_type, iaas, kontena, os end |
#delete ⇒ Object
collect service name from user and proceed service delete request
103 104 105 106 107 |
# File 'lib/app42/command/service.rb', line 103 def delete @options[:service] = ask_service_name if @options[:service].nil? response = delete_service @options[:service] if is_service_exist? @options[:service] exit! if response end |
#get_service ⇒ Object
ask service name to user
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/app42/command/service.rb', line 11 def get_service service_hash = {} get_services['services'].select {|each_service| service_hash["#{each_service['id']}"] = each_service['name'] + ' ' + each_service['version']} service = input "Select Service", service_hash.values, true service_id = nil service_hash.each_pair{|s| service_id = s[0] if s[1] == service} return service_id end |
#get_service_name ⇒ Object
ask service name to user
74 75 76 77 78 |
# File 'lib/app42/command/service.rb', line 74 def get_service_name service_name = ask_service_name service_name = service_name_availability service_name service_name ? (return service_name) : get_service_name end |
#get_services ⇒ Object
list all available service of requested user
6 7 8 |
# File 'lib/app42/command/service.rb', line 6 def get_services build_get_request params, 'info', 'services' end |
#get_uploadbackup_path ⇒ Object
:nodoc:
26 27 28 29 30 |
# File 'lib/app42/command/service.rb', line 26 def get_uploadbackup_path #:nodoc: path = ask(Paint["\nEnter Backup File Path", :cyan]) valid_path = validate_upload_backup_path path.strip valid_path ? (return valid_path) : get_uploadbackup_path end |
#get_user_services ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/app42/command/service.rb', line 22 def get_user_services#:nodoc: build_get_request params, 'service', nil end |
#info ⇒ Object
list details of specific service
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/app42/command/service.rb', line 240 def info @options[:service] = ask_user_service_name if @options[:service].nil? query_params = params query_params.store('serviceName', @options[:service]) service_info = build_get_request query_params, 'service', "#{@options[:service]}" rows, rows_header_final, rows_header = [], [], nil if service_info && service_info['service'] rows_header = service_info['service'].keys rows << service_info['service'].values rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== #{@options[:service]} Details ===", :green], :headings => rows_header_final, :rows => rows puts table end end |
#reset_pass ⇒ Object
collect service name from user and proceed service resetPassword request
163 164 165 166 167 168 |
# File 'lib/app42/command/service.rb', line 163 def reset_pass @options[:service] = ask_service_name if @options[:service].nil? service_token = ask_service_token if is_service_exist? @options[:service] res = reset_password @options[:service], service_token (puts "Your new password is: #{res['service']['password']}", false, 'green') && exit! if res end |
#restart ⇒ Object
collect service name from user and proceed service restart request
117 118 119 120 121 |
# File 'lib/app42/command/service.rb', line 117 def restart @options[:service] = ask_service_name if @options[:service].nil? response = service_operation __method__, @options[:service] if is_service_exist? @options[:service] exit! if response end |
#service_bind ⇒ Object
collect service name,source IP and access time from user and proceed service resetPassword request
171 172 173 174 175 |
# File 'lib/app42/command/service.rb', line 171 def service_bind @options[:service] = ask_service_name if @options[:service].nil? source_ip = ask_source_ip 'bind' if is_service_exist? @options[:service] create_service_tunnel @options[:service], source_ip end |
#service_bindInfo ⇒ Object
list details of specific service
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/app42/command/service.rb', line 186 def service_bindInfo @options[:service] = ask_user_service_name if @options[:service].nil? query_params = params query_params.store('serviceName', @options[:service]) service_info = build_get_request query_params, 'service', "tunnel/#{@options[:service]}" rows, rows_header_final, rows_header = [], [], nil if service_info && service_info['service'] rows_header = service_info['service'].keys rows << service_info['service'].values rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== #{@options[:service]} Details ===", :green], :headings => rows_header_final, :rows => rows puts table end end |
#service_unbind ⇒ Object
collect service name and source IP from user and proceed service unbind request
178 179 180 181 182 183 |
# File 'lib/app42/command/service.rb', line 178 def service_unbind @options[:service] = ask_service_name if @options[:service].nil? source_ip = ask_source_ip 'unbind' if is_service_exist? @options[:service] res = delete_service_tunnel @options[:service], source_ip exit! if res end |
#services ⇒ Object
list all available service on app42pass
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/app42/command/service.rb', line 223 def services rows, rows_header_final, rows_header = [], [], nil services = get_user_services if services && services['services'] services['services'].each do |e| rows_header = e.keys rows << e.values end rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== Service List ===", :green], :headings => rows_header_final, :rows => rows puts table end end |
#start ⇒ Object
collect service name from user and proceed service start request
110 111 112 113 114 |
# File 'lib/app42/command/service.rb', line 110 def start @options[:service] = ask_service_name if @options[:service].nil? response = service_operation __method__, @options[:service] if is_service_exist? @options[:service] exit! if response end |
#stop ⇒ Object
collect service name from user and proceed service stop request
124 125 126 127 128 |
# File 'lib/app42/command/service.rb', line 124 def stop @options[:service] = ask_service_name if @options[:service].nil? response = service_operation __method__, @options[:service] if is_service_exist? @options[:service] exit! if response end |
#uploadbackup ⇒ Object
read app name and number of instance
from user then vertically descale app by no of instance
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/app42/command/service.rb', line 150 def uploadbackup @options[:service] = ask_service_name if @options[:service].nil? path = get_uploadbackup_path if is_service_exist? @options[:service] restore = ask( Paint["\nDo you also want to restore uploaded backup?", :cyan], :default => true ) status = upload_service_backup @options[:service], path, restore return status end |
#vdescale ⇒ Object
read app name and number of instance
from user then vertically descale app by no of instance
141 142 143 144 145 146 |
# File 'lib/app42/command/service.rb', line 141 def vdescale @options[:service] = ask_service_name if @options[:service].nil? @options[:kontena] = get_kontena "Vertical descale" if is_service_exist? @options[:service] and @options[:kontena].nil? vscale_or_vdescal_res = vscale_or_vdescale_service __method__, @options[:kontena], @options[:service] exit! if vscale_or_vdescal_res end |
#vscale ⇒ Object
read service name and number of instance
from user then vertically scale service by no of instance
132 133 134 135 136 137 |
# File 'lib/app42/command/service.rb', line 132 def vscale @options[:service] = ask_service_name if @options[:service].nil? @options[:kontena] = get_kontena "Vertical scale" if is_service_exist? @options[:service] and @options[:kontena].nil? vscale_or_vdescal_res = vscale_or_vdescale_service __method__, @options[:kontena], @options[:service] exit! if vscale_or_vdescal_res end |