From 28999b377b3ee467441956c84d647d35b0a5498d Mon Sep 17 00:00:00 2001 From: Nik Conwell Date: Fri, 14 Jul 2023 06:52:52 -0400 Subject: [PATCH 1/3] Use re.search for more flexibility in selecting a datastore --- changelogs/fragments/0000-autoselect_datastore-use-regex.yaml | 2 ++ plugins/modules/vmware_guest.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/0000-autoselect_datastore-use-regex.yaml diff --git a/changelogs/fragments/0000-autoselect_datastore-use-regex.yaml b/changelogs/fragments/0000-autoselect_datastore-use-regex.yaml new file mode 100644 index 000000000..c27403640 --- /dev/null +++ b/changelogs/fragments/0000-autoselect_datastore-use-regex.yaml @@ -0,0 +1,2 @@ +minor_changes: + - autoselect_datastore-use-regex - when using autoselect_datastore, use re.search() to match the datastore instead of substring .find() diff --git a/plugins/modules/vmware_guest.py b/plugins/modules/vmware_guest.py index 51e4aba1f..bb5b893e8 100644 --- a/plugins/modules/vmware_guest.py +++ b/plugins/modules/vmware_guest.py @@ -2758,7 +2758,7 @@ def select_datastore(self, vm_obj=None): if (ds.summary.freeSpace > datastore_freespace) or (ds.summary.freeSpace == datastore_freespace and not datastore): # If datastore field is provided, filter destination datastores - if self.params['disk'][0]['datastore'] and ds.name.find(self.params['disk'][0]['datastore']) < 0: + if self.params['disk'][0]['datastore'] and not re.search(self.params['disk'][0]['datastore'],ds.name): continue datastore = ds From 037dfe539f813915326f880c7d5991741d677cd9 Mon Sep 17 00:00:00 2001 From: Nik Conwell Date: Fri, 14 Jul 2023 06:57:26 -0400 Subject: [PATCH 2/3] Updated changelog fragment filename to match the PR --- ...re-use-regex.yaml => 1793-autoselect_datastore-use-regex.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changelogs/fragments/{0000-autoselect_datastore-use-regex.yaml => 1793-autoselect_datastore-use-regex.yaml} (100%) diff --git a/changelogs/fragments/0000-autoselect_datastore-use-regex.yaml b/changelogs/fragments/1793-autoselect_datastore-use-regex.yaml similarity index 100% rename from changelogs/fragments/0000-autoselect_datastore-use-regex.yaml rename to changelogs/fragments/1793-autoselect_datastore-use-regex.yaml From 818bde129dba2478a38387b2d782d19af435f9d0 Mon Sep 17 00:00:00 2001 From: Nik Conwell Date: Fri, 14 Jul 2023 06:59:51 -0400 Subject: [PATCH 3/3] Adjust whitespace --- plugins/modules/vmware_guest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/vmware_guest.py b/plugins/modules/vmware_guest.py index bb5b893e8..ebe9d865d 100644 --- a/plugins/modules/vmware_guest.py +++ b/plugins/modules/vmware_guest.py @@ -2758,7 +2758,7 @@ def select_datastore(self, vm_obj=None): if (ds.summary.freeSpace > datastore_freespace) or (ds.summary.freeSpace == datastore_freespace and not datastore): # If datastore field is provided, filter destination datastores - if self.params['disk'][0]['datastore'] and not re.search(self.params['disk'][0]['datastore'],ds.name): + if self.params['disk'][0]['datastore'] and not re.search(self.params['disk'][0]['datastore'], ds.name): continue datastore = ds