vagrant-rbvmomi 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +6 -0
- data/LICENSE +19 -0
- data/README.rdoc +78 -0
- data/Rakefile +31 -0
- data/VERSION +1 -0
- data/bin/rbvmomish +138 -0
- data/devel/analyze-vim-declarations.rb +213 -0
- data/devel/analyze-xml.rb +46 -0
- data/devel/benchmark.rb +117 -0
- data/devel/collisions.rb +18 -0
- data/devel/merge-internal-vmodl.rb +59 -0
- data/devel/merge-manual-vmodl.rb +32 -0
- data/examples/annotate.rb +54 -0
- data/examples/cached_ovf_deploy.rb +120 -0
- data/examples/clone_vm.rb +84 -0
- data/examples/create_vm-1.9.rb +93 -0
- data/examples/create_vm.rb +93 -0
- data/examples/extraConfig.rb +54 -0
- data/examples/lease_tool.rb +102 -0
- data/examples/logbundle.rb +63 -0
- data/examples/logtail.rb +60 -0
- data/examples/nfs_datastore.rb +95 -0
- data/examples/power.rb +59 -0
- data/examples/readme-1.rb +35 -0
- data/examples/readme-2.rb +51 -0
- data/examples/run.sh +41 -0
- data/examples/screenshot.rb +48 -0
- data/examples/vdf.rb +81 -0
- data/examples/vm_drs_behavior.rb +76 -0
- data/lib/rbvmomi.rb +12 -0
- data/lib/rbvmomi/basic_types.rb +375 -0
- data/lib/rbvmomi/connection.rb +270 -0
- data/lib/rbvmomi/deserialization.rb +248 -0
- data/lib/rbvmomi/fault.rb +17 -0
- data/lib/rbvmomi/pbm.rb +66 -0
- data/lib/rbvmomi/sms.rb +61 -0
- data/lib/rbvmomi/sms/SmsStorageManager.rb +7 -0
- data/lib/rbvmomi/trivial_soap.rb +114 -0
- data/lib/rbvmomi/trollop.rb +70 -0
- data/lib/rbvmomi/type_loader.rb +136 -0
- data/lib/rbvmomi/utils/admission_control.rb +398 -0
- data/lib/rbvmomi/utils/deploy.rb +336 -0
- data/lib/rbvmomi/utils/leases.rb +142 -0
- data/lib/rbvmomi/utils/perfdump.rb +628 -0
- data/lib/rbvmomi/vim.rb +128 -0
- data/lib/rbvmomi/vim/ComputeResource.rb +51 -0
- data/lib/rbvmomi/vim/Datacenter.rb +17 -0
- data/lib/rbvmomi/vim/Datastore.rb +68 -0
- data/lib/rbvmomi/vim/DynamicTypeMgrAllTypeInfo.rb +75 -0
- data/lib/rbvmomi/vim/DynamicTypeMgrDataTypeInfo.rb +20 -0
- data/lib/rbvmomi/vim/DynamicTypeMgrManagedTypeInfo.rb +46 -0
- data/lib/rbvmomi/vim/Folder.rb +207 -0
- data/lib/rbvmomi/vim/HostSystem.rb +174 -0
- data/lib/rbvmomi/vim/ManagedEntity.rb +57 -0
- data/lib/rbvmomi/vim/ManagedObject.rb +60 -0
- data/lib/rbvmomi/vim/ObjectContent.rb +23 -0
- data/lib/rbvmomi/vim/ObjectUpdate.rb +23 -0
- data/lib/rbvmomi/vim/OvfManager.rb +200 -0
- data/lib/rbvmomi/vim/PerfCounterInfo.rb +26 -0
- data/lib/rbvmomi/vim/PerformanceManager.rb +110 -0
- data/lib/rbvmomi/vim/PropertyCollector.rb +25 -0
- data/lib/rbvmomi/vim/ReflectManagedMethodExecuter.rb +30 -0
- data/lib/rbvmomi/vim/ResourcePool.rb +55 -0
- data/lib/rbvmomi/vim/ServiceInstance.rb +55 -0
- data/lib/rbvmomi/vim/Task.rb +65 -0
- data/lib/rbvmomi/vim/VirtualMachine.rb +74 -0
- data/test/test_deserialization.rb +383 -0
- data/test/test_emit_request.rb +128 -0
- data/test/test_exceptions.rb +14 -0
- data/test/test_helper.rb +14 -0
- data/test/test_misc.rb +24 -0
- data/test/test_parse_response.rb +69 -0
- data/test/test_serialization.rb +311 -0
- data/vmodl.db +0 -0
- metadata +163 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'trollop'
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'rbvmomi/trollop'
|
5
|
+
|
6
|
+
VIM = RbVmomi::VIM
|
7
|
+
|
8
|
+
opts = Trollop.options do
|
9
|
+
banner <<-EOS
|
10
|
+
Clone a VM.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
clone_vm.rb [options] source_vm dest_vm
|
14
|
+
|
15
|
+
VIM connection options:
|
16
|
+
EOS
|
17
|
+
|
18
|
+
rbvmomi_connection_opts
|
19
|
+
|
20
|
+
text <<-EOS
|
21
|
+
|
22
|
+
VM location options:
|
23
|
+
EOS
|
24
|
+
|
25
|
+
rbvmomi_datacenter_opt
|
26
|
+
|
27
|
+
text <<-EOS
|
28
|
+
|
29
|
+
Other options:
|
30
|
+
EOS
|
31
|
+
|
32
|
+
opt :linked_clone, "Use a linked clone instead of a full clone"
|
33
|
+
end
|
34
|
+
|
35
|
+
Trollop.die("must specify host") unless opts[:host]
|
36
|
+
ARGV.size == 2 or abort "must specify VM source name and VM target name"
|
37
|
+
vm_source = ARGV[0]
|
38
|
+
vm_target = ARGV[1]
|
39
|
+
|
40
|
+
vim = VIM.connect opts
|
41
|
+
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
|
42
|
+
vm = dc.find_vm(vm_source) or abort "VM not found"
|
43
|
+
|
44
|
+
if opts[:linked_clone]
|
45
|
+
# The API for linked clones is quite strange. We can't create a linked
|
46
|
+
# straight from any VM. The disks of the VM for which we can create a
|
47
|
+
# linked clone need to be read-only and thus VC demands that the VM we
|
48
|
+
# are cloning from uses delta-disks. Only then it will allow us to
|
49
|
+
# share the base disk.
|
50
|
+
#
|
51
|
+
# Thus, this code first create a delta disk on top of the base disk for
|
52
|
+
# the to-be-cloned VM, if delta disks aren't used already.
|
53
|
+
disks = vm.config.hardware.device.grep(VIM::VirtualDisk)
|
54
|
+
disks.select { |x| x.backing.parent == nil }.each do |disk|
|
55
|
+
spec = {
|
56
|
+
:deviceChange => [
|
57
|
+
{
|
58
|
+
:operation => :remove,
|
59
|
+
:device => disk
|
60
|
+
},
|
61
|
+
{
|
62
|
+
:operation => :add,
|
63
|
+
:fileOperation => :create,
|
64
|
+
:device => disk.dup.tap { |x|
|
65
|
+
x.backing = x.backing.dup
|
66
|
+
x.backing.fileName = "[#{disk.backing.datastore.name}]"
|
67
|
+
x.backing.parent = disk.backing
|
68
|
+
},
|
69
|
+
}
|
70
|
+
]
|
71
|
+
}
|
72
|
+
vm.ReconfigVM_Task(:spec => spec).wait_for_completion
|
73
|
+
end
|
74
|
+
|
75
|
+
relocateSpec = VIM.VirtualMachineRelocateSpec(:diskMoveType => :moveChildMostDiskBacking)
|
76
|
+
else
|
77
|
+
relocateSpec = VIM.VirtualMachineRelocateSpec
|
78
|
+
end
|
79
|
+
|
80
|
+
spec = VIM.VirtualMachineCloneSpec(:location => relocateSpec,
|
81
|
+
:powerOn => false,
|
82
|
+
:template => false)
|
83
|
+
|
84
|
+
vm.CloneVM_Task(:folder => vm.parent, :name => vm_target, :spec => spec).wait_for_completion
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'trollop'
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'rbvmomi/trollop'
|
5
|
+
|
6
|
+
VIM = RbVmomi::VIM
|
7
|
+
|
8
|
+
opts = Trollop.options do
|
9
|
+
banner <<-EOS
|
10
|
+
Create a VM.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
create_vm-1.9.rb [options]
|
14
|
+
|
15
|
+
VIM connection options:
|
16
|
+
EOS
|
17
|
+
|
18
|
+
rbvmomi_connection_opts
|
19
|
+
|
20
|
+
text <<-EOS
|
21
|
+
|
22
|
+
VM location options:
|
23
|
+
EOS
|
24
|
+
|
25
|
+
rbvmomi_datacenter_opt
|
26
|
+
|
27
|
+
text <<-EOS
|
28
|
+
|
29
|
+
Other options:
|
30
|
+
EOS
|
31
|
+
end
|
32
|
+
|
33
|
+
Trollop.die("must specify host") unless opts[:host]
|
34
|
+
vm_name = ARGV[0] or abort "must specify VM name"
|
35
|
+
|
36
|
+
vim = VIM.connect opts
|
37
|
+
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
|
38
|
+
vmFolder = dc.vmFolder
|
39
|
+
hosts = dc.hostFolder.children
|
40
|
+
rp = hosts.first.resourcePool
|
41
|
+
|
42
|
+
vm_cfg = {
|
43
|
+
name: vm_name,
|
44
|
+
guestId: 'otherGuest',
|
45
|
+
files: { vmPathName: '[datastore1]' },
|
46
|
+
numCPUs: 1,
|
47
|
+
memoryMB: 128,
|
48
|
+
deviceChange: [
|
49
|
+
{
|
50
|
+
operation: :add,
|
51
|
+
device: VIM.VirtualLsiLogicController(
|
52
|
+
key: 1000,
|
53
|
+
busNumber: 0,
|
54
|
+
sharedBus: :noSharing,
|
55
|
+
)
|
56
|
+
}, {
|
57
|
+
operation: :add,
|
58
|
+
fileOperation: :create,
|
59
|
+
device: VIM.VirtualDisk(
|
60
|
+
key: 0,
|
61
|
+
backing: VIM.VirtualDiskFlatVer2BackingInfo(
|
62
|
+
fileName: '[datastore1]',
|
63
|
+
diskMode: :persistent,
|
64
|
+
thinProvisioned: true,
|
65
|
+
),
|
66
|
+
controllerKey: 1000,
|
67
|
+
unitNumber: 0,
|
68
|
+
capacityInKB: 4000000,
|
69
|
+
)
|
70
|
+
}, {
|
71
|
+
operation: :add,
|
72
|
+
device: VIM.VirtualE1000(
|
73
|
+
key: 0,
|
74
|
+
deviceInfo: {
|
75
|
+
label: 'Network Adapter 1',
|
76
|
+
summary: 'VM Network',
|
77
|
+
},
|
78
|
+
backing: VIM.VirtualEthernetCardNetworkBackingInfo(
|
79
|
+
deviceName: 'VM Network',
|
80
|
+
),
|
81
|
+
addressType: 'generated'
|
82
|
+
)
|
83
|
+
}
|
84
|
+
],
|
85
|
+
extraConfig: [
|
86
|
+
{
|
87
|
+
key: 'bios.bootOrder',
|
88
|
+
value: 'ethernet0'
|
89
|
+
}
|
90
|
+
]
|
91
|
+
}
|
92
|
+
|
93
|
+
vmFolder.CreateVM_Task(:config => vm_cfg, :pool => rp).wait_for_completion
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'trollop'
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'rbvmomi/trollop'
|
5
|
+
|
6
|
+
VIM = RbVmomi::VIM
|
7
|
+
|
8
|
+
opts = Trollop.options do
|
9
|
+
banner <<-EOS
|
10
|
+
Create a VM.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
create_vm.rb [options]
|
14
|
+
|
15
|
+
VIM connection options:
|
16
|
+
EOS
|
17
|
+
|
18
|
+
rbvmomi_connection_opts
|
19
|
+
|
20
|
+
text <<-EOS
|
21
|
+
|
22
|
+
VM location options:
|
23
|
+
EOS
|
24
|
+
|
25
|
+
rbvmomi_datacenter_opt
|
26
|
+
|
27
|
+
text <<-EOS
|
28
|
+
|
29
|
+
Other options:
|
30
|
+
EOS
|
31
|
+
end
|
32
|
+
|
33
|
+
Trollop.die("must specify host") unless opts[:host]
|
34
|
+
vm_name = ARGV[0] or abort "must specify VM name"
|
35
|
+
|
36
|
+
vim = VIM.connect opts
|
37
|
+
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
|
38
|
+
vmFolder = dc.vmFolder
|
39
|
+
hosts = dc.hostFolder.children
|
40
|
+
rp = hosts.first.resourcePool
|
41
|
+
|
42
|
+
vm_cfg = {
|
43
|
+
:name => vm_name,
|
44
|
+
:guestId => 'otherGuest',
|
45
|
+
:files => { :vmPathName => '[datastore1]' },
|
46
|
+
:numCPUs => 1,
|
47
|
+
:memoryMB => 128,
|
48
|
+
:deviceChange => [
|
49
|
+
{
|
50
|
+
:operation => :add,
|
51
|
+
:device => VIM.VirtualLsiLogicController(
|
52
|
+
:key => 1000,
|
53
|
+
:busNumber => 0,
|
54
|
+
:sharedBus => :noSharing
|
55
|
+
)
|
56
|
+
}, {
|
57
|
+
:operation => :add,
|
58
|
+
:fileOperation => :create,
|
59
|
+
:device => VIM.VirtualDisk(
|
60
|
+
:key => 0,
|
61
|
+
:backing => VIM.VirtualDiskFlatVer2BackingInfo(
|
62
|
+
:fileName => '[datastore1]',
|
63
|
+
:diskMode => :persistent,
|
64
|
+
:thinProvisioned => true
|
65
|
+
),
|
66
|
+
:controllerKey => 1000,
|
67
|
+
:unitNumber => 0,
|
68
|
+
:capacityInKB => 4000000
|
69
|
+
)
|
70
|
+
}, {
|
71
|
+
:operation => :add,
|
72
|
+
:device => VIM.VirtualE1000(
|
73
|
+
:key => 0,
|
74
|
+
:deviceInfo => {
|
75
|
+
:label => 'Network Adapter 1',
|
76
|
+
:summary => 'VM Network'
|
77
|
+
},
|
78
|
+
:backing => VIM.VirtualEthernetCardNetworkBackingInfo(
|
79
|
+
:deviceName => 'VM Network'
|
80
|
+
),
|
81
|
+
:addressType => 'generated'
|
82
|
+
)
|
83
|
+
}
|
84
|
+
],
|
85
|
+
:extraConfig => [
|
86
|
+
{
|
87
|
+
:key => 'bios.bootOrder',
|
88
|
+
:value => 'ethernet0'
|
89
|
+
}
|
90
|
+
]
|
91
|
+
}
|
92
|
+
|
93
|
+
vmFolder.CreateVM_Task(:config => vm_cfg, :pool => rp).wait_for_completion
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'trollop'
|
2
|
+
require 'rbvmomi'
|
3
|
+
require 'rbvmomi/trollop'
|
4
|
+
|
5
|
+
VIM = RbVmomi::VIM
|
6
|
+
CMDS = %w(list set)
|
7
|
+
|
8
|
+
opts = Trollop.options do
|
9
|
+
banner <<-EOS
|
10
|
+
View and modify VM extraConfig options.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
extraConfig.rb [options] VM list
|
14
|
+
extraConfig.rb [options] VM set key=value [key=value...]
|
15
|
+
|
16
|
+
Commands: #{CMDS * ' '}
|
17
|
+
|
18
|
+
VIM connection options:
|
19
|
+
EOS
|
20
|
+
|
21
|
+
rbvmomi_connection_opts
|
22
|
+
|
23
|
+
text <<-EOS
|
24
|
+
|
25
|
+
VM location options:
|
26
|
+
EOS
|
27
|
+
|
28
|
+
rbvmomi_datacenter_opt
|
29
|
+
|
30
|
+
text <<-EOS
|
31
|
+
|
32
|
+
Other options:
|
33
|
+
EOS
|
34
|
+
|
35
|
+
stop_on CMDS
|
36
|
+
end
|
37
|
+
|
38
|
+
vm_name = ARGV[0] or Trollop.die("no VM name given")
|
39
|
+
cmd = ARGV[1] or Trollop.die("no command given")
|
40
|
+
abort "invalid command" unless CMDS.member? cmd
|
41
|
+
Trollop.die("must specify host") unless opts[:host]
|
42
|
+
|
43
|
+
vim = VIM.connect opts
|
44
|
+
|
45
|
+
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
|
46
|
+
vm = dc.find_vm(vm_name) or abort "VM not found"
|
47
|
+
|
48
|
+
case cmd
|
49
|
+
when 'list'
|
50
|
+
vm.config.extraConfig.each { |x| puts "#{x.key}: #{x.value}" }
|
51
|
+
when 'set'
|
52
|
+
extraConfig = ARGV[2..-1].map { |x| x.split("=", 2) }.map { |k,v| { :key => k, :value => v } }
|
53
|
+
vm.ReconfigVM_Task(:spec => VIM.VirtualMachineConfigSpec(:extraConfig => extraConfig)).wait_for_completion
|
54
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'trollop'
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'rbvmomi/trollop'
|
5
|
+
require 'rbvmomi/utils/leases'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
VIM = RbVmomi::VIM
|
9
|
+
CMDS = ['set_lease_on_leaseless_vms', 'show_expired_vms',
|
10
|
+
'show_soon_expired_vms', 'kill_expired_vms']
|
11
|
+
|
12
|
+
opts = Trollop.options do
|
13
|
+
banner <<-EOS
|
14
|
+
Tool for managing leases on VMs where leases are stored in YAML on VM annotations.
|
15
|
+
|
16
|
+
Usage:
|
17
|
+
lease_tool.rb [options] <cmd>
|
18
|
+
|
19
|
+
Commands: #{CMDS * ' '}
|
20
|
+
|
21
|
+
VIM connection options:
|
22
|
+
EOS
|
23
|
+
|
24
|
+
rbvmomi_connection_opts
|
25
|
+
|
26
|
+
text <<-EOS
|
27
|
+
|
28
|
+
VM location options:
|
29
|
+
EOS
|
30
|
+
|
31
|
+
rbvmomi_datacenter_opt
|
32
|
+
|
33
|
+
text <<-EOS
|
34
|
+
|
35
|
+
Other options:
|
36
|
+
EOS
|
37
|
+
|
38
|
+
opt :vm_folder_path, "Path to VM folder to deploy VM into", :type => :string
|
39
|
+
opt :force, "Really perform VMs. Used with kill_expired_vms"
|
40
|
+
|
41
|
+
stop_on CMDS
|
42
|
+
end
|
43
|
+
|
44
|
+
Trollop.die("must specify host") unless opts[:host]
|
45
|
+
cmd = ARGV[0] or Trollop.die("no command given")
|
46
|
+
Trollop.die("no vm folder path given") unless opts[:vm_folder_path]
|
47
|
+
|
48
|
+
vim = VIM.connect opts
|
49
|
+
dc = vim.serviceInstance.find_datacenter(opts[:datacenter]) or abort "datacenter not found"
|
50
|
+
|
51
|
+
root_vm_folder = dc.vmFolder
|
52
|
+
vm_folder = root_vm_folder.traverse(opts[:vm_folder_path], VIM::Folder)
|
53
|
+
|
54
|
+
lease_tool = LeaseTool.new
|
55
|
+
vms_props_list = (['runtime.powerState'] + lease_tool.vms_props_list).uniq
|
56
|
+
inventory = vm_folder.inventory_flat('VirtualMachine' => vms_props_list)
|
57
|
+
inventory = inventory.select{|obj, props| obj.is_a?(VIM::VirtualMachine)}
|
58
|
+
case cmd
|
59
|
+
when 'set_lease_on_leaseless_vms'
|
60
|
+
lease_tool.set_lease_on_leaseless_vms(
|
61
|
+
inventory.keys, inventory,
|
62
|
+
:lease_minutes => 3 * 24 * 60 * 60 # 3 days
|
63
|
+
)
|
64
|
+
when 'show_expired_vms'
|
65
|
+
vms = lease_tool.filter_expired_vms inventory.keys, inventory
|
66
|
+
vms.each do |vm, time_to_expiration|
|
67
|
+
puts "VM '#{inventory[vm]['name']}' is expired"
|
68
|
+
end
|
69
|
+
when 'kill_expired_vms'
|
70
|
+
vms = lease_tool.filter_expired_vms inventory.keys, inventory
|
71
|
+
vms.each do |vm, time_to_expiration|
|
72
|
+
puts "VM '#{inventory[vm]['name']}' is expired"
|
73
|
+
if !opts[:force]
|
74
|
+
puts "NOT killing VM '#{inventory[vm]['name']}' because --force not set"
|
75
|
+
else
|
76
|
+
puts "Killing expired VM '#{inventory[vm]['name']}'"
|
77
|
+
# Destroying VMs is very stressful for vCenter, and we aren't in a rush
|
78
|
+
# so do one VM at a time
|
79
|
+
if inventory[vm]['runtime.powerState'] == 'poweredOn'
|
80
|
+
vm.PowerOffVM_Task.wait_for_completion
|
81
|
+
end
|
82
|
+
vm.Destroy_Task.wait_for_completion
|
83
|
+
end
|
84
|
+
end
|
85
|
+
when 'show_soon_expired_vms'
|
86
|
+
vms = lease_tool.filter_expired_vms(
|
87
|
+
inventory.keys, inventory,
|
88
|
+
:time_delta => 3.5 * 24 * 60 * 60, # 3.5 days
|
89
|
+
)
|
90
|
+
# We could send the user emails here, but for this example, just print the
|
91
|
+
# VMs that will expire within the next 3.5 days
|
92
|
+
vms.each do |vm, time_to_expiration|
|
93
|
+
if time_to_expiration > 0
|
94
|
+
hours_to_expiration = time_to_expiration / (60.0 * 60.0)
|
95
|
+
puts "VM '%s' expires in %.2fh" % [inventory[vm]['name'], hours_to_expiration]
|
96
|
+
else
|
97
|
+
puts "VM '#{inventory[vm]['name']}' is expired"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
else
|
101
|
+
abort "invalid command"
|
102
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# @todo Retrieve ESX log bundles when run against VC.
|
2
|
+
require 'trollop'
|
3
|
+
require 'rbvmomi'
|
4
|
+
require 'rbvmomi/trollop'
|
5
|
+
|
6
|
+
VIM = RbVmomi::VIM
|
7
|
+
DEFAULT_SERVER_PLACEHOLDER = '0.0.0.0'
|
8
|
+
|
9
|
+
opts = Trollop.options do
|
10
|
+
banner <<-EOS
|
11
|
+
Generate and retrieve a log bundle.
|
12
|
+
|
13
|
+
Usage:
|
14
|
+
logbundle.rb [options] dest
|
15
|
+
|
16
|
+
dest must be a directory.
|
17
|
+
|
18
|
+
VIM connection options:
|
19
|
+
EOS
|
20
|
+
|
21
|
+
rbvmomi_connection_opts
|
22
|
+
|
23
|
+
text <<-EOS
|
24
|
+
|
25
|
+
Other options:
|
26
|
+
EOS
|
27
|
+
end
|
28
|
+
|
29
|
+
Trollop.die("must specify host") unless opts[:host]
|
30
|
+
dest = ARGV[0] or abort("must specify destination directory")
|
31
|
+
|
32
|
+
abort "destination is not a directory" unless File.directory? dest
|
33
|
+
|
34
|
+
vim = VIM.connect opts
|
35
|
+
is_vc = vim.serviceContent.about.apiType == 'VirtualCenter'
|
36
|
+
diagMgr = vim.serviceContent.diagnosticManager
|
37
|
+
|
38
|
+
bundles =
|
39
|
+
begin
|
40
|
+
diagMgr.GenerateLogBundles_Task(includeDefault: true).wait_for_completion
|
41
|
+
rescue VIM::TaskInProgress
|
42
|
+
$!.task.wait_for_completion
|
43
|
+
end
|
44
|
+
|
45
|
+
bundles.each do |b|
|
46
|
+
uri = URI.parse(b.url.sub('*', DEFAULT_SERVER_PLACEHOLDER))
|
47
|
+
dest_path = File.join(dest, File.basename(uri.path))
|
48
|
+
puts "downloading bundle #{b.url} to #{dest_path}"
|
49
|
+
if uri.host == DEFAULT_SERVER_PLACEHOLDER
|
50
|
+
vim.http.request_get(uri.path) do |res|
|
51
|
+
File.open dest_path, 'w' do |io|
|
52
|
+
res.read_body do |data|
|
53
|
+
io.write data
|
54
|
+
$stdout.write '.'
|
55
|
+
$stdout.flush
|
56
|
+
end
|
57
|
+
end
|
58
|
+
puts
|
59
|
+
end
|
60
|
+
else
|
61
|
+
puts 'not supported yet'
|
62
|
+
end
|
63
|
+
end
|