Skip to content

Commit 76fddb8

Browse files
authored
Merge pull request #204 from lae/fix/storage_booleans
Idempotency fixes for proxmox_storage
2 parents 6274a16 + ea902c8 commit 76fddb8

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

library/proxmox_role.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,4 @@ def main():
186186
module.exit_json(**result)
187187

188188
if __name__ == '__main__':
189-
main()
189+
main()

library/proxmox_storage.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ def lookup(self):
202202
for item in self.existing_storages:
203203
if item['storage'] == self.name:
204204
# pvesh doesn't return the disable param value if it's false,
205-
# so we set it to False.
205+
# so we set it to 0, which is what PVE would normally use.
206206
if item.get('disable') is None:
207-
item['disable'] = False
207+
item['disable'] = 0
208208
return item
209209
return None
210210

@@ -218,13 +218,15 @@ def prepare_storage_args(self):
218218
args = {}
219219

220220
args['type'] = self.type
221-
args['content'] = ','.join(self.content)
221+
if self.content is not None and len(self.content) > 0:
222+
args['content'] = ','.join(self.content)
223+
else:
224+
# PVE uses "none" to represent when no content types are selected
225+
args['content'] = 'none'
222226
if self.nodes is not None:
223227
args['nodes'] = ','.join(self.nodes)
224228
if self.disable is not None:
225-
args['disable'] = self.disable
226-
else:
227-
args['disable'] = False
229+
args['disable'] = 1 if self.disable else 0
228230
if self.path is not None:
229231
args['path'] = self.path
230232
if self.pool is not None:
@@ -234,7 +236,7 @@ def prepare_storage_args(self):
234236
if self.username is not None:
235237
args['username'] = self.username
236238
if self.krbd is not None:
237-
args['krbd'] = self.krbd
239+
args['krbd'] = 1 if self.krbd else 0
238240
if self.maxfiles is not None:
239241
args['maxfiles'] = self.maxfiles
240242
if self.server is not None:
@@ -248,7 +250,7 @@ def prepare_storage_args(self):
248250
if self.thinpool is not None:
249251
args['thinpool'] = self.thinpool
250252
if self.sparse is not None:
251-
args['sparse'] = self.sparse
253+
args['sparse'] = 1 if self.sparse else 0
252254

253255
if self.maxfiles is not None and 'backup' not in self.content:
254256
self.module.fail_json(msg="maxfiles is not allowed when there is no 'backup' in content")
@@ -275,7 +277,8 @@ def modify_storage(self):
275277

276278
for key in new_storage:
277279
if key == 'content':
278-
if set(self.content) != set(lookup.get('content', '').split(',')):
280+
if set(new_storage['content'].split(',')) \
281+
!= set(lookup.get('content', '').split(',')):
279282
updated_fields.append(key)
280283
staged_storage[key] = new_storage[key]
281284
elif key == 'monhost':

tests/vagrant/group_vars/all

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ pve_storages:
5858
type: dir
5959
content: [ "iso", "vztmpl", "backup" ]
6060
path: /testpool/zfs2
61+
- name: disabled-dir
62+
type: dir
63+
disable: yes
64+
content: [ "images" ]
65+
path: /tmp/fakedir
66+
- name: no-content-dir
67+
type: dir
68+
path: /tmp/fakedir2
6169
pve_zfs_create_volumes:
6270
- testpool/zfs2
6371
pve_ceph_osds:

0 commit comments

Comments
 (0)