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
|
# File 'lib/chef/knife/xapi_vmselect.rb', line 14
def select_vm(name)
if name.nil?
ui.msg "Must Provide VM Name"
ui.msg "Usage: " + banner
exit 1
end
vms = []
if config[:uuid]
vms << xapi.VM.get_by_uuid(name).flatten
else
vms << xapi.VM.get_by_name_label(name).flatten
end
vms.flatten!
if vms.empty?
ui.msg ui.color "could not find vm named #{name}", :red
exit 1
end
if vms.length > 1
vm = user_select(vms)
if vm == :all
return vms
end
else
vm = vms.first
end
vm
end
|