示例#1
0
def ba_gather_ip_pool(ip_range):
    command = '--json search --display-integers --range {0}'.format(ip_range)
    nas, (resp_code, resp_list) = do_dispatch(shlex.split(command))
    raw_json = '\n'.join(resp_list)
    if 'error_messages' in raw_json:
        return None, raw_json
    return json.loads(raw_json), None
示例#2
0
def ba_import(dict_blob, commit=False):
    """
    Import a blob of data. The data you pass in should have been originally
    exported via one of the ``ba_export`` functions.

    This function will convert the passed python dictionary into a JSON
    dictionary before sending it to Inventory to be processed.

    This function will return a dictionary and if that dictionary has the key
    'errors' then there were errors and nothing was saved during processing.

    :param dict_blob: A blob of data to import
    :type dict_blob: dict

    """
    if commit:
        dict_blob['commit'] = True
    json_blob = json.dumps(dict_blob)
    command = ['ba_import']
    if commit:
        command.append('--commit')
    with io.BytesIO(json_blob) as json_blob_fd:
        nas, (resp_code, resp_list) = do_dispatch(command, IN=json_blob_fd)
        raw_json = '\n'.join(resp_list)
        if 'errors' in raw_json:
            return None, raw_json
        try:
            resp = json.loads(raw_json)
        except ValueError:
            print raw_json
            return None, "Couldn't decode json from server"
        return resp, None
示例#3
0
文件: ba.py 项目: jvehent/inv-tool
def ba_import(dict_blob, commit=False):
    """
    Import a blob of data. The data you pass in should have been originally
    exported via one of the ``ba_export`` functions.

    This function will convert the passed python dictionary into a JSON
    dictionary before sending it to Inventory to be processed.

    This function will return a dictionary and if that dictionary has the key
    'errors' then there were errors and nothing was saved during processing.

    :param dict_blob: A blob of data to import
    :type dict_blob: dict

    """
    if commit:
        dict_blob['commit'] = True
    json_blob = json.dumps(dict_blob)
    command = ['ba_import']
    if commit:
        command.append('--commit')
    with io.BytesIO(json_blob) as json_blob_fd:
        nas, (resp_code, resp_list) = do_dispatch(command, IN=json_blob_fd)
        raw_json = '\n'.join(resp_list)
        if 'errors' in raw_json:
            return None, raw_json
        return json.loads(raw_json), None
示例#4
0
文件: ba.py 项目: jvehent/inv-tool
def ba_export_systems_raw(search):
    command = 'ba_export --query {0}'.format(search)
    nas, (resp_code, resp_list) = do_dispatch(shlex.split(command))
    raw_json = '\n'.join(resp_list)
    if 'errors' in raw_json:
        return None, raw_json
    return json.loads(raw_json), None
示例#5
0
文件: ba.py 项目: jvehent/inv-tool
def ba_gather_ip_pool(ip_range):
    command = '--json search --display-integers --range {0}'.format(ip_range)
    nas, (resp_code, resp_list) = do_dispatch(shlex.split(command))
    raw_json = '\n'.join(resp_list)
    if 'error_messages' in raw_json:
        return None, raw_json
    return json.loads(raw_json), None
示例#6
0
def ba_export_systems_raw(search):
    command = 'ba_export --query {0}'.format(search)
    nas, (resp_code, resp_list) = do_dispatch(shlex.split(command))
    raw_json = '\n'.join(resp_list)
    if 'errors' in raw_json:
        return None, raw_json
    try:
        r = json.loads(raw_json)
    except ValueError:
        raise ValueError(
            "Couldn't decode from server. Response from server was: "
            "{0}".format(raw_json))
    return r, None
示例#7
0
文件: ba.py 项目: gerva/inv-tool
def ba_export_systems_raw(search):
    command = 'ba_export --query {0}'.format(search)
    nas, (resp_code, resp_list) = do_dispatch(shlex.split(command))
    raw_json = '\n'.join(resp_list)
    if 'errors' in raw_json:
        return None, raw_json
    try:
        r = json.loads(raw_json)
    except ValueError:
        raise ValueError(
            "Couldn't decode from server. Response from server was: "
            "{0}".format(raw_json)
        )
    return r, None