Class: Kontena::Machine::Azure::NodeDestroyer
- Inherits:
-
Object
- Object
- Kontena::Machine::Azure::NodeDestroyer
- 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
14 15 16 17 18 19 20 21 22 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 14 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.
9 10 11 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 9 def api_client @api_client end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
9 10 11 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 9 def client @client end |
Instance Method Details
#cloud_service_name(vm_name, grid) ⇒ Object
47 48 49 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 47 def cloud_service_name(vm_name, grid) "kontena-#{grid}-#{vm_name}" end |
#run!(grid, name) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kontena/machine/azure/node_destroyer.rb', line 24 def run!(grid, name) ShellSpinner "Terminating Azure Virtual Machine #{name.colorize(:cyan)} " do vm = client.vm_management.get_virtual_machine(name, cloud_service_name(name, grid['name'])) if vm out = StringIO.new $stdout = out # to avoid debug data (https://github.com/Azure/azure-sdk-for-ruby/issues/200) client.vm_management.delete_virtual_machine(name, cloud_service_name(name, grid['name'])) storage_account = client.storage_management.list_storage_accounts.find{|a| a.label == cloud_service_name(name, grid['name'])} client.storage_management.delete_storage_account(storage_account.name) if storage_account $stdout = STDOUT else abort "\nCannot find Virtual Machine #{name.colorize(:cyan)} in Azure" end end node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name} if node ShellSpinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do api_client.delete("grids/#{grid['id']}/nodes/#{name}") end end end |