manageiq_provider: don't send top-level null fields on creation (#38448)
* manageiq_provider: method docstrings fixes * manageiq_provider: refactoring step towards DRY `resource` is now same in `edit_provider()` and `create_provider()`, to be extracted to main later. * manageiq_provider: Fix creation of openshift provider Fixes #38331. Sending `api_version` to openshift provider would cause error: "OpenShift api_version cannot be modified" due to https://github.com/ManageIQ/manageiq-providers-kubernetes/blob/gaprindashvili-2/app/models/manageiq/providers/kubernetes/container_manager.rb#L37 In `edit_provider` we `delete_nulls()` on the whole data being sent so `api_version` was omitted if not specified. In `create_provider()` we only did it on endpoints list so `api_version` was always sent - now doing on whole data.
This commit is contained in:
parent
ffee906c54
commit
0c5f03d3f4
1 changed files with 19 additions and 20 deletions
|
@ -694,7 +694,7 @@ class ManageIQProvider(object):
|
|||
def edit_provider(self, provider, name, provider_type, endpoints, zone_id, provider_region,
|
||||
host_default_vnc_port_start, host_default_vnc_port_end,
|
||||
subscription, project, uid_ems, tenant_mapping_enabled, api_version):
|
||||
""" Edit a user from manageiq.
|
||||
""" Edit a provider from manageiq.
|
||||
|
||||
Returns:
|
||||
a short message describing the operation executed.
|
||||
|
@ -737,22 +737,13 @@ class ManageIQProvider(object):
|
|||
def create_provider(self, name, provider_type, endpoints, zone_id, provider_region,
|
||||
host_default_vnc_port_start, host_default_vnc_port_end,
|
||||
subscription, project, uid_ems, tenant_mapping_enabled, api_version):
|
||||
""" Creates the user in manageiq.
|
||||
""" Creates the provider in manageiq.
|
||||
|
||||
Returns:
|
||||
the created user id, name, created_on timestamp,
|
||||
updated_on timestamp, userid and current_group_id.
|
||||
a short message describing the operation executed.
|
||||
"""
|
||||
# clean nulls, we do not send nulls to the api
|
||||
endpoints = delete_nulls(endpoints)
|
||||
|
||||
# try to create a new provider
|
||||
try:
|
||||
url = '%s/providers' % (self.api_url)
|
||||
result = self.client.post(
|
||||
url,
|
||||
resource = dict(
|
||||
name=name,
|
||||
type=supported_providers()[provider_type]['class_name'],
|
||||
zone={'id': zone_id},
|
||||
provider_region=provider_region,
|
||||
host_default_vnc_port_start=host_default_vnc_port_start,
|
||||
|
@ -764,6 +755,14 @@ class ManageIQProvider(object):
|
|||
api_version=api_version,
|
||||
connection_configurations=endpoints,
|
||||
)
|
||||
|
||||
# clean nulls, we do not send nulls to the api
|
||||
resource = delete_nulls(resource)
|
||||
|
||||
# try to create a new provider
|
||||
try:
|
||||
url = '%s/providers' % (self.api_url)
|
||||
result = self.client.post(url, type=supported_providers()[provider_type]['class_name'], **resource)
|
||||
except Exception as e:
|
||||
self.module.fail_json(msg="failed to create provider %s: %s" % (name, str(e)))
|
||||
|
||||
|
|
Loading…
Reference in a new issue