Class: Chef::Knife::VoxelVoxserversDelete

Inherits:
Chef::Knife
  • Object
show all
Includes:
VoxelBase
Defined in:
lib/chef/knife/voxel_voxservers_delete.rb

Instance Method Summary collapse

Methods included from VoxelBase

#hapi, included

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/chef/knife/voxel_voxservers_delete.rb', line 10

def run
  if @name_args.empty?
    ui.error("knife voxel voxservers delete DEVICE_ID (options)")
  else
    @name_args.each do |device_id|
      device = hapi.voxel_devices_list( :device_id => device_id, :verbosity => 'extended' )

      if device['stat'] == "fail"
        ui.error(device['err']['msg'])
      else
        device = device['devices']['device']

        if device['type']['content'] == "Server"
          puts "#{ui.color("Device ID", :cyan)}: #{device['id']}"
          puts "#{ui.color("Name", :cyan)}: #{device['label']}"
          puts "#{ui.color("Image Id", :cyan)}: #{config[:image_id]}"
          puts "#{ui.color("Facility", :cyan)}: #{device['location']['facility']['code']}"
          puts "#{ui.color("Public IP Address", :cyan)}: #{device['ipassignments']['ipassignment'].select { |i| i['type'] == 'frontend' }.first['content']}"
          puts "#{ui.color("Private IP Address", :cyan)}: #{device['ipassignments']['ipassignment'].select { |i| i['type'] == 'backend' }.first['content']}"
          puts "\n"

          confirm("Do you really want to delete this VoxSERVER device")

          delete = hapi.voxel_voxservers_delete( :device_id => device_id )

          if delete['stat'] == "ok"
            ui.info("Deleted VoxSERVER device #{device['id']} named #{device['label']}")
          else
            ui.error("Error removing VoxSERVER device #{device['label']}: #{delete['err']['msg']}")
          end
        else
          ui.error("Device #{device['id']} is not a VoxSERVER device.")
        end
      end
    end
  end
end