mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-06 13:23:06 +00:00
Refactor ironic authentication into a new module_utils module
This change merely moves the code to one location. The next logical step would be to make IronicModule inherit the common ansible module. Change-Id: Iec0ca1e33de6ebc36d7664941eafe1d77203d8f2
This commit is contained in:
committed by
Sagi Shnaidman
parent
d081bb5378
commit
8b98452cbb
@@ -75,10 +75,14 @@ EXAMPLES = '''
|
||||
name: "testnode1"
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (openstack_full_argument_spec,
|
||||
openstack_module_kwargs,
|
||||
openstack_cloud_from_module)
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.ironic import (
|
||||
IronicModule,
|
||||
ironic_argument_spec,
|
||||
)
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (
|
||||
openstack_module_kwargs,
|
||||
openstack_cloud_from_module
|
||||
)
|
||||
|
||||
|
||||
def _choose_id_value(module):
|
||||
@@ -90,37 +94,14 @@ def _choose_id_value(module):
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = openstack_full_argument_spec(
|
||||
auth_type=dict(required=False),
|
||||
argument_spec = ironic_argument_spec(
|
||||
uuid=dict(required=False),
|
||||
name=dict(required=False),
|
||||
mac=dict(required=False),
|
||||
ironic_url=dict(required=False),
|
||||
timeout=dict(default=1200, type='int', required=False),
|
||||
)
|
||||
module_kwargs = openstack_module_kwargs()
|
||||
module = AnsibleModule(argument_spec, **module_kwargs)
|
||||
|
||||
if (
|
||||
module.params['auth_type'] in [None, 'None', 'none']
|
||||
and module.params['ironic_url'] is None
|
||||
and not module.params['cloud']
|
||||
and not (module.params['auth']
|
||||
and module.params['auth'].get('endpoint'))
|
||||
):
|
||||
module.fail_json(msg="Authentication appears to be disabled, "
|
||||
"Please define either ironic_url, or cloud, "
|
||||
"or auth.endpoint")
|
||||
|
||||
if (
|
||||
module.params['ironic_url']
|
||||
and module.params['auth_type'] in [None, 'None', 'none']
|
||||
and not (module.params['auth']
|
||||
and module.params['auth'].get('endpoint'))
|
||||
):
|
||||
module.params['auth'] = dict(
|
||||
endpoint=module.params['ironic_url']
|
||||
)
|
||||
module = IronicModule(argument_spec, **module_kwargs)
|
||||
|
||||
sdk, cloud = openstack_cloud_from_module(module)
|
||||
try:
|
||||
|
||||
@@ -164,10 +164,15 @@ try:
|
||||
except ImportError:
|
||||
HAS_JSONPATCH = False
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (openstack_full_argument_spec,
|
||||
openstack_module_kwargs,
|
||||
openstack_cloud_from_module)
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.ironic import (
|
||||
IronicModule,
|
||||
ironic_argument_spec,
|
||||
)
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (
|
||||
openstack_module_kwargs,
|
||||
openstack_cloud_from_module
|
||||
)
|
||||
|
||||
|
||||
def _parse_properties(module):
|
||||
@@ -225,14 +230,13 @@ def _exit_node_not_updated(module, server):
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = openstack_full_argument_spec(
|
||||
argument_spec = ironic_argument_spec(
|
||||
uuid=dict(required=False),
|
||||
name=dict(required=False),
|
||||
driver=dict(required=False),
|
||||
driver_info=dict(type='dict', required=True),
|
||||
nics=dict(type='list', required=True, elements="dict"),
|
||||
properties=dict(type='dict', default={}),
|
||||
ironic_url=dict(required=False),
|
||||
chassis_uuid=dict(required=False),
|
||||
skip_update_of_masked_password=dict(
|
||||
required=False,
|
||||
@@ -243,30 +247,10 @@ def main():
|
||||
state=dict(required=False, default='present', choices=['present', 'absent'])
|
||||
)
|
||||
module_kwargs = openstack_module_kwargs()
|
||||
module = AnsibleModule(argument_spec, **module_kwargs)
|
||||
module = IronicModule(argument_spec, **module_kwargs)
|
||||
|
||||
if not HAS_JSONPATCH:
|
||||
module.fail_json(msg='jsonpatch is required for this module')
|
||||
if (
|
||||
module.params['auth_type'] in [None, 'None', 'none']
|
||||
and module.params['ironic_url'] is None
|
||||
and not module.params['cloud']
|
||||
and not (module.params['auth']
|
||||
and module.params['auth'].get('endpoint'))
|
||||
):
|
||||
module.fail_json(msg="Authentication appears to be disabled, "
|
||||
"Please define either ironic_url, or cloud, "
|
||||
"or auth.endpoint")
|
||||
|
||||
if (
|
||||
module.params['ironic_url']
|
||||
and module.params['auth_type'] in [None, 'None', 'none']
|
||||
and not (module.params['auth']
|
||||
and module.params['auth'].get('endpoint'))
|
||||
):
|
||||
module.params['auth'] = dict(
|
||||
endpoint=module.params['ironic_url']
|
||||
)
|
||||
|
||||
node_id = _choose_id_value(module)
|
||||
|
||||
|
||||
@@ -132,10 +132,15 @@ EXAMPLES = '''
|
||||
delegate_to: localhost
|
||||
'''
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (openstack_full_argument_spec,
|
||||
openstack_module_kwargs,
|
||||
openstack_cloud_from_module)
|
||||
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.ironic import (
|
||||
IronicModule,
|
||||
ironic_argument_spec,
|
||||
)
|
||||
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import (
|
||||
openstack_module_kwargs,
|
||||
openstack_cloud_from_module
|
||||
)
|
||||
|
||||
|
||||
def _choose_id_value(module):
|
||||
@@ -227,12 +232,11 @@ def _check_set_power_state(module, cloud, node):
|
||||
|
||||
|
||||
def main():
|
||||
argument_spec = openstack_full_argument_spec(
|
||||
argument_spec = ironic_argument_spec(
|
||||
uuid=dict(required=False),
|
||||
name=dict(required=False),
|
||||
instance_info=dict(type='dict', required=False),
|
||||
config_drive=dict(type='raw', required=False),
|
||||
ironic_url=dict(required=False),
|
||||
state=dict(required=False, default='present'),
|
||||
maintenance=dict(required=False),
|
||||
maintenance_reason=dict(required=False),
|
||||
@@ -242,28 +246,7 @@ def main():
|
||||
timeout=dict(required=False, type='int', default=1800),
|
||||
)
|
||||
module_kwargs = openstack_module_kwargs()
|
||||
module = AnsibleModule(argument_spec, **module_kwargs)
|
||||
|
||||
if (
|
||||
module.params['auth_type'] in [None, 'None', 'none']
|
||||
and module.params['ironic_url'] is None
|
||||
and not module.params['cloud']
|
||||
and not (module.params['auth']
|
||||
and module.params['auth'].get('endpoint'))
|
||||
):
|
||||
module.fail_json(msg="Authentication appears to be disabled, "
|
||||
"Please define either ironic_url, or cloud, "
|
||||
"or auth.endpoint")
|
||||
|
||||
if (
|
||||
module.params['ironic_url']
|
||||
and module.params['auth_type'] in [None, 'None', 'none']
|
||||
and not (module.params['auth']
|
||||
and module.params['auth'].get('endpoint'))
|
||||
):
|
||||
module.params['auth'] = dict(
|
||||
endpoint=module.params['ironic_url']
|
||||
)
|
||||
module = IronicModule(argument_spec, **module_kwargs)
|
||||
|
||||
if (
|
||||
module.params['config_drive']
|
||||
|
||||
Reference in New Issue
Block a user