linode_v4: add support for `private_ip` option. (#2249)
* linode_v4: add support for `private_ip` option. * linode_v4: remove `required` attribute from `private_ip` parameter. * linode_v4: add changelog fragment. * linode_v4: add PR link to changelog fragment. Co-authored-by: Amin Vakil <info@aminvakil.com> * linode_v4: add the `version_added` attribute to the `private_ip` section of module documentation Co-authored-by: Felix Fontein <felix@fontein.de> * linode_v4: improve styling of `private_ip` docs Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Amin Vakil <info@aminvakil.com> Co-authored-by: Felix Fontein <felix@fontein.de>pull/2264/head
parent
1400051890
commit
f9e3e229dd
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- linode_v4 - add support for ``private_ip`` option (https://github.com/ansible-collections/community.general/pull/2249).
|
|
@ -53,6 +53,13 @@ options:
|
||||||
group labelling is deprecated but still supported. The encouraged
|
group labelling is deprecated but still supported. The encouraged
|
||||||
method for marking instances is to use tags.
|
method for marking instances is to use tags.
|
||||||
type: str
|
type: str
|
||||||
|
private_ip:
|
||||||
|
description:
|
||||||
|
- If C(true), the created Linode will have private networking enabled and
|
||||||
|
assigned a private IPv4 address.
|
||||||
|
type: bool
|
||||||
|
default: false
|
||||||
|
version_added: 3.0.0
|
||||||
tags:
|
tags:
|
||||||
description:
|
description:
|
||||||
- The tags that the instance should be marked under. See
|
- The tags that the instance should be marked under. See
|
||||||
|
@ -238,6 +245,7 @@ def initialise_module():
|
||||||
authorized_keys=dict(type='list', elements='str', no_log=False),
|
authorized_keys=dict(type='list', elements='str', no_log=False),
|
||||||
group=dict(type='str'),
|
group=dict(type='str'),
|
||||||
image=dict(type='str'),
|
image=dict(type='str'),
|
||||||
|
private_ip=dict(type='bool', default=False),
|
||||||
region=dict(type='str'),
|
region=dict(type='str'),
|
||||||
root_pass=dict(type='str', no_log=True),
|
root_pass=dict(type='str', no_log=True),
|
||||||
tags=dict(type='list', elements='str'),
|
tags=dict(type='list', elements='str'),
|
||||||
|
@ -283,6 +291,7 @@ def main():
|
||||||
group=module.params['group'],
|
group=module.params['group'],
|
||||||
image=module.params['image'],
|
image=module.params['image'],
|
||||||
label=module.params['label'],
|
label=module.params['label'],
|
||||||
|
private_ip=module.params['private_ip'],
|
||||||
region=module.params['region'],
|
region=module.params['region'],
|
||||||
root_pass=module.params['root_pass'],
|
root_pass=module.params['root_pass'],
|
||||||
tags=module.params['tags'],
|
tags=module.params['tags'],
|
||||||
|
|
|
@ -175,6 +175,55 @@ def test_optional_image_is_validated(default_args, capfd, access_token):
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('value', [True, False])
|
||||||
|
def test_private_ip_valid_values(default_args, access_token, value):
|
||||||
|
default_args.update({'private_ip': value})
|
||||||
|
set_module_args(default_args)
|
||||||
|
|
||||||
|
module = linode_v4.initialise_module()
|
||||||
|
|
||||||
|
assert module.params['private_ip'] is value
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('value', ['not-a-bool', 42])
|
||||||
|
def test_private_ip_invalid_values(default_args, capfd, access_token, value):
|
||||||
|
default_args.update({'private_ip': value})
|
||||||
|
set_module_args(default_args)
|
||||||
|
|
||||||
|
with pytest.raises(SystemExit):
|
||||||
|
linode_v4.initialise_module()
|
||||||
|
|
||||||
|
out, err = capfd.readouterr()
|
||||||
|
results = json.loads(out)
|
||||||
|
|
||||||
|
assert results['failed'] is True
|
||||||
|
assert 'not a valid boolean' in results['msg']
|
||||||
|
|
||||||
|
|
||||||
|
def test_private_ip_default_value(default_args, access_token):
|
||||||
|
default_args.pop('private_ip', None)
|
||||||
|
set_module_args(default_args)
|
||||||
|
|
||||||
|
module = linode_v4.initialise_module()
|
||||||
|
|
||||||
|
assert module.params['private_ip'] is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_private_ip_is_forwarded_to_linode(default_args, mock_linode, access_token):
|
||||||
|
default_args.update({'private_ip': True})
|
||||||
|
set_module_args(default_args)
|
||||||
|
|
||||||
|
target = 'linode_api4.linode_client.LinodeGroup.instances'
|
||||||
|
with mock.patch(target, return_value=[]):
|
||||||
|
with pytest.raises(SystemExit):
|
||||||
|
target = 'linode_api4.linode_client.LinodeGroup.instance_create'
|
||||||
|
with mock.patch(target, return_value=(mock_linode, 'passw0rd')) as instance_create_mock:
|
||||||
|
linode_v4.main()
|
||||||
|
|
||||||
|
args, kwargs = instance_create_mock.call_args
|
||||||
|
assert kwargs['private_ip'] is True
|
||||||
|
|
||||||
|
|
||||||
def test_instance_already_created(default_args,
|
def test_instance_already_created(default_args,
|
||||||
mock_linode,
|
mock_linode,
|
||||||
capfd,
|
capfd,
|
||||||
|
|
Loading…
Reference in New Issue