mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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>
This commit is contained in:
parent
1400051890
commit
f9e3e229dd
3 changed files with 60 additions and 0 deletions
|
@ -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
|
||||
method for marking instances is to use tags.
|
||||
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:
|
||||
description:
|
||||
- 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),
|
||||
group=dict(type='str'),
|
||||
image=dict(type='str'),
|
||||
private_ip=dict(type='bool', default=False),
|
||||
region=dict(type='str'),
|
||||
root_pass=dict(type='str', no_log=True),
|
||||
tags=dict(type='list', elements='str'),
|
||||
|
@ -283,6 +291,7 @@ def main():
|
|||
group=module.params['group'],
|
||||
image=module.params['image'],
|
||||
label=module.params['label'],
|
||||
private_ip=module.params['private_ip'],
|
||||
region=module.params['region'],
|
||||
root_pass=module.params['root_pass'],
|
||||
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,
|
||||
mock_linode,
|
||||
capfd,
|
||||
|
|
Loading…
Reference in a new issue