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))
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))
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))
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)
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)
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))