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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/vcloud/cli/utils/rename_vm.rb', line 13
def self.run
main do |identifier, name|
Fog.mock! if ENV['FOG_MOCK']
if identifier =~ /^vm-[-0-9a-f]+/
vapp = Vcloud::Core::Vapp.get_by_child_vm_id(identifier)
vm = Vcloud::Core::Vm.new(identifier, vapp)
elsif identifier =~ /^vapp-[-0-9a-f]+/
vapp = Vcloud::Core::Vapp.new(identifier)
vm_href = vapp.vms.first.fetch(:href)
vm = Vcloud::Core::Vm.new(vm_href.split('/').last, vapp)
else
vapp = Vcloud::Core::Vapp.get_by_name(identifier)
vm_href = vapp.vms.first.fetch(:href)
vm = Vcloud::Core::Vm.new(vm_href.split('/').last, vapp)
end
if options[:rename_to_match_vapp]
new_name = vapp.name
else
if name.nil?
raise "Need a name to rename the VM to!"
else
new_name = name
end
end
vm.update_name(new_name)
end
arg :identifier
arg :name, :optional
on("-r", "--rename_to_match_vapp", "Make the vm name match the vApp name")
description "
Renames a vCloud VM given by :identifier (existing name or ID).
If a 'name' parameter is specified, renames to that.
If --rename_to_match_vapp is specified, treat the identifier as a selector of the vApp, and
rename the VM to that.
If a vApp with multiple VMs is given, only the first is renamed.
"
go!
end
|