knife-esx 0.2.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,75 @@
1
+ # 0.3.0 - 2012/03/26
2
+
3
+ * Added template commands
4
+
5
+ knife esx template import --esx-password password \
6
+ --esx-host esx-test-host \
7
+ /path/to/template.vmdk
8
+
9
+ knife esx template list --esx-password password \
10
+ --esx-host esx-test-host
11
+
12
+ knife esx template delete --esx-password password \
13
+ --esx-host esx-test-host \
14
+ template.vmdk
15
+
16
+ * Added --use-template argument to *vm create* command
17
+
18
+ knife esx vm create --esx-password password \
19
+ --esx-host esx-test-host \
20
+ --use-template template.vmdk \
21
+ my-new-vm
22
+
23
+ ## Create a new VM using templates
24
+
25
+ 1. Import the template first with "knife esx template import"
26
+
27
+ knife esx template import --esx-host esx-test-host \
28
+ --esx-password password \
29
+ /path/to/template.vmdk
30
+
31
+ 2. Deploy using knife esx vm create
32
+
33
+ knife esx vm create --esx-host esx-test-host \
34
+ --esx-password password \
35
+ --vm-name my-foo-vm \
36
+ --use-template template.vmdk
37
+
38
+ ## Using templates with async batch deploys
39
+
40
+ 1. Import the template first with "knife esx template import"
41
+
42
+ knife esx template import --esx-host esx-test-host \
43
+ --esx-password password \
44
+ /path/to/template.vmdk
45
+
46
+ 2. Deploy using knife esx vm create --async --batch
47
+ Sample batch config for "knife esx vm create":
48
+
49
+ ---
50
+ :tc01:
51
+ 'use-template': template.vmdk
52
+ 'extra-args': --no-host-key-verify
53
+ 'vm-memory': 128
54
+ 'esx-host': esx-test-host
55
+ 'esx-password': password
56
+ 'ssh-user': ubuntu
57
+ 'ssh-password': ubuntu
58
+ 'datastore': datastore1
59
+ :tc02:
60
+ 'use-template': template.vmdk
61
+ 'extra-args': --no-host-key-verify
62
+ 'vm-memory': 128
63
+ 'esx-host': esx-test-host
64
+ 'esx-password': password
65
+ 'ssh-user': ubuntu
66
+ 'ssh-password': ubuntu
67
+ 'datastore': datastore1
68
+
69
+ # 0.2.1 - 2012/02/28
70
+
71
+ * Fixed namespaces
72
+
1
73
  # 0.2 - 2012/02/28
2
74
 
3
75
  * **Added --batch and --async options**
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.add_dependency "esx", ">= 0.3.2"
19
+ s.add_dependency "esx", ">= 0.4.1"
20
20
  s.add_dependency "terminal-table"
21
21
  s.add_dependency "chef", ">= 0.10"
22
22
  s.add_dependency "celluloid", ">= 0.9"
@@ -0,0 +1,55 @@
1
+ #
2
+ # Author:: Sergio Rubio (<rubiojr@frameos.org>)
3
+ # Copyright:: Copyright (c) 2011 Sergio Rubio
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife/esx_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class EsxTemplateDelete < Knife
24
+
25
+ include Knife::ESXBase
26
+
27
+ banner "knife esx template delete TEMPLATE_NAME [TEMPLATE_NAME] (options)"
28
+
29
+ option :force_delete,
30
+ :long => "--force-delete NO",
31
+ :default => 'no',
32
+ :description => "Do not confirm VM deletion when yes"
33
+
34
+ def run
35
+ deleted = []
36
+ connection.list_templates.each do |tmpl|
37
+ @name_args.each do |tmpl_name|
38
+ if tmpl_name == File.basename(tmpl)
39
+ if config[:force_delete] !~ /true|yes/i
40
+ confirm("Do you really want to delete this template '#{tmpl_name}'")
41
+ end
42
+ connection.delete_template tmpl_name
43
+ deleted << tmpl_name
44
+ ui.info("Deleted virtual machine #{tmpl_name}")
45
+ end
46
+ end
47
+ end
48
+ @name_args.each do |tmpl_name|
49
+ ui.warn "Template #{tmpl_name} not found" if not deleted.include?(tmpl_name)
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,42 @@
1
+ #
2
+ # Author:: Sergio Rubio (<rubiojr@frameos.org>)
3
+ # Copyright:: Copyright (c) 2011 Sergio Rubio
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife/esx_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class EsxTemplateImport < Knife
24
+
25
+ include Knife::ESXBase
26
+
27
+ banner "knife esx template import TEMPLATE_FILE"
28
+
29
+ def run
30
+ $stdout.sync = true
31
+ @name_args.each do |vm_name|
32
+ if not File.exist?(vm_name)
33
+ ui.error("The file #{vm_name} does not exist.")
34
+ exit 1
35
+ end
36
+ connection.import_template vm_name, :print_progress => true
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,42 @@
1
+ #
2
+ # Author:: Sergio Rubio (<rubiojr@frameos.org>)
3
+ # Copyright:: Copyright (c) 2011 Sergio Rubio
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'chef/knife/esx_base'
20
+
21
+ class Chef
22
+ class Knife
23
+ class EsxTemplateList < Knife
24
+
25
+ include Knife::ESXBase
26
+
27
+ banner "knife esx template list"
28
+
29
+ def run
30
+ $stdout.sync = true
31
+ table = table do |t|
32
+ t.headings = %w{DISK_TEMPLATES}
33
+ connection.list_templates.each do |tmpl|
34
+ t << [File.basename(tmpl)]
35
+ end
36
+ end
37
+ puts table
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -197,6 +197,11 @@ class Chef
197
197
  :proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t },
198
198
  :default => false
199
199
 
200
+ option :use_template,
201
+ :long => "--use-template NAME",
202
+ :description => "Try to use an existing template instead of importing disk",
203
+ :default => nil
204
+
200
205
  option :run_list,
201
206
  :short => "-r RUN_LIST",
202
207
  :long => "--run-list RUN_LIST",
@@ -312,14 +317,16 @@ class Chef
312
317
  return
313
318
  end
314
319
 
315
- unless config[:vm_disk]
316
- ui.error("You have not provided a valid VMDK file. (--vm-disk)")
317
- exit 1
318
- end
319
-
320
- if not File.exist?(config[:vm_disk])
321
- ui.error("Invalid VMDK disk file (--vm-disk)")
322
- exit 1
320
+ if not config[:use_template]
321
+ unless config[:vm_disk]
322
+ ui.error("You have not provided a valid VMDK file. (--vm-disk)")
323
+ exit 1
324
+ end
325
+
326
+ unless File.exist?(config[:vm_disk])
327
+ ui.error("Invalid VMDK disk file (--vm-disk)")
328
+ exit 1
329
+ end
323
330
  end
324
331
 
325
332
  vm_name = config[:vm_name]
@@ -336,10 +343,21 @@ class Chef
336
343
  destination_path = "/vmfs/volumes/#{datastore}/#{vm_name}"
337
344
 
338
345
  connection.remote_command "mkdir #{destination_path}"
339
- puts "#{ui.color("Creating VM #{vm_name}... ", :magenta)}"
340
- puts "#{ui.color("Importing VM disk... ", :magenta)}"
346
+ ui.info "Creating VM #{vm_name}"
341
347
 
342
- connection.import_disk vm_disk, destination_path + "/#{vm_name}.vmdk"
348
+ if config[:use_template]
349
+ ui.info "Using template #{config[:use_template]}"
350
+ if connection.template_exist?(config[:use_template])
351
+ puts "#{ui.color("Cloning template...",:magenta)}"
352
+ connection.copy_from_template config[:use_template], destination_path + "/#{vm_name}.vmdk"
353
+ else
354
+ ui.error "Template #{config[:use_template]} not found"
355
+ exit 1
356
+ end
357
+ else
358
+ puts "#{ui.color("Importing VM disk... ", :magenta)}"
359
+ connection.import_disk vm_disk, destination_path + "/#{vm_name}.vmdk"
360
+ end
343
361
  vm = connection.create_vm :vm_name => vm_name,
344
362
  :datastore => datastore,
345
363
  :disk_file => "#{vm_name}/#{vm_name}.vmdk",
@@ -348,6 +366,7 @@ class Chef
348
366
  :nics => create_nics(config[:vm_network], config[:mac_address])
349
367
  vm.power_on
350
368
 
369
+ puts "#{ui.color("VM Created", :cyan)}"
351
370
  puts "#{ui.color("VM Name", :cyan)}: #{vm.name}"
352
371
  puts "#{ui.color("VM Memory", :cyan)}: #{(vm.memory_size.to_f/1024/1024).round} MB"
353
372
 
@@ -36,14 +36,14 @@ class Chef
36
36
  connection.virtual_machines.each do |vm|
37
37
  @name_args.each do |vm_name|
38
38
  if vm_name == vm.name
39
- if config[:force_delete] != 'yes'
39
+ if config[:force_delete] =~ /(no|NO|false|FALSE)/
40
40
  confirm("Do you really want to delete this virtual machine '#{vm.name}'")
41
41
  end
42
42
 
43
43
  vm.power_off if (vm.name =~ /#{vm.name}/ and vm.power_state == 'poweredOn')
44
44
  vm.destroy
45
45
  deleted << vm_name
46
- ui.warn("Deleted virtual machine #{vm.name}")
46
+ ui.info("Deleted virtual machine #{vm.name}")
47
47
  end
48
48
  end
49
49
  end
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module ESX
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3"
4
4
  MAJOR, MINOR, TINY = VERSION.split('.')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-esx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-28 00:00:00.000000000 Z
12
+ date: 2012-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: esx
16
- requirement: &19203900 !ruby/object:Gem::Requirement
16
+ requirement: &19768260 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.3.2
21
+ version: 0.4.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19203900
24
+ version_requirements: *19768260
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: terminal-table
27
- requirement: &19203400 !ruby/object:Gem::Requirement
27
+ requirement: &19766280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *19203400
35
+ version_requirements: *19766280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: chef
38
- requirement: &19202600 !ruby/object:Gem::Requirement
38
+ requirement: &19763120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0.10'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *19202600
46
+ version_requirements: *19763120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: celluloid
49
- requirement: &19201620 !ruby/object:Gem::Requirement
49
+ requirement: &19754700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0.9'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *19201620
57
+ version_requirements: *19754700
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: open4
60
- requirement: &19530300 !ruby/object:Gem::Requirement
60
+ requirement: &19753280 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *19530300
68
+ version_requirements: *19753280
69
69
  description: ESX Support for Chef's Knife Command
70
70
  email:
71
71
  - rubiojr@frameos.org
@@ -85,6 +85,9 @@ files:
85
85
  - features/support/env.rb
86
86
  - knife-esx.gemspec
87
87
  - lib/chef/knife/esx_base.rb
88
+ - lib/chef/knife/esx_template_delete.rb
89
+ - lib/chef/knife/esx_template_import.rb
90
+ - lib/chef/knife/esx_template_list.rb
88
91
  - lib/chef/knife/esx_vm_create.rb
89
92
  - lib/chef/knife/esx_vm_delete.rb
90
93
  - lib/chef/knife/esx_vm_list.rb