Class: AvstCloud::AzureConnection
- Inherits:
-
CloudConnection
- Object
- CloudConnection
- AvstCloud::AzureConnection
- Defined in:
- lib/avst-cloud/azure_connection.rb
Constant Summary
Constants inherited from CloudConnection
CloudConnection::UNIMPLEMENTED
Instance Attribute Summary collapse
-
#provider_api_url ⇒ Object
Returns the value of attribute provider_api_url.
Attributes inherited from CloudConnection
#connection, #provider, #provider_pass, #provider_user
Instance Method Summary collapse
- #create_server(server_name, user, private_key_file, location, image_id, vm_size, storage_account_name) ⇒ Object
- #delete_storage_account(storage_account_name) ⇒ Object
- #find_fog_server(server_name, should_fail = true) ⇒ Object
- #find_storage_account(storage_account_name) ⇒ Object
- #find_storage_account_for_server(server_name) ⇒ Object
-
#initialize(provider_user, provider_pass, provider_api_url = 'management.core.windows.net') ⇒ AzureConnection
constructor
A new instance of AzureConnection.
- #list_images ⇒ Object
-
#list_known_servers ⇒ Object
Returns list of servers from fog.
- #list_storage_accounts ⇒ Object
- #server(server_name, root_user, root_password) ⇒ Object
- #server_status(server_name) ⇒ Object
Methods included from Logging
included, logger, #logger, logger=, mask_message, show_passwords=
Constructor Details
#initialize(provider_user, provider_pass, provider_api_url = 'management.core.windows.net') ⇒ AzureConnection
Returns a new instance of AzureConnection.
25 26 27 28 |
# File 'lib/avst-cloud/azure_connection.rb', line 25 def initialize(provider_user, provider_pass, provider_api_url='management.core.windows.net') super('azure', provider_user, provider_pass) @provider_api_url = provider_api_url end |
Instance Attribute Details
#provider_api_url ⇒ Object
Returns the value of attribute provider_api_url.
23 24 25 |
# File 'lib/avst-cloud/azure_connection.rb', line 23 def provider_api_url @provider_api_url end |
Instance Method Details
#create_server(server_name, user, private_key_file, location, image_id, vm_size, storage_account_name) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/avst-cloud/azure_connection.rb', line 38 def create_server(server_name, user, private_key_file, location, image_id, vm_size, storage_account_name) image_id = image_id || '0b11de9248dd4d87b18621318e037d37__RightImage-CentOS-7.0-x64-v14.1.5.1' location = location || 'West Europe' user = user || get_root_user vm_size = vm_size || "Small" storage_account_name = storage_account_name || "storage#{Time.now.to_i}" private_key_file = private_key_file || "~/.ssh/id_rsa" existing_server = find_fog_server(server_name, false) if existing_server and existing_server.deployment_status != 'Suspended' logger.error "Server #{server_name} found in state: #{existing_server.deployment_status}".yellow raise "Running server with the same name found!" elsif existing_server and existing_server.deployment_status == 'Suspended' result_server = AvstCloud::AzureServer.new(existing_server, server_name, existing_server.ipaddress, user, private_key_file) result_server.start wait_for_state(server_name, "ReadyRole") logger.debug "[DONE]\n\n" logger.debug "The server was successfully re-started.\n\n" result_server else logger.debug "Creating Azure server:" logger.debug "Server name - #{server_name}" logger.debug "location - #{location}" logger.debug "storage_account_name - #{storage_account_name}" logger.debug "vm_size - #{vm_size}" logger.debug "image_template_id - #{image_id}" logger.debug "user - #{user}" logger.debug "private_key_file - #{private_key_file}" logger.debug "region - #{@provider_api_url}" # create server server = connect.servers.create( :image => image_id, # Allowed values are East US,South Central US,Central US,North Europe,West Europe,Southeast Asia,Japan West,Japan East :location => location, :vm_name => server_name, :vm_user => user, :storage_account_name => storage_account_name, :vm_size => vm_size, :private_key_file => File.(private_key_file), ) result_server = AvstCloud::AzureServer.new(server, server_name, nil, user, File.(private_key_file)) wait_for_state(server_name, "ReadyRole") ipaddress = find_fog_server(server_name).ipaddress logger.debug "[DONE]\n\n" logger.debug "The server has been successfully created, to login onto the server:\n" logger.debug "\t ssh -i #{private_key_file} #{user}@#{ipaddress} \n" result_server.ip_address = ipaddress result_server end end |
#delete_storage_account(storage_account_name) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/avst-cloud/azure_connection.rb', line 93 def delete_storage_account(storage_account_name) logger.debug "Deleting #{storage_account_name}" account = find_storage_account(storage_account_name) account.destroy logger.debug "Storage deleted" end |
#find_fog_server(server_name, should_fail = true) ⇒ Object
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/avst-cloud/azure_connection.rb', line 136 def find_fog_server(server_name, should_fail=true) serv = connect.servers.find{|serv| serv.vm_name == server_name} unless serv if should_fail logger.debug "Server not found for name: #{server_name}" raise "Server not found for name: #{server_name}" end end serv end |
#find_storage_account(storage_account_name) ⇒ Object
106 107 108 |
# File 'lib/avst-cloud/azure_connection.rb', line 106 def find_storage_account(storage_account_name) connect.storage_accounts.get(storage_account_name) end |
#find_storage_account_for_server(server_name) ⇒ Object
110 111 112 |
# File 'lib/avst-cloud/azure_connection.rb', line 110 def find_storage_account_for_server(server_name) connect.storage_accounts.find{|sa| sa.label == server_name} end |
#list_images ⇒ Object
123 124 125 126 127 |
# File 'lib/avst-cloud/azure_connection.rb', line 123 def list_images connect.images.each do |im| logger.debug im.inspect end end |
#list_known_servers ⇒ Object
Returns list of servers from fog
130 131 132 133 134 |
# File 'lib/avst-cloud/azure_connection.rb', line 130 def list_known_servers connect.servers.each do |sr| logger.debug sr.inspect end end |
#list_storage_accounts ⇒ Object
100 101 102 103 104 |
# File 'lib/avst-cloud/azure_connection.rb', line 100 def list_storage_accounts connect.storage_accounts.each do |storage_acc| logger.debug storage_acc.inspect end end |
#server(server_name, root_user, root_password) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/avst-cloud/azure_connection.rb', line 30 def server(server_name, root_user, root_password) server = find_fog_server(server_name) if !root_user root_user = get_root_user end AvstCloud::AzureServer.new(server, server_name, server.ipaddress, root_user, root_password) end |
#server_status(server_name) ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/avst-cloud/azure_connection.rb', line 114 def server_status(server_name) server = find_fog_server(server_name, false) if server server.deployment_status else 'not_created' end end |