Class: Central::Machine::Azure::NodeDestroyer
- Inherits:
-
Object
- Object
- Central::Machine::Azure::NodeDestroyer
- Defined in:
- lib/central/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, stack) ⇒ Object
-
#initialize(api_client, subscription_id, certificate) ⇒ NodeDestroyer
constructor
A new instance of NodeDestroyer.
- #run!(stack, name) ⇒ Object
Constructor Details
#initialize(api_client, subscription_id, certificate) ⇒ NodeDestroyer
Returns a new instance of NodeDestroyer.
13 14 15 16 17 18 19 20 21 |
# File 'lib/central/machine/azure/node_destroyer.rb', line 13 def initialize(api_client, subscription_id, certificate) @api_client = api_client abort('Invalid management certificate') unless File.exist?(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.
8 9 10 |
# File 'lib/central/machine/azure/node_destroyer.rb', line 8 def api_client @api_client end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/central/machine/azure/node_destroyer.rb', line 8 def client @client end |
Instance Method Details
#cloud_service_name(vm_name, stack) ⇒ Object
46 47 48 |
# File 'lib/central/machine/azure/node_destroyer.rb', line 46 def cloud_service_name(vm_name, stack) "central-#{stack}-#{vm_name}" end |
#run!(stack, name) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/central/machine/azure/node_destroyer.rb', line 23 def run!(stack, name) ShellSpinner "Terminating Azure Virtual Machine #{name.colorize(:cyan)} " do vm = client.vm_management.get_virtual_machine(name, cloud_service_name(name, stack['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, stack['name'])) storage_account = client.storage_management.list_storage_accounts.find { |a| a.label == cloud_service_name(name, stack['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("stacks/#{stack['id']}/nodes")['nodes'].find { |n| n['name'] == name } if node ShellSpinner "Removing node #{name.colorize(:cyan)} from stack #{stack['name'].colorize(:cyan)} " do api_client.delete("stacks/#{stack['id']}/nodes/#{name}") end end end |