Class: Chef::Knife::DigitalOceanDropletDestroy
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::DigitalOceanDropletDestroy
- Includes:
- DigitalOceanBase
- Defined in:
- lib/chef/knife/digital_ocean_droplet_destroy.rb
Instance Method Summary collapse
Methods included from DigitalOceanBase
#client, included, load_deps, #locate_config_value, #validate!, #wait_for_status
Instance Method Details
#run ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/knife/digital_ocean_droplet_destroy.rb', line 32 def run $stdout.sync = true validate! droplets_ids = [] if locate_config_value(:server) droplets_ids = [locate_config_value(:server)] elsif locate_config_value(:all) ui.error('Warning all servers will be lost unless you exit with ctrl-c now!') 15.times { |x| print x; print 13.chr; sleep 1 } droplets_ids = client.droplets.all.map(&:id) else ui.error 'You need to specify either a --server id or --all' exit 1 end if droplets_ids.empty? ui.error('Could not find any droplet(s)') exit 1 end droplets_ids.each do |id| ui.info "Delete droplet with id: #{id}" result = client.droplets.delete(id: id) ui.info 'OK' if result == true || ui.error(JSON.parse(result)['message']) end end |