Пример #1
0
def getorgactionbatch(cmd_args):
    apikey = cmd_args['apikey'].replace('\n', '').replace(' ', '')
    orgid = cmd_args['orgid'].replace('\n', '').replace(' ', '')
    prettyprint = cmd_args['prettyprint']

    # make API call
    apicall_success, orgbatch_data = actionbatchrequests.get_org_action_batches(
        apikey, orgid)

    # test for bad API call and a space returned as the data
    if not apicall_success and orgbatch_data == ' ':
        usermessage = usermessages.api_error_nostatus(apikey, orgid)
        print(usermessage)

    # test for successful API call but no Action Batches returned for org given
    elif apicall_success and not orgbatch_data:
        usermessage = usermessages.api_org_nullbatches(apikey, orgid)
        print(usermessage)

    # test for failed API call (and attempt to print API error message)
    elif not apicall_success:
        usermessage = usermessages.api_error_status(apikey, orgid,
                                                    orgbatch_data)
        print(usermessage)

    # success
    else:
        print(json.dumps(orgbatch_data,
                         indent=4)) if prettyprint else print(orgbatch_data)
Пример #2
0
def updateactionbatch(cmd_args):
    apikey = cmd_args['apikey'].replace('\n', '').replace(' ', '')
    orgid = cmd_args['orgid'].replace('\n', '').replace(' ', '')
    batchid = cmd_args['batchid'].replace('\n', '').replace(' ', '')
    confirmed = cmd_args['confirmed']
    synchronous = cmd_args['synchronous']
    prettyprint = cmd_args['prettyprint']

    apicall_success, updatebatch_data = actionbatchrequests.update_action_batch(
        apikey, orgid, batchid, confirmed, synchronous)

    # test for bad API call and a space returned as the data
    if not apicall_success and updatebatch_data == ' ':
        usermessage = usermessages.api_error_nostatus(apikey, orgid)
        print(usermessage)

    # test for failed API call (and attempt to print API error message)
    elif not apicall_success:
        usermessage = usermessages.api_error_status(apikey, orgid,
                                                    updatebatch_data)
        print(usermessage)

    # success
    elif apicall_success:
        print(json.dumps(updatebatch_data,
                         indent=4)) if prettyprint else print(updatebatch_data)
Пример #3
0
def createactionbatch(cmd_args):
    apikey = cmd_args['apikey'].replace('\n', '').replace(' ', '')
    orgid = cmd_args['orgid'].replace('\n', '').replace(' ', '')
    jsonfiles = []
    jsonfiles = str.split(cmd_args['jsonfiles'], ':')
    confirmed = cmd_args['confirmed']
    synchronous = cmd_args['synchronous']
    exportfile = cmd_args['exportfile']
    prettyprint = cmd_args['prettyprint']

    #define our json header based upon user input:
    jsonhead = {
        "confirmed": confirmed,
        "synchronous": synchronous,
    }

    # pass our jsonfiles to the jsontools module we wrote.
    # keeps track of .all_jsonfiles, .invalid_jsonfiles, .valid_jsonfiles, and allows us to merge JSON
    working_json = jsontools.JSONTools(jsonfiles=jsonfiles)

    # if there are ANY invlaid JSON files then pass the full list of JSON files to function that notifies the user
    # otherwise merge all JSON and call the Meraki Dashboard API
    if working_json.invalid_jsonfiles:
        usermessages.invalid_json_usermessage(working_json.all_jsonfiles)
    else:
        # passes all valid JSON to the mergejson object in the JSONTools class instance
        # this merges the JSON from all files in order and builds a payload.  Also creates the exportfile if it is not an empty string
        jsonpayload = working_json.mergejson(head=jsonhead,
                                             schema=actionbatch_schema,
                                             exportfile=exportfile)

        # make our API call with the payload
        apicall_success, createbatch_data = actionbatchrequests.create_action_batch(
            apikey, orgid, confirmed, synchronous, jsonpayload)

        # test for bad API call and a space returned as the data
        if not apicall_success and createbatch_data == ' ':
            usermessage = usermessages.api_error_nostatus(apikey, orgid)
            print(usermessage)

        # test for failed API call (and attempt to print API error message)
        elif not apicall_success:
            usermessage = usermessages.api_error_status(
                apikey, orgid, createbatch_data)
            print(usermessage)

        # success
        elif apicall_success:
            print(json.dumps(
                createbatch_data,
                indent=4)) if prettyprint else print(createbatch_data)
Пример #4
0
def deleteactionbatches(cmd_args):
    apikey = cmd_args['apikey'].replace('\n', '').replace(' ', '')
    orgid = cmd_args['orgid'].replace('\n', '').replace(' ', '')
    all_batchid = cmd_args['batchid'].replace('\n', '').replace(' ', '')
    batchids = []
    batchids = str.split(cmd_args['batchid'], ',')

    for batchid in batchids:
        apicall_success, delbatches_data = actionbatchrequests.delete_action_batch(
            apikey, orgid, batchid)
        print(
            stylize(
                '\n_______________________________________________________\n',
                usermessages.bold_formatting, usermessages.reset_formatting) +
            stylize('\nAttempting to delete BatchID: ', usermessages.
                    info_formatting, usermessages.reset_formatting) +
            stylize((batchid), usermessages.info_formatting,
                    usermessages.reset_formatting) + '\n')

        # test for bad API call and a space returned as the data
        if not apicall_success and delbatches_data == ' ':
            usermessage = usermessages.api_error_nostatus(apikey,
                                                          orgid,
                                                          batchid=batchid)
            print(usermessage)

        # deletebatch API call returns no data (null) when successful
        elif apicall_success and delbatches_data == '':
            usermessage = usermessages.api_delsuccess(apikey,
                                                      orgid,
                                                      batchid=batchid)
            print(usermessage)

        # test for failed API call (and attempt to print API error message)
        elif not apicall_success:
            usermessage = usermessages.api_error_status(apikey,
                                                        orgid,
                                                        delbatches_data,
                                                        batchid=batchid)
            print(usermessage)

        else:
            print(delbatches_data)
Пример #5
0
def batchstatus(cmd_args):
    apikey = cmd_args['apikey'].replace('\n', '').replace(' ', '')
    orgid = cmd_args['orgid'].replace('\n', '').replace(' ', '')
    batchstatus = cmd_args['batchstatus']
    prettyprint = cmd_args['prettyprint']

    # make our API call
    apicall_success, batchstatus_data = actionbatchrequests.get_org_action_batches(
        apikey, orgid)

    # test for bad API call and a space returned as the data
    if not apicall_success and batchstatus_data == ' ':
        usermessage = usermessages.api_error_nostatus(apikey, orgid)
        print(usermessage)

    # test for successful API call but no Action Batches returned for org given
    elif apicall_success and not batchstatus_data:
        usermessage = usermessages.api_org_nullbatches(apikey, orgid)
        print(usermessage)

    # test for failed API call (and attempt to print API error message)
    elif not apicall_success:
        usermessage = usermessages.api_error_status(apikey, orgid)
        print(usermessage)

    else:
        if prettyprint:
            print(json.dumps(batchstatus_data, indent=4))
        else:
            pass

        # call compare_batches function and assign 4 vars based upon return
        condition1, condition2, compare1, compare2 = compare_batches(
            batchstatus, batchstatus_data)
        print('\n')
        print(
            stylize(
                f'Summary: This org has {len(compare1)} {condition1} Action Batches and {len(compare2)} {condition2} Action Batches\n',
                usermessages.info_formatting))
        print(
            stylize(
                'Use PrettyPrint option to show matching Action Batches with detail.',
                usermessages.info_formatting))
Пример #6
0
def getactionbatch(cmd_args):
    apikey = cmd_args['apikey'].replace('\n', '').replace(' ', '')
    orgid = cmd_args['orgid'].replace('\n', '').replace(' ', '')
    batchid = cmd_args['batchid'].replace('\n', '').replace(' ', '')
    prettyprint = cmd_args['prettyprint']

    # make API call
    apicall_success, batch_data = actionbatchrequests.get_action_batch(
        apikey, orgid, batchid)

    # test for bad API call and a space returned as the data
    if not apicall_success and batch_data == ' ':
        usermessage = usermessages.api_error_nostatus(apikey, orgid, batchid)
        print(usermessage)

    # test for failed API call (and attempt to print API error message)
    elif not apicall_success:
        usermessage = usermessages.api_error_status(apikey, orgid, batch_data,
                                                    batchid)
        print(usermessage)

    else:
        print(json.dumps(batch_data,
                         indent=4)) if prettyprint else print(batch_data)