示例#1
0
def cloud_list(key_filter=None, result_filter=None):
    """
    Return a list of all clouds known by UCSD Director
    :param key_filter: A sub-list of keys from the returned data to filter for
    :param result_filter: A dictionary of key/value pairs to filter the result list down by (OR logic).
    :return:
    """
    if result_filter is None:
        result_filter = {}
    if key_filter is None:
        key_filter = []
    apioperation = "userAPIGetCloudsListReport"
    u = url % ucsdserver + getstring % apioperation

    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    r = requests.get(u, headers=headers, verify=False)

    j = json.loads(r.text)
    j['serviceResult']['rows'] = list_search(j['serviceResult']['rows'],
                                             result_filter)

    search_results = [
        dict_filter(r, key_filter) for r in j['serviceResult']['rows']
    ]
    return search_results
示例#2
0
def vdc_list(group="", provider="", key_filter = [], result_filter = {}):
    '''
    Return a list of all VDCs for a group if provided
    :param group:  The ICFD Group to return VDCs for... default all groups
    :param key_filter: A sub-list of keys from the returned data to filter for
    :param result_filter: A dictionary of key/value pairs to filter the result list down by (OR logic).
    :return:
    '''
    apioperation = "userAPIGetAllVDCs"
    getstring = "formatType=json&opName=%s"
    u = url % (icfdserver) + getstring % (apioperation)

    r = requests.get(u, headers=headers)

    j = json.loads(r.text)

    all_vdcs = j['serviceResult']['rows']
    group_vdcs = []

    for vdc in all_vdcs:
        if (vdc['Group'] == group or group == ""):
            if (vdc['Cloud'] == provider or provider ==""):
                group_vdcs.append(vdc)

    group_vdcs = list_search(group_vdcs, result_filter)

    search_results = [dict_filter(r, key_filter) for r in group_vdcs]
    return search_results
示例#3
0
def catalog_list_all(key_filter=None, result_filter=None):
    """
    Get a list of Catalog Options for a Group
    :param key_filter: A sub-list of keys from the returned data to filter for
    :param result_filter: A dictionary of key/value pairs to filter the result list down by (OR logic).
    :return:
    """
    if result_filter is None:
        result_filter = {}
    if key_filter is None:
        key_filter = []
    apioperation = "userAPIGetAllCatalogs"
    u = url % ucsdserver + getstring % apioperation + parameter_lead + \
        "{}"

    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    r = requests.get(u, headers=headers, verify=False)

    j = json.loads(r.text)

    j['serviceResult']['rows'] = list_search(j['serviceResult']['rows'],
                                             result_filter)

    search_results = [
        dict_filter(r, key_filter) for r in j['serviceResult']['rows']
    ]
    return search_results
示例#4
0
def vm_details(vmid, key_filter=None, result_filter=None):
    """
    Return the known details of the specified VM
    :param vmid: The ICFD VMID for the Virtual Machine
    :param key_filter: A sub-list of keys from the returned data to filter for
    :param result_filter: A dictionary of key/value pairs to filter the result list down by (OR logic).
    :return:
    """
    if result_filter is None:
        result_filter = {}
    if key_filter is None:
        key_filter = []
    apioperation = "userAPIGetVMSummary"
    u = url % ucsdserver + getstring % apioperation + parameter_lead + \
        "{param0:\"" + vmid + '"' + '}'

    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    r = requests.get(u, headers=headers, verify=False)

    j = json.loads(r.text)
    if j['serviceError']:
        return j['serviceError']
    else:
        j['serviceResult']['rows'] = list_search(j['serviceResult']['rows'],
                                                 result_filter)
        search_results = [
            dict_filter(r, key_filter) for r in j['serviceResult']['rows']
        ]
        return search_results
示例#5
0
def vdc_list(group="", provider="", key_filter=None, result_filter=None):
    """
    Return a list of all VDCs for a group if provided
    :param group:  The UCSD Group to return VDCs for... default all groups
    :param provider:
    :param key_filter: A sub-list of keys from the returned data to filter for
    :param result_filter: A dictionary of key/value pairs to filter the result list down by (OR logic).
    :return:
    """
    if result_filter is None:
        result_filter = {}
    if key_filter is None:
        key_filter = []
    apioperation = "userAPIGetAllVDCs"
    u = url % ucsdserver + getstring % apioperation

    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    r = requests.get(u, headers=headers, verify=False)
    print(r.text)

    j = json.loads(r.text)

    all_vdcs = j['serviceResult']['rows']
    group_vdcs = []

    for vdc in all_vdcs:
        if vdc['Group'] == group or group == "":
            if vdc['Cloud'] == provider or provider == "":
                group_vdcs.append(vdc)

    group_vdcs = list_search(group_vdcs, result_filter)

    search_results = [dict_filter(r, key_filter) for r in group_vdcs]
    return search_results
示例#6
0
def workflow_list(folder = "", key_filter = [], result_filter = {}):
    '''
    Query UCS Director for the workflows for a folder
    :param folder: The UCSD Orchestration Folder to Query - defaults to all
    :return:
    '''
    apioperation = "userAPIGetWorkflows"
    u = url % (ucsdserver) + getstring % (apioperation) + parameter_lead + \
    "{param0:\"" + folder + '"' + '}'

    r = requests.get(u, headers=headers)
    j = json.loads(r.text)

    j['serviceResult'] = list_search(j['serviceResult'], result_filter)

    search_results = [dict_filter(r, key_filter) for r in j['serviceResult']]
    return search_results
示例#7
0
def vm_list(key_filter = [], result_filter = {}):
    '''
    Return a list of all VMs known by ICF Director
    :param key_filter: A sub-list of keys from the returned data to filter for
    :param result_filter: A dictionary of key/value pairs to filter the result list down by (OR logic).
    :return:
    '''
    apioperation = "userAPIGetAllVMs"
    getstring = "formatType=json&opName=%s"
    u = url % (icfdserver) + getstring % (apioperation)

    r = requests.get(u, headers=headers)

    j = json.loads(r.text)
    j['serviceResult']['rows'] = list_search(j['serviceResult']['rows'], result_filter)

    search_results = [dict_filter(r, key_filter) for r in j['serviceResult']['rows']]
    return search_results
示例#8
0
def icfcloud_details(icfCloudId, key_filter = [], result_filter = {}):
    '''
    Return the details of the specified icfCloud
    :param icfCloudId:  The icfCloud ID to return status for
    :param key_filter: A sub-list of keys from the returned data to filter for
    :param result_filter: A dictionary of key/value pairs to filter the result list down by (OR logic).
    :return:
    '''
    apioperation = "Intercloud:userAPIGeticfCloudSummary"
    u = url % (icfdserver) + getstring % (apioperation) + parameter_lead + \
     "{param0:\"" + icfCloudId + '"' + '}'

    r = requests.get(u, headers=headers)

    j = json.loads(r.text)
    j['serviceResult']['rows'] = list_search(j['serviceResult']['rows'], result_filter)

    search_results = [dict_filter(r, key_filter) for r in j['serviceResult']['rows']]
    return search_results
示例#9
0
def catalog_list(group="Default Group", key_filter = [], result_filter = {}):
    '''
    Get a list of Catalog Options for a Group
    :param group:  The ICFD Group to Query on behalf of
    :param key_filter: A sub-list of keys from the returned data to filter for
    :param result_filter: A dictionary of key/value pairs to filter the result list down by (OR logic).
    :return:
    '''
    apioperation = "userAPIGetCatalogsPerGroup"
    u = url % (icfdserver) + getstring % (apioperation) + parameter_lead + \
     "{param0:\"" + group + '"' + '}'

    r = requests.get(u, headers=headers)

    j = json.loads(r.text)

    j['serviceResult']['rows'] = list_search(j['serviceResult']['rows'], result_filter)

    search_results = [dict_filter(r, key_filter) for r in j['serviceResult']['rows']]
    return search_results
示例#10
0
def vm_details(vmid, key_filter = [], result_filter = {}):
    '''
    Return the known details of the specified VM
    :param vmid: The ICFD VMID for the Virtual Machine
    :param key_filter: A sub-list of keys from the returned data to filter for
    :param result_filter: A dictionary of key/value pairs to filter the result list down by (OR logic).
    :return:
    '''
    apioperation = "Intercloud:userAPIGetVMSummary"
    u = url % (icfdserver) + getstring % (apioperation) + parameter_lead + \
     "{param0:\"" + vmid + '"' + '}'

    r = requests.get(u, headers=headers)

    j = json.loads(r.text)
    if j['serviceError']:
        return j['serviceError']
    else:
        j['serviceResult']['rows'] = list_search(j['serviceResult']['rows'], result_filter)
        search_results = [dict_filter(r, key_filter) for r in j['serviceResult']['rows']]
        return search_results
示例#11
0
def workflow_list(folder="", key_filter=None, result_filter=None):
    """
    Query UCS Director for the workflows for a folder
    :param folder: The UCSD Orchestration Folder to Query - defaults to all
    :param key_filter:
    :param result_filter:
    :return:
    """
    if result_filter is None:
        result_filter = {}
    if key_filter is None:
        key_filter = []
    apioperation = "userAPIGetWorkflows"
    u = url % ucsdserver + getstring % apioperation + parameter_lead + \
        "{param0:\"" + folder + '"' + '}'

    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
    r = requests.get(u, headers=headers, verify=False)
    j = json.loads(r.text)

    j['serviceResult'] = list_search(j['serviceResult'], result_filter)

    search_results = [dict_filter(r, key_filter) for r in j['serviceResult']]
    return search_results