Beispiel #1
0
def asn_pool(module):

    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    # Check ID / Name and Content
    if margs['content'] is not None:

        content = content_to_dict(module, margs['content'])

        if 'display_name' in content.keys():
            item_name = content['display_name']
        else:
            module.fail_json(
                msg="Unable to extract 'display_name' from 'content'")

    elif margs['name'] is not None:
        item_name = margs['name']

    elif margs['id'] is not None:
        item_id = margs['id']

    # If ranges are provided, check if they are valid
    if 'ranges' in margs.keys():
        check_ranges_are_valid(module, margs['ranges'])

    # ----------------------------------------------------
    # Find Object if available based on ID or Name
    # ----------------------------------------------------
    try:
        my_pool = find_collection_item(aos.AsnPools,
                                       item_name=item_name,
                                       item_id=item_id)
    except:
        module.fail_json(
            msg=
            "Unable to find the IP Pool based on name or ID, something went wrong"
        )

    # ----------------------------------------------------
    # Proceed based on State value
    # ----------------------------------------------------
    if margs['state'] == 'absent':

        asn_pool_absent(module, aos, my_pool)

    elif margs['state'] == 'present':

        asn_pool_present(module, aos, my_pool)
Beispiel #2
0
def asn_pool(module):

    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    # Check ID / Name and Content
    if margs['content'] is not None:

        content = content_to_dict(module, margs['content'] )

        if 'display_name' in content.keys():
            item_name = content['display_name']
        else:
            module.fail_json(msg="Unable to extract 'display_name' from 'content'")

    elif margs['name'] is not None:
        item_name = margs['name']

    elif margs['id'] is not None:
        item_id = margs['id']

    # If ranges are provided, check if they are valid
    if 'ranges' in margs.keys():
        check_ranges_are_valid(module, margs['ranges'])

    # ----------------------------------------------------
    # Find Object if available based on ID or Name
    # ----------------------------------------------------
    try:
        my_pool = find_collection_item(aos.AsnPools,
                            item_name=item_name,
                            item_id=item_id)
    except:
        module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")

    # ----------------------------------------------------
    # Proceed based on State value
    # ----------------------------------------------------
    if margs['state'] == 'absent':

        asn_pool_absent(module, aos, my_pool)

    elif margs['state'] == 'present':

        asn_pool_present(module, aos, my_pool)
def ext_router(module):

    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    if margs['content'] is not None:

        content = content_to_dict(module, margs['content'])

        if 'display_name' in content.keys():
            item_name = content['display_name']
        else:
            module.fail_json(
                msg="Unable to extract 'display_name' from 'content'")

    elif margs['name'] is not None:
        item_name = margs['name']

    elif margs['id'] is not None:
        item_id = margs['id']

    #----------------------------------------------------
    # Find Object if available based on ID or Name
    #----------------------------------------------------
    try:
        my_ext_router = find_collection_item(aos.ExternalRouters,
                                             item_name=item_name,
                                             item_id=item_id)
    except:
        module.fail_json(
            msg=
            "Unable to find the IP Pool based on name or ID, something went wrong"
        )

    #----------------------------------------------------
    # Proceed based on State value
    #----------------------------------------------------
    if margs['state'] == 'absent':

        ext_router_absent(module, aos, my_ext_router)

    elif margs['state'] == 'present':

        ext_router_present(module, aos, my_ext_router)
Beispiel #4
0
def aos_device(module):
    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    if margs['id'] is not None:
        item_id = margs['id']

    elif margs['name'] is not None:
        item_name = margs['name']

    #----------------------------------------------------
    # Find Object if available based on ID or Name
    #----------------------------------------------------
    dev = find_collection_item(aos.Devices,
                               item_name=item_name,
                               item_id=item_id)

    if dev.exists is False:
        module.fail_json(msg="unknown device '%s'" % margs['name'])

    #----------------------------------------------------
    # Valid device state for reference
    #----------------------------------------------------
    # DEVICE_STATE_IS_ACTIVE = 1;
    # DEVICE_STATE_IS_READY = 2;
    # DEVICE_STATE_IS_NOCOMMS = 3;
    # DEVICE_STATE_IS_MAINT = 4;
    # DEVICE_STATE_IS_REBOOTING = 5;
    # DEVICE_STATE_OOS_STOCKED = 6;
    # DEVICE_STATE_OOS_QUARANTINED = 7;
    # DEVICE_STATE_OOS_READY = 8;
    # DEVICE_STATE_OOS_NOCOMMS = 9;
    # DEVICE_STATE_OOS_DECOMM = 10;
    # DEVICE_STATE_OOS_MAINT = 11;
    # DEVICE_STATE_OOS_REBOOTING = 12;
    # DEVICE_STATE_ERROR = 13;
    #----------------------------------------------------
    # State == Normal
    #----------------------------------------------------
    if margs['state'] == 'normal':
        aos_device_normal(module, aos, dev)
Beispiel #5
0
def aos_device(module):
    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    if margs['id'] is not None:
        item_id = margs['id']

    elif margs['name'] is not None:
        item_name = margs['name']

    #----------------------------------------------------
    # Find Object if available based on ID or Name
    #----------------------------------------------------
    dev = find_collection_item(aos.Devices,
                        item_name=item_name,
                        item_id=item_id)

    if dev.exists is False:
        module.fail_json(msg="unknown device '%s'" % margs['name'])

    #----------------------------------------------------
    # Valid device state for reference
    #----------------------------------------------------
        # DEVICE_STATE_IS_ACTIVE = 1;
        # DEVICE_STATE_IS_READY = 2;
        # DEVICE_STATE_IS_NOCOMMS = 3;
        # DEVICE_STATE_IS_MAINT = 4;
        # DEVICE_STATE_IS_REBOOTING = 5;
        # DEVICE_STATE_OOS_STOCKED = 6;
        # DEVICE_STATE_OOS_QUARANTINED = 7;
        # DEVICE_STATE_OOS_READY = 8;
        # DEVICE_STATE_OOS_NOCOMMS = 9;
        # DEVICE_STATE_OOS_DECOMM = 10;
        # DEVICE_STATE_OOS_MAINT = 11;
        # DEVICE_STATE_OOS_REBOOTING = 12;
        # DEVICE_STATE_ERROR = 13;
    #----------------------------------------------------
    # State == Normal
    #----------------------------------------------------
    if margs['state'] == 'normal':
        aos_device_normal(module, aos, dev)
Beispiel #6
0
def ip_pool(module):

    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    if margs['content'] is not None:

        content = content_to_dict(module, margs['content'] )

        if 'display_name' in content.keys():
            item_name = content['display_name']
        else:
            module.fail_json(msg="Unable to extract 'display_name' from 'content'")

    elif margs['name'] is not None:
        item_name = margs['name']

    elif margs['id'] is not None:
        item_id = margs['id']

    #----------------------------------------------------
    # Find Object if available based on ID or Name
    #----------------------------------------------------
    try:
        my_pool = find_collection_item(aos.IpPools,
                            item_name=item_name,
                            item_id=item_id)
    except:
        module.fail_json(msg="Unable to find the IP Pool based on name or ID, something went wrong")

    #----------------------------------------------------
    # Proceed based on State value
    #----------------------------------------------------
    if margs['state'] == 'absent':

        ip_pool_absent(module, aos, my_pool)

    elif margs['state'] == 'present':

        ip_pool_present(module, aos, my_pool)
Beispiel #7
0
def logical_device(module):

    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    if margs['content'] is not None:

        content = content_to_dict(module, margs['content'])

        if 'display_name' in content.keys():
            item_name = content['display_name']
        else:
            module.fail_json(
                msg="Unable to extract 'display_name' from 'content'")

    elif margs['name'] is not None:
        item_name = margs['name']

    elif margs['id'] is not None:
        item_id = margs['id']

    #----------------------------------------------------
    # Find Object if available based on ID or Name
    #----------------------------------------------------
    my_logical_dev = find_collection_item(aos.LogicalDevices,
                                          item_name=item_name,
                                          item_id=item_id)

    #----------------------------------------------------
    # Proceed based on State value
    #----------------------------------------------------
    if margs['state'] == 'absent':

        logical_device_absent(module, aos, my_logical_dev)

    elif margs['state'] == 'present':

        logical_device_present(module, aos, my_logical_dev)
Beispiel #8
0
def aos_blueprint(module):

    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    if margs['name'] is not None:
        item_name = margs['name']

    elif margs['id'] is not None:
        item_id = margs['id']

    #----------------------------------------------------
    # Find Object if available based on ID or Name
    #----------------------------------------------------
    try:
        my_blueprint = find_collection_item(aos.Blueprints,
                                            item_name=item_name,
                                            item_id=item_id)
    except:
        module.fail_json(
            msg=
            "Unable to find the Blueprint based on name or ID, something went wrong"
        )

    #----------------------------------------------------
    # Proceed based on State value
    #----------------------------------------------------
    if margs['state'] == 'absent':

        ensure_absent(module, aos, my_blueprint)

    elif margs['state'] == 'present':

        ensure_present(module, aos, my_blueprint)

    elif margs['state'] == 'build-ready':

        ensure_build_ready(module, aos, my_blueprint)
Beispiel #9
0
def aos_hardware(module):

    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except Exception as exc:
        module.fail_json(msg="Unable to login to the AOS server: %s" %
                         str(exc))

    item_name = False
    item_id = False

    if margs['content'] is not None:

        content = content_to_dict(module, margs['content'])

        if 'display_name' in content.keys():
            item_name = content['display_name']
        else:
            module.fail_json(
                msg="Unable to extract 'display_name' from 'content'")

    elif margs['name'] is not None:
        item_name = margs['name']

    elif margs['id'] is not None:
        item_id = margs['id']

    # ----------------------------------------------------
    # Find Object if available based on ID or Name
    # ----------------------------------------------------

    item = find_collection_item(aos.Hardware,
                                item_name=item_name,
                                item_id=item_id)

    # ----------------------------------------------------
    # Proceed based on State value
    # ----------------------------------------------------

    if margs['state'] == 'absent':
        item_absent(module, item)
    elif margs['state'] == 'present':
        item_present(module, item)
Beispiel #10
0
def rack_type(module):

    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    if margs['content'] is not None:

        content = content_to_dict(module, margs['content'] )

        if 'display_name' in content.keys():
            item_name = content['display_name']
        else:
            module.fail_json(msg="Unable to extract 'display_name' from 'content'")

    elif margs['name'] is not None:
        item_name = margs['name']

    elif margs['id'] is not None:
        item_id = margs['id']

    #----------------------------------------------------
    # Find Object if available based on ID or Name
    #----------------------------------------------------
    my_rack_type = find_collection_item(aos.RackTypes,
                                          item_name=item_name,
                                          item_id=item_id)

    #----------------------------------------------------
    # Proceed based on State value
    #----------------------------------------------------
    if margs['state'] == 'absent':

        rack_type_absent(module, aos, my_rack_type)

    elif margs['state'] == 'present':

        rack_type_present(module, aos, my_rack_type)
Beispiel #11
0
def aos_blueprint(module):

    margs = module.params

    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    item_name = False
    item_id = False

    if margs['name'] is not None:
        item_name = margs['name']

    elif margs['id'] is not None:
        item_id = margs['id']

    #----------------------------------------------------
    # Find Object if available based on ID or Name
    #----------------------------------------------------
    try:
        my_blueprint = find_collection_item(aos.Blueprints,
                                        item_name=item_name,
                                        item_id=item_id)
    except:
        module.fail_json(msg="Unable to find the Blueprint based on name or ID, something went wrong")

    #----------------------------------------------------
    # Proceed based on State value
    #----------------------------------------------------
    if margs['state'] == 'absent':

        ensure_absent(module, aos, my_blueprint)

    elif margs['state'] == 'present':

        ensure_present(module, aos, my_blueprint)

    elif margs['state'] == 'build-ready':

        ensure_build_ready(module, aos, my_blueprint)
Beispiel #12
0
def blueprint_virtnet(module):

    margs = module.params

    # --------------------------------------------------------------------
    # Get AOS session object based on Session Info
    # --------------------------------------------------------------------
    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    # --------------------------------------------------------------------
    # Get the blueprint Object based on either name or ID
    # --------------------------------------------------------------------
    try:
        blueprint = find_collection_item(aos.Blueprints,
                                         item_name=margs['blueprint'],
                                         item_id=margs['blueprint'])
    except:
        module.fail_json(
            msg=
            "Unable to find the Blueprint based on name or ID, something went wrong"
        )

    if blueprint.exists is False:
        module.fail_json(msg='Blueprint %s does not exist.\n'
                         'known blueprints are [%s]' %
                         (margs['blueprint'], ','.join(aos.Blueprints.names)))

    # --------------------------------------------------------------------
    # Convert "content" to dict and extract name
    # --------------------------------------------------------------------
    if margs['content'] is not None:

        content = content_to_dict(module, margs['content'])

        if 'display_name' in content.keys():
            item_name = content['display_name']
        else:
            module.fail_json(
                msg="Unable to extract 'display_name' from 'content'")

    elif margs['name'] is not None:
        item_name = margs['name']

    # --------------------------------------------------------------------
    # Try to find VirtualNetwork object
    # --------------------------------------------------------------------
    try:
        virtnet = blueprint.VirtualNetworks[item_name]
    except:
        module.fail_json(
            msg=
            "Something went wrong while trying to find Virtual Network %s in blueprint %s"
            % (item_name, blueprint.name))

    # --------------------------------------------------------------------
    # Proceed based on State value
    # --------------------------------------------------------------------
    if margs['state'] == 'absent':

        ensure_absent(module, aos, blueprint, virtnet)

    elif margs['state'] == 'present':

        ensure_present(module, aos, blueprint, virtnet)
def blueprint_param(module):

    margs = module.params

    # --------------------------------------------------------------------
    # Get AOS session object based on Session Info
    # --------------------------------------------------------------------
    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    # --------------------------------------------------------------------
    # Get the blueprint Object based on either name or ID
    # --------------------------------------------------------------------
    try:
        blueprint = find_collection_item(aos.Blueprints,
                                         item_name=margs['blueprint'],
                                         item_id=margs['blueprint'])
    except:
        module.fail_json(
            msg=
            "Unable to find the Blueprint based on name or ID, something went wrong"
        )

    if blueprint.exists is False:
        module.fail_json(msg='Blueprint %s does not exist.\n'
                         'known blueprints are [%s]' %
                         (margs['blueprint'], ','.join(aos.Blueprints.names)))

    # --------------------------------------------------------------------
    # If get_param_list is defined, build the list of supported parameters
    # and extract info for each
    # --------------------------------------------------------------------
    if margs['get_param_list']:

        params_list = {}
        for param in blueprint.params.names:
            params_list[param] = blueprint.params[param].info

        module.exit_json(changed=False,
                         blueprint=blueprint.name,
                         params_list=params_list)

    # --------------------------------------------------------------------
    # Check Param name, return an error if not supported by this blueprint
    # --------------------------------------------------------------------
    if margs['name'] in blueprint.params.names:
        param = blueprint.params[margs['name']]
    else:
        module.fail_json(msg='unable to access param %s' % margs['name'])

    # --------------------------------------------------------------------
    # Check if param_value needs to be converted to an object
    # based on param_map
    # --------------------------------------------------------------------
    param_value = margs['value']
    param_collection = get_collection_from_param_map(module, aos)

    # If a collection is find and param_value is defined,
    #   convert param_value into an object
    if param_collection and param_value:
        param_value = param_collection.from_label(param_value)

    # --------------------------------------------------------------------
    # Proceed based on State value
    # --------------------------------------------------------------------
    if margs['state'] == 'absent':

        blueprint_param_absent(module, aos, blueprint, param, param_value)

    elif margs['state'] == 'present':

        blueprint_param_present(module, aos, blueprint, param, param_value)
Beispiel #14
0
def blueprint_param(module):

    margs = module.params

    # --------------------------------------------------------------------
    # Get AOS session object based on Session Info
    # --------------------------------------------------------------------
    try:
        aos = get_aos_session(module, margs['session'])
    except:
        module.fail_json(msg="Unable to login to the AOS server")

    # --------------------------------------------------------------------
    # Get the blueprint Object based on either name or ID
    # --------------------------------------------------------------------
    try:
        blueprint = find_collection_item(aos.Blueprints,
                                        item_name=margs['blueprint'],
                                        item_id=margs['blueprint'])
    except:
        module.fail_json(msg="Unable to find the Blueprint based on name or ID, something went wrong")

    if blueprint.exists is False:
        module.fail_json(msg='Blueprint %s does not exist.\n'
                             'known blueprints are [%s]'%
                             (margs['blueprint'],','.join(aos.Blueprints.names)))

    # --------------------------------------------------------------------
    # If get_param_list is defined, build the list of supported parameters
    # and extract info for each
    # --------------------------------------------------------------------
    if margs['get_param_list']:

        params_list = {}
        for param in blueprint.params.names:
            params_list[param] = blueprint.params[param].info

        module.exit_json(changed=False,
                         blueprint= blueprint.name,
                         params_list=params_list )

    # --------------------------------------------------------------------
    # Check Param name, return an error if not supported by this blueprint
    # --------------------------------------------------------------------
    if margs['name'] in blueprint.params.names:
        param = blueprint.params[margs['name']]
    else:
        module.fail_json(msg='unable to access param %s' % margs['name'] )

    # --------------------------------------------------------------------
    # Check if param_value needs to be converted to an object
    # based on param_map
    # --------------------------------------------------------------------
    param_value = margs['value']
    param_collection = get_collection_from_param_map(module, aos)

    # If a collection is find and param_value is defined,
    #   convert param_value into an object
    if param_collection and param_value:
        param_value = param_collection.from_label(param_value)

    # --------------------------------------------------------------------
    # Proceed based on State value
    # --------------------------------------------------------------------
    if margs['state'] == 'absent':

        blueprint_param_absent(module, aos, blueprint, param, param_value)

    elif margs['state'] == 'present':

        blueprint_param_present(module, aos, blueprint, param, param_value)