headers= { 'x-auth-token': token['token'], 'content-type' : 'application/json'}
    try:
        project_id = project_name_to_id(project_name)
    except ValueError as v:
        print("NO project: %s" % project_name)
        return {}
    delete_url = url + '/%s?deleteRule=1&deleteDevice=1' % project_id

    print("DELETE: %s" % delete_url)
    try:
        response = requests.delete(delete_url, headers=headers,  verify=False)
        response.raise_for_status()
    except requests.exceptions.RequestException  as cerror:
        print("Error processing request", cerror)
        sys.exit(1)

    taskid = response.json()['response']['taskId']
    print("Waiting for Task %s" % taskid)
    task_result = wait_on_task(taskid, token)
    return task_result

if __name__ == "__main__":
    if len(sys.argv) >1  and sys.argv[1] == "-a":
        project_list = get_project_names()

        for project in project_list:
            response = delete_project(name_wrap(project))
            print(json.dumps(response, indent=2))
    else:
        response = delete_project(name_wrap("Sydney"))
        print(json.dumps(response, indent=2))
예제 #2
0
def create_project(project_name):
    token = get_auth_token()
    url = create_url(path="pnp-project")

    print ("POST URL %s" % url)
    print ("Creating project %s" % project_name)
    headers= { 'x-auth-token': token['token'], 'content-type' : 'application/json'}
    body = [{"siteName": project_name}]
    try:
        response = requests.post(url, headers=headers, data=json.dumps(body), verify=False)
    except requests.exceptions.RequestException  as cerror:
        print ("Error processing request", cerror)
        sys.exit(1)

    taskid = response.json()['response']['taskId']
    print ("Waiting for Task %s" % taskid)
    task_result = wait_on_task(taskid, token)

    return task_result

if __name__ == "__main__":
    if len(sys.argv) >1  and sys.argv[1] == "-a":
        project_names = get_project_names()

        for project in project_names:
            response = create_project(name_wrap(project))
            print (json.dumps(response, indent=2))
    else:
        response = create_project(name_wrap("Canberra"))
        print (json.dumps(response, indent=2))
예제 #3
0
        project_id = project_name_to_id(project_name)
    except ValueError as v:
        print("NO project: %s" % project_name)
        return {}
    delete_url = url + '/%s?deleteRule=1&deleteDevice=1' % project_id

    print("DELETE: %s" % delete_url)
    try:
        response = requests.delete(delete_url, headers=headers, verify=False)
        response.raise_for_status()
    except requests.exceptions.RequestException as cerror:
        print("Error processing request", cerror)
        sys.exit(1)

    taskid = response.json()['response']['taskId']
    print("Waiting for Task %s" % taskid)
    task_result = wait_on_task(taskid, token)
    return task_result


if __name__ == "__main__":
    if len(sys.argv) > 1 and sys.argv[1] == "-a":
        project_list = get_project_names()

        for project in project_list:
            response = delete_project(name_wrap(project))
            print(json.dumps(response, indent=2))
    else:
        response = delete_project(name_wrap("Canberra"))
        print(json.dumps(response, indent=2))