knife-vsphere 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/chef/knife/vsphere_vm_clone.rb +24 -11
  2. metadata +4 -3
@@ -31,8 +31,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
31
31
 
32
32
  option :resource_pool,
33
33
  :long => "--resource-pool POOL",
34
- :description => "The resource pool into which to put the cloned VM",
35
- :default => ''
34
+ :description => "The resource pool into which to put the cloned VM"
36
35
 
37
36
  option :source_vm,
38
37
  :long => "--template TEMPLATE",
@@ -75,15 +74,15 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
75
74
  :long => "--cram CUST_MEMORY_GB",
76
75
  :description => "Gigabytes of RAM"
77
76
 
78
- option :power,
77
+ option :power,
79
78
  :long => "--start STARTVM",
80
79
  :description => "Indicates whether to start the VM after a successful clone",
81
- :default => true
80
+ :default => false
82
81
 
83
- option :bootstrap,
82
+ option :bootstrap,
84
83
  :long => "--bootstrap FALSE",
85
84
  :description => "Indicates whether to bootstrap the VM",
86
- :default => true
85
+ :default => false
87
86
 
88
87
  option :fqdn,
89
88
  :long => "--fqdn SERVER_FQDN",
@@ -156,7 +155,6 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
156
155
  :default => false
157
156
 
158
157
  def run
159
-
160
158
  $stdout.sync = true
161
159
 
162
160
  vmname = @name_args[0]
@@ -167,16 +165,21 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
167
165
  config[:fqdn] = vmname unless config[:fqdn]
168
166
  config[:chef_node_name] = vmname unless config[:chef_node_name]
169
167
 
170
- get_vim_connection
168
+ vim = get_vim_connection
171
169
 
172
- src_folder = find_folder(config[:folder])
170
+ dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
171
+ dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
172
+
173
+ src_folder = find_folder(config[:folder]) || dc.vmFolder
173
174
 
174
175
  src_vm = find_in_folder(src_folder, RbVmomi::VIM::VirtualMachine, config[:source_vm]) or
175
176
  abort "VM/Template not found"
176
177
 
177
178
  clone_spec = generate_clone_spec(src_vm.config)
178
179
 
179
- dest_folder = find_folder(config[:dest_folder] || config[:folder]);
180
+ cust_folder = config[:dest_folder] || config[:folder]
181
+
182
+ dest_folder = cust_folder.nil? ? src_vm.vmFolder : find_folder(cust_folder)
180
183
 
181
184
  task = src_vm.CloneVM_Task(:folder => dest_folder, :name => vmname, :spec => clone_spec)
182
185
  puts "Cloning template #{config[:source_vm]} to new VM #{vmname}"
@@ -201,7 +204,17 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
201
204
 
202
205
  # Builds a CloneSpec
203
206
  def generate_clone_spec (src_config)
204
- rspec = RbVmomi::VIM.VirtualMachineRelocateSpec(:pool => find_pool(config[:resource_pool]))
207
+
208
+ rspec = nil
209
+ if config[:resource_pool]
210
+ rspec = RbVmomi::VIM.VirtualMachineRelocateSpec(:pool => find_pool(config[:resource_pool]))
211
+ else
212
+ dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
213
+ dc = config[:vim].serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
214
+ hosts = find_all_in_folder(dc.hostFolder, RbVmomi::VIM::ComputeResource)
215
+ rp = hosts.first.resourcePool
216
+ rspec = RbVmomi::VIM.VirtualMachineRelocateSpec(:pool => rp)
217
+ end
205
218
 
206
219
  if config[:datastore]
207
220
  rspec.datastore = find_datastore(config[:datastore])
metadata CHANGED
@@ -2,15 +2,16 @@
2
2
  name: knife-vsphere
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.6
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ezra Pagel
9
+ - Jesse Campbell
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
13
 
13
- date: 2012-01-17 00:00:00 -06:00
14
+ date: 2012-01-24 00:00:00 -06:00
14
15
  default_executable:
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
@@ -64,7 +65,7 @@ files:
64
65
  - lib/chef/knife/vsphere_vm_state.rb
65
66
  - lib/knife-vsphere/version.rb
66
67
  has_rdoc: true
67
- homepage:
68
+ homepage: http://github.com/ezrapagel/knife-vsphere
68
69
  licenses: []
69
70
 
70
71
  post_install_message: