Module: AppScaleTools
- Defined in:
- lib/appscale_tools.rb
Constant Summary collapse
- ADD_KEYPAIR_FLAGS =
["help", "usage", "h", "ips", "keyname", "version", "auto"]
- ADD_KEYPAIR_USAGE =
UsageText.get_usage("appscale-add-keypair", ADD_KEYPAIR_FLAGS)
- IP_REGEX =
/\d+\.\d+\.\d+\.\d+/- FQDN_REGEX =
/([\w\d\.\-]+\.){2,}/- IP_OR_FQDN =
/#{IP_REGEX}|#{FQDN_REGEX}/- DESCRIBE_INSTANCES_FLAGS =
["help", "usage", "h", "keyname", "version"]
- DESCRIBE_INSTANCES_USAGE =
UsageText.get_usage("appscale-describe-instances", DESCRIBE_INSTANCES_FLAGS)
- NO_APPNAME_GIVEN =
"You failed to specify an application to remove."- APP_NOT_RUNNING =
"We could not stop your application because it was " + "not running."
- APP_REMOVAL_CANCELLED =
"Application removal cancelled."- REMOVE_APP_FLAGS =
["help", "h", "usage", "appname", "version", "keyname", "confirm"]
- REMOVE_APP_USAGE =
UsageText.get_usage("appscale-remove-app", REMOVE_APP_FLAGS)
- APPSCALE_NOT_RUNNING =
"AppScale does not appear to be running. If you are " + "using a cloud deployment, please manually terminate any running instances."
- RESET_PASSWORD_FLAGS =
["help", "usage", "h", "keyname", "version"]
- RESET_PASSWORD_USAGE =
UsageText.get_usage("appscale-reset-pwd", RESET_PASSWORD_FLAGS)
- DJINN_SERVER_DIED_MSG =
"\nEither the head node was unable to get IP" + " addresses for any slave nodes or a bug in the head node's code" + " caused it to crash. We have left your virtual machines running" + " in case you wish to submit a bug report or investigate further" + " via the Troubleshooting page."
- NO_MACHINE_SET =
"You failed to provide a machine image via the --machine" + " flag or the APPSCALE_MACHINE environment variable."
- RUN_INSTANCES_FLAGS =
["help", "h", "min", "max", "file", "table", "ips", "v", "verbose", "machine", "instance_type", "usage", "version", "keyname", "iaas", "infrastructure", "n", "r", "w", "scp", "test", "appengine", "force", "restore_from_tar", "restore_neptune_info", "group"]
- RUN_INSTANCES_USAGE =
UsageText.get_usage("appscale-run-instances", RUN_INSTANCES_FLAGS)
- SSH_PORT =
22- PBSERVER_PORT =
443- DJINN_SERVER_PORT =
17443- UA_SERVER_PORT =
4343- USE_SSL =
true- TERMINATE_INSTANCES_FLAGS =
["help", "h", "usage", "version", "verbose", "keyname", "backup_neptune_info"]
- TERMINATE_INSTANCES_USAGE =
UsageText.get_usage( "appscale-terminate-instances", TERMINATE_INSTANCES_FLAGS)
- UNABLE_TO_TERMINATE_ANY_MACHINES =
"We were unable to shut down any of " + "your machines running AppScale. \nPlease verify that the machines are " + "live, running AppScale, and reachable from your current location."
- NO_FILE_PROVIDED_MSG =
"You failed to provide a file to upload. Please do " + "so via the --file flag and try again."
- APP_ALREADY_EXISTS =
"An app with the name you provided in app.yaml " + "already exists. Please change the provided name in app.yaml and retry " + "uploading your app. If you want to upload a new version of your " + "application, use appscale-remove-app to remove the old version, then " + "use this tool to upload the new version."
- USER_NOT_ADMIN =
"An app with the name you provided in app.yaml has already" + " been reserved by a different user. Please change the provided name in " + "app.yaml and retry uploading your application."
- UPLOAD_APP_FLAGS =
["help", "h", "usage", "file", "version", "keyname", "test", "email"]
- UPLOAD_APP_USAGE =
UsageText.get_usage("appscale-upload-app", UPLOAD_APP_FLAGS)
Class Method Summary collapse
- .add_keypair(options) ⇒ Object
- .describe_instances(options) ⇒ Object
- .remove_app(options) ⇒ Object
- .reset_password(options) ⇒ Object
- .run_instances(options) ⇒ Object
- .terminate_instances(options) ⇒ Object
- .upload_app(options) ⇒ Object
Class Method Details
.add_keypair(options) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/appscale_tools.rb', line 165 def self.add_keypair() keyname = ['keyname'] ips_yaml = ['ips'] auto = ['auto'] if ips_yaml.nil? raise BadConfigurationException.new(ADD_KEYPAIR_USAGE) end node_layout = NodeLayout.new(ips_yaml, { :database => "cassandra" } ) required_commands = ["ssh-keygen", "ssh-copy-id"] if auto required_commands << "expect" end CommonFunctions.require_commands(required_commands) CommonFunctions.make_appscale_directory() path = File.("~/.appscale/#{keyname}") pub_key, backup_key = CommonFunctions.generate_rsa_key(keyname) if auto print "\nEnter SSH password of root: " password = CommonFunctions.get_line_from_stdin_no_echo() # Location of expect script that interacts with ssh-copy-id expect_script = File.join(File.join(File.dirname(__FILE__), "..", "lib"),"sshcopyid") end ips = node_layout.nodes.collect { |node| node.id } copy_success = true ips.each { |ip| CommonFunctions.ssh_copy_id(ip, path, auto, expect_script, password) } head_node_ip = node_layout.head_node.id CommonFunctions.scp_ssh_key_to_ip(head_node_ip, path, pub_key) FileUtils.cp(path, backup_key) puts "A new ssh key has been generated for you and placed at" + " #{path}. You can now use this key to log into any of the " + "machines you specified without providing a password via the" + " following command:\n\tssh root@#{head_node_ip} -i #{path}" end |
.describe_instances(options) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/appscale_tools.rb', line 213 def self.describe_instances() keyname = ['keyname'] CommonFunctions.update_locations_file(keyname) secret_key = CommonFunctions.get_secret_key(keyname) instance_info = [] all_ips = CommonFunctions.get_all_public_ips(keyname) all_ips.each { |ip| acc = AppControllerClient.new(ip, secret_key) instance_info << acc.status() } return {:error => nil, :result => instance_info } end |
.remove_app(options) ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/appscale_tools.rb', line 229 def self.remove_app() CommonFunctions.update_locations_file(['keyname']) if ['appname'].nil? raise BadConfigurationException.new(NO_APPNAME_GIVEN) end result = CommonFunctions.confirm_app_removal(['confirm'], ['appname']) if result == "NO" raise AppScaleException.new(APP_REMOVAL_CANCELLED) end CommonFunctions.remove_app(['appname'], ['keyname']) Kernel.puts "Done shutting down app #{options['appname']}" end |
.reset_password(options) ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/appscale_tools.rb', line 246 def self.reset_password() keyname = ['keyname'] CommonFunctions.update_locations_file(keyname) secret = CommonFunctions.get_secret_key(keyname) head_node_ip = CommonFunctions.get_load_balancer_ip(keyname) if head_node_ip.empty? raise BadConfigurationException.new(APPSCALE_NOT_RUNNING) end user = CommonFunctions.get_email pass = CommonFunctions.get_password puts "\n" encrypted_pass = CommonFunctions.encrypt_password(user, pass) acc = AppControllerClient.new(head_node_ip, secret) userappserver_ip = acc.get_userappserver_ip uac = UserAppClient.new(userappserver_ip, secret) uac.change_password(user, encrypted_pass) end |
.run_instances(options) ⇒ Object
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/appscale_tools.rb', line 269 def self.run_instances() infrastructure = ['infrastructure'] instance_type = ['instance_type'] machine = ['machine'] max_images = ['max_images'] table = ['table'] CommonFunctions.make_appscale_directory() CommonFunctions.() CommonFunctions.(infrastructure, instance_type) RemoteLogging.remote_post(max_images, table, infrastructure, "starting", "unknown") sleep(2) apps_to_start, app_info = CommonFunctions.() node_layout, result = CommonFunctions.generate_node_layout() head_node_result = CommonFunctions.start_head_node(, node_layout, apps_to_start) print "\nPlease wait for AppScale to prepare your machines for use." STDOUT.flush puts "\n" acc = head_node_result[:acc] secret_key = head_node_result[:secret_key] head_node_ip = head_node_result[:head_node_ip] CommonFunctions.write_and_copy_node_file(, node_layout, head_node_result) userappserver_ip = acc.get_userappserver_ip(LOGS_VERBOSE) CommonFunctions.update_locations_file(['keyname'], [head_node_ip]) CommonFunctions.verbose("Run instances: UserAppServer is at #{userappserver_ip}", ['verbose']) uac = UserAppClient.new(userappserver_ip, secret_key) user, pass = CommonFunctions.get_credentials(['test']) CommonFunctions.create_user(user, ['test'], head_node_ip, secret_key, uac, pass) uac.set_cloud_admin_status(user, new_status="true") uac.set_cloud_admin_capabilities(user) CommonFunctions.wait_for_nodes_to_load(head_node_ip, secret_key) if ['file_location'].nil? puts "No app uploaded. Use appscale-upload-app to upload an app later." else remote_file_path = CommonFunctions.scp_app_to_ip(app_info[:app_name], user, app_info[:language], ['keyname'], head_node_ip, app_info[:file], uac) acc.done_uploading(app_info[:app_name], remote_file_path) CommonFunctions.wait_for_app_to_start(head_node_ip, secret_key, app_info[:app_name]) CommonFunctions.clear_app(app_info[:file]) end login_ip = CommonFunctions.get_login_ip(head_node_ip, secret_key) puts "The status of your AppScale instance is at the following" + " URL: http://#{login_ip}/status" CommonFunctions.write_and_copy_node_file(, node_layout, head_node_result) RemoteLogging.remote_post(max_images, table, infrastructure, "started", "success") end |
.terminate_instances(options) ⇒ Object
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/appscale_tools.rb', line 333 def self.terminate_instances() keyname = ['keyname'] locations_yaml = File.("~/.appscale/locations-#{keyname}.yaml") if !File.exists?(locations_yaml) raise AppScaleException.new(APPSCALE_NOT_RUNNING) end CommonFunctions.update_locations_file(keyname) shadow_ip = CommonFunctions.get_head_node_ip(keyname) secret = CommonFunctions.get_secret_key(keyname) if ['backup_neptune_info'] CommonFunctions.backup_neptune_info(keyname, shadow_ip, ['backup_neptune_info']) end infrastructure = CommonFunctions.get_infrastructure(keyname, required=true) if VALID_CLOUD_TYPES.include?(infrastructure) CommonFunctions.terminate_via_infrastructure(infrastructure, keyname, shadow_ip, secret) else CommonFunctions.terminate_via_vmm(keyname, ['verbose']) end CommonFunctions.delete_appscale_files(keyname) end |
.upload_app(options) ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/appscale_tools.rb', line 360 def self.upload_app() file_location = ['file_location'] if file_location.nil? raise AppScaleException.new(NO_FILE_PROVIDED_MSG) end keyname = ['keyname'] CommonFunctions.update_locations_file(keyname) secret_key = CommonFunctions.get_secret_key(keyname) head_node_ip = CommonFunctions.get_head_node_ip(keyname) database = CommonFunctions.get_table(keyname) app_info = CommonFunctions.get_app_name_from_tar(file_location) app_name, file_location, language = app_info[:app_name], app_info[:file], app_info[:language] CommonFunctions.validate_app_name(app_name, database) acc = AppControllerClient.new(head_node_ip, secret_key) user = CommonFunctions.() userappserver_ip = acc.get_userappserver_ip(LOGS_VERBOSE) uac = UserAppClient.new(userappserver_ip, secret_key) if !uac.does_user_exist?(user) CommonFunctions.create_user(user, ['test'], head_node_ip, secret_key, uac) end Kernel.puts "" if uac.does_app_exist?(app_name) raise AppScaleException.new(APP_ALREADY_EXISTS) end app_admin = uac.get_app_admin(app_name) if !app_admin.empty? and user != app_admin raise AppScaleException.new(USER_NOT_ADMIN) end remote_file_path = CommonFunctions.scp_app_to_ip(app_name, user, language, keyname, head_node_ip, file_location, uac) CommonFunctions.update_appcontroller(head_node_ip, secret_key, app_name, remote_file_path) CommonFunctions.wait_for_app_to_start(head_node_ip, secret_key, app_name) CommonFunctions.clear_app(file_location) end |