knife-vsphere 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,14 +56,13 @@ class Chef
56
56
  :description => "The VI SDK port number to use"
57
57
  $default[:vsphere_port] = 443
58
58
 
59
- option :vshere_ssl,
60
- :long => "--vsssl USE_SSL",
61
- :description => "Whether to use SSL connection"
62
- $default[:vsphere_ssl] = true
59
+ option :vshere_nossl,
60
+ :long => "--vsnossl",
61
+ :description => "Disable SSL connectivity"
63
62
 
64
63
  option :vsphere_insecure,
65
- :long => "--vsinsecure USE_INSECURE_SSL",
66
- :description => "Determines whether SSL certificate verification is skipped"
64
+ :long => "--vsinsecure",
65
+ :description => "Disable SSL certificate verification"
67
66
 
68
67
  option :folder,
69
68
  :short => "-f FOLDER",
@@ -85,7 +84,7 @@ class Chef
85
84
  :host => get_config(:vsphere_host),
86
85
  :path => get_config(:vshere_path),
87
86
  :port => get_config(:vsphere_port),
88
- :use_ssl => get_config(:vsphere_ssl),
87
+ :use_ssl => !get_config(:vsphere_nossl),
89
88
  :user => get_config(:vsphere_user),
90
89
  :password => get_config(:vsphere_pass),
91
90
  :insecure => get_config(:vsphere_insecure)
@@ -154,7 +153,17 @@ class Chef
154
153
 
155
154
 
156
155
  def find_all_in_folder(folder, type)
157
- folder.childEntity.grep(type)
156
+ if folder.instance_of?(RbVmomi::VIM::ClusterComputeResource)
157
+ folder = folder.resourcePool
158
+ end
159
+ if folder.instance_of?(RbVmomi::VIM::ResourcePool)
160
+ folder.resourcePool.grep(type)
161
+ elsif folder.instance_of?(RbVmomi::VIM::Folder)
162
+ folder.childEntity.grep(type)
163
+ else
164
+ puts "Unknown type #{folder.class}, not enumerating"
165
+ nil
166
+ end
158
167
  end
159
168
 
160
169
  def find_in_folder(folder, type, name)
@@ -0,0 +1,45 @@
1
+ #
2
+ # Author:: Jesse Campbell (<hikeit@gmail.com>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ require 'chef/knife'
6
+ require 'chef/knife/BaseVsphereCommand'
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
+ dcname = get_config(:vsphere_dc)
27
+ dc = config[:vim].serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
28
+ baseEntity = dc.hostFolder
29
+ entityArray = folderName.split('/')
30
+ entityArray.each do |entityArrItem|
31
+ if entityArrItem != ''
32
+ baseEntity = baseEntity.childEntity.grep(RbVmomi::VIM::ManagedObject).find { |f| f.name == entityArrItem } or
33
+ abort "no such folder #{folderName} while looking for #{entityArrItem}"
34
+ end
35
+ end
36
+ baseEntity
37
+ end
38
+
39
+ def run
40
+ $stdout.sync = true
41
+ vim = get_vim_connection
42
+ baseFolder = find_pool_folder(get_config(:folder));
43
+ traverse_folders(baseFolder)
44
+ end
45
+ end
@@ -83,12 +83,14 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
83
83
  :description => "Gigabytes of RAM"
84
84
 
85
85
  option :power,
86
- :long => "--start STARTVM",
87
- :description => "Indicates whether to start the VM after a successful clone"
86
+ :long => "--start",
87
+ :description => "Indicates whether to start the VM after a successful clone",
88
+ :boolean => false
88
89
 
89
90
  option :bootstrap,
90
- :long => "--bootstrap FALSE",
91
- :description => "Indicates whether to bootstrap the VM"
91
+ :long => "--bootstrap",
92
+ :description => "Indicates whether to bootstrap the VM",
93
+ :boolean => false
92
94
 
93
95
  option :fqdn,
94
96
  :long => "--fqdn SERVER_FQDN",
@@ -123,7 +125,8 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
123
125
 
124
126
  option :prerelease,
125
127
  :long => "--prerelease",
126
- :description => "Install the pre-release chef gems"
128
+ :description => "Install the pre-release chef gems",
129
+ :boolean => false
127
130
 
128
131
  option :bootstrap_version,
129
132
  :long => "--bootstrap-version VERSION",
@@ -243,10 +246,15 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
243
246
 
244
247
  if get_config(:customization_vlan)
245
248
  network = find_network(get_config(:customization_vlan))
246
- switch_port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection(:switchUuid => network.config.distributedVirtualSwitch.uuid ,:portgroupKey => network.key)
247
249
  card = src_config.hardware.device.find { |d| d.deviceInfo.label == "Network adapter 1" } or
248
250
  abort "Can't find source network card to customize"
249
- card.backing.port = switch_port
251
+ begin
252
+ switch_port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection(:switchUuid => network.config.distributedVirtualSwitch.uuid ,:portgroupKey => network.key)
253
+ card.backing.port = switch_port
254
+ rescue
255
+ # not connected to a distibuted switch?
256
+ card.backing.deviceName = network.name
257
+ end
250
258
  dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(:device => card, :operation => "edit")
251
259
  clone_spec.config.deviceChange.push dev_spec
252
260
  end
@@ -384,7 +392,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
384
392
  rescue Errno::ECONNREFUSED
385
393
  sleep 2
386
394
  false
387
- rescue Errno::EHOSTUNREACH
395
+ rescue Errno::EHOSTUNREACH, Errno::ENETUNREACH
388
396
  sleep 2
389
397
  false
390
398
  ensure
@@ -33,7 +33,7 @@ class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
33
33
  def print_vms_in_folder(folder)
34
34
  vms = find_all_in_folder(folder, RbVmomi::VIM::VirtualMachine)
35
35
  vms.each do |vm|
36
- puts "#{ui.color("VM Name", :cyan)}: #{vm.name}"
36
+ puts "#{ui.color("VM Name:", :cyan)} #{vm.name}\t#{ui.color("IP:", :magenta)} #{vm.guest.ipAddress}\t#{ui.color("RAM:", :magenta)} #{vm.summary.config.memorySizeMB}"
37
37
  end
38
38
  end
39
39
 
@@ -1,4 +1,4 @@
1
1
  module KnifeVsphere
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.3"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-25 00:00:00.000000000 -05:00
12
+ date: 2012-08-14 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: netaddr
17
- requirement: &70341464746140 !ruby/object:Gem::Requirement
17
+ requirement: &70275405040840 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,21 +22,21 @@ dependencies:
22
22
  version: 1.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70341464746140
25
+ version_requirements: *70275405040840
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: chef
28
- requirement: &70341464742000 !ruby/object:Gem::Requirement
28
+ requirement: &70275405038940 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
- - - ~>
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.10.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70341464742000
36
+ version_requirements: *70275405038940
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rbvmomi
39
- requirement: &70341464684660 !ruby/object:Gem::Requirement
39
+ requirement: &70275405038180 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 1.5.1
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70341464684660
47
+ version_requirements: *70275405038180
48
48
  description: VMware vSphere Support for Chef's Knife Command
49
49
  email: ezra@cpan.org
50
50
  executables: []
@@ -54,6 +54,7 @@ files:
54
54
  - lib/chef/knife/BaseVsphereCommand.rb
55
55
  - lib/chef/knife/vsphere_customization_list.rb
56
56
  - lib/chef/knife/vsphere_datastore_list.rb
57
+ - lib/chef/knife/vsphere_pool_list.rb
57
58
  - lib/chef/knife/vsphere_template_list.rb
58
59
  - lib/chef/knife/vsphere_vlan_list.rb
59
60
  - lib/chef/knife/vsphere_vm_clone.rb
@@ -62,7 +63,7 @@ files:
62
63
  - lib/chef/knife/vsphere_vm_state.rb
63
64
  - lib/knife-vsphere/version.rb
64
65
  has_rdoc: true
65
- homepage:
66
+ homepage: http://github.com/ezrapagel/knife-vsphere
66
67
  licenses: []
67
68
  post_install_message:
68
69
  rdoc_options: []