Beispiel #1
0
def update(config, args):
    url = config['url'] + "/api/session/" + args['session'] + "/"

    data = {}

    if args['name'] is not None:
        data['name'] = args['name']

    if args['description'] is not None:
        data['description'] = args['description']

    if args['upstreamHost'] is not None:
        data['upstreamHost'] = args['upstreamHost']

    if args['upstreamPort'] is not None:
        data['upstreamPort'] = args['upstreamPort']

    if args['testplan'] is not None:
        data['testPlan'] = {"id": args['testplan'] }

    if args['serverOverloadProfile'] is not None:
        data['serverOverloadProfile'] = {"id": args['serverOverloadProfile']}

    if args['qosProfile'] is not None:
        data['qosProfile'] = {"id": args['qosProfile']}

    token = auth.get_token(config)
    r = requests.put(url, data=json.dumps(data), headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #2
0
def read(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/recording/"

    if (args['all'] is False) and (args['recording'] is None):
        print("No recording(s) specified to read. Use -h to see usage.")
        return

    params = {}

    if (args['recording'] is not None) and (args['all'] is False):
        url += args['recording'] + "/"
        if args['traffic'] is True:
            url += "traffic/"
        if args['start'] is not None:
            params['start'] = args['start']
        if args['offset'] is not None:
            params['offset'] = args['offset']

    token = auth.get_token(config)
    r = requests.get(url, params=params, headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #3
0
def update(config, args):
    url = config['url'] + "/api/qos/" + args['qosprofile'] + "/"

    data = {}

    if args['name'] is not None:
        data['name'] = args['name']

    if args['latency'] is not None:
        data['latency'] = args['latency']

    if args['description'] is not None:
        data['description'] = args['description']

    if (args['jittermin'] is not None) or (args['jittermax'] is not None):
        data['jitter'] = {
            "min": args['jittermin'],
            "max": args['jittermax'],
        }

    if args['trafficloss'] is not None:
        data['trafficLoss'] = args['trafficloss']

    token = auth.get_token(config)
    r = requests.put(url,
                     data=json.dumps(data),
                     headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #4
0
def create(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/session/"

    data = {
       "name": args['name'],
       "description": args['description'],
       "upstreamHost": args['upstreamHost'],
       "upstreamPort": args['upstreamPort'],
    }

    if args['testplan'] is not None:
        data['testPlan'] = {"id": args['testplan']}

    if args['serverOverloadProfile'] is not None:
        data['serverOverloadProfile'] = {"id": args['serverOverloadProfile']}

    if args['qosProfile'] is not None:
        data['qosProfile'] = {"id": args['qosProfile']}

    token = auth.get_token(config)
    r = requests.post(url, data=json.dumps(data), headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
def read(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/serveroverload/"

    if (args['all'] is False) and (args['serveroverloadprofile'] is None):
        print("No serveroverload(s) specified to read. Use -h to see usage.")
        return
    elif args['serveroverloadprofile'] is not None:
        url += args['serveroverloadprofile'] + "/"

    token = auth.get_token(config)
    r = requests.get(url, headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        profiles = json.loads(r.content)
        if "profiles" not in profiles:  # Put single responses in an array, the same way --all behaves
            profiles = {"profiles": [profiles, ]}

        # Step through response triggers in profiles, and append the 'number' key to indicate their sequence in the array
        for profile in profiles['profiles']:
            if "response_triggers" in profile:
                trigger_num = 0
                for response_trigger in profile['response_triggers']:
                    response_trigger['position'] = trigger_num
                    trigger_num += 1

        pp.pprint(profiles)
Beispiel #6
0
def update(config, args):
    url = config['url'] + "/api/qos/" + args['qosprofile'] + "/"

    data = {}

    if args['name'] is not None:
        data['name'] = args['name']

    if args['latency'] is not None:
        data['latency'] = args['latency']

    if args['description'] is not None:
        data['description'] = args['description']

    if (args['jittermin'] is not None) or (args['jittermax'] is not None):
        data['jitter'] = {
            "min": args['jittermin'],
            "max": args['jittermax'],
        }

    if args['trafficloss'] is not None:
        data['trafficLoss'] = args['trafficloss']

    token = auth.get_token(config)
    r = requests.put(url, data=json.dumps(data), headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #7
0
def read(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/serveroverload/"

    if (args['all'] is False) and (args['serveroverloadprofile'] is None):
        print("No serveroverload(s) specified to read. Use -h to see usage.")
        return
    elif args['serveroverloadprofile'] is not None:
        url += args['serveroverloadprofile'] + "/"

    token = auth.get_token(config)
    r = requests.get(url, headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        profiles = json.loads(r.content)
        if "profiles" not in profiles:  # Put single responses in an array, the same way --all behaves
            profiles = {
                "profiles": [
                    profiles,
                ]
            }

        # Step through response triggers in profiles, and append the 'number' key to indicate their sequence in the array
        for profile in profiles['profiles']:
            if "response_triggers" in profile:
                trigger_num = 0
                for response_trigger in profile['response_triggers']:
                    response_trigger['position'] = trigger_num
                    trigger_num += 1

        pp.pprint(profiles)
Beispiel #8
0
def update(config, args):
    url = config['url'] + "/api/testplan/" + args[
        'testplan'] + "/rule/" + args['rule'] + "/"
    token = auth.get_token(config)
    r = requests.put(url,
                     data=args['rulejson'],
                     headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #9
0
def stop(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/proxy/stop/"

    token = auth.get_token(config)
    r = requests.post(url, headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #10
0
def create(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/testplan/" + args['testplan'] + "/rule/"

    token = auth.get_token(config)
    r = requests.post(url, data=args['rulejson'], headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #11
0
def stop(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/proxy/stop/"

    token = auth.get_token(config)
    r = requests.post(url, headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #12
0
def create(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/testplan/" + args['testplan'] + "/rule/"

    token = auth.get_token(config)
    r = requests.post(url,
                      data=args['rulejson'],
                      headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #13
0
def read(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/user/"
    if (args['all'] is False) and (args['username'] is None):
        print("No user object(s) specified to read. Use -h to see usage.")
        return
    elif args['all'] is True:
        token = auth.get_token(config)
        r = requests.get(url, headers={"X-Auth-Token": token})
        if r.status_code != 200:
            print("API returned status code %s" % (r.status_code))
            sys.exit(1)
        else:
            pp.pprint(json.loads(r.content))
    elif args['username'] is not None:
        url += args['username'] + "/"
        token = auth.get_token(config)
        r = requests.get(url, headers={"X-Auth-Token": token})
        if r.status_code != 200:
            print("API returned status code %s" % (r.status_code))
            sys.exit(1)
        else:
            pp.pprint(json.loads(r.content))
Beispiel #14
0
def read(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/user/"
    if (args['all'] is False) and (args['username'] is None):
        print("No user object(s) specified to read. Use -h to see usage.")
        return
    elif args['all'] is True:
        token = auth.get_token(config)
        r = requests.get(url, headers={"X-Auth-Token": token})
        if r.status_code != 200:
            print("API returned status code %s" % (r.status_code))
            sys.exit(1)
        else:
            pp.pprint(json.loads(r.content))
    elif args['username'] is not None:
        url += args['username'] + "/"
        token = auth.get_token(config)
        r = requests.get(url, headers={"X-Auth-Token": token})
        if r.status_code != 200:
            print("API returned status code %s" % (r.status_code))
            sys.exit(1)
        else:
            pp.pprint(json.loads(r.content))
Beispiel #15
0
def update(config, args):
    url = config['url'] + "/api/recording/" + args['recording'] + "/"

    data = {}

    if args['name'] is not None:
        data['name'] = args['name']

    if args['description'] is not None:
        data['description'] = args['description']

    token = auth.get_token(config)
    r = requests.put(url, data=json.dumps(data), headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #16
0
def deletetrigger(config, args):
    url = config['url'] + "/api/serveroverload/" + args['serveroverload'] + "/"
    token = auth.get_token(config)
    r = requests.get(url, headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    profile = json.loads(r.content)
    try:
        profile['response_triggers'].pop(args['position'])
    except IndexError:
        print("Position %s was invalid in the response triggers!" % (args['position']))
        sys.exit(1)
    r = requests.put(url, data=json.dumps(profile), headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #17
0
def create(config, args):
    url = config['url'] + "/api/user/"
    data = {
        "username": args['username'],
        "password": args['password'],
        "email": args['email'],
    }
    if args['admin'] is not None:
        if args['admin'] == "yes":
            data['roles'] = ["admin"]
        else:
            data['roles'] = ["standard"]
    token = auth.get_token(config)
    r = requests.post(url, headers={"X-Auth-Token": token}, data=json.dumps(data))
    print("API returned status code %s" % (r.status_code))
Beispiel #18
0
def update(config, args):
    url = config['url'] + "/api/testplan/" + args['testplan'] + "/"

    data = {}

    if args['name'] is not None:
        data['name'] = args['name']

    if args['description'] is not None:
        data['description'] = args['description']

    token = auth.get_token(config)
    r = requests.put(url,
                     data=json.dumps(data),
                     headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #19
0
def create(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/recording/"

    data = {
       "name": args['name'],
       "description": args['description'],
    }

    token = auth.get_token(config)
    r = requests.post(url, data=json.dumps(data), headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #20
0
def create(config, args):
    url = config['url'] + "/api/user/"
    data = {
        "username": args['username'],
        "password": args['password'],
        "email": args['email'],
    }
    if args['admin'] is not None:
        if args['admin'] == "yes":
            data['roles'] = ["admin"]
        else:
            data['roles'] = ["standard"]
    token = auth.get_token(config)
    r = requests.post(url,
                      headers={"X-Auth-Token": token},
                      data=json.dumps(data))
    print("API returned status code %s" % (r.status_code))
Beispiel #21
0
def deletetrigger(config, args):
    url = config['url'] + "/api/serveroverload/" + args['serveroverload'] + "/"
    token = auth.get_token(config)
    r = requests.get(url, headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    profile = json.loads(r.content)
    try:
        profile['response_triggers'].pop(args['position'])
    except IndexError:
        print("Position %s was invalid in the response triggers!" %
              (args['position']))
        sys.exit(1)
    r = requests.put(url,
                     data=json.dumps(profile),
                     headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #22
0
def create(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/testplan/"

    data = {
        "name": args['name'],
        "description": args['description'],
    }

    token = auth.get_token(config)
    r = requests.post(url,
                      data=json.dumps(data),
                      headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #23
0
def update(config, args):
    url = config['url'] + "/api/serveroverload/" + args['serveroverload'] + "/"

    data = {}

    if args['name'] is not None:
        data['name'] = args['name']

    if args['description'] is not None:
        data['description'] = args['description']

    update_function = False
    function = {}

    if args['functiontype'] is not None:
        function['type'] = args['functiontype']
        update_function = True

    if args['functionexpvalue'] is not None:
        function['expValue'] = args['functionexpvalue']
        update_function = True

    if args['functiongrowthrate'] is not None:
        function['growthRate'] = args['functiongrowthrate']
        update_function = True

    if update_function is True:  # verify they provided all the pieces needed to update a function
        try:
            assert "type" in function
            assert "expValue" in function
            assert "growthRate" in function
            data['function'] = function
        except AssertionError:
            print(
                "To update a function, you must provide the type, expvalue, and growthrate together."
            )
            sys.exit(1)

    token = auth.get_token(config)
    r = requests.put(url,
                     data=json.dumps(data),
                     headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #24
0
def inserttrigger(config, args):
    url = config['url'] + "/api/serveroverload/" + args['serveroverload'] + "/"
    token = auth.get_token(config)
    r = requests.get(url, headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    profile = json.loads(r.content)
    response_trigger = {
        "fromLoad": args['fromload'],
        "toLoad": args['toload'],
        "actions": [{
            "type": args['actiontype'],
            "value": args['actionvalue'],
            "percentage": args['actionpercentage'],
        }]
    }
    profile['response_triggers'].insert(args['position'], response_trigger)
    r = requests.put(url, data=json.dumps(profile), headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #25
0
def update(config, args):
    url = config['url'] + "/api/serveroverload/" + args['serveroverload'] + "/"

    data = {}

    if args['name'] is not None:
        data['name'] = args['name']

    if args['description'] is not None:
        data['description'] = args['description']

    update_function = False
    function = {}

    if args['functiontype'] is not None:
        function['type'] = args['functiontype']
        update_function = True

    if args['functionexpvalue'] is not None:
        function['expValue'] = args['functionexpvalue']
        update_function = True

    if args['functiongrowthrate'] is not None:
        function['growthRate'] = args['functiongrowthrate']
        update_function = True

    if update_function is True:  # verify they provided all the pieces needed to update a function
        try:
            assert "type" in function
            assert "expValue" in function
            assert "growthRate" in function
            data['function'] = function
        except AssertionError:
            print("To update a function, you must provide the type, expvalue, and growthrate together.")
            sys.exit(1)

    token = auth.get_token(config)
    r = requests.put(url, data=json.dumps(data), headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #26
0
def create(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/serveroverload/"

    data = {
       "name": args['name'],
       "description": args['description'],
       "function": {
            "type": args['functiontype'],
            "expValue": args['functionexpvalue'],
            "growthRate": args['functiongrowthrate'],
       },
       "response_triggers": [],
    }

    token = auth.get_token(config)
    r = requests.post(url, data=json.dumps(data), headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #27
0
def create(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/qos/"

    data = {
       "name": args['name'],
       "description": args['description'],
       "latency": args['latency'],
       "jitter": {
            "min": args['jittermin'],
            "max": args['jittermax'],
       },
       "trafficLoss": args['trafficloss'],
    }

    token = auth.get_token(config)
    r = requests.post(url, data=json.dumps(data), headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #28
0
def create(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/qos/"

    data = {
        "name": args['name'],
        "description": args['description'],
        "latency": args['latency'],
        "jitter": {
            "min": args['jittermin'],
            "max": args['jittermax'],
        },
        "trafficLoss": args['trafficloss'],
    }

    token = auth.get_token(config)
    r = requests.post(url,
                      data=json.dumps(data),
                      headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #29
0
def inserttrigger(config, args):
    url = config['url'] + "/api/serveroverload/" + args['serveroverload'] + "/"
    token = auth.get_token(config)
    r = requests.get(url, headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    profile = json.loads(r.content)
    response_trigger = {
        "fromLoad":
        args['fromload'],
        "toLoad":
        args['toload'],
        "actions": [{
            "type": args['actiontype'],
            "value": args['actionvalue'],
            "percentage": args['actionpercentage'],
        }]
    }
    profile['response_triggers'].insert(args['position'], response_trigger)
    r = requests.put(url,
                     data=json.dumps(profile),
                     headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #30
0
def create(config, args):
    pp = pprint.PrettyPrinter()
    url = config['url'] + "/api/serveroverload/"

    data = {
        "name": args['name'],
        "description": args['description'],
        "function": {
            "type": args['functiontype'],
            "expValue": args['functionexpvalue'],
            "growthRate": args['functiongrowthrate'],
        },
        "response_triggers": [],
    }

    token = auth.get_token(config)
    r = requests.post(url,
                      data=json.dumps(data),
                      headers={"X-Auth-Token": token})
    if r.status_code != 200:
        print("API returned status code %s" % (r.status_code))
        sys.exit(1)
    else:
        pp.pprint(json.loads(r.content))
Beispiel #31
0
def stop(config, args):
    url = config['url'] + "/api/recording/" + args['recording'] + "/start/"
    token = auth.get_token(config)
    r = requests.get(url, headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #32
0
def update(config, args):
    url = config['url'] + "/api/testplan/" + args['testplan'] + "/rule/" + args['rule'] + "/"
    token = auth.get_token(config)
    r = requests.put(url, data=args['rulejson'], headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #33
0
def delete(config, args):
    url = config['url'] + "/api/serveroverload/" + args['serveroverload'] + "/"
    token = auth.get_token(config)
    r = requests.delete(url, headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #34
0
def start(config, args):
    url = config['url'] + "/api/session/" + args['session'] + "/start/"
    token = auth.get_token(config)
    r = requests.post(url, headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))
Beispiel #35
0
def delete(config, args):
    url = config['url'] + "/api/qos/" + args['qosprofile'] + "/"
    token = auth.get_token(config)
    r = requests.delete(url, headers={"X-Auth-Token": token})
    print("API returned status code %s" % (r.status_code))