Class: Chef::Knife::Cloud::OvirtVolumeCreate

Inherits:
Command
  • Object
show all
Includes:
OvirtHelpers, OvirtServiceOptions, OvirtVolumeCreateOptions
Defined in:
lib/chef/knife/ovirt_volume_create.rb

Instance Method Summary collapse

Methods included from OvirtServiceOptions

included

Methods included from OvirtVolumeCreateOptions

included

Methods included from OvirtHelpers

#create_service_instance, #humanize, #validate!, #volume_ready

Instance Method Details

#before_exec_commandObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chef/knife/ovirt_volume_create.rb', line 26

def before_exec_command
  super
  # setup the create options
  @create_options = {
    size_gb: locate_config_value('volume_size'),
    active: 'true',
  }
  [:storage_domain, :interface, :bootable, :alias].each do |opt|
    @create_options[opt] = locate_config_value("volume_#{opt}") if locate_config_value("volume_#{opt}")
  end
  # binding.pry
  @columns_with_info = [
    { label: 'Name', key: 'name' },
    { label: 'Status', key: 'status' },
  ]
end

#execute_commandObject



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/chef/knife/ovirt_volume_create.rb', line 43

def execute_command
  result = service.connection.add_volume(locate_config_value(:vm_id), @create_options)
  name = (result / 'disk/name').first.text
  id = (result / 'disk').first['id']

  print "\nWaiting For Volume(#{name}) to become available"
  Fog.wait_for(120) do
    print '.'
    volume_ready(locate_config_value(:vm_id), id)
  end
  print "\nActivating Volume"
  service.connection.activate_volume(locate_config_value(:vm_id), id: id)
end