Fix unused network_interfaces parameter

When using the boto_ec2.instance_present state module,
network_interfaces parameter was not used.
This commit is contained in:
Alex Zeleznikov 2018-04-21 17:26:29 +03:00
parent 8e21703f13
commit 1ece61ddfa

View file

@ -65,6 +65,7 @@ try:
import boto.ec2
# pylint: enable=unused-import
from boto.ec2.blockdevicemapping import BlockDeviceMapping, BlockDeviceType
from boto.ec2.networkinterface import NetworkInterfaceSpecification, NetworkInterfaceCollection
HAS_BOTO = True
except ImportError:
HAS_BOTO = False
@ -1003,14 +1004,19 @@ def run(image_id, name=None, tags=None, key_name=None, security_groups=None,
return False
security_group_ids += [r]
if all((network_interface_id, network_interface_name)):
raise SaltInvocationError('Only one of network_interface_id or '
'network_interface_name may be provided.')
network_interface_args = map(int, [network_interface_id is not None,
network_interface_name is not None,
network_interfaces is not None])
if sum(network_interface_args) > 1:
raise SaltInvocationError('Only one of network_interface_id, '
'network_interface_name or '
'network_interfaces may be provided.')
if network_interface_name:
result = get_network_interface_id(network_interface_name,
region=region, key=key,
keyid=keyid,
profile=profile)
region=region, key=key,
keyid=keyid,
profile=profile)
network_interface_id = result['result']
if not network_interface_id:
log.warning(
@ -1019,17 +1025,20 @@ def run(image_id, name=None, tags=None, key_name=None, security_groups=None,
)
if network_interface_id:
interface = boto.ec2.networkinterface.NetworkInterfaceSpecification(
interface = NetworkInterfaceSpecification(
network_interface_id=network_interface_id,
device_index=0
)
device_index=0)
else:
interface = boto.ec2.networkinterface.NetworkInterfaceSpecification(
interface = NetworkInterfaceSpecification(
subnet_id=subnet_id,
groups=security_group_ids,
device_index=0
)
interfaces = boto.ec2.networkinterface.NetworkInterfaceCollection(interface)
device_index=0)
if network_interfaces:
interfaces_specs = map(lambda x: NetworkInterfaceSpecification(**x), network_interfaces)
interfaces = NetworkInterfaceCollection(*interfaces_specs)
else:
interfaces = NetworkInterfaceCollection(interface)
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)