Пример #1
0
def vpc_needs_update(module, vpc, vpc_id, dns_support, dns_hostnames, dhcp_id,
                     tags):
    """This returns True or False. Intended to run after vpc_exists.
    It will check all the characteristics of the parameters passed and compare them
    to the active VPC. If any discrepancy is found, it will report true, meaning that
    the VPC needs to be update in order to match the specified state in the params.
    """

    update_dhcp = False
    update_tags = False
    dhcp_match = False

    try:
        dhcp_list = vpc.get_all_dhcp_options()

        if dhcp_id is not None:
            has_default = vpc.get_all_vpcs(filters={
                'dhcp-options-id': 'default',
                'vpc-id': vpc_id
            })
            for opts in dhcp_list:
                if (str(opts).split(':')[1] == dhcp_id) or has_default:
                    dhcp_match = True
                    break
                else:
                    pass
    except Exception, e:
        e_msg = boto_exception(e)
        module.fail_json(msg=e_msg)

        if not dhcp_match or (has_default and dhcp_id != 'default'):
            update_dhcp = True
Пример #2
0
def update_dhcp_opts(module, vpc, vpc_id, dhcp_id):
    try:
        vpc.associate_dhcp_options(dhcp_id, vpc_id)
        dhcp_list = vpc.get_all_dhcp_options()
    except Exception, e:
        e_msg = boto_exception(e)
        module.fail_json(msg=e_msg)
Пример #3
0
        module.fail_json(msg=str(e))

    already_exists, vpc_id = vpc_exists(module, vpc, name, cidr_block, multi)

    if already_exists:
        update_dhcp, update_tags = vpc_needs_update(module, vpc, vpc_id,
                                                    dns_support, dns_hostnames,
                                                    dhcp_id, tags)
        if update_dhcp or update_tags:
            changed = True

        try:
            e_tags = dict(
                (t.name, t.value)
                for t in vpc.get_all_tags(filters={'resource-id': vpc_id}))
            dhcp_list = vpc.get_all_dhcp_options()
            has_default = vpc.get_all_vpcs(filters={
                'dhcp-options-id': 'default',
                'vpc-id': vpc_id
            })
        except Exception, e:
            e_msg = boto_exception(e)
            module.fail_json(msg=e_msg)

        dhcp_opts = None

        try:
            for opts in dhcp_list:
                if vpc.get_all_vpcs(filters={
                        'dhcp-options-id': opts,
                        'vpc-id': vpc_id