knife-vsphere 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,71 @@
1
+ V#
2
+ # Author:: Ezra Pagel (<ezra@cpan.org>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'chef/knife'
18
+ require 'chef/knife/VsphereBaseCommand'
19
+ require 'rbvmomi'
20
+
21
+ class Chef
22
+ class Knife
23
+ class VsphereVmClone < VsphereBaseCommand
24
+
25
+ banner "knife vsphere vm clone (options)"
26
+
27
+ get_common_options
28
+
29
+ option :template,
30
+ :short => "-t TEMPLATE",
31
+ :long => "--template TEMPLATE",
32
+ :description => "The template to create the VM from"
33
+
34
+ option :vmname,
35
+ :short => "-N VMNAME",
36
+ :long => "--vmname VMNAME",
37
+ :description => "The name for the new virtual machine"
38
+
39
+ def run
40
+
41
+ $stdout.sync = true
42
+
43
+ vim = get_vim_connection
44
+
45
+ dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
46
+ dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
47
+ vmFolder = dc.vmFolder
48
+ hosts = dc.hostFolder.children
49
+ rp = hosts.first.resourcePool
50
+
51
+ template = config[:template] or abort "source template name required"
52
+ vmname = config[:vmname] or abort "destination vm name required"
53
+
54
+ puts "searching for template #{template}"
55
+
56
+ src_vm = dc.find_vm(template) or abort "VM not found"
57
+
58
+ rspec = RbVmomi::VIM.VirtualMachineRelocateSpec(:pool => rp)
59
+ spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => rspec,
60
+ :powerOn => false,
61
+ :template => false)
62
+
63
+ task = src_vm.CloneVM_Task(:folder => src_vm.parent, :name => vmname, :spec => spec)
64
+ puts "Cloning template #{template} to new VM #{vmname}"
65
+ task.wait_for_completion
66
+ puts "Finished creating virtual machine #{vmname}"
67
+
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,3 +1,19 @@
1
+ #
2
+ # Author:: Ezra Pagel (<ezra@cpan.org>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
1
17
  require 'chef/knife'
2
18
  require 'rbvmomi'
3
19
 
@@ -33,12 +49,6 @@ class Chef
33
49
  :long => "--password PASSWORD",
34
50
  :description => "The password for the host"
35
51
 
36
- option :name,
37
- :short => "-n NAME",
38
- :long => "--name NAME",
39
- :description => "The name for the new VM",
40
- :proc => Proc.new { |i| Chef::Config[:knife][:name] = i }
41
-
42
52
  option :datacenter,
43
53
  :short => "-d DATACENTER",
44
54
  :long => "--datacenter DATACENTER",
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Ezra Pagel (<ezra.pagel@gmail.com>)
2
+ # Author:: Ezra Pagel (<ezra@cpan.org>)
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -0,0 +1,71 @@
1
+ #
2
+ # Author:: Ezra Pagel (<ezra@cpan.org>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'chef/knife'
18
+ require 'chef/knife/VsphereBaseCommand'
19
+ require 'rbvmomi'
20
+
21
+ class Chef
22
+ class Knife
23
+ class VsphereVmClone < VsphereBaseCommand
24
+
25
+ banner "knife vsphere vm clone (options)"
26
+
27
+ get_common_options
28
+
29
+ option :template,
30
+ :short => "-t TEMPLATE",
31
+ :long => "--template TEMPLATE",
32
+ :description => "The template to create the VM from"
33
+
34
+ option :vmname,
35
+ :short => "-N VMNAME",
36
+ :long => "--vmname VMNAME",
37
+ :description => "The name for the new virtual machine"
38
+
39
+ def run
40
+
41
+ $stdout.sync = true
42
+
43
+ vim = get_vim_connection
44
+
45
+ dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
46
+ dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
47
+ vmFolder = dc.vmFolder
48
+ hosts = dc.hostFolder.children
49
+ rp = hosts.first.resourcePool
50
+
51
+ template = config[:template] or abort "source template name required"
52
+ vmname = config[:vmname] or abort "destination vm name required"
53
+
54
+ puts "searching for template #{template}"
55
+
56
+ src_vm = dc.find_vm(template) or abort "VM not found"
57
+
58
+ rspec = RbVmomi::VIM.VirtualMachineRelocateSpec(:pool => rp)
59
+ spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => rspec,
60
+ :powerOn => false,
61
+ :template => false)
62
+
63
+ task = src_vm.CloneVM_Task(:folder => src_vm.parent, :name => vmname, :spec => spec)
64
+ puts "Cloning template #{template} to new VM #{vmname}"
65
+ task.wait_for_completion
66
+ puts "Finished creating virtual machine #{vmname}"
67
+
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Author:: Ezra Pagel (<ezra@cpan.org>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'chef/knife'
18
+ require 'chef/knife/VsphereBaseCommand'
19
+ require 'rbvmomi'
20
+
21
+ class Chef
22
+ class Knife
23
+ class VsphereVmDelete < VsphereBaseCommand
24
+
25
+ banner "knife vsphere vm delete (options)"
26
+
27
+ get_common_options
28
+
29
+ option :vmname,
30
+ :short => "-N VMNAME",
31
+ :long => "--vmname VMNAME",
32
+ :description => "The name of the virtual machine to delete"
33
+
34
+ def run
35
+
36
+ $stdout.sync = true
37
+
38
+ vmname = config[:vmname] or abort "virtual machine name required"
39
+
40
+ vim = get_vim_connection
41
+
42
+ dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
43
+ dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
44
+
45
+ vm = dc.find_vm(vmname) or abort "VM not found"
46
+
47
+ vm.PowerOffVM_Task.wait_for_completion unless vm.runtime.powerState == "poweredOff"
48
+ vm.UnregisterVM
49
+ puts "Finished unregistering virtual machine #{vmname}"
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Author:: Ezra Pagel (<ezra@cpan.org>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'chef/knife'
18
+ require 'chef/knife/VsphereBaseCommand'
19
+ require 'rbvmomi'
20
+
21
+ class Chef
22
+ class Knife
23
+ class VsphereVmDelete < VsphereBaseCommand
24
+
25
+ banner "knife vsphere vm delete (options)"
26
+
27
+ get_common_options
28
+
29
+ option :vmname,
30
+ :short => "-N VMNAME",
31
+ :long => "--vmname VMNAME",
32
+ :description => "The name of the virtual machine to delete"
33
+
34
+ def run
35
+
36
+ $stdout.sync = true
37
+
38
+ vmname = config[:vmname] or abort "virtual machine name required"
39
+
40
+ vim = get_vim_connection
41
+
42
+ dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
43
+ dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
44
+
45
+ vm = dc.find_vm(vmname) or abort "VM not found"
46
+
47
+ vm.PowerOffVM_Task.wait_for_completion
48
+ vm.UnregisterVM
49
+ puts "Finished unregistering virtual machine #{vmname}"
50
+
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Author:: Ezra Pagel (<ezra.pagel@gmail.com>)
2
+ # Author:: Ezra Pagel (<ezra@cpan.org>)
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
1
  module KnifeVsphere
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ezra Pagel
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-28 00:00:00 -05:00
18
+ date: 2011-06-29 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -51,7 +51,7 @@ dependencies:
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  description: VMware Vsphere Support for Chef's Knife Command
54
- email: ezra.pagel@gmail.com
54
+ email: ezra@cpan.org
55
55
  executables: []
56
56
 
57
57
  extensions: []
@@ -59,7 +59,11 @@ extensions: []
59
59
  extra_rdoc_files: []
60
60
 
61
61
  files:
62
+ - lib/chef/knife/#vsphere_vm_clone.rb#
62
63
  - lib/chef/knife/vsphere_template_list.rb
64
+ - lib/chef/knife/vsphere_vm_clone.rb
65
+ - lib/chef/knife/vsphere_vm_delete.rb
66
+ - lib/chef/knife/vsphere_vm_delete.rb~
63
67
  - lib/chef/knife/vsphere_vm_list.rb
64
68
  - lib/chef/knife/VsphereBaseCommand.rb
65
69
  - lib/knife-vsphere/version.rb