-
-
Save scoates/8d229802dcfd7532c135 to your computer and use it in GitHub Desktop.
_states/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
''' | |
TODO | |
''' | |
# Import Python Libs | |
from __future__ import absolute_import | |
import logging | |
log = logging.getLogger(__name__) | |
def __virtual__(): | |
''' | |
Only load if boto is available. | |
(We use VPC here because it's already available if this is going to work.) | |
''' | |
return 'boto_fk' if 'boto_vpc.exists' in __salt__ else False | |
def subnet_public_ips(name, subnet_id=None, vpc_name=None, vpc_id=None, | |
region=None, key=None, keyid=None, profile=None): | |
''' | |
Ensure subnet has 'Auto Assign Public IP' turned on | |
name | |
Name of the VPC. | |
region | |
Region to connect to. | |
key | |
Secret key to be used. | |
keyid | |
Access key to be used. | |
profile | |
A dict with region, key and keyid, or a pillar key (string) that | |
contains a dict with region, key and keyid. | |
''' | |
# import needs to be here because of __context__ | |
from salt.utils import boto | |
ret = {'name': name, | |
'result': True, | |
'comment': '', | |
'changes': {} | |
} | |
if vpc_id is None: | |
vpc_id = __salt__['boto_vpc.check_vpc'](vpc_name=vpc_name) | |
if not vpc_id: | |
ret['result'] = False | |
ret['comment'] = 'Could not find VPC: id={} name={}'.format(vpc_id, vpc_name) | |
return ret | |
if subnet_id is None: | |
subnets_desc = __salt__['boto_vpc.describe_subnets']( | |
subnet_names=name, | |
vpc_id=vpc_id | |
) | |
if not subnets_desc: | |
ret['result'] = False | |
ret['comment'] = 'Could not find subnet: name={}'.format(name) | |
return ret | |
subnet_id = subnets_desc['subnets'][0]['id'] | |
# temporary hack to bypass __opts__ | |
region = 'x' | |
key = 'x' | |
keyid = 'x' | |
ec2_conn = boto.get_connection('ec2', region=region, key=key, keyid=keyid, profile=profile) | |
orig_api_version = ec2_conn.APIVersion | |
ec2_conn.APIVersion = '2014-06-15' | |
ret['result'] = ec2_conn.get_status( | |
'ModifySubnetAttribute', | |
{'SubnetId': subnet_id, 'MapPublicIpOnLaunch.Value': 'true'}, | |
verb='POST') | |
ec2_conn.APIVersion = orig_api_version | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results in