Class: Chef::Knife::VoxelVoxcloudDelete

Inherits:
Chef::Knife show all
Includes:
VoxelBase
Defined in:
lib/chef/knife/voxel_voxcloud_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
47
# File 'lib/chef/knife/voxel_voxcloud_delete.rb', line 10

def run
  if @name_args.empty?
    ui.error( "knife voxel voxcloud delete DEVICE_ID" )
  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'] == "Virtual 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 VoxCLOUD device")

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

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