vmware_guest: refactor spec serialization (#30819)
* Refactor spec serialization so that native types are evaluated last. * Remove redundant type checks Fixes #30818
This commit is contained in:
parent
e4c9ffa7e6
commit
ada404d0ac
1 changed files with 17 additions and 11 deletions
|
@ -31,6 +31,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_PYVMOMI = False
|
HAS_PYVMOMI = False
|
||||||
|
|
||||||
|
from ansible.module_utils._text import to_text
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.urls import fetch_url
|
||||||
from ansible.module_utils.six import integer_types, iteritems, string_types
|
from ansible.module_utils.six import integer_types, iteritems, string_types
|
||||||
|
|
||||||
|
@ -593,22 +594,14 @@ def serialize_spec(clonespec):
|
||||||
xt = type(xo)
|
xt = type(xo)
|
||||||
if xo is None:
|
if xo is None:
|
||||||
data[x] = None
|
data[x] = None
|
||||||
elif issubclass(xt, list):
|
|
||||||
data[x] = []
|
|
||||||
for xe in xo:
|
|
||||||
data[x].append(serialize_spec(xe))
|
|
||||||
elif issubclass(xt, string_types + integer_types + (float, bool)):
|
|
||||||
data[x] = xo
|
|
||||||
elif issubclass(xt, dict):
|
|
||||||
data[x] = {}
|
|
||||||
for k, v in xo.items():
|
|
||||||
data[x][k] = serialize_spec(v)
|
|
||||||
elif isinstance(xo, vim.vm.ConfigSpec):
|
elif isinstance(xo, vim.vm.ConfigSpec):
|
||||||
data[x] = serialize_spec(xo)
|
data[x] = serialize_spec(xo)
|
||||||
elif isinstance(xo, vim.vm.RelocateSpec):
|
elif isinstance(xo, vim.vm.RelocateSpec):
|
||||||
data[x] = serialize_spec(xo)
|
data[x] = serialize_spec(xo)
|
||||||
elif isinstance(xo, vim.vm.device.VirtualDisk):
|
elif isinstance(xo, vim.vm.device.VirtualDisk):
|
||||||
data[x] = serialize_spec(xo)
|
data[x] = serialize_spec(xo)
|
||||||
|
elif isinstance(xo, vim.vm.device.VirtualDeviceSpec.FileOperation):
|
||||||
|
data[x] = serialize_spec(xo)
|
||||||
elif isinstance(xo, vim.Description):
|
elif isinstance(xo, vim.Description):
|
||||||
data[x] = {
|
data[x] = {
|
||||||
'dynamicProperty': serialize_spec(xo.dynamicProperty),
|
'dynamicProperty': serialize_spec(xo.dynamicProperty),
|
||||||
|
@ -617,9 +610,22 @@ def serialize_spec(clonespec):
|
||||||
'summary': serialize_spec(xo.summary),
|
'summary': serialize_spec(xo.summary),
|
||||||
}
|
}
|
||||||
elif hasattr(xo, 'name'):
|
elif hasattr(xo, 'name'):
|
||||||
data[x] = str(xo) + ':' + xo.name
|
data[x] = to_text(xo) + ':' + to_text(xo.name)
|
||||||
elif isinstance(xo, vim.vm.ProfileSpec):
|
elif isinstance(xo, vim.vm.ProfileSpec):
|
||||||
pass
|
pass
|
||||||
|
elif issubclass(xt, list):
|
||||||
|
data[x] = []
|
||||||
|
for xe in xo:
|
||||||
|
data[x].append(serialize_spec(xe))
|
||||||
|
elif issubclass(xt, string_types + integer_types + (float, bool)):
|
||||||
|
data[x] = to_text(xt)
|
||||||
|
elif issubclass(xt, bool):
|
||||||
|
data[x] = xo
|
||||||
|
elif issubclass(xt, dict):
|
||||||
|
data[to_text(x)] = {}
|
||||||
|
for k, v in xo.items():
|
||||||
|
k = to_text(k)
|
||||||
|
data[x][k] = serialize_spec(v)
|
||||||
else:
|
else:
|
||||||
data[x] = str(xt)
|
data[x] = str(xt)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue