From 33dd8a48f3a0d0d6a8af7fcc538ae424cf71c83f Mon Sep 17 00:00:00 2001 From: Michal Bicz Date: Fri, 24 Oct 2014 22:57:34 -0700 Subject: [PATCH 1/2] module that gathers vpc properties, returns dict --- salt/modules/boto_vpc.py | 46 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/salt/modules/boto_vpc.py b/salt/modules/boto_vpc.py index 4c802b46db..b999f3cfaa 100644 --- a/salt/modules/boto_vpc.py +++ b/salt/modules/boto_vpc.py @@ -1209,6 +1209,52 @@ def _get_conn(region, key, keyid, profile): return conn +def describe(vpc_id=None, region=None, key=None, keyid=None, profile=None): + ''' + Given a VPC ID describe it's properties. + + Returns a dictionary of interesting properties. + CLI example:: + + .. code-block:: bash + + salt myminion boto_vpc.describe vpc_id=vpc-123456 + + ''' + conn = _get_conn(region, key, keyid, profile) + _ret = dict(cidr_block=None, + is_default=None, + state=None, + tags=None, + dhcp_options_id=None, + instance_tenancy=None + ) + + + if not conn: + return False + + if not vpc_id: + raise SaltInvocationError( + 'VPC ID needs to be specified.') + + try: + filter_parameters = {'filters': {'vpc-id': vpc_id}} + + vpcs = conn.get_all_vpcs(**filter_parameters) + + if vpcs: + vpc = vpcs[0] # Found! + log.debug('Found VPC: {0}'.format(vpc.id)) + for k in _ret.keys(): + _ret[k] = getattr(vpc,k) + return _ret + + except boto.exception.BotoServerError as e: + log.error(e) + return False + + def _create_dhcp_options(conn, domain_name=None, domain_name_servers=None, ntp_servers=None, netbios_name_servers=None, netbios_node_type=None): return conn.create_dhcp_options(domain_name=domain_name, domain_name_servers=domain_name_servers, From 333c477071ea2b9d0ce517f50aa4744a2921c4ca Mon Sep 17 00:00:00 2001 From: Thomas S Hatch Date: Thu, 30 Oct 2014 10:06:04 -0600 Subject: [PATCH 2/2] minor lint fixes --- salt/modules/boto_vpc.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/salt/modules/boto_vpc.py b/salt/modules/boto_vpc.py index b999f3cfaa..35039d755b 100644 --- a/salt/modules/boto_vpc.py +++ b/salt/modules/boto_vpc.py @@ -1230,7 +1230,6 @@ def describe(vpc_id=None, region=None, key=None, keyid=None, profile=None): instance_tenancy=None ) - if not conn: return False @@ -1244,10 +1243,10 @@ def describe(vpc_id=None, region=None, key=None, keyid=None, profile=None): vpcs = conn.get_all_vpcs(**filter_parameters) if vpcs: - vpc = vpcs[0] # Found! + vpc = vpcs[0] # Found! log.debug('Found VPC: {0}'.format(vpc.id)) for k in _ret.keys(): - _ret[k] = getattr(vpc,k) + _ret[k] = getattr(vpc, k) return _ret except boto.exception.BotoServerError as e: