knife-opennebula 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c579c6e65a3a6104bbd48c49c8016f340c5e0558
4
+ data.tar.gz: 9afbd1d86b5ae99eaed6f77bfc1eabcdd816574c
5
+ SHA512:
6
+ metadata.gz: 48feba45696a64d0263cf48e387833d1c44e55dcbf04060e12de124ddff63253f73b54544fd84334bd0ace2fa347a82f2b7f8fb33c5596e663ddbd178424b222
7
+ data.tar.gz: 77dd5682f5b7765d964e815bcdf6b849871f3eacb15b3ad68381085bec230a6ec2892a04db4799c0d7a86c857489275f91cd2641d27605b0ba4c63ba34f3a207
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'opennebula', '= 4.4.0'
4
+ gem 'chef', '> 10.0.0'
5
+
6
+ group :test, :development do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ end
data/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # knife plugin for opennebula
2
+
3
+ ## Description
4
+
5
+ This plugin gives knife the ability to create, bootstrap, and manage OpenNebula Virtual Machines
6
+
7
+ ## Development
8
+
9
+ To contribute bug patches or new features, you can use the github Pull Request model. It is assumed that code and documentation are contributed under the Apache License 2.0.
10
+
11
+ More info:
12
+ * [How to Contribute](http://opennebula.org/software:add-ons#how_to_contribute_to_an_existing_add-on)
13
+ * Support: [OpenNebula user mailing list](http://opennebula.org/community:mailinglists)
14
+ * Development: [OpenNebula developers mailing list](http://opennebula.org/community:mailinglists)
15
+ * Issues Tracking: Github issues (https://github.com/OpenNebula/addon-iscsi/issues)
16
+
17
+ ## Authors
18
+
19
+ * Leader: Thomas Alrin (alrin@megam.co.in)
20
+ * Kishore Kumar (nkishore@megam.co.in)
21
+
22
+ ## Compatibility
23
+
24
+ This add-on is compatible with OpenNebula 4.4, 4.6.
25
+ Tested extensively with 4.6 (EC2)
26
+
27
+ ## Requirements
28
+
29
+ ### Chef
30
+
31
+ Hosted Chef 11.0.x (or) On Premises Chef (http://www.getchef.com/chef/choose-your-version/) configured with a client.
32
+
33
+ [For more information about Chef](https://learnchef.opscode.com/get-started/)
34
+
35
+ ## Installation
36
+
37
+ To install the plugin you need to do the following in your workstation:
38
+
39
+ * `gem install chef`
40
+ * `gem install opennebula`
41
+ * `gem install knife-opennebula`
42
+
43
+
44
+ ## Configuration
45
+
46
+ Configuration can be done either of any three ways.
47
+
48
+ ### 1. Configuring the ENV variables
49
+
50
+ * `export OPENNEBULA_USERNAME="MY_OPENNEBULA_USERNAME"`
51
+
52
+ * `export OPENNEBULA_PASSWORD="MY_OPENNEBULA_PASSWORD"`
53
+
54
+ * `export OPENNEBULA_ENDPOINT="MY_OPENNEBULA_ENDPOINT"`
55
+
56
+
57
+ ### 2. Configuring knife.rb
58
+ * `knife[:opennebula_username] = "MY_OPENNEBULA_USERNAME"`
59
+
60
+ * `knife[:opennebula_password] = "MY_OPENNEBULA_PASSWORD"`
61
+
62
+ * `knife[:opennebula_endpoint] = "MY_OPENNEBULA_ENDPOINT"`
63
+
64
+ ### 3. Configure while running commands by passing options
65
+ * `-A` or `--username` -> `OPENNEBULA_USERNAME`
66
+ * `-K` or `--password` -> `OPENNEBULA_PASSWORD`
67
+ * `-e` or `--endpoint` -> `OPENNEBULA_ENDPOINT`
68
+
69
+ Specific command options can be found by invoking the subcommand with a `--help` flag
70
+
71
+ ## Usage
72
+
73
+ This plugin provides the following Knife subcommands. Specific command options can be found by invoking the subcommand with a `--help` flag
74
+
75
+
76
+ #### To list the virtual resource templates
77
+
78
+ `knife opennebula template list`
79
+
80
+
81
+ #### To list the virual machines
82
+
83
+ `knife opennebula server list`
84
+
85
+
86
+ #### To create a virtual machine by instantiating a template
87
+
88
+ `knife opennebula server create`
89
+
90
+
91
+ #### To undeploy and delete a virtual machine
92
+
93
+ `knife opennebula server delete SERVER_NAME`
94
+
95
+ eg:
96
+
97
+ knife opennebula template list -A OPENNEBULA_USERNAME -K OPENNEBULA_USER_PASSWORD -e http://my-opennebula.com:2633/RPC2
98
+
99
+ knife opennebula server create -A OPENNEBULA_USERNAME -K OPENNEBULA_USER_PASSWORD -e http://my-opennebula.com:2633/RPC2 -t MY_TEMPLATE_NAME -i IDENTITY_FILE -x USER -r 'role[test]' -N TEST1
100
+
101
+ knife opennebula server list -A OPENNEBULA_USERNAME -K OPENNEBULA_USER_PASSWORD -e http://my-opennebula.com:2633/RPC2
102
+
103
+ knife opennebula server delete SERVER_NAME -A OPENNEBULA_USERNAME -K OPENNEBULA_USER_PASSWORD -e http://my-opennebula.com:2633/RPC2 -P -N NODE_NAME
104
+
105
+
106
+ To launch ubuntu-precise template on opennebula host http://canvpn.megam.co.in:2633/RPC2 using private key canvpn.key and role recipe[apt] with name tom
107
+
108
+ knife opennebula server create -A oneadmin -K ephamnilnik5 -e http://canvpn.megam.co.in:2633/RPC2 -t Ubuntu-precise -i ~/canvpn.key -x root -r 'recipe[apt]' -N tom
109
+
@@ -0,0 +1,84 @@
1
+ require 'chef/knife'
2
+
3
+ class Chef
4
+ class Knife
5
+ module OpennebulaBase
6
+
7
+ def self.included(includer)
8
+ includer.class_eval do
9
+
10
+ deps do
11
+ require 'highline'
12
+ require 'chef/json_compat'
13
+ Chef::Knife.load_deps
14
+ end
15
+
16
+ option :opennebula_username,
17
+ :short => "-A OPENNEBULA_USERNAME",
18
+ :long => "--username OPENNEBULA_USERNAME",
19
+ :description => "Opennebula user's name",
20
+ :proc => Proc.new { |user| Chef::Config[:knife][:opennebula_username] = user }
21
+
22
+ option :opennebula_passowrd,
23
+ :short => "-K OPENNEBULA_PASSWORD",
24
+ :long => "--password OPENNEBULA_PASSWORD",
25
+ :description => "Opennebula user's password",
26
+ :proc => Proc.new { |password| Chef::Config[:knife][:opennebula_password] = password }
27
+
28
+ option :opennebula_endpoint,
29
+ :short => "-e OPENNEBULA_ENDPOINT",
30
+ :long => "--endpoint OPENNEBULA_ENDPOIN",
31
+ :description => "Opennebula Endpoint",
32
+ :proc => Proc.new { |endpoint| Chef::Config[:knife][:opennebula_endpoint] = endpoint }
33
+ end
34
+ end
35
+
36
+
37
+ require 'opennebula'
38
+
39
+ include OpenNebula
40
+
41
+ def validate!
42
+ if (!opennebula_username)
43
+ ui.error "You did not configure your opennebula_username"
44
+ exit 1
45
+ elsif (!opennebula_password)
46
+ ui.error "You did not configure your opennebula_password"
47
+ exit 1
48
+ elsif (!opennebula_endpoint)
49
+ ui.error "You did not configure your opennebula_endpoint"
50
+ exit 1
51
+ end
52
+ end
53
+
54
+ def client
55
+ cli = Client.new("#{opennebula_username}:#{opennebula_password}", "#{opennebula_endpoint}")
56
+ cli
57
+ end
58
+
59
+ def msg_pair(label, value, color=:cyan)
60
+ if value && !value.to_s.empty?
61
+ ui.info "#{ui.color(label, color)}: #{value}"
62
+ end
63
+ end
64
+
65
+ def opennebula_username
66
+ locate_config_value(:opennebula_username) || ENV['OPENNEBULA_USERNAME']
67
+ end
68
+
69
+ def opennebula_password
70
+ locate_config_value(:opennebula_password) || ENV['OPENNEBULA_PASSWORD']
71
+ end
72
+
73
+ def opennebula_endpoint
74
+ locate_config_value(:opennebula_endpoint) || ENV['OPENNEBULA_ENDPOINT']
75
+ end
76
+
77
+ def locate_config_value(key)
78
+ key = key.to_sym
79
+ config[key] || Chef::Config[:knife][key]
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,197 @@
1
+ require 'chef/knife'
2
+ require 'chef/json_compat'
3
+ require 'chef/knife/opennebula_base'
4
+
5
+ #require_relative 'opennebula_base'
6
+ class Chef
7
+ class Knife
8
+ class OpennebulaServerCreate < Knife
9
+
10
+ deps do
11
+ require 'highline'
12
+ require 'chef/knife/bootstrap'
13
+ require 'net/ssh'
14
+ require 'net/ssh/multi'
15
+ Chef::Knife.load_deps
16
+ end
17
+ include Knife::OpennebulaBase
18
+
19
+ banner "knife opennebula server create OPTIONS"
20
+
21
+ option :opennebula_template,
22
+ :short => "-t TEMPLATE_NAME",
23
+ :long => "--template-name TEMPLATE_NAME",
24
+ :description => "name for the OpenNebula VM TEMPLATE",
25
+ :required => true,
26
+ :proc => Proc.new { |template| Chef::Config[:knife][:opennebula_template] = template}
27
+
28
+ option :bootstrap,
29
+ :long => "--[no-]bootstrap",
30
+ :description => "Bootstrap the server with knife bootstrap, default true",
31
+ :boolean => true,
32
+ :default => true
33
+
34
+
35
+ option :ssh_user,
36
+ :short => "-x USERNAME",
37
+ :long => "--ssh-user USERNAME",
38
+ :description => "The authorized user to ssh into the instance, default is 'root'",
39
+ :default => "root"
40
+
41
+
42
+ option :ssh_port,
43
+ :short => "-p PORT",
44
+ :long => "--ssh-port PORT",
45
+ :description => "The ssh port, default is 22",
46
+ :default => "22",
47
+ :proc => Proc.new { |key| Chef::Config[:knife][:ssh_port] = key }
48
+
49
+ option :run_list,
50
+ :short => "-r RUN_LIST",
51
+ :long => "--run-list RUN_LIST",
52
+ :description => "Comma separated list of roles/recipes to apply",
53
+ :proc => lambda { |o| o.split(/[\s,]+/) },
54
+ :default => []
55
+
56
+ option :distro,
57
+ :short => "-d DISTRO",
58
+ :long => "--distro DISTRO",
59
+ :description => "Bootstrap a distro using a template; default is 'chef-full'",
60
+ :proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
61
+ :default => "chef-full"
62
+
63
+ option :chef_node_name,
64
+ :short => "-N NAME",
65
+ :long => "--node-name NAME",
66
+ :description => "The name for chef node and your vm",
67
+ :required => true,
68
+ :proc => Proc.new { |t| Chef::Config[:knife][:chef_node_name] = t }
69
+
70
+ option :template_file,
71
+ :long => "--template-file TEMPLATE",
72
+ :description => "Full path to location of bootstrap template to use, default false",
73
+ :proc => Proc.new { |t| Chef::Config[:knife][:template_file] = t },
74
+ :default => false
75
+
76
+ option :host_key_verify,
77
+ :long => "--[no-]host-key-verify",
78
+ :description => "Verify host key, enabled by default.",
79
+ :boolean => true,
80
+ :default => true
81
+
82
+ option :identity_file,
83
+ :short => "-i IDENTITY_FILE",
84
+ :long => "--identity-file IDENTITY_FILE",
85
+ :description => "The SSH identity file used for authentication"
86
+
87
+ def h
88
+ @highline ||= HighLine.new
89
+ end
90
+
91
+ def run
92
+ #Validate opennebula credentials
93
+ validate!
94
+ #Get the template details
95
+ temp = template("#{locate_config_value(:opennebula_template)}")
96
+ unless "#{temp.class}" == "OpenNebula::Template"
97
+ ui.error("Template Not found #{temp.class}")
98
+ exit 1
99
+ end
100
+ puts ui.color("Instantiating Template......", :green)
101
+ #Instantiating a template
102
+ vm_id = temp.instantiate(name = "#{locate_config_value(:chef_node_name)}", hold = false, template = "")
103
+ #Opennebula error message
104
+ if OpenNebula.is_error?(vm_id)
105
+ ui.error("Some problem in instantiating template")
106
+ ui.error("#{vm_id.message}")
107
+ exit -1
108
+ end
109
+ unless "#{vm_id.class}" == "Fixnum"
110
+ ui.error("Some problem in instantiating template")
111
+ exit 1
112
+ end
113
+ puts ui.color("Template Instantiated, and a VM created with id #{vm_id}", :green)
114
+ puts ui.color("Fetching ip address of the VM ", :magenta)
115
+ #Get the VM details
116
+ vir_mac = virtual_machine("#{vm_id}")
117
+ unless "#{vir_mac.class}" == "OpenNebula::VirtualMachine"
118
+ ui.error("Some problem in Getting Virtual Machine")
119
+ exit 1
120
+ end
121
+ @vm_hash = vir_mac.to_hash
122
+ #VM can have more ip addresses. Priority to get vm ip is AWS_IP_ADDRESS, MEGAM_IP_ADDRESS and PRIVATE_IP_ADDRESS.
123
+ if @vm_hash['VM']['TEMPLATE'].has_key?('AWS_IP_ADDRESS')
124
+ @ip_add = @vm_hash['VM']['TEMPLATE']['AWS_IP_ADDRESS']
125
+ else
126
+ @ip_add = @vm_hash['VM']['USER_TEMPLATE']['MEGAM_IP_ADDRESS']
127
+ end
128
+ puts ui.color("\nServer:", :green)
129
+ msg_pair("Name", @vm_hash['VM']['name'])
130
+ msg_pair("IP", @ip_add)
131
+ #Bootstrap VM
132
+ bootstrap()
133
+
134
+ puts ui.color("Server:", :green)
135
+ msg_pair("Name", @vm_hash['VM']['name'])
136
+ msg_pair("IP", @ip_add)
137
+ end
138
+
139
+ def virtual_machine(id)
140
+ vm_pool = VirtualMachinePool.new(client, -1)
141
+ rc = vm_pool.info
142
+ if OpenNebula.is_error?(rc)
143
+ puts rc.message
144
+ exit -1
145
+ end
146
+ vm_pool.each do |vm|
147
+ if "#{vm.id}" == "#{id}"
148
+ v_hash = vm.to_hash
149
+ #Sleep untill get the VM's Ip address from either vm_hash['VM']['TEMPLATE']['AWS_IP_ADDRESS'] or vm_hash['VM']['USER_TEMPLATE']['MEGAM_IP_ADDRESS'].
150
+ #vm_hash['VM']['USER_TEMPLATE']['MEGAM_IP_ADDRESS'] can be set by onegate. In our case, we get that ip from vpn.
151
+ if v_hash['VM']['TEMPLATE'].has_key?('AWS_IP_ADDRESS') || v_hash['VM']['USER_TEMPLATE'].has_key?('MEGAM_IP_ADDRESS')
152
+ @re_obj = vm
153
+ else
154
+ sleep 1
155
+ print "."
156
+ virtual_machine("#{vm.id}")
157
+ end
158
+ end
159
+ end
160
+ @re_obj
161
+ end
162
+
163
+ def template(name)
164
+ #Searching user's vm template
165
+ puts ui.color("Locating Template......", :green)
166
+ temp_pool = TemplatePool.new(client, -1)
167
+ rc = temp_pool.info
168
+ if OpenNebula.is_error?(rc)
169
+ puts rc.message
170
+ exit -1
171
+ end
172
+ temp_pool.each do |temp|
173
+ if "#{temp.name}" == "#{name}"
174
+ puts ui.color("Template Found.", :green)
175
+ return temp
176
+ end
177
+ end
178
+ end
179
+
180
+ def bootstrap
181
+ bootstrap = Chef::Knife::Bootstrap.new
182
+ bootstrap.name_args = @ip_add
183
+ bootstrap.config[:run_list] = locate_config_value(:run_list)
184
+ bootstrap.config[:ssh_user] = locate_config_value(:ssh_user)
185
+ bootstrap.config[:ssh_port] = locate_config_value(:ssh_port)
186
+ bootstrap.config[:identity_file] = locate_config_value(:identity_file)
187
+ bootstrap.config[:distro] = locate_config_value(:distro)
188
+ bootstrap.config[:host_key_verify] = config[:host_key_verify]
189
+ bootstrap.config[:template_file] = locate_config_value(:template_file)
190
+ bootstrap.config[:chef_node_name] = locate_config_value(:chef_node_name) || @vm_hash['VM']['name']
191
+ bootstrap.config[:use_sudo] = true unless bootstrap.config[:ssh_user] == 'root'
192
+ bootstrap.run
193
+ end
194
+
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,88 @@
1
+ require 'chef/knife'
2
+ require 'chef/json_compat'
3
+ require 'chef/knife/opennebula_base'
4
+
5
+ #require_relative 'opennebula_base'
6
+ class Chef
7
+ class Knife
8
+ class OpennebulaServerDelete < Knife
9
+
10
+ deps do
11
+ require 'highline'
12
+ Chef::Knife.load_deps
13
+ end
14
+ include Knife::OpennebulaBase
15
+
16
+ banner "knife opennebula server delete VM_NAME (OPTIONS)"
17
+
18
+ option :purge,
19
+ :short => "-P",
20
+ :long => "--purge",
21
+ :boolean => true,
22
+ :default => false,
23
+ :description => "Destroy corresponding node and client on the Chef Server, in addition to destroying the opennebula vm itself. Assumes node and client have the same name as the server (if not, add the '--node-name' option)."
24
+
25
+ option :chef_node_name,
26
+ :short => "-N NAME",
27
+ :long => "--node-name NAME",
28
+ :description => "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option."
29
+
30
+
31
+ def h
32
+ @highline ||= HighLine.new
33
+ end
34
+
35
+ def destroy_item(klass, name, type_name)
36
+ begin
37
+ object = klass.load(name)
38
+ object.destroy
39
+ ui.warn("Deleted #{type_name} #{name}")
40
+ rescue Net::HTTPServerException
41
+ ui.warn("Could not find a #{type_name} named #{name} to delete!")
42
+ end
43
+ end
44
+
45
+ def run
46
+ validate!
47
+ if @name_args.empty?
48
+ ui.error("no vm name is specific")
49
+ exit -1
50
+ else
51
+ @vm_name = @name_args[0]
52
+ end
53
+ vm_pool = VirtualMachinePool.new(client, -1)
54
+ rc = vm_pool.info
55
+ if OpenNebula.is_error?(rc)
56
+ puts rc.message
57
+ exit -1
58
+ end
59
+
60
+ vm_pool.each do |vm|
61
+ if "#{vm.name}" == "#{@vm_name}"
62
+ @vm_hash = vm.to_hash
63
+ msg_pair("VM ID", @vm_hash['VM']['ID'])
64
+ msg_pair("VM Name", @vm_hash['VM']['NAME'])
65
+ msg_pair("Availability Zone", @vm_hash['VM']['TEMPLATE']['AWS_AVAILABILITY_ZONE'])
66
+ msg_pair("Public IP Address", @vm_hash['VM']['TEMPLATE']['AWS_IP_ADDRESS'])
67
+ confirm("Do you really want to delete this server")
68
+ vm.delete(recreate = false)
69
+ ui.warn("Deleted server #{@vm_hash['VM']['NAME']}")
70
+ if config[:purge]
71
+ if config[:chef_node_name]
72
+ thing_to_delete = config[:chef_node_name]
73
+ destroy_item(Chef::Node, thing_to_delete, "node")
74
+ destroy_item(Chef::ApiClient, thing_to_delete, "client")
75
+ else
76
+ ui.error("Please Provide Chef NODE_NAME in -N")
77
+ end
78
+ else
79
+ ui.warn("Corresponding node and client for the #{@vm_name} server were not deleted and remain registered with the Chef Server")
80
+ end
81
+ end
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,74 @@
1
+ require 'chef/knife'
2
+ require 'chef/json_compat'
3
+ require 'chef/knife/opennebula_base'
4
+
5
+ #require_relative 'opennebula_base'
6
+ class Chef
7
+ class Knife
8
+ class OpennebulaServerList < Knife
9
+
10
+ deps do
11
+ require 'highline'
12
+ Chef::Knife.load_deps
13
+ end
14
+ include Knife::OpennebulaBase
15
+
16
+ banner "knife opennebula server list OPTIONS"
17
+
18
+ def h
19
+ @highline ||= HighLine.new
20
+ end
21
+
22
+ def run
23
+ validate!
24
+
25
+ vm_pool = VirtualMachinePool.new(client, -1)
26
+ rc = vm_pool.info
27
+ if OpenNebula.is_error?(rc)
28
+ puts rc.message
29
+ exit -1
30
+ end
31
+
32
+ # TO-DO: This is tailored for AWS, need to be fixed, just so it works for private/public
33
+
34
+ vm_list = [
35
+ ui.color('ID', :bold),
36
+ ui.color('Name', :bold),
37
+ ui.color('Memory', :bold),
38
+ ui.color('Cpu', :bold),
39
+ #ui.color('AWS_ZONE', :bold),
40
+ #ui.color('INSTANCE_TYPE', :bold),
41
+ #ui.color('IP', :bold),
42
+ #ui.color('AWS_Key', :bold),
43
+ ui.color('State', :bold)]
44
+ vm_pool.each do |vm|
45
+ vm_hash = vm.to_hash
46
+ vm_list << vm_hash['VM']['ID']
47
+ vm_list << vm_hash['VM']['NAME']
48
+ vm_list << vm_hash['VM']['TEMPLATE']['MEMORY']
49
+ vm_list << vm_hash['VM']['TEMPLATE']['CPU']
50
+ #vm_list << vm_hash['VM']['TEMPLATE']['AWS_AVAILABILITY_ZONE'] if vm_hash['VM']['TEMPLATE'].has_key?('AWS_AVAILABILITY_ZONE')
51
+ #vm_list << vm_hash['VM']['TEMPLATE']['AWS_INSTANCE_TYPE'] if vm_hash['VM']['TEMPLATE'].has_key?('AWS_INSTANCE_TYPE')
52
+ #vm_list << vm_hash['VM']['TEMPLATE']['AWS_IP_ADDRESS'] if vm_hash['VM']['TEMPLATE'].has_key?('AWS_IP_ADDRESS')
53
+ #vm_list << vm_hash['VM']['TEMPLATE']['AWS_KEY_NAME'] if vm_hash['VM']['TEMPLATE'].has_key?('AWS_KEY_NAME')
54
+ vm_list << begin
55
+ state = vm_hash['VM']['STATE']
56
+ case state
57
+ when '1'
58
+ ui.color(state, :red)
59
+ when '2'
60
+ ui.color(state, :yellow)
61
+ else
62
+ ui.color(state, :green)
63
+ end
64
+ end
65
+
66
+ end
67
+ puts ui.color("Virtual Machines Listed Successfully", :green)
68
+ puts ui.list(vm_list, :uneven_columns_across, 5)
69
+
70
+ end
71
+
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,61 @@
1
+ require 'chef/knife'
2
+ require 'chef/json_compat'
3
+ require 'chef/knife/opennebula_base'
4
+
5
+ #require_relative 'opennebula_base'
6
+ class Chef
7
+ class Knife
8
+ class OpennebulaTemplateList < Knife
9
+
10
+ deps do
11
+ require 'highline'
12
+ Chef::Knife.load_deps
13
+ end
14
+ include Knife::OpennebulaBase
15
+
16
+ banner "knife opennebula template list OPTIONS"
17
+
18
+ def h
19
+ @highline ||= HighLine.new
20
+ end
21
+
22
+ def run
23
+ validate!
24
+
25
+ temp_pool = TemplatePool.new(client, -1)
26
+ rc = temp_pool.info
27
+ if OpenNebula.is_error?(rc)
28
+ puts rc.message
29
+ exit -1
30
+ end
31
+
32
+ # This needs to be fixed as this is tailored for AWS.
33
+ temp_list = [
34
+ ui.color('ID', :bold),
35
+ ui.color('Name', :bold),
36
+ #ui.color('AMI', :bold),
37
+ #ui.color('INSTANCE_TYPE', :bold),
38
+ #ui.color('KEY_PAIR', :bold),
39
+ #ui.color('SECURITY_GROUP', :bold),
40
+ ui.color('CPU', :bold),
41
+ ui.color('MEMORY', :bold)]
42
+
43
+ temp_pool.each do |temp|
44
+ temp_hash = temp.to_hash
45
+ temp_list << temp_hash['VMTEMPLATE']['ID']
46
+ temp_list << temp_hash['VMTEMPLATE']['NAME']
47
+ #temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['EC2']['AMI'] if temp_hash['VMTEMPLATE']['TEMPLATE'].has_key?('EC2')
48
+ #temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['EC2']['INSTANCETYPE'] if temp_hash['VMTEMPLATE']['TEMPLATE'].has_key?('EC2')
49
+ #temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['EC2']['KEYPAIR'] if temp_hash['VMTEMPLATE']['TEMPLATE'].has_key?('EC2')
50
+ #temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['EC2']['SECURITYGROUPS'] if temp_hash['VMTEMPLATE']['TEMPLATE'].has_key?('EC2')
51
+ temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['CPU']
52
+ temp_list << temp_hash['VMTEMPLATE']['TEMPLATE']['MEMORY']
53
+ end
54
+
55
+ puts ui.color("VM Templates Listed Successfully", :green)
56
+ puts ui.list(temp_list, :uneven_columns_across, 4)
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ class Chef
2
+ class Opennebula
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-opennebula
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kishorekumar Neelamegam, Thomas Alrin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opennebula
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: chef
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: highline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Knife plugin to manage OpenNebula VMs
56
+ email:
57
+ - nkishore@megam.co.in
58
+ - alrin@megam.co.in
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files:
62
+ - README.md
63
+ files:
64
+ - Gemfile
65
+ - README.md
66
+ - lib/chef/knife/opennebula_base.rb
67
+ - lib/chef/knife/opennebula_server_create.rb
68
+ - lib/chef/knife/opennebula_server_delete.rb
69
+ - lib/chef/knife/opennebula_server_list.rb
70
+ - lib/chef/knife/opennebula_template_list.rb
71
+ - lib/chef/opennebula/version.rb
72
+ homepage: http://github.com/opennebula/addons-knife
73
+ licenses:
74
+ - Apache V2
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Knife plugin to manage OpenNebula VMs
96
+ test_files: []