knife-vsphere 0.9.9 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bcf97f655379f73a1f5f3c3a6afa654377b4209a
4
+ data.tar.gz: cd751fa09644f4b616edd7c94d3739b1332e91ea
5
+ SHA512:
6
+ metadata.gz: 205fe4416e68241f9aa5eab64e82e168caa849c4e889ca0a6a99c48018bf5a58270cb7120a3bf94a59dcee6d1a32044b69deebc18827c6db96b8b2beabaaed21
7
+ data.tar.gz: 42733ce3777bd548744c7487e89f69e4d4b5cd7e021648a53433fdb0b16e8a5a8b07cef8fea49ed194852da7b9620deeabe7e75c614ce4c958fe42fb5ba77db2
@@ -138,6 +138,26 @@ class Chef
138
138
  return false
139
139
  end
140
140
 
141
+ def get_vms(vmname)
142
+ vim = get_vim_connection
143
+ baseFolder = find_folder(get_config(:folder));
144
+ retval = traverse_folders_for_vms(baseFolder, vmname)
145
+ return retval
146
+ end
147
+
148
+ def traverse_folders_for_vms(folder, vmname)
149
+ retval = []
150
+ children = folder.children.find_all
151
+ children.each do |child|
152
+ if child.class == RbVmomi::VIM::VirtualMachine && child.name == vmname
153
+ retval << child
154
+ elsif child.class == RbVmomi::VIM::Folder
155
+ retval.concat(traverse_folders_for_vms(child, vmname))
156
+ end
157
+ end
158
+ return retval
159
+ end
160
+
141
161
  def traverse_folders_for_dc(folder, dcname)
142
162
  children = folder.children.find_all
143
163
  children.each do |child|
@@ -252,6 +272,12 @@ class Chef
252
272
  baseEntity.find { |f| f.info.name == dsName } or abort "no such datastore #{dsName}"
253
273
  end
254
274
 
275
+ def find_datastorecluster(dsName)
276
+ dc = get_datacenter
277
+ baseEntity = dc.datastoreFolder.childEntity
278
+ baseEntity.find { |f| f.name == dsName and f.instance_of?(RbVmomi::VIM::StoragePod) } or abort "no such datastorecluster #{dsName}"
279
+ end
280
+
255
281
  def find_device(vm, deviceName)
256
282
  vm.config.hardware.device.each do |device|
257
283
  return device if device.deviceInfo.label == deviceName
@@ -273,6 +299,19 @@ class Chef
273
299
  end
274
300
  end
275
301
 
302
+ def get_path_to_object(object)
303
+ if object.is_a?(RbVmomi::VIM:: ManagedEntity)
304
+ if object.parent.is_a?(RbVmomi::VIM:: ManagedEntity)
305
+ return get_path_to_object(object.parent) + "/" + object.parent.name
306
+ else
307
+ return ""
308
+ end
309
+ else
310
+ puts "Unknown type #{object.class}, not enumerating"
311
+ nil
312
+ end
313
+ end
314
+
276
315
  def find_in_folder(folder, type, name)
277
316
  folder.childEntity.grep(type).find { |o| o.name == name }
278
317
  end
@@ -1,47 +1,47 @@
1
- #
2
- # Author:: Brian Dupras (<bdupras@rallydev.com>)
3
- # License:: Apache License, Version 2.0
4
- #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
7
-
8
- # Lists all known virtual machines in the configured datacenter
9
- class Chef::Knife::VsphereVmMove < Chef::Knife::BaseVsphereCommand
10
-
11
- banner "knife vsphere vm move"
12
-
13
- get_common_options
14
-
15
- option :dest_name,
16
- :long => "--dest-name NAME",
17
- :short => "-r",
18
- :description => "Destination name of the VM or template"
19
-
20
- option :dest_folder,
21
- :long => "--dest-folder FOLDER",
22
- :description => "The destination folder into which the VM or template should be moved"
23
-
24
-
25
- def run
26
- $stdout.sync = true
27
- vmname = @name_args[0]
28
- if vmname.nil?
29
- show_usage
30
- fatal_exit("You must specify a virtual machine name")
31
- end
32
-
33
- vim = get_vim_connection
34
- dcname = get_config(:vsphere_dc)
35
- dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
36
- folder = find_folder(get_config(:folder)) || dc.vmFolder
37
-
38
- vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or
39
- abort "VM #{vmname} not found"
40
-
41
- dest_name = config[:dest_name] || vmname
42
- dest_folder = config[:dest_folder].nil? ? (vm.parent) : (find_folder(get_config(:dest_folder)))
43
-
44
- vm.Rename_Task(:newName => dest_name).wait_for_completion unless vmname == dest_name
45
- dest_folder.MoveIntoFolder_Task(:list => [vm]).wait_for_completion unless folder == dest_folder
46
- end
47
- end
1
+ #
2
+ # Author:: Brian Dupras (<bdupras@rallydev.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ require 'chef/knife'
6
+ require 'chef/knife/base_vsphere_command'
7
+
8
+ # Lists all known virtual machines in the configured datacenter
9
+ class Chef::Knife::VsphereVmMove < Chef::Knife::BaseVsphereCommand
10
+
11
+ banner "knife vsphere vm move"
12
+
13
+ get_common_options
14
+
15
+ option :dest_name,
16
+ :long => "--dest-name NAME",
17
+ :short => "-r",
18
+ :description => "Destination name of the VM or template"
19
+
20
+ option :dest_folder,
21
+ :long => "--dest-folder FOLDER",
22
+ :description => "The destination folder into which the VM or template should be moved"
23
+
24
+
25
+ def run
26
+ $stdout.sync = true
27
+ vmname = @name_args[0]
28
+ if vmname.nil?
29
+ show_usage
30
+ fatal_exit("You must specify a virtual machine name")
31
+ end
32
+
33
+ vim = get_vim_connection
34
+ dcname = get_config(:vsphere_dc)
35
+ dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
36
+ folder = find_folder(get_config(:folder)) || dc.vmFolder
37
+
38
+ vm = find_in_folder(folder, RbVmomi::VIM::VirtualMachine, vmname) or
39
+ abort "VM #{vmname} not found"
40
+
41
+ dest_name = config[:dest_name] || vmname
42
+ dest_folder = config[:dest_folder].nil? ? (vm.parent) : (find_folder(get_config(:dest_folder)))
43
+
44
+ vm.Rename_Task(:newName => dest_name).wait_for_completion unless vmname == dest_name
45
+ dest_folder.MoveIntoFolder_Task(:list => [vm]).wait_for_completion unless folder == dest_folder
46
+ end
47
+ end
@@ -1,29 +1,29 @@
1
- #
2
- # Author:: Ezra Pagel (<ezra@cpan.org>)
3
- # License:: Apache License, Version 2.0
4
- #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
7
-
8
- # Lists all customization specifications in the configured datacenter
9
- class Chef::Knife::VsphereCustomizationList < Chef::Knife::BaseVsphereCommand
10
-
11
- banner "knife vsphere customization list"
12
-
13
- get_common_options
14
-
15
- def run
16
-
17
- $stdout.sync = true
18
-
19
- vim = get_vim_connection
20
-
21
- csm = vim.serviceContent.customizationSpecManager
22
- csm.info.each do |c|
23
- puts "#{ui.color("Customization Name", :cyan)}: #{c.name}"
24
-
25
- end
26
-
27
- end
28
- end
29
-
1
+ #
2
+ # Author:: Ezra Pagel (<ezra@cpan.org>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ require 'chef/knife'
6
+ require 'chef/knife/base_vsphere_command'
7
+
8
+ # Lists all customization specifications in the configured datacenter
9
+ class Chef::Knife::VsphereCustomizationList < Chef::Knife::BaseVsphereCommand
10
+
11
+ banner "knife vsphere customization list"
12
+
13
+ get_common_options
14
+
15
+ def run
16
+
17
+ $stdout.sync = true
18
+
19
+ vim = get_vim_connection
20
+
21
+ csm = vim.serviceContent.customizationSpecManager
22
+ csm.info.each do |c|
23
+ puts "#{ui.color("Customization Name", :cyan)}: #{c.name}"
24
+
25
+ end
26
+
27
+ end
28
+ end
29
+
@@ -1,58 +1,58 @@
1
- # Copyright (C) 2012, SCM Ventures AB
2
- # Author: Ian Delahorne <ian@scmventures.se>
3
- #
4
- # Permission to use, copy, modify, and/or distribute this software for
5
- # any purpose with or without fee is hereby granted, provided that the
6
- # above copyright notice and this permission notice appear in all
7
- # copies.
8
- #
9
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10
- # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11
- # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12
- # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13
- # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
14
- # OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15
- # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
- # PERFORMANCE OF THIS SOFTWARE
17
-
18
- require 'chef/knife'
19
- require 'chef/knife/base_vsphere_command'
20
-
21
- def number_to_human_size(number)
22
- number = number.to_f
23
- storage_units_fmt = ["byte", "kB", "MB", "GB", "TB"]
24
- base = 1024
25
- if number.to_i < base
26
- unit = storage_units_fmt[0]
27
- else
28
- max_exp = storage_units_fmt.size - 1
29
- exponent = (Math.log(number) / Math.log(base)).to_i # Convert to base
30
- exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit
31
- number /= base ** exponent
32
- unit = storage_units_fmt[exponent]
33
- end
34
-
35
- return sprintf("%0.2f %s", number, unit)
36
- end
37
-
38
-
39
- # Lists all known data stores in datacenter with sizes
40
- class Chef::Knife::VsphereDatastoreList < Chef::Knife::BaseVsphereCommand
41
-
42
- banner "knife vsphere datastore list"
43
-
44
- get_common_options
45
-
46
- def run
47
- $stdout.sync = true
48
-
49
- vim = get_vim_connection
50
- dc = get_datacenter
51
- dc.datastore.each do |store|
52
- avail = number_to_human_size(store.summary[:freeSpace])
53
- cap = number_to_human_size(store.summary[:capacity])
54
- puts "#{ui.color("Datastore", :cyan)}: #{store.name} (#{avail} / #{cap})"
55
- end
56
- end
57
- end
58
-
1
+ # Copyright (C) 2012, SCM Ventures AB
2
+ # Author: Ian Delahorne <ian@scmventures.se>
3
+ #
4
+ # Permission to use, copy, modify, and/or distribute this software for
5
+ # any purpose with or without fee is hereby granted, provided that the
6
+ # above copyright notice and this permission notice appear in all
7
+ # copies.
8
+ #
9
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12
+ # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13
+ # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
14
+ # OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15
+ # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ # PERFORMANCE OF THIS SOFTWARE
17
+
18
+ require 'chef/knife'
19
+ require 'chef/knife/base_vsphere_command'
20
+
21
+ def number_to_human_size(number)
22
+ number = number.to_f
23
+ storage_units_fmt = ["byte", "kB", "MB", "GB", "TB"]
24
+ base = 1024
25
+ if number.to_i < base
26
+ unit = storage_units_fmt[0]
27
+ else
28
+ max_exp = storage_units_fmt.size - 1
29
+ exponent = (Math.log(number) / Math.log(base)).to_i # Convert to base
30
+ exponent = max_exp if exponent > max_exp # we need this to avoid overflow for the highest unit
31
+ number /= base ** exponent
32
+ unit = storage_units_fmt[exponent]
33
+ end
34
+
35
+ return sprintf("%0.2f %s", number, unit)
36
+ end
37
+
38
+
39
+ # Lists all known data stores in datacenter with sizes
40
+ class Chef::Knife::VsphereDatastoreList < Chef::Knife::BaseVsphereCommand
41
+
42
+ banner "knife vsphere datastore list"
43
+
44
+ get_common_options
45
+
46
+ def run
47
+ $stdout.sync = true
48
+
49
+ vim = get_vim_connection
50
+ dc = get_datacenter
51
+ dc.datastore.each do |store|
52
+ avail = number_to_human_size(store.summary[:freeSpace])
53
+ cap = number_to_human_size(store.summary[:capacity])
54
+ puts "#{ui.color("Datastore", :cyan)}: #{store.name} (#{avail} / #{cap})"
55
+ end
56
+ end
57
+ end
58
+
@@ -1,44 +1,44 @@
1
- #
2
- # Author:: Jesse Campbell (<hikeit@gmail.com>)
3
- # License:: Apache License, Version 2.0
4
- #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
7
-
8
- # Lists all known pools in the configured datacenter
9
- class Chef::Knife::VspherePoolList < Chef::Knife::BaseVsphereCommand
10
-
11
- banner "knife vsphere pool list"
12
-
13
- get_common_options
14
-
15
- def traverse_folders(folder)
16
- puts "#{ui.color("#{folder.class}", :cyan)}: "+(folder.path[3..-1].map { |x| x[1] }.* '/')
17
- folders = find_all_in_folder(folder, RbVmomi::VIM::ManagedObject)
18
- unless folders.nil?
19
- folders.each do |child|
20
- traverse_folders(child)
21
- end
22
- end
23
- end
24
-
25
- def find_pool_folder(folderName)
26
- dc = get_datacenter
27
- baseEntity = dc.hostFolder
28
- entityArray = folderName.split('/')
29
- entityArray.each do |entityArrItem|
30
- if entityArrItem != ''
31
- baseEntity = baseEntity.childEntity.grep(RbVmomi::VIM::ManagedObject).find { |f| f.name == entityArrItem } or
32
- abort "no such folder #{folderName} while looking for #{entityArrItem}"
33
- end
34
- end
35
- baseEntity
36
- end
37
-
38
- def run
39
- $stdout.sync = true
40
- vim = get_vim_connection
41
- baseFolder = find_pool_folder(get_config(:folder));
42
- traverse_folders(baseFolder)
43
- end
44
- end
1
+ #
2
+ # Author:: Jesse Campbell (<hikeit@gmail.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ require 'chef/knife'
6
+ require 'chef/knife/base_vsphere_command'
7
+
8
+ # Lists all known pools in the configured datacenter
9
+ class Chef::Knife::VspherePoolList < Chef::Knife::BaseVsphereCommand
10
+
11
+ banner "knife vsphere pool list"
12
+
13
+ get_common_options
14
+
15
+ def traverse_folders(folder)
16
+ puts "#{ui.color("#{folder.class}", :cyan)}: "+(folder.path[3..-1].map { |x| x[1] }.* '/')
17
+ folders = find_all_in_folder(folder, RbVmomi::VIM::ManagedObject)
18
+ unless folders.nil?
19
+ folders.each do |child|
20
+ traverse_folders(child)
21
+ end
22
+ end
23
+ end
24
+
25
+ def find_pool_folder(folderName)
26
+ dc = get_datacenter
27
+ baseEntity = dc.hostFolder
28
+ entityArray = folderName.split('/')
29
+ entityArray.each do |entityArrItem|
30
+ if entityArrItem != ''
31
+ baseEntity = baseEntity.childEntity.grep(RbVmomi::VIM::ManagedObject).find { |f| f.name == entityArrItem } or
32
+ abort "no such folder #{folderName} while looking for #{entityArrItem}"
33
+ end
34
+ end
35
+ baseEntity
36
+ end
37
+
38
+ def run
39
+ $stdout.sync = true
40
+ vim = get_vim_connection
41
+ baseFolder = find_pool_folder(get_config(:folder));
42
+ traverse_folders(baseFolder)
43
+ end
44
+ end
@@ -1,37 +1,37 @@
1
- # Author: Jesse Campbell
2
- #
3
- # Permission to use, copy, modify, and/or distribute this software for
4
- # any purpose with or without fee is hereby granted, provided that the
5
- # above copyright notice and this permission notice appear in all
6
- # copies.
7
- #
8
- # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9
- # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10
- # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
11
- # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12
- # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
13
- # OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
14
- # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
- # PERFORMANCE OF THIS SOFTWARE
16
-
17
- require 'chef/knife'
18
- require 'chef/knife/base_vsphere_command'
19
-
20
- # Lists all known data stores in datacenter with sizes
21
- class Chef::Knife::VsphereVlanList < Chef::Knife::BaseVsphereCommand
22
-
23
- banner "knife vsphere vlan list"
24
-
25
- get_common_options
26
-
27
- def run
28
- $stdout.sync = true
29
-
30
- vim = get_vim_connection
31
- dc = get_datacenter
32
- dc.network.each do |network|
33
- puts "#{ui.color("VLAN", :cyan)}: #{network.name}"
34
- end
35
- end
36
- end
37
-
1
+ # Author: Jesse Campbell
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for
4
+ # any purpose with or without fee is hereby granted, provided that the
5
+ # above copyright notice and this permission notice appear in all
6
+ # copies.
7
+ #
8
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
9
+ # WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
10
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
11
+ # AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12
+ # DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
13
+ # OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
14
+ # TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ # PERFORMANCE OF THIS SOFTWARE
16
+
17
+ require 'chef/knife'
18
+ require 'chef/knife/base_vsphere_command'
19
+
20
+ # Lists all known data stores in datacenter with sizes
21
+ class Chef::Knife::VsphereVlanList < Chef::Knife::BaseVsphereCommand
22
+
23
+ banner "knife vsphere vlan list"
24
+
25
+ get_common_options
26
+
27
+ def run
28
+ $stdout.sync = true
29
+
30
+ vim = get_vim_connection
31
+ dc = get_datacenter
32
+ dc.network.each do |network|
33
+ puts "#{ui.color("VLAN", :cyan)}: #{network.name}"
34
+ end
35
+ end
36
+ end
37
+