ec2_vpn_gateway.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:f5-aws-vpn 作者: f5devcentral 项目源码 文件源码
def main():
    argument_spec = ec2_argument_spec()
    argument_spec.update(dict(
            state={ 'required': True, 'choices': ['present', 'absent'] },
            id={ 'default': None, 'required': False, 'type': 'str' },
            type={ 'default': 'ipsec.1', 'required': False, 'type': 'str' },
            availability_zone={ 'default': None, 'required': False, 'type': 'str' },
            vpc={ 'default': None, 'required': False, 'type': 'str'},
            route_table_ids={ 'default': None, 'required': False, 'type': 'list' },
            tags={ 'required': True, 'type': 'dict' }
        )
    )

    module = AnsibleModule(
        argument_spec=argument_spec,
    )


    region, ec2_url, aws_connect_params = get_aws_connection_info(module)


    state = module.params['state']
    id = module.params['id']
    type = module.params['type']
    availability_zone = module.params['availability_zone']
    vpc = module.params['vpc']
    route_table_ids = module.params['route_table_ids']
    tags = module.params['tags']


    if not region:
        module.fail_json(msg="Region must be specified as a parameter, in EC2_REGION or AWS_REGION environment variables or in boto configuration file")


    vpn_gw_man = VPNGatewayManager( module, id, type, availability_zone, vpc, route_table_ids, tags,
                                    region, **aws_connect_params )

    if state == 'present':
        if route_table_ids and vpn_gw_man.vpn_gw:
            vpn_gw_man._enable_route_propagation()
        else: 
            vpn_gw_man.ensure_ok()

    if state == 'absent':
        if route_table_ids and vpn_gw_man.vpn_gw:
            vpn_gw_man._disable_route_propagation()
        else: 
            vpn_gw_man.ensure_gone()


    ansible_facts = {'ec2_vpn_gateway': 'info'}
    ec2_facts_result = dict(changed=vpn_gw_man.changed,
                            vpn_gw=vpn_gw_man.get_info(),
                            ansible_facts=ansible_facts)

    module.exit_json(**ec2_facts_result)

# import module snippets
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号