Class: Kontena::Machine::Packet::NodeDestroyer
- Inherits:
-
Object
- Object
- Kontena::Machine::Packet::NodeDestroyer
- Includes:
- Cli::ShellSpinner, PacketCommon, RandomName
- Defined in:
- lib/kontena/machine/packet/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
-
#initialize(api_client, token) ⇒ NodeDestroyer
constructor
A new instance of NodeDestroyer.
- #run!(grid, project_id, name) ⇒ Object
Methods included from PacketCommon
#api_retry, #check_or_create_ssh_key, #create_ssh_key, #device_public_ip, #erb, #find_device, #find_facility, #find_os, #find_plan, #find_project, #login, #refresh, #ssh_key_exist?, #ssh_key_label, #user_data
Constructor Details
#initialize(api_client, token) ⇒ NodeDestroyer
Returns a new instance of NodeDestroyer.
13 14 15 16 |
# File 'lib/kontena/machine/packet/node_destroyer.rb', line 13 def initialize(api_client, token) @api_client = api_client @client = login(token) end |
Instance Attribute Details
#api_client ⇒ Object (readonly)
Returns the value of attribute api_client.
9 10 11 |
# File 'lib/kontena/machine/packet/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/packet/node_destroyer.rb', line 9 def client @client end |
Instance Method Details
#run!(grid, project_id, name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kontena/machine/packet/node_destroyer.rb', line 18 def run!(grid, project_id, name) device = client.list_devices(project_id).find{|d| d.hostname == name} abort("Device #{name.colorize(:cyan)} not found in Packet") unless device spinner "Terminating Packet device #{name.colorize(:cyan)} " do begin response = client.delete_device(device.id) raise unless response.success? rescue abort "Cannot delete device #{name.colorize(:cyan)} in Packet" end end node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name} Kontena.run(['node', 'rm', '--force', '--grid', grid['name'], name]) if node end |