chef-provisioning-opennebula 0.4.7 → 0.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 798eb6e4b57c623beb0ae99b82260ddcd73e31be
|
4
|
+
data.tar.gz: 04bcf4eb734161c936cbfbd3a47c07ab1bb4f9d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d24fd26f66e346ac1049f4c5b36c3197402629cc5a7906caf789ffcfd6514b176e9d36af65a2b47b97ab125255975533f7efb9f5fc199c71cf13509bd8d65d3a
|
7
|
+
data.tar.gz: ce67ffb81da9cddb2dce49b5af2909562c870ecce4b5833fd7543883e0b9b85055498fc266d0458baa3979d3e667892bf4adc6231723315f59190e6556de226b
|
@@ -49,7 +49,100 @@ class Chef
|
|
49
49
|
|
50
50
|
action :allocate do
|
51
51
|
if exists?
|
52
|
-
|
52
|
+
# Image already exists, check whether we need/can update it
|
53
|
+
# OpenNebula Image example:
|
54
|
+
# ID : 14202
|
55
|
+
# NAME : ey-test
|
56
|
+
# USER : Mandolin
|
57
|
+
# GROUP : users
|
58
|
+
# DATASTORE : orn-svc01-ds
|
59
|
+
# TYPE : DATABLOCK
|
60
|
+
# REGISTER TIME : 10/19 18:16:02
|
61
|
+
# PERSISTENT : No
|
62
|
+
# SOURCE : /var/lib/one/datastores/103/743dff63f337a0192b13f2963f92d741
|
63
|
+
# FSTYPE : raw
|
64
|
+
# SIZE : 1000M
|
65
|
+
# STATE : rdy
|
66
|
+
# RUNNING_VMS : 0
|
67
|
+
#
|
68
|
+
# PERMISSIONS
|
69
|
+
# OWNER : um-
|
70
|
+
# GROUP : ---
|
71
|
+
# OTHER : ---
|
72
|
+
#
|
73
|
+
# IMAGE TEMPLATE
|
74
|
+
# DESCRIPTION="what a heck!"
|
75
|
+
# DEV_PREFIX="vd"
|
76
|
+
# DRIVER="qcow2"
|
77
|
+
# FSTYPE="ext4"
|
78
|
+
# SIZE="100"
|
79
|
+
#
|
80
|
+
# We can update many parameters and whatever we update goes into section below 'IMAGE TEMPLATE'.
|
81
|
+
# IMPORTANT: if the parameter we are updating exists above 'IMAGE TEMPLATE' then our modification has no effect.
|
82
|
+
# In other words a value for a parameter defined above wins over parameter defined below 'IMAGE TEMPLATE'.
|
83
|
+
|
84
|
+
on_image = @image.to_hash['IMAGE']
|
85
|
+
|
86
|
+
# We can update only following attributes. This is a map of one_image attributes to OpenNebula image attributes
|
87
|
+
attrs_map = { 'name' => 'NAME', 'size' => 'SIZE', 'datastore_id' => 'DATASTORE_ID', 'type' => 'TYPE', 'description' => 'DESCRIPTION', 'fs_type' => 'FSTYPE',
|
88
|
+
'img_driver' => 'DRIVER', 'prefix' => 'DEV_PREFIX', 'persistent' => 'PERSISTENT', 'mode' => 'PERMISSIONS', 'disk_type' => 'DISK_TYPE' }
|
89
|
+
|
90
|
+
# Find out what attribute needs to be updated
|
91
|
+
attrs_to_update = {}
|
92
|
+
new_resource_hash = @new_resource.to_hash # hash keys are symbols
|
93
|
+
new_resource_hash.each do |k, v|
|
94
|
+
next if v.nil? || !attrs_map.key?(k.to_s)
|
95
|
+
v = v.to_s # everything is String in what we get in OpenNebula Image info
|
96
|
+
on_attr = attrs_map[k.to_s]
|
97
|
+
|
98
|
+
# For some one_image attributes provided in new_resource we need to find respective values in ON Image
|
99
|
+
case k
|
100
|
+
when :type
|
101
|
+
image_types = %w(OS CDROM DATABLOCK KERNEL RAMDISK CONTEXT)
|
102
|
+
on_image['TYPE'] = image_types[on_image['TYPE'].to_i] # convert Image Type Id into String
|
103
|
+
when :persistent
|
104
|
+
on_image['PERSISTENT'] = (on_image['PERSISTENT'] == '1' ? 'true' : 'false')
|
105
|
+
when :mode
|
106
|
+
perm = on_image['PERMISSIONS']
|
107
|
+
perm_octet_u = perm['OWNER_U'].to_i * 4 + perm['OWNER_M'].to_i * 2 + perm['OWNER_A'].to_i
|
108
|
+
perm_octet_g = perm['GROUP_U'].to_i * 4 + perm['GROUP_M'].to_i * 2 + perm['GROUP_A'].to_i
|
109
|
+
perm_octet_o = perm['OTHER_U'].to_i * 4 + perm['OTHER_M'].to_i * 2 + perm['OTHER_A'].to_i
|
110
|
+
on_image['PERMISSIONS'] = "#{perm_octet_u}#{perm_octet_g}#{perm_octet_o}"
|
111
|
+
when :disk_type
|
112
|
+
disk_types = %w(BLOCK CDROM FILE)
|
113
|
+
on_image['DISK_TYPE'] = disk_types[on_image['DISK_TYPE'].to_i] # convert Disk Type into String
|
114
|
+
end
|
115
|
+
next if on_image.key?(on_attr) && (v == on_image[on_attr])
|
116
|
+
next if on_image['TEMPLATE'].key?(on_attr) && (new_resource_hash[k] == on_image['TEMPLATE'][on_attr])
|
117
|
+
fail "Cannot update '#{on_attr}' as it is defined above 'IMAGE TEMPLATE' section." if on_image.key?(on_attr) && !on_image[on_attr].empty? && on_attr != 'PERMISSIONS'
|
118
|
+
attrs_to_update[on_attr] = v
|
119
|
+
end
|
120
|
+
|
121
|
+
unless attrs_to_update.empty?
|
122
|
+
# Prepare template to update
|
123
|
+
img_template = ''
|
124
|
+
attrs_to_update.each do |k, v|
|
125
|
+
next if k == 'PERMISSIONS' # needs special treatment
|
126
|
+
img_template << case k
|
127
|
+
when 'SIZE', 'PERSISTENT'
|
128
|
+
"#{k} = #{v}\n"
|
129
|
+
when 'TYPE', 'DESCRIPTION', 'FSTYPE', 'DRIVER', 'DEV_PREFIX', 'DISK_TYPE'
|
130
|
+
"#{k} = \"#{v}\"\n"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
# Perform actual update
|
134
|
+
description = "updated image '#{new_resource.name}'\n" + attrs_to_update.to_s
|
135
|
+
action_handler.perform_action description do
|
136
|
+
unless img_template == '' # can happen when we update only PERMISSIONS
|
137
|
+
rc = @image.update(img_template, true)
|
138
|
+
fail "failed to update image '#{new_resource.name}': #{rc.message}" if OpenNebula.is_error?(rc)
|
139
|
+
end
|
140
|
+
if attrs_to_update.key?('PERMISSIONS')
|
141
|
+
rc = @image.chmod_octet(attrs_to_update['PERMISSIONS'])
|
142
|
+
fail "failed to update image '#{new_resource.name}': #{rc.message}" if OpenNebula.is_error?(rc)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
53
146
|
else
|
54
147
|
fail "'size' must be specified" unless new_resource.size
|
55
148
|
fail "'datastore_id' must be specified" unless new_resource.datastore_id
|
@@ -81,7 +174,6 @@ class Chef
|
|
81
174
|
@new_resource.updated_by_last_action(true)
|
82
175
|
end
|
83
176
|
when 'READY', 'USED', 'USED_PERS'
|
84
|
-
action_handler.report_progress "image '#{new_resource.name}' is already in #{@image.state_str} state - (up to date)"
|
85
177
|
else
|
86
178
|
fail "Image #{new_resource.name} is in unexpected state '#{@image.state_str}'"
|
87
179
|
end
|
@@ -208,7 +208,7 @@ class Chef
|
|
208
208
|
return machine_spec unless instance.nil?
|
209
209
|
|
210
210
|
unless machine_options[:bootstrap_options]
|
211
|
-
instance = retry_one("Retrying allocate_machine.instance_for (missing bootstrap options)") do
|
211
|
+
instance = @one.retry_one("Retrying allocate_machine.instance_for (missing bootstrap options)") do
|
212
212
|
instance_for(machine_spec)
|
213
213
|
end
|
214
214
|
return machine_spec unless instance.nil?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-provisioning-opennebula
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew J. Brown
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2016-
|
15
|
+
date: 2016-10-24 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: chef
|