Change attached parameter default to None

This commit is contained in:
Filipe Niero Felisbino 2016-06-15 10:49:29 -03:00
parent c81e88856a
commit 753ddf87ac

View file

@ -18,8 +18,9 @@ DOCUMENTATION = '''
module: ec2_eni module: ec2_eni
short_description: Create and optionally attach an Elastic Network Interface (ENI) to an instance short_description: Create and optionally attach an Elastic Network Interface (ENI) to an instance
description: description:
- Create and optionally attach an Elastic Network Interface (ENI) to an instance. If an ENI ID is provided, \ - Create and optionally attach an Elastic Network Interface (ENI) to an instance. If an ENI ID or private_ip is \
an attempt is made to update the existing ENI. By passing state=detached, an ENI can be detached from its instance. provided, the existing ENI (if any) will be modified. The 'attached' parameter controls the attachment status \
of the network interface.
version_added: "2.0" version_added: "2.0"
author: "Rob White (@wimnat)" author: "Rob White (@wimnat)"
options: options:
@ -30,8 +31,8 @@ options:
default: null default: null
instance_id: instance_id:
description: description:
- Instance ID that you wish to attach ENI to, if None the new ENI will be created in detached state, existing \ - Instance ID that you wish to attach ENI to. Since version 2.2, use the 'attached' parameter to attach or \
ENI will keep current attachment state. detach an ENI. Prior to 2.2, to detach an ENI from an instance, use 'None'.
required: false required: false
default: null default: null
private_ip_address: private_ip_address:
@ -67,8 +68,8 @@ options:
default: 0 default: 0
attached: attached:
description: description:
- Specifies if network interface should be attached or detached from instance. If attached=yes and no \ - Specifies if network interface should be attached or detached from instance. If ommited, attachment status \
instance_id is given, attachment status won't change won't change
required: false required: false
default: yes default: yes
version_added: 2.2 version_added: 2.2
@ -306,7 +307,7 @@ def create_eni(connection, vpc_id, module):
eni = find_eni(connection, module) eni = find_eni(connection, module)
if eni is None: if eni is None:
eni = connection.create_network_interface(subnet_id, private_ip_address, description, security_groups) eni = connection.create_network_interface(subnet_id, private_ip_address, description, security_groups)
if attached and instance_id is not None: if attached == True and instance_id is not None:
try: try:
eni.attach(instance_id, device_index) eni.attach(instance_id, device_index)
except BotoServerError: except BotoServerError:
@ -389,12 +390,11 @@ def modify_eni(connection, vpc_id, module, eni):
secondary_addresses_to_remove_count = current_secondary_address_count - secondary_private_ip_address_count secondary_addresses_to_remove_count = current_secondary_address_count - secondary_private_ip_address_count
connection.unassign_private_ip_addresses(network_interface_id=eni.id, private_ip_addresses=current_secondary_addresses[:secondary_addresses_to_remove_count], dry_run=False) connection.unassign_private_ip_addresses(network_interface_id=eni.id, private_ip_addresses=current_secondary_addresses[:secondary_addresses_to_remove_count], dry_run=False)
if attached: if attached == True and instance_id is not None:
if instance_id is not None:
eni.attach(instance_id, device_index) eni.attach(instance_id, device_index)
wait_for_eni(eni, "attached") wait_for_eni(eni, "attached")
changed = True changed = True
else: elif attached == False:
detach_eni(eni, module) detach_eni(eni, module)
except BotoServerError as e: except BotoServerError as e:
@ -506,7 +506,7 @@ def main():
delete_on_termination=dict(default=None, type='bool'), delete_on_termination=dict(default=None, type='bool'),
secondary_private_ip_addresses=dict(default=None, type='list'), secondary_private_ip_addresses=dict(default=None, type='list'),
secondary_private_ip_address_count=dict(default=None, type='int'), secondary_private_ip_address_count=dict(default=None, type='int'),
attached=dict(default=True, type='bool') attached=dict(default=None, type='bool')
) )
) )
@ -516,7 +516,8 @@ def main():
], ],
required_if=([ required_if=([
('state', 'present', ['subnet_id']), ('state', 'present', ['subnet_id']),
('state', 'absent', ['eni_id']) ('state', 'absent', ['eni_id']),
('attached', True, ['instance_id'])
]) ])
) )