def template_present(module, aos, my_template):

    margs = module.params

    # if content is defined, create object from Content

    if margs['content'] is not None:

        if 'display_name' in module.params['content'].keys():
            do_load_resource(module, aos.DesignTemplates,
                             module.params['content']['display_name'])
        else:
            module.fail_json(
                msg="Unable to find display_name in 'content', Mandatory")

    # if template doesn't exist already, create a new one
    if my_template.exists is False and 'content' not in margs.keys():
        module.fail_json(
            msg="'content' is mandatory for module that don't exist currently")

    # if module already exist, just return it
    module.exit_json(changed=False,
                     name=my_template.name,
                     id=my_template.id,
                     value=my_template.value)
Esempio n. 2
0
def ip_pool_present(module, aos, my_pool):

    margs = module.params

    # if content is defined, create object from Content
    try:
        if margs['content'] is not None:

            if 'display_name' in module.params['content'].keys():
                do_load_resource(module, aos.IpPools,
                                 module.params['content']['display_name'])
            else:
                module.fail_json(
                    msg="Unable to find display_name in 'content', Mandatory")

    except:
        module.fail_json(
            msg="Unable to load resource from content, something went wrong")

    # if ip_pool doesn't exist already, create a new one

    if my_pool.exists is False and 'name' not in margs.keys():
        module.fail_json(
            msg="Name is mandatory for module that don't exist currently")

    elif my_pool.exists is False:

        if not module.check_mode:
            try:
                my_new_pool = create_new_ip_pool(my_pool, margs['name'],
                                                 margs['subnets'])
                my_pool = my_new_pool
            except:
                module.fail_json(
                    msg=
                    "An error occurred while trying to create a new IP Pool ")

        module.exit_json(changed=True,
                         name=my_pool.name,
                         id=my_pool.id,
                         value=my_pool.value)

    # if pool already exist, check if list of network is the same
    # if same just return the object and report change false
    if set(get_list_of_subnets(my_pool)) == set(margs['subnets']):
        module.exit_json(changed=False,
                         name=my_pool.name,
                         id=my_pool.id,
                         value=my_pool.value)
    else:
        module.fail_json(
            msg=
            "ip_pool already exist but value is different, currently not supported to update a module"
        )
Esempio n. 3
0
def asn_pool_present(module, aos, my_pool):

    margs = module.params

    # if content is defined, create object from Content
    if margs['content'] is not None:

        if 'display_name' in module.params['content'].keys():
            do_load_resource(module, aos.AsnPools,
                             module.params['content']['display_name'])
        else:
            module.fail_json(
                msg="Unable to find display_name in 'content', Mandatory")

    # if asn_pool doesn't exist already, create a new one
    if my_pool.exists is False and 'name' not in margs.keys():
        module.fail_json(
            msg="name is mandatory for module that don't exist currently")

    elif my_pool.exists is False:

        if not module.check_mode:
            try:
                my_new_pool = create_new_asn_pool(my_pool, margs['name'],
                                                  margs['ranges'])
                my_pool = my_new_pool
            except:
                module.fail_json(
                    msg=
                    "An error occured while trying to create a new ASN Pool ")

        module.exit_json(changed=True,
                         name=my_pool.name,
                         id=my_pool.id,
                         value=my_pool.value)

    # Currently only check if the pool exist or not
    #    if exist return change false
    #
    # Later it would be good to check if the list of ASN are same
    # if pool already exist, check if list of ASN is the same
    # if same just return the object and report change false
    # if set(get_list_of_range(my_pool)) == set(margs['ranges']):
    module.exit_json(changed=False,
                     name=my_pool.name,
                     id=my_pool.id,
                     value=my_pool.value)
Esempio n. 4
0
def ip_pool_present(module, aos, my_pool):

    margs = module.params

    # if content is defined, create object from Content
    try:
        if margs['content'] is not None:

            if 'display_name' in module.params['content'].keys():
                do_load_resource(module, aos.IpPools, module.params['content']['display_name'])
            else:
                module.fail_json(msg="Unable to find display_name in 'content', Mandatory")

    except:
        module.fail_json(msg="Unable to load resource from content, something went wrong")

    # if ip_pool doesn't exist already, create a new one

    if my_pool.exists is False and 'name' not in margs.keys():
        module.fail_json(msg="Name is mandatory for module that don't exist currently")

    elif my_pool.exists is False:

        if not module.check_mode:
            try:
                my_new_pool = create_new_ip_pool(my_pool, margs['name'], margs['subnets'])
                my_pool = my_new_pool
            except:
                module.fail_json(msg="An error occurred while trying to create a new IP Pool ")

        module.exit_json( changed=True,
                          name=my_pool.name,
                          id=my_pool.id,
                          value=my_pool.value )

    # if pool already exist, check if list of network is the same
    # if same just return the object and report change false
    if set(get_list_of_subnets(my_pool)) == set(margs['subnets']):
        module.exit_json( changed=False,
                          name=my_pool.name,
                          id=my_pool.id,
                          value=my_pool.value )
    else:
        module.fail_json(msg="ip_pool already exist but value is different, currently not supported to update a module")
Esempio n. 5
0
def logical_device_present(module, aos, my_logical_dev):

    margs = module.params

    if margs['content'] is not None:

        if 'display_name' in module.params['content'].keys():
            do_load_resource(module, aos.LogicalDevices, module.params['content']['display_name'])
        else:
            module.fail_json(msg="Unable to find display_name in 'content', Mandatory")

    # if logical_device doesn't exist already, create a new one
    if my_logical_dev.exists is False and 'content' not in margs.keys():
        module.fail_json(msg="'content' is mandatory for module that don't exist currently")

    module.exit_json( changed=False,
                      name=my_logical_dev.name,
                      id=my_logical_dev.id,
                      value=my_logical_dev.value )
Esempio n. 6
0
def rack_type_present(module, aos, my_rack_type):

    margs = module.params

    if margs['content'] is not None:

        if 'display_name' in module.params['content'].keys():
            do_load_resource(module, aos.RackTypes, module.params['content']['display_name'])
        else:
            module.fail_json(msg="Unable to find display_name in 'content', Mandatory")

    # if rack_type doesn't exist already, create a new one
    if my_rack_type.exists is False and 'content' not in margs.keys():
        module.fail_json(msg="'content' is mandatory for module that don't exist currently")

    module.exit_json( changed=False,
                      name=my_rack_type.name,
                      id=my_rack_type.id,
                      value=my_rack_type.value )
Esempio n. 7
0
def asn_pool_present(module, aos, my_pool):

    margs = module.params

    # if content is defined, create object from Content
    if margs['content'] is not None:

        if 'display_name' in module.params['content'].keys():
            do_load_resource(module, aos.AsnPools, module.params['content']['display_name'])
        else:
            module.fail_json(msg="Unable to find display_name in 'content', Mandatory")

    # if asn_pool doesn't exist already, create a new one
    if my_pool.exists is False and 'name' not in margs.keys():
        module.fail_json(msg="name is mandatory for module that don't exist currently")

    elif my_pool.exists is False:

        if not module.check_mode:
            try:
                my_new_pool = create_new_asn_pool(my_pool, margs['name'], margs['ranges'])
                my_pool = my_new_pool
            except:
                module.fail_json(msg="An error occurred while trying to create a new ASN Pool ")

        module.exit_json( changed=True,
                          name=my_pool.name,
                          id=my_pool.id,
                          value=my_pool.value )

    # Currently only check if the pool exist or not
    #    if exist return change false
    #
    # Later it would be good to check if the list of ASN are same
    # if pool already exist, check if list of ASN is the same
    # if same just return the object and report change false
    # if set(get_list_of_range(my_pool)) == set(margs['ranges']):
    module.exit_json( changed=False,
                      name=my_pool.name,
                      id=my_pool.id,
                      value=my_pool.value )
Esempio n. 8
0
def logical_device_map_present(module, aos, my_log_dev_map):

    margs = module.params

    # if content is defined, create object from Content
    if margs['content'] is not None:

        if 'display_name' in module.params['content'].keys():
            do_load_resource(module, aos.LogicalDeviceMaps, module.params['content']['display_name'])
        else:
            module.fail_json(msg="Unable to find display_name in 'content', Mandatory")

    # if my_log_dev_map doesn't exist already, create a new one

    if my_log_dev_map.exists is False and 'content' not in margs.keys():
        module.fail_json(msg="'Content' is mandatory for module that don't exist currently")

    module.exit_json( changed=False,
                      name=my_log_dev_map.name,
                      id=my_log_dev_map.id,
                      value=my_log_dev_map.value )
Esempio n. 9
0
def item_present(module, item):

    margs = module.params

    if margs['content'] is not None:

        if 'display_name' in module.params['content'].keys():
            do_load_resource(module, item.collection,
                             module.params['content']['display_name'])
        else:
            module.fail_json(
                msg="Unable to find display_name in 'content', Mandatory")

    # if item doesn't exist already, create a new one

    if item.exists is False and 'content' not in margs.keys():
        module.fail_json(
            msg="'content' is mandatory for module that don't exist currently")

    module.exit_json(changed=False,
                     name=item.name,
                     id=item.id,
                     value=item.value)
def ext_router_present(module, aos, my_ext_router):

    margs = module.params

    # if content is defined, create object from Content
    if my_ext_router.exists is False and margs['content'] is not None:
        do_load_resource(module, aos.ExternalRouters,
                         module.params['content']['display_name'])

    # if my_ext_router doesn't exist already, create a new one
    if my_ext_router.exists is False and margs['name'] is None:
        module.fail_json(
            msg="Name is mandatory for module that don't exist currently")

    elif my_ext_router.exists is False:

        if not module.check_mode:
            try:
                my_new_ext_router = create_new_ext_router(
                    module, my_ext_router, margs['name'], margs['loopback'],
                    margs['asn'])
                my_ext_router = my_new_ext_router
            except:
                module.fail_json(
                    msg=
                    "An error occurred while trying to create a new External Router"
                )

        module.exit_json(changed=True,
                         name=my_ext_router.name,
                         id=my_ext_router.id,
                         value=my_ext_router.value)

    # if external Router already exist, check if loopback and ASN are the same
    # if same just return the object and report change false
    loopback = None
    asn = None

    # Identify the Loopback, parameter 'loopback' has priority over 'content'
    if margs['loopback'] is not None:
        loopback = margs['loopback']
    elif margs['content'] is not None:
        if 'address' in margs['content'].keys():
            loopback = margs['content']['address']

    # Identify the ASN, parameter 'asn' has priority over 'content'
    if margs['asn'] is not None:
        asn = margs['asn']
    elif margs['content'] is not None:
        if 'asn' in margs['content'].keys():
            asn = margs['content']['asn']

    # Compare Loopback and ASN if defined
    if loopback is not None:
        if loopback != my_ext_router.value['address']:
            module.fail_json(
                msg=
                "my_ext_router already exist but Loopback is different, currently not supported to update a module"
            )

    if asn is not None:
        if int(asn) != int(my_ext_router.value['asn']):
            module.fail_json(
                msg=
                "my_ext_router already exist but ASN is different, currently not supported to update a module"
            )

    module.exit_json(changed=False,
                     name=my_ext_router.name,
                     id=my_ext_router.id,
                     value=my_ext_router.value)
Esempio n. 11
0
def ext_router_present(module, aos, my_ext_router):

    margs = module.params

    # if content is defined, create object from Content
    if my_ext_router.exists is False and margs['content'] is not None:
        do_load_resource(module, aos.ExternalRouters, module.params['content']['display_name'])

    # if my_ext_router doesn't exist already, create a new one
    if my_ext_router.exists is False and margs['name'] is None:
        module.fail_json(msg="Name is mandatory for module that don't exist currently")

    elif my_ext_router.exists is False:

        if not module.check_mode:
            try:
                my_new_ext_router = create_new_ext_router(module,
                                                          my_ext_router,
                                                          margs['name'],
                                                          margs['loopback'],
                                                          margs['asn'] )
                my_ext_router = my_new_ext_router
            except:
                module.fail_json(msg="An error occurred while trying to create a new External Router")


        module.exit_json( changed=True,
                          name=my_ext_router.name,
                          id=my_ext_router.id,
                          value=my_ext_router.value )

    # if external Router already exist, check if loopback and ASN are the same
    # if same just return the object and report change false
    loopback = None
    asn = None

    # Identify the Loopback, parameter 'loopback' has priority over 'content'
    if margs['loopback'] is not None:
        loopback = margs['loopback']
    elif margs['content'] is not None:
        if 'address' in margs['content'].keys():
            loopback = margs['content']['address']

    # Identify the ASN, parameter 'asn' has priority over 'content'
    if margs['asn'] is not None:
        asn = margs['asn']
    elif margs['content'] is not None:
        if 'asn' in margs['content'].keys():
            asn = margs['content']['asn']

    # Compare Loopback and ASN if defined
    if loopback is not None:
        if loopback != my_ext_router.value['address']:
            module.fail_json(msg="my_ext_router already exist but Loopback is different, currently not supported to update a module")

    if asn is not None:
        if int(asn) != int(my_ext_router.value['asn']):
            module.fail_json(msg="my_ext_router already exist but ASN is different, currently not supported to update a module")

    module.exit_json( changed=False,
                      name=my_ext_router.name,
                      id=my_ext_router.id,
                      value=my_ext_router.value )