Class: Kontena::Machine::Azure::NodeDestroyer
- Inherits:
-
Object
- Object
- Kontena::Machine::Azure::NodeDestroyer
- Includes:
- Cli::ShellSpinner
- Defined in:
- lib/kontena/machine/azure/node_destroyer.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
readonly
Returns the value of attribute api_client.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #cloud_service_name(vm_name, grid) ⇒ Object
-
#initialize(api_client, subscription_id, certificate) ⇒ NodeDestroyer
constructor
A new instance of NodeDestroyer.
- #run!(grid, name) ⇒ Object
Constructor Details
#initialize(api_client, subscription_id, certificate) ⇒ NodeDestroyer
Returns a new instance of NodeDestroyer.
15 16 17 18 19 20 21 22 23 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 15 def initialize(api_client, subscription_id, certificate) @api_client = api_client abort('Invalid management certificate') unless File.exists?(File.(certificate)) @client = ::Azure client.management_certificate = certificate client.subscription_id = subscription_id client.vm_management.initialize_external_logger(Logger.new) # We don't want all the output end |
Instance Attribute Details
#api_client ⇒ Object (readonly)
Returns the value of attribute api_client.
10 11 12 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 10 def api_client @api_client end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 10 def client @client end |
Instance Method Details
#cloud_service_name(vm_name, grid) ⇒ Object
50 51 52 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 50 def cloud_service_name(vm_name, grid) "kontena-#{grid}-#{vm_name}" end |
#run!(grid, name) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 25 def run!(grid, name) vm = client.vm_management.get_virtual_machine(name, cloud_service_name(name, grid['name'])) if vm spinner "Terminating Azure Virtual Machine #{name.colorize(:cyan)} " do client.vm_management.delete_virtual_machine(name, cloud_service_name(name, grid['name'])) end storage_account = client.storage_management.list_storage_accounts.find{|a| a.label == cloud_service_name(name, grid['name'])} if storage_account spinner "Removing Azure Storage Account #{storage_account.name.colorize(:cyan)} " do client.storage_management.delete_storage_account(storage_account.name) end end else abort "\nCannot find Virtual Machine #{name.colorize(:cyan)} in Azure" end node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name} if node spinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do api_client.delete("nodes/#{grid['id']}/#{name}") end end end |