Class: Knifecosmic::CosmicVolumeDetach

Inherits:
Chef::Knife show all
Includes:
Chef::Knife::KnifecosmicBase
Defined in:
lib/chef/knife/cosmic_volume_detach.rb

Instance Method Summary collapse

Methods included from Chef::Knife::KnifecosmicBase

included

Instance Method Details

#runObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/chef/knife/cosmic_volume_detach.rb', line 37

def run
  validate_base_options

  volumename = locate_config_value(:volume) || @name_args[0]
  exit_with_error 'Invalid volumename.' unless valid_cosmic_name? volumename

  volume = connection.get_volume(volumename)
  exit_with_error "Volume #{volumename} not found." unless volume && volume['id']
  exit_with_error "Volume #{volumename} is not attached." unless volume['vmname']

  puts ui.color("Detaching volume: #{volumename}", :magenta)

  params = {
    'command' => 'detachVolume',
    'id' => volume['id']
  }

  json = connection.send_async_request(params)
  exit_with_error 'Unable to detach volume' unless json

  puts "Volume #{volumename} is now detached."

end