knife-vsphere 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,95 @@
1
+ require 'chef/knife'
2
+ require 'rbvmomi'
3
+
4
+ class Chef
5
+ class Knife
6
+ class VsphereBaseCommand < Knife
7
+
8
+ deps do
9
+ require 'chef/knife/bootstrap'
10
+ Chef::Knife::Bootstrap.load_deps
11
+ require 'fog'
12
+ require 'socket'
13
+ require 'net/ssh/multi'
14
+ require 'readline'
15
+ require 'chef/json_compat'
16
+ end
17
+
18
+
19
+ def self.get_common_options
20
+
21
+ option :host,
22
+ :short => "-H HOST",
23
+ :long => "--host HOST",
24
+ :description => "The host to create the VM on"
25
+
26
+ option :vsphere_user,
27
+ :short => "-u USERNAME",
28
+ :long => "--user USERNAME",
29
+ :description => "The username for the host"
30
+
31
+ option :password,
32
+ :short => "-p PASSWORD",
33
+ :long => "--password PASSWORD",
34
+ :description => "The password for the host"
35
+
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
+ option :datacenter,
43
+ :short => "-d DATACENTER",
44
+ :long => "--datacenter DATACENTER",
45
+ :description => "The Datacenter to create the VM in"
46
+
47
+ option :path,
48
+ :short => "-P SOAP_PATH",
49
+ :long => "--path SOAP_PATH",
50
+ :description => "The SOAP endpoint path",
51
+ :proc => Proc.new { |p| Chef::Config[:knife][:path] = p },
52
+ :default => "/sdk"
53
+
54
+ option :port,
55
+ :short => "-p PORT",
56
+ :long => "--port PORT",
57
+ :description => "The VI SDK port number to use",
58
+ :proc => Proc.new { |p| Chef::Config[:knife][:port] = p },
59
+ :default => 443
60
+
61
+ option :use_ssl,
62
+ :short => "-s USE_SSL",
63
+ :long => "--ssl USE_SSL",
64
+ :description => "Whether to use SSL connection",
65
+ :default => true
66
+
67
+ option :insecure,
68
+ :short => "-i USE_INSECURE_SSL",
69
+ :long => "--insecure USE_INSECURE_SSL",
70
+ :description => "Determines whether SSL certificate verification is skipped",
71
+ :default => true
72
+
73
+ end
74
+
75
+ def get_vim_connection
76
+
77
+ conn_opts = {
78
+ :host => config[:host] || Chef::Config[:knife][:vsphere_host],
79
+ :path => config[:path],
80
+ :port => config[:port],
81
+ :use_ssl => config[:ssl],
82
+ :user => config[:vsphere_user] || Chef::Config[:knife][:vsphere_user],
83
+ :password => config[:password] || Chef::Config[:knife][:vsphere_pass],
84
+ :insecure => config[:insecure]
85
+ }
86
+
87
+ # opt :insecure, "don't verify ssl certificate", :short => 'k', :default => (ENV['RBVMOMI_INSECURE'] == '1')
88
+ # opt :debug, "Log SOAP messages", :short => 'd', :default => (ENV['RBVMOMI_DEBUG'] || false)
89
+
90
+ vim = RbVmomi::VIM.connect conn_opts
91
+ return vim
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Author:: Ezra Pagel (<ezra.pagel@gmail.com>)
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
+
20
+ class Chef
21
+ class Knife
22
+ class VsphereTemplateList < VsphereBaseCommand
23
+
24
+ banner "knife vsphere template list"
25
+
26
+ get_common_options
27
+
28
+
29
+ def run
30
+
31
+ $stdout.sync = true
32
+
33
+ vim = get_vim_connection
34
+
35
+ dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
36
+ dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
37
+ vmFolder = dc.vmFolder
38
+
39
+ vms = vmFolder.childEntity.grep(RbVmomi::VIM::VirtualMachine)
40
+ if (!vms.nil?)
41
+ templates = vms.find_all{ |v| !v.config.nil? && v.config.template == true }
42
+ if (!templates.nil?)
43
+ templates.each do |vm|
44
+ puts "#{ui.color("Template Name", :cyan)}: #{vm.name}"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,45 @@
1
+ #
2
+ # Author:: Ezra Pagel (<ezra.pagel@gmail.com>)
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
+
20
+ class Chef
21
+ class Knife
22
+ class VsphereVmList < VsphereBaseCommand
23
+
24
+ banner "knife vsphere vm list"
25
+
26
+ get_common_options
27
+
28
+
29
+ def run
30
+
31
+ $stdout.sync = true
32
+
33
+ vim = get_vim_connection
34
+
35
+ dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
36
+ dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
37
+ vmFolder = dc.vmFolder
38
+
39
+ vmFolder.childEntity.grep(RbVmomi::VIM::VirtualMachine).each do |vm|
40
+ puts "#{ui.color("VM Name", :cyan)}: #{vm.name}"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ module KnifeVsphere
2
+ VERSION = "0.1.0"
3
+ end
4
+
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-vsphere
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Ezra Pagel
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-28 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: chef
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 55
30
+ segments:
31
+ - 0
32
+ - 10
33
+ - 0
34
+ version: 0.10.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rbvmomi
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 25
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 3
50
+ version: 1.2.3
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: VMware Vsphere Support for Chef's Knife Command
54
+ email: ezra.pagel@gmail.com
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files: []
60
+
61
+ files:
62
+ - lib/chef/knife/vsphere_template_list.rb
63
+ - lib/chef/knife/vsphere_vm_list.rb
64
+ - lib/chef/knife/VsphereBaseCommand.rb
65
+ - lib/knife-vsphere/version.rb
66
+ has_rdoc: true
67
+ homepage:
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ requirements: []
94
+
95
+ rubyforge_project:
96
+ rubygems_version: 1.6.2
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: VSphere Support for Knife
100
+ test_files: []
101
+