chef-provisioning-opennebula 0.3.4 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -35
- data/lib/chef/provider/one_image.rb +69 -48
- data/lib/chef/provider/one_template.rb +113 -35
- data/lib/chef/provider/one_user.rb +1 -1
- data/lib/chef/provider/one_vnet.rb +2 -1
- data/lib/chef/provider/one_vnet_lease.rb +2 -17
- data/lib/chef/provisioning/opennebula_driver/credentials.rb +6 -2
- data/lib/chef/provisioning/opennebula_driver/driver.rb +69 -51
- data/lib/chef/provisioning/opennebula_driver/one_lib.rb +192 -53
- data/lib/chef/provisioning/opennebula_driver/version.rb +1 -1
- data/lib/chef/resource/one_image.rb +3 -2
- data/lib/chef/resource/one_template.rb +7 -5
- data/lib/chef/resource/one_vnet.rb +1 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8609a2bdd368fd8004c7451eec93e7f4801cae99
|
4
|
+
data.tar.gz: bb88358b632d8f75e45ed1d3e6f0719302428499
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c6633a838fb95a2d98183088b7e1c64939cf1efd4f5f161937dd74fd46472b4fb4a15ef6127be71ce0a039d3397b3f534b755cfcebbfedb60608fd3327ae31e
|
7
|
+
data.tar.gz: 6932c9456a158bd2b32a805462b25037f54889399e1941779e8a2f17e08f8846195066701d37a55f46280728519506a687e4d0040113868b556527735d754379
|
data/README.md
CHANGED
@@ -45,27 +45,6 @@ A sample one_config file would look like this:
|
|
45
45
|
}
|
46
46
|
```
|
47
47
|
|
48
|
-
If no profile is specified the driver will attempt to read and use the ```ENV['ONE_AUTH']``` file or ```~/.one/one_auth``` or ```/var/lib/one/.one/one_auth```.
|
49
|
-
The driver is still backward compatible with previous format and passing ```:secret_file``` or ```:credentials``` in```:driver_options```.
|
50
|
-
|
51
|
-
Additional options to OpenNebual client can be passed vi ```:one_options```.
|
52
|
-
|
53
|
-
```ruby
|
54
|
-
with_driver "opennebula:http://1.2.3.4/endpoint:port",
|
55
|
-
:credentials => "<username>:<text_password>",
|
56
|
-
:one_options => { :timeout => 3 }
|
57
|
-
```
|
58
|
-
|
59
|
-
or
|
60
|
-
|
61
|
-
```ruby
|
62
|
-
with_driver "opennebula:http://1.2.3.4/endpoint:port",
|
63
|
-
:secret_file => "<local_path_to_file_with_credentials>",
|
64
|
-
:one_options => { :timeout => 3 }
|
65
|
-
```
|
66
|
-
|
67
|
-
If additional OpenNebula client options need to be passed they can be specified as a hash ```:one_options => {}```.
|
68
|
-
|
69
48
|
In context of OpenNebula ```machine``` resource will take the following additional options:
|
70
49
|
|
71
50
|
```ruby
|
@@ -76,12 +55,13 @@ machine_options {
|
|
76
55
|
:template_name => String name of the OpenNebula template to use
|
77
56
|
:template_id => Integer id of the OpenNebula template to use
|
78
57
|
:template_options => Hash values to be merged with VM template
|
79
|
-
:enforce_chef_fqdn => [TrueClass, FalseClass] flag indicating if fqdn names should be used for machine names
|
80
58
|
:is_shutdown => [TrueClass, FalseClass] call vm.shutodwn instead of vm.stop during :stop action
|
81
59
|
:shutdown_hard => [TrueClass, FalseClass] flag indicating hard or soft shutdown
|
60
|
+
:mode => String octed to set permissions to the machine
|
82
61
|
},
|
83
62
|
:sudo => true,
|
84
63
|
:ssh_username => 'local',
|
64
|
+
:ssh_gateway => 'gary@myproxy.net',
|
85
65
|
:ssh_options => {
|
86
66
|
Hash containing SSH options as specified by net-ssh gem
|
87
67
|
please see https://github.com/net-ssh/net-ssh for all options
|
@@ -91,9 +71,16 @@ machine_options {
|
|
91
71
|
:keys => [ File.open(File.expand_path('~/.ssh/id_rsa_new')).read ]
|
92
72
|
:keys_only => false,
|
93
73
|
:forward_agent => true,
|
74
|
+
:proxy => 'ssh myproxy.net nc %h %p',
|
94
75
|
:use_agent => true,
|
95
76
|
:user_known_hosts_file => '/dev/null'
|
96
77
|
}
|
78
|
+
:vm_name => [Symbol, String] Change how the machine shows up in OpenNebula UI and CLI tools.
|
79
|
+
Use :short to rename the machine to the short hostname.
|
80
|
+
Use a string to rename the machine to an arbitrary name.
|
81
|
+
Note this does not change the hostname of the machine, it
|
82
|
+
simply renames the VM in OpenNebula.
|
83
|
+
:connection_timeout => [Integer] max wait time to establish connection
|
97
84
|
}
|
98
85
|
```
|
99
86
|
|
@@ -109,6 +96,7 @@ This resource will allow to create and delete OpenNebula templates.
|
|
109
96
|
```ruby
|
110
97
|
:template => Hash defining OpenNebula template
|
111
98
|
:template_file => String location of the VM template file
|
99
|
+
:mode => String octet to set permissions
|
112
100
|
```
|
113
101
|
|
114
102
|
### Actions
|
@@ -201,6 +189,8 @@ This resource will manage images within OpenNebula.
|
|
201
189
|
:driver => String Image driver eq. 'qcow2'
|
202
190
|
:machine_id => [String, Integer] id of the machine (VM) for disk attach
|
203
191
|
:disk_id => [String, Integer] id or name of the disk to attach/snapshot
|
192
|
+
:mode => String octet to set permissions
|
193
|
+
:http_port => Integer port number to start local HTTP server at, for :image_file uploads. Default: 8066
|
204
194
|
```
|
205
195
|
|
206
196
|
### Actions
|
@@ -272,20 +262,31 @@ one_image "snapshot-img" do
|
|
272
262
|
end
|
273
263
|
```
|
274
264
|
|
275
|
-
#### 6. Upload a local qcow2 image file to OpenNebula
|
265
|
+
#### 6. Upload a local qcow2 image file to OpenNebula, starting HTTP server on port 4567
|
276
266
|
|
277
267
|
```ruby
|
278
|
-
one_image "
|
268
|
+
one_image "upload-img" do
|
279
269
|
datastore_id 103
|
280
270
|
image_file "/local/path/to/qcow/image/file"
|
281
271
|
img_driver "qcow2"
|
282
272
|
type "OS"
|
273
|
+
http_port 4567
|
283
274
|
description "This is my cool qcow image"
|
284
275
|
action :upload
|
285
276
|
end
|
286
277
|
```
|
287
278
|
|
288
|
-
#### 7.
|
279
|
+
#### 7. Upload a qcow2 image file residing on a different host to OpenNebula
|
280
|
+
|
281
|
+
```ruby
|
282
|
+
one_image "upload-img" do
|
283
|
+
datastore_id 103
|
284
|
+
download_url "http://my.image.host/path/to/qcow/image/file"
|
285
|
+
action :upload
|
286
|
+
end
|
287
|
+
```
|
288
|
+
|
289
|
+
#### 8. Download a 'boggi-test-img' and store it in /home/local/my-image.qcow2. Download URL is read from ENV[ONE_DOWNLOAD] variable. It will be stored locally in Chef::Config[:file_cache_path]/boggi-test-img.qcow2.
|
289
290
|
|
290
291
|
```ruby
|
291
292
|
one_image "boggi-test-img" do
|
@@ -293,7 +294,7 @@ one_image "boggi-test-img" do
|
|
293
294
|
end
|
294
295
|
```
|
295
296
|
|
296
|
-
####
|
297
|
+
#### 9. Download image ID 12345 and store it in /tmp/image.qcow2.
|
297
298
|
|
298
299
|
```ruby
|
299
300
|
one_image "boggi-test-img" do
|
@@ -319,6 +320,7 @@ This resource will allow to create and delete OpenNebula vnets.
|
|
319
320
|
:mac_ip => String ip or mac address
|
320
321
|
:template_file => String local file containing the template of a new vnet
|
321
322
|
:cluster_id => Integer cluster in which to create a vnet
|
323
|
+
:mode => String octet to set permissions
|
322
324
|
```
|
323
325
|
|
324
326
|
### Actions
|
@@ -507,24 +509,21 @@ example:
|
|
507
509
|
|
508
510
|
## <a name="authors"></a> Authors
|
509
511
|
|
510
|
-
Created by [Bogdan Buczynski]
|
512
|
+
Created by [Bogdan Buczynski](https://github.com/bbuczynski) (<pikus1@gmail.com>)
|
511
513
|
|
512
514
|
## <a name="maintainers"></a> Maintainers
|
513
515
|
|
514
516
|
Maintained by
|
515
|
-
* [
|
516
|
-
* [
|
517
|
-
* [
|
518
|
-
* [Evgeny Yurchenko]
|
517
|
+
* [Andrew J. Brown](https://github.com/andrewjamesbrown) (<anbrown@blackberry.com>)
|
518
|
+
* [Bogdan Buczynski](https://github.com/bbuczynski) (<pikus1@gmail.com>)
|
519
|
+
* [Dongyu 'Gary' Zheng](https://github.com/dongyuzheng) (<garydzheng@gmail.com>)
|
520
|
+
* [Evgeny Yurchenko](https://github.com/EYurchenko) (<eyurchenko@blackberry.com>)
|
521
|
+
* [Phil Oliva](https://github.com/poliva83) (<philoliva8@gmail.com>)
|
519
522
|
|
520
523
|
## <a name="license"></a> License
|
521
524
|
|
522
525
|
Apache 2.0 (see [LICENSE][license])
|
523
526
|
|
524
|
-
[author]: https://github.com/bbuczynski
|
525
|
-
[maintainer]: https://github.com/poliva83
|
526
|
-
[maintainer]: https://github.com/andrewjamesbrown
|
527
|
-
[maintainer]: https://github.com/EYurchenko
|
528
527
|
[issues]: https://github.com/blackberry/chef-provisioning-opennebula/issues
|
529
528
|
[license]: https://github.com/blackberry/chef-provisioning-opennebula/blob/master/LICENSE
|
530
529
|
[repo]: https://github.com/blackberry/chef-provisioning-opennebula
|
@@ -43,7 +43,7 @@ class Chef
|
|
43
43
|
|
44
44
|
def exists?
|
45
45
|
new_driver = driver
|
46
|
-
@image = new_driver.one.get_resource(
|
46
|
+
@image = new_driver.one.get_resource(:image, :name => @new_resource.name)
|
47
47
|
!@image.nil?
|
48
48
|
end
|
49
49
|
|
@@ -56,14 +56,15 @@ class Chef
|
|
56
56
|
|
57
57
|
action_handler.perform_action "allocated image '#{new_resource.name}'" do
|
58
58
|
@image = new_driver.one.allocate_img(
|
59
|
-
new_resource.name,
|
60
|
-
new_resource.size,
|
61
|
-
new_resource.datastore_id,
|
62
|
-
new_resource.type || 'OS',
|
63
|
-
new_resource.fs_type || 'ext2',
|
64
|
-
new_resource.img_driver || 'qcow2',
|
65
|
-
new_resource.prefix || 'vd',
|
66
|
-
new_resource.persistent || false)
|
59
|
+
:name => new_resource.name,
|
60
|
+
:size => new_resource.size,
|
61
|
+
:datastore_id => new_resource.datastore_id,
|
62
|
+
:type => new_resource.type || 'OS',
|
63
|
+
:fs_type => new_resource.fs_type || 'ext2',
|
64
|
+
:driver => new_resource.img_driver || 'qcow2',
|
65
|
+
:prefix => new_resource.prefix || 'vd',
|
66
|
+
:persistent => new_resource.persistent || false)
|
67
|
+
new_driver.one.chmod_resource(@image, new_resource.mode)
|
67
68
|
Chef::Log.info("Image '#{new_resource.name}' allocate in initial state #{@image.state_str}")
|
68
69
|
@new_resource.updated_by_last_action(true)
|
69
70
|
end
|
@@ -91,7 +92,7 @@ class Chef
|
|
91
92
|
action_handler.perform_action "deleted image '#{new_resource.name}'" do
|
92
93
|
rc = @image.delete
|
93
94
|
fail "Failed to delete image '#{new_resource.name}' : #{rc.message}" if OpenNebula.is_error?(rc)
|
94
|
-
until new_driver.one.get_resource(
|
95
|
+
until new_driver.one.get_resource(:image, :name => new_resource.name).nil?
|
95
96
|
Chef::Log.debug("Waiting for delete image to finish...")
|
96
97
|
sleep 1
|
97
98
|
end
|
@@ -106,8 +107,8 @@ class Chef
|
|
106
107
|
fail "Missing attribute 'machine_id'" unless new_resource.machine_id
|
107
108
|
fail "Failed to attach disk - image '#{new_resource.name}' does not exist" unless exists?
|
108
109
|
|
109
|
-
vm = new_driver.one.get_resource(
|
110
|
-
fail "Failed to attach disk - VM '#{new_resource.
|
110
|
+
vm = new_driver.one.get_resource(:virtualmachine, new_resource.machine_id.is_a?(Integer) ? :id : :name => new_resource.machine_id)
|
111
|
+
fail "Failed to attach disk - VM '#{new_resource.machine_id}' does not exist" if vm.nil?
|
111
112
|
action_handler.perform_action "attached disk #{new_resource.name} to #{vm.name}" do
|
112
113
|
disk_hash = @image.to_hash
|
113
114
|
disk_tpl = "DISK = [ "
|
@@ -133,16 +134,16 @@ class Chef
|
|
133
134
|
action :snapshot do
|
134
135
|
fail "Missing attribute 'machine_id'" unless new_resource.machine_id
|
135
136
|
fail "snapshot '#{new_resource.name}' already exists" if exists?
|
136
|
-
vm = new_driver.one.get_resource(
|
137
|
+
vm = new_driver.one.get_resource(:virtualmachine, new_resource.machine_id.is_a?(Integer) ? :id : :name => new_resource.machine_id)
|
137
138
|
fail "Failed to create snapshot - VM '#{new_resource.machine_id}' does not exist" if vm.nil?
|
138
139
|
action_handler.perform_action "created snapshot from '#{new_resource.machine_id}'" do
|
139
140
|
disk_id = new_resource.disk_id.is_a?(Integer) ? new_resource.disk_id : new_driver.one.get_disk_id(vm, new_resource.disk_id)
|
140
141
|
fail "No disk '#{new_resource.disk_id}' found on '#{vm.name}'" if disk_id.nil?
|
141
|
-
|
142
|
-
@image = vm.disk_snapshot(disk_id, new_resource.name, "", true)
|
142
|
+
@image = new_driver.one.version_ge_4_14 ? vm.disk_saveas(disk_id, new_resource.name) : vm.disk_snapshot(disk_id, new_resource.name, "", true)
|
143
143
|
fail "Failed to create snapshot '#{new_resource.name}': #{@image.message}" if OpenNebula.is_error?(@image)
|
144
144
|
|
145
145
|
@image = new_driver.one.wait_for_img(new_resource.name, @image)
|
146
|
+
new_driver.one.chmod_resource(image, new_resource.mode)
|
146
147
|
if new_resource.persistent
|
147
148
|
action_handler.report_progress "make image '#{new_resource.name}' persistent"
|
148
149
|
@image.persistent
|
@@ -153,47 +154,67 @@ class Chef
|
|
153
154
|
|
154
155
|
action :upload do
|
155
156
|
fail "'datastore_id' is required" unless new_resource.datastore_id
|
156
|
-
fail "'image_file' is required" unless new_resource.image_file
|
157
|
-
fail "image_file #{new_resource.image_file} does not exist" unless ::File.exist? new_resource.image_file
|
157
|
+
fail "'image_file' or 'download_url' attribute is required" unless new_resource.image_file || new_resource.download_url
|
158
158
|
|
159
|
-
file_url =
|
160
|
-
|
161
|
-
|
159
|
+
file_url = nil
|
160
|
+
if new_resource.image_file
|
161
|
+
fail "image_file #{new_resource.image_file} does not exist" unless ::File.exist? new_resource.image_file
|
162
|
+
file_url = "http://#{node['ipaddress']}:#{@new_resource.http_port}/#{::File.basename(@new_resource.image_file)}"
|
163
|
+
else
|
164
|
+
file_url = new_resource.download_url
|
165
|
+
end
|
166
|
+
image_config = {
|
167
|
+
:name => @new_resource.name,
|
168
|
+
:datastore_id => @new_resource.datastore_id.to_s,
|
169
|
+
:path => file_url,
|
170
|
+
:driver => @new_resource.img_driver || 'qcow2',
|
171
|
+
:description => @new_resource.description || "#{@new_resource.name} image",
|
172
|
+
:type => @new_resource.type,
|
173
|
+
:mode => @new_resource.mode,
|
174
|
+
:prefix => @new_resource.prefix,
|
175
|
+
:persistent => @new_resource.persistent,
|
176
|
+
:public => @new_resource.public,
|
177
|
+
:target => @new_resource.target,
|
178
|
+
:disk_type => @new_resource.disk_type,
|
179
|
+
:source => @new_resource.source,
|
180
|
+
:size => @new_resource.size,
|
181
|
+
:fs_type => @new_resource.fs_type
|
182
|
+
}
|
162
183
|
|
163
184
|
if exists?
|
164
|
-
if @image.name ==
|
165
|
-
@image['PATH'] ==
|
166
|
-
@image['TEMPLATE/DRIVER'] ==
|
167
|
-
@image['TEMPLATE/DESCRIPTION'] == description &&
|
168
|
-
@image['DATASTORE_ID'] ==
|
185
|
+
if @image.name == image_config[:name] &&
|
186
|
+
@image['PATH'] == image_config[:path] &&
|
187
|
+
@image['TEMPLATE/DRIVER'] == image_config[:driver] &&
|
188
|
+
@image['TEMPLATE/DESCRIPTION'] == image_config[:description] &&
|
189
|
+
@image['DATASTORE_ID'] == image_config[:datastore_id]
|
169
190
|
action_handler.report_progress("image '#{@new_resource.name}' (ID: #{@image.id}) already exists - nothing to do")
|
170
191
|
else
|
171
192
|
fail "image '#{new_resource.name}' already exists, but it is not the same image"
|
172
193
|
end
|
173
194
|
else
|
174
|
-
action_handler.perform_action "upload image '#{@new_resource.
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
@new_resource.
|
191
|
-
|
192
|
-
|
193
|
-
|
195
|
+
action_handler.perform_action "upload image '#{@new_resource.name}'" do
|
196
|
+
if @new_resource.image_file
|
197
|
+
begin
|
198
|
+
success = false
|
199
|
+
pid = nil
|
200
|
+
trap("CLD") do
|
201
|
+
cpid = Process.wait
|
202
|
+
fail "Could not start HTTP server on port #{@new_resource.http_port}" if cpid == pid && !success
|
203
|
+
end
|
204
|
+
pid = Process.spawn("python -m SimpleHTTPServer #{@new_resource.http_port}",
|
205
|
+
:chdir => ::File.dirname(@new_resource.image_file),
|
206
|
+
STDOUT => "/dev/null",
|
207
|
+
STDERR => "/dev/null",
|
208
|
+
:pgroup => true)
|
209
|
+
new_driver.one.upload_img(image_config)
|
210
|
+
success = true
|
211
|
+
@new_resource.updated_by_last_action(true)
|
212
|
+
ensure
|
213
|
+
system("sudo kill -9 -#{pid}")
|
214
|
+
end
|
215
|
+
else
|
216
|
+
new_driver.one.upload_img(image_config)
|
194
217
|
@new_resource.updated_by_last_action(true)
|
195
|
-
ensure
|
196
|
-
system("sudo kill -9 -#{pid}")
|
197
218
|
end
|
198
219
|
end
|
199
220
|
end
|
@@ -208,7 +229,7 @@ class Chef
|
|
208
229
|
You can get the value for 'download_url' by loging into your OpenNebula CLI
|
209
230
|
and reading the ONE_DOWNLOAD environment variable) if download_url.nil?
|
210
231
|
# You can get the value for 'download_url' by loging into your OpenNebula CLI and reading the ONE_DOWNLOAD environment variable" if download_url.nil?
|
211
|
-
image = new_driver.one.get_resource(
|
232
|
+
image = new_driver.one.get_resource(:image, !@new_resource.image_id.nil? ? { :id => @new_resource.image_id } : { :name => @new_resource.name })
|
212
233
|
fail "Image 'NAME: #{@new_resource.name}/ID: #{@new_resource.image_id}' does not exist" if image.nil?
|
213
234
|
local_path = @new_resource.image_file || ::File.join(Chef::Config[:file_cache_path], "#{@new_resource.name}.qcow2")
|
214
235
|
fail "Will not overwrite an existing file: #{local_path}" if ::File.exist?(local_path)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright 2015, BlackBerry,
|
1
|
+
# Copyright 2015, BlackBerry, Ltd.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -28,67 +28,145 @@ class Chef
|
|
28
28
|
|
29
29
|
provides :one_template
|
30
30
|
|
31
|
-
attr_reader :
|
31
|
+
attr_reader :uname
|
32
|
+
attr_reader :equal_template
|
33
|
+
attr_reader :equal_mode
|
34
|
+
attr_reader :current_id
|
32
35
|
|
33
36
|
def whyrun_supported?
|
34
37
|
true
|
35
38
|
end
|
36
39
|
|
37
40
|
def load_current_resource
|
38
|
-
|
41
|
+
driver = self.driver
|
42
|
+
@uname = uname
|
43
|
+
@current_resource = Chef::Resource::OneTemplate.new(new_resource.name,
|
44
|
+
run_context)
|
45
|
+
@current_resource.name(new_resource.name)
|
46
|
+
template = driver.one.get_resource(:template,
|
47
|
+
:name => @current_resource.name,
|
48
|
+
:uname => @uname)
|
49
|
+
@current_resource.exists = !template.nil?
|
39
50
|
|
40
|
-
|
41
|
-
|
42
|
-
|
51
|
+
return unless @current_resource.exists
|
52
|
+
|
53
|
+
new_resource_template = @new_resource.template_file.nil? ?
|
54
|
+
@new_resource.template :
|
55
|
+
driver.one.template_from_file(@new_resource.template_file)
|
43
56
|
|
44
|
-
|
45
|
-
|
46
|
-
@
|
47
|
-
|
57
|
+
@current_id = template.to_hash['VMTEMPLATE']['ID'].to_i
|
58
|
+
@current_resource.template(template.to_hash['VMTEMPLATE']['TEMPLATE'])
|
59
|
+
@current_resource.mode(get_mode(template))
|
60
|
+
@equal_template = @current_resource.template == new_resource_template
|
61
|
+
@equal_mode = @current_resource.mode == new_resource.mode
|
62
|
+
@current_resource.equal = @equal_template && @equal_mode
|
48
63
|
end
|
49
64
|
|
50
65
|
action :create do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
@
|
66
|
+
template_str = create_template
|
67
|
+
|
68
|
+
unless @current_resource.equal
|
69
|
+
if @current_resource.exists
|
70
|
+
unless @equal_template
|
71
|
+
converge_by "update template content on '#{new_resource.name}'" do
|
72
|
+
driver.one.update_template(@current_id, template_str)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
unless @equal_mode
|
76
|
+
converge_by('update template permissions on ' \
|
77
|
+
"'#{new_resource.name}' to #{new_resource.mode}") do
|
78
|
+
template = driver.one.get_resource(:template,
|
79
|
+
:name => @current_resource.name,
|
80
|
+
:uname => @uname)
|
81
|
+
driver.one.chmod_resource(template, new_resource.mode)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
else
|
85
|
+
converge_by("create template '#{new_resource.name}'") do
|
86
|
+
create_one_template(template_str)
|
87
|
+
end
|
61
88
|
end
|
89
|
+
new_resource.updated_by_last_action(true)
|
62
90
|
end
|
63
91
|
end
|
64
92
|
|
65
|
-
action :
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
@new_resource.updated_by_last_action(true)
|
93
|
+
action :create_if_missing do
|
94
|
+
template_str = create_template
|
95
|
+
|
96
|
+
unless @current_resource.exists
|
97
|
+
converge_by("create template '#{new_resource.name}'") do
|
98
|
+
create_one_template(template_str)
|
72
99
|
end
|
100
|
+
new_resource.updated_by_last_action(true)
|
73
101
|
end
|
74
102
|
end
|
75
103
|
|
104
|
+
action :delete do
|
105
|
+
converge_by("delete template '#{new_resource.name}'") do
|
106
|
+
template = driver.one.get_resource(:template,
|
107
|
+
:name => @current_resource.name,
|
108
|
+
:uname => @uname)
|
109
|
+
template.delete
|
110
|
+
new_resource.updated_by_last_action(true)
|
111
|
+
end if @current_resource.exists
|
112
|
+
end
|
113
|
+
|
76
114
|
protected
|
77
115
|
|
78
116
|
def driver
|
79
|
-
|
80
|
-
|
117
|
+
current_driver = begin
|
118
|
+
if new_resource.driver
|
119
|
+
run_context.chef_provisioning.driver_for(new_resource.driver)
|
120
|
+
elsif run_context.chef_provisioning.current_driver
|
121
|
+
run_context.chef_provisioning.driver_for(run_context.chef_provisioning.current_driver)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
fail "Driver not specified for one_template #{new_resource.name}" unless current_driver
|
125
|
+
current_driver
|
126
|
+
end
|
127
|
+
|
128
|
+
def create_one_template(template_str)
|
129
|
+
unless new_resource.template.key?('NAME')
|
130
|
+
template_str << "\n" << 'NAME="' << new_resource.name << '"'
|
81
131
|
end
|
82
|
-
|
83
|
-
|
132
|
+
driver.one.allocate_template(template_str)
|
133
|
+
template = driver.one.get_resource(:template,
|
134
|
+
:name => @current_resource.name,
|
135
|
+
:uname => @uname)
|
136
|
+
driver.one.chmod_resource(template, new_resource.mode)
|
84
137
|
end
|
85
138
|
|
86
|
-
def
|
87
|
-
|
139
|
+
def create_template
|
140
|
+
if new_resource.template_file && new_resource.template.size > 0
|
141
|
+
fail("Attributes 'template_file' and 'template' are mutually " \
|
142
|
+
'exclusive.')
|
143
|
+
elsif new_resource.template_file
|
144
|
+
::File.read(new_resource.template_file)
|
145
|
+
elsif new_resource.template.size > 0
|
146
|
+
driver.one.create_template(new_resource.template)
|
147
|
+
else
|
148
|
+
fail("Missing attribute 'template_file' or 'template' in " \
|
149
|
+
'resource block.')
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def get_mode(template)
|
154
|
+
perms = template.to_hash['VMTEMPLATE']['PERMISSIONS']
|
155
|
+
mode = 0
|
156
|
+
%w(OWNER_U OWNER_M OWNER_A GROUP_U GROUP_M GROUP_A
|
157
|
+
OTHER_U OTHER_M OTHER_A).each do |m|
|
158
|
+
mode += perms[m].to_i
|
159
|
+
mode = mode << 1
|
160
|
+
end
|
161
|
+
mode = mode >> 1
|
162
|
+
mode.to_s(8)
|
88
163
|
end
|
89
164
|
|
90
|
-
def
|
91
|
-
|
165
|
+
def uname
|
166
|
+
xml = OpenNebula::User.build_xml(OpenNebula::User::SELF)
|
167
|
+
my_user = OpenNebula::User.new(xml, driver.one.client)
|
168
|
+
my_user.info!
|
169
|
+
my_user.to_hash['USER']['NAME']
|
92
170
|
end
|
93
171
|
end
|
94
172
|
end
|