How to use api_token method in yandex-tank

Best Python code snippet using yandex-tank

io.py

Source:io.py Github

copy

Full Screen

1import json2from misttests.api.mistrequests import MistRequests3class MistIoApi(object):4 def __init__(self, uri):5 self.uri = uri6 #################################################7 # CLOUDS #8 #################################################9 def supported_providers(self, api_token=None):10 req = MistRequests(uri=self.uri + '/api/v1/providers',11 api_token=api_token)12 req.post = req.unavailable_api_call13 req.put = req.unavailable_api_call14 req.delete = req.unavailable_api_call15 return req16 def list_clouds(self, api_token=None):17 req = MistRequests(uri=self.uri + '/api/v1/clouds',18 api_token=api_token)19 req.post = req.unavailable_api_call20 req.put = req.unavailable_api_call21 req.delete = req.unavailable_api_call22 return req23 def add_cloud(self, title, provider, api_token=None, **kwargs):24 payload = {25 'title': title,26 'provider': provider27 }28 payload.update(kwargs)29 req = MistRequests(uri=self.uri + '/api/v1/clouds',30 data=json.dumps(payload), api_token=api_token)31 req.get = req.unavailable_api_call32 req.put = req.unavailable_api_call33 req.delete = req.unavailable_api_call34 return req35 def rename_cloud(self, cloud_id, new_name, cookie=None, csrf_token=None,36 api_token=None):37 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id,38 data={'new_name': new_name}, cookie=cookie,39 csrf_token=csrf_token, api_token=api_token)40 req.get = req.unavailable_api_call41 req.post = req.unavailable_api_call42 req.delete = req.unavailable_api_call43 return req44 def delete_cloud(self, cloud_id, cookie=None, csrf_token=None,45 api_token=None):46 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id,47 cookie=cookie, csrf_token=csrf_token,48 api_token=api_token)49 req.get = req.unavailable_api_call50 req.post = req.unavailable_api_call51 req.put = req.unavailable_api_call52 return req53 def toggle_cloud(self, cloud_id, api_token=None, new_state=None):54 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id,55 data={'new_state': new_state}, api_token=api_token)56 req.get = req.unavailable_api_call57 req.delete = req.unavailable_api_call58 req.put = req.unavailable_api_call59 return req60 def list_sizes(self, cloud_id, cookie=None, csrf_token=None,61 api_token=None):62 req = MistRequests(uri=self.uri + '/api/v1/clouds/' +63 cloud_id + '/sizes', cookie=cookie,64 csrf_token=csrf_token, api_token=api_token)65 req.post = req.unavailable_api_call66 req.put = req.unavailable_api_call67 req.delete = req.unavailable_api_call68 return req69 def list_locations(self, cloud_id, cookie=None, csrf_token=None,70 api_token=None):71 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +72 '/locations', cookie=cookie,73 csrf_token=csrf_token, api_token=api_token)74 req.post = req.unavailable_api_call75 req.put = req.unavailable_api_call76 req.delete = req.unavailable_api_call77 return req78 #################################################79 # IMAGES #80 #################################################81 def list_images(self, cloud_id, search_term=None, cookie=None,82 csrf_token=None, api_token=None):83 kwargs = {84 'uri': self.uri + '/api/v1/clouds/' + cloud_id + '/images',85 'cookie': cookie,86 'csrf_token': csrf_token,87 'api_token': api_token88 }89 if search_term:90 kwargs.update({'data': {'search_term': search_term}})91 req = MistRequests(**kwargs)92 req.put = req.unavailable_api_call93 req.delete = req.unavailable_api_call94 return req95 def star_image(self, cloud_id, image_id, api_token=None):96 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id97 + '/images/' + image_id, api_token=api_token)98 req.get = req.unavailable_api_call99 req.delete = req.unavailable_api_call100 req.put = req.unavailable_api_call101 return req102 #################################################103 # MACHINES #104 #################################################105 def list_machines(self, cloud_id, cookie=None, csrf_token=None,106 api_token=None):107 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +108 '/machines', cookie=cookie, csrf_token=csrf_token,109 api_token=api_token)110 req.post = req.unavailable_api_call111 req.put = req.unavailable_api_call112 req.delete = req.unavailable_api_call113 return req114 def create_machine(self, cloud_id, key_id, name, provider, location, image,115 size, script="", disk=None, image_extra=None,116 cookie=None, csrf_token=None, api_token=None,117 cron_enable=False, cron_type=None, cron_entry=None,118 cron_script=None, cron_name=None, async=False,119 monitoring=False, cloud_init="", location_name='',120 job_id=None):121 # ! disk and image_extra are required only for Linode122 # ! cronjobs' variables are required only if we want to set a scheduler123 # ! this way cronjob vars pass empty in create machine params124 payload = {125 # 'cloud': cloud_id,126 'key': key_id,127 'name': name,128 'provider': provider,129 'location': location,130 'location_name': location_name,131 'image': image,132 'size': size,133 'script': script,134 'disk': disk,135 'image_extra': image_extra,136 'cronjob_enabled': cron_enable,137 'cronjob_type': cron_type,138 'cronjob_entry': cron_entry,139 'cronjob_script_id': cron_script,140 'cronjob_name': cron_name,141 'async': async,142 'monitoring': monitoring,143 'cloud_init': cloud_init,144 'job_id': job_id,145 }146 req = MistRequests(uri=self.uri + '/api/v1/clouds/' +147 cloud_id + '/machines', cookie=cookie,148 data=json.dumps(payload), timeout=600,149 csrf_token=csrf_token, api_token=api_token)150 req.get = req.unavailable_api_call151 req.put = req.unavailable_api_call152 req.delete = req.unavailable_api_call153 return req154 def destroy_machine(self, cloud_id, machine_id, cookie=None,155 csrf_token=None, api_token=None):156 uri = self.uri + '/api/v1/clouds/' + cloud_id + '/machines/'\157 + machine_id158 req = MistRequests(uri=uri, data={'action': 'destroy'}, cookie=cookie,159 csrf_token=csrf_token, api_token=api_token)160 req.get = req.unavailable_api_call161 req.put = req.unavailable_api_call162 req.delete = req.unavailable_api_call163 return req164 def machine_action(self, cloud_id, machine_id, cookie=None,165 csrf_token=None, api_token=None, action=''):166 data = {}167 if action:168 data = {'action': action}169 uri = self.uri + '/api/v1/clouds/' + cloud_id +\170 '/machines/' + machine_id171 req = MistRequests(uri=uri, cookie=cookie, data=data,172 csrf_token=csrf_token, api_token=api_token)173 req.get = req.unavailable_api_call174 req.put = req.unavailable_api_call175 req.delete = req.unavailable_api_call176 return req177 def set_machine_tags(self, api_token, cloud_id, machine_id, tags):178 resource_data = {179 'item_id': machine_id,180 'type': 'machine',181 'cloud_id': cloud_id182 }183 tags_data = []184 tags_data.append(tags)185 data = [{186 'tags': tags_data,187 'resource': resource_data188 }]189 payload = json.dumps(data)190 req = MistRequests(uri=self.uri + '/api/v1/tags',191 data=payload, api_token=api_token)192 req.get = req.unavailable_api_call193 req.put = req.unavailable_api_call194 req.delete = req.unavailable_api_call195 return req196 def associate_key(self, cloud_id, machine_id, key_id, cookie=None,197 csrf_token=None, api_token=None):198 uri = self.uri + '/api/v1/clouds/' + cloud_id + \199 '/machines/' + machine_id + '/keys/' + key_id200 req = MistRequests(uri=uri, cookie=cookie,201 csrf_token=csrf_token, api_token=api_token)202 req.get = req.unavailable_api_call203 req.post = req.unavailable_api_call204 req.delete = req.unavailable_api_call205 return req206 def machine_monitoring(self, cloud_id, machine_id, cookie=None,207 csrf_token=None, api_token=None, action=''):208 data = {}209 if action:210 data = {'action': action}211 uri = self.uri + '/api/v1/clouds/' + cloud_id + \212 '/machines/' + machine_id + '/monitoring'213 req = MistRequests(uri=uri, cookie=cookie, data=data,214 csrf_token=csrf_token, api_token=api_token)215 req.get = req.unavailable_api_call216 req.put = req.unavailable_api_call217 req.delete = req.unavailable_api_call218 return req219 #################################################220 # KEYS #221 #################################################222 def list_keys(self, cookie=None, csrf_token=None, api_token=None):223 req = MistRequests(uri=self.uri + '/api/v1/keys', cookie=cookie,224 csrf_token=csrf_token, api_token=api_token)225 req.post = req.unavailable_api_call226 req.put = req.unavailable_api_call227 req.delete = req.unavailable_api_call228 return req229 def add_key(self, name, private, cookie=None, csrf_token=None,230 api_token=None, is_default=''):231 payload = {232 'name': name,233 'priv': private234 }235 if is_default:236 payload.update({'isDefault': is_default})237 req = MistRequests(uri=self.uri + '/api/v1/keys', cookie=cookie,238 data=json.dumps(payload),239 csrf_token=csrf_token, api_token=api_token)240 req.get = req.unavailable_api_call241 req.post = req.unavailable_api_call242 req.delete = req.unavailable_api_call243 return req244 def edit_key(self, id, new_name, cookie=None, csrf_token=None,245 api_token=None):246 req = MistRequests(uri=self.uri + '/api/v1/keys/' + id,247 data=json.dumps({'new_name': new_name}),248 cookie=cookie,249 csrf_token=csrf_token, api_token=api_token)250 req.get = req.unavailable_api_call251 req.post = req.unavailable_api_call252 req.delete = req.unavailable_api_call253 return req254 def delete_key(self, key_id, cookie=None, csrf_token=None, api_token=None):255 req = MistRequests(uri=self.uri + '/api/v1/keys/' + key_id,256 cookie=cookie,257 csrf_token=csrf_token, api_token=api_token)258 req.get = req.unavailable_api_call259 req.post = req.unavailable_api_call260 req.put = req.unavailable_api_call261 return req262 def delete_keys(self, key_ids, api_token=None):263 req = MistRequests(uri=self.uri + '/api/v1/keys',264 api_token=api_token,265 json={'key_ids': key_ids})266 req.get = req.unavailable_api_call267 req.post = req.unavailable_api_call268 req.put = req.unavailable_api_call269 return req270 def generate_keypair(self, cookie=None, csrf_token=None, api_token=None):271 req = MistRequests(uri=self.uri + '/api/v1/keys', cookie=cookie,272 csrf_token=csrf_token, api_token=api_token)273 req.get = req.unavailable_api_call274 req.put = req.unavailable_api_call275 req.delete = req.unavailable_api_call276 return req277 def get_private_key(self, key_id, cookie=None, csrf_token=None,278 api_token=None):279 req = MistRequests(uri=self.uri + '/api/v1/keys/' + key_id +280 '/private', cookie=cookie,281 csrf_token=csrf_token, api_token=api_token)282 req.post = req.unavailable_api_call283 req.put = req.unavailable_api_call284 req.delete = req.unavailable_api_call285 return req286 def get_public_key(self, key_id, cookie=None, csrf_token=None,287 api_token=None):288 req = MistRequests(uri=self.uri + '/api/v1/keys/' + key_id + '/public',289 cookie=cookie, csrf_token=csrf_token,290 api_token=api_token)291 req.post = req.unavailable_api_call292 req.put = req.unavailable_api_call293 req.delete = req.unavailable_api_call294 return req295 def set_default_key(self, key_id, cookie=None, csrf_token=None,296 api_token=None):297 req = MistRequests(uri=self.uri + '/api/v1/keys/' + key_id,298 cookie=cookie, csrf_token=csrf_token,299 api_token=api_token)300 req.get = req.unavailable_api_call301 req.put = req.unavailable_api_call302 req.delete = req.unavailable_api_call303 return req304 #################################################305 # SCRIPTS #306 #################################################307 def add_script(self, api_token, script_data, script=None,308 entrypoint=None, description=None):309 data = {}310 data.update(script_data)311 if script is not None:312 data['script'] = script313 if entrypoint is not None:314 data['entrypoint'] = entrypoint315 if description is not None:316 data['description'] = description317 req = MistRequests(uri=self.uri + '/api/v1/scripts',318 api_token=api_token, data=data)319 req.get = req.unavailable_api_call320 req.delete = req.unavailable_api_call321 req.put = req.unavailable_api_call322 return req323 def show_script(self, api_token, script_id):324 req = MistRequests(uri=self.uri + '/api/v1/scripts/%s' % script_id,325 api_token=api_token)326 req.post = req.unavailable_api_call327 req.delete = req.unavailable_api_call328 req.put = req.unavailable_api_call329 return req330 def list_scripts(self, api_token):331 req = MistRequests(uri=self.uri + '/api/v1/scripts',332 api_token=api_token)333 req.post = req.unavailable_api_call334 req.delete = req.unavailable_api_call335 req.put = req.unavailable_api_call336 return req337 def edit_script(self, api_token, script_id, new_name, new_description=''):338 data = {'new_name': new_name}339 if new_description:340 data.update({'new_description': new_description})341 req = MistRequests(uri=self.uri + '/api/v1/scripts/%s' % script_id,342 api_token=api_token, data=data)343 req.get = req.unavailable_api_call344 req.post = req.unavailable_api_call345 req.delete = req.unavailable_api_call346 return req347 def run_script(self, api_token, cloud_id, machine_id, script_id, job_id):348 data = {349 'cloud_id': cloud_id,350 'machine_id': machine_id,351 'job_id': job_id,352 }353 req = MistRequests(uri=self.uri + '/api/v1/scripts/%s' % script_id,354 api_token=api_token, data=data)355 req.get = req.unavailable_api_call356 req.put = req.unavailable_api_call357 req.delete = req.unavailable_api_call358 return req359 def delete_script(self, api_token, script_id):360 req = MistRequests(uri=self.uri + '/api/v1/scripts/%s' % script_id,361 api_token=api_token)362 req.get = req.unavailable_api_call363 req.post = req.unavailable_api_call364 req.put = req.unavailable_api_call365 return req366 def download_script(self, api_token, script_id):367 req = MistRequests(uri=self.uri + '/api/v1/scripts/%s/file'368 % script_id,369 api_token=api_token)370 req.delete = req.unavailable_api_call371 req.post = req.unavailable_api_call372 req.put = req.unavailable_api_call373 return req374 def url_script(self, api_token, script_id):375 req = MistRequests(uri=self.uri + '/api/v1/scripts/%s/url' % script_id,376 api_token=api_token)377 req.delete = req.unavailable_api_call378 req.post = req.unavailable_api_call379 req.put = req.unavailable_api_call380 return req381 def delete_scripts(self, api_token, script_ids):382 req = MistRequests(uri=self.uri + '/api/v1/scripts',383 json={'script_ids': script_ids},384 api_token=api_token)385 req.get = req.unavailable_api_call386 req.post = req.unavailable_api_call387 req.put = req.unavailable_api_call388 return req389 #################################################390 # SCHEDULES #391 #################################################392 def list_schedules(self, api_token):393 req = MistRequests(uri=self.uri + '/api/v1/schedules',394 api_token=api_token)395 req.post = req.unavailable_api_call396 req.delete = req.unavailable_api_call397 req.put = req.unavailable_api_call398 return req399 def add_schedule(self, api_token, name, schedule_type,400 conditions, schedule_entry='',401 description='', task_enabled=True, expires='',402 script_id='', action='',403 max_run_count='', run_immediately=False):404 data = {405 'conditions': conditions,406 'name': name,407 'description': description,408 'schedule_type': schedule_type,409 'schedule_entry': schedule_entry,410 'task_enabled': task_enabled,411 'action': action,412 'script_id': script_id,413 'expires': expires,414 'max_run_count': max_run_count,415 'run_immediately': run_immediately416 }417 req = MistRequests(uri=self.uri + '/api/v1/schedules',418 api_token=api_token, data=json.dumps(data))419 req.delete = req.unavailable_api_call420 req.get = req.unavailable_api_call421 req.put = req.unavailable_api_call422 return req423 def delete_schedule(self, api_token, schedule_id):424 req = MistRequests(uri=self.uri + '/api/v1/schedules/' + schedule_id,425 api_token=api_token)426 req.post = req.unavailable_api_call427 req.get = req.unavailable_api_call428 req.put = req.unavailable_api_call429 return req430 def edit_schedule(self, api_token, schedule_id, data=''):431 req = MistRequests(uri=self.uri + '/api/v1/schedules/' + schedule_id,432 api_token=api_token, data=data)433 req.post = req.unavailable_api_call434 req.get = req.unavailable_api_call435 req.put = req.unavailable_api_call436 req.delete = req.unavailable_api_call437 return req438 def show_schedule(self, api_token, schedule_id):439 req = MistRequests(uri=self.uri + '/api/v1/schedules/' + schedule_id,440 api_token=api_token)441 req.post = req.unavailable_api_call442 req.put = req.unavailable_api_call443 req.delete = req.unavailable_api_call444 return req445 #################################################446 # ZONES #447 #################################################448 def list_zones(self, api_token, cloud_id):449 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +450 '/dns/zones', api_token=api_token)451 req.post = req.unavailable_api_call452 req.put = req.unavailable_api_call453 req.delete = req.unavailable_api_call454 return req455 def list_records(self, api_token, cloud_id, zone_id):456 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +457 '/dns/zones/' + zone_id + '/records',458 api_token=api_token)459 req.post = req.unavailable_api_call460 req.put = req.unavailable_api_call461 req.delete = req.unavailable_api_call462 return req463 def create_zone(self, api_token, cloud_id, domain, type, ttl):464 data = {465 'domain': domain,466 'type': type,467 'ttl': ttl468 }469 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +470 '/dns/zones', api_token=api_token, data=data)471 req.get = req.unavailable_api_call472 req.put = req.unavailable_api_call473 req.delete = req.unavailable_api_call474 return req475 def delete_zone(self, api_token, cloud_id, zone_id):476 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +477 '/dns/zones/' + zone_id, api_token=api_token)478 req.get = req.unavailable_api_call479 req.post = req.unavailable_api_call480 req.put = req.unavailable_api_call481 return req482 def create_record(self, api_token, cloud_id, zone_id, name, type,483 data, ttl):484 data = {485 'name': name,486 'type': type,487 'data': data,488 'ttl': ttl489 }490 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +491 '/dns/zones/' + zone_id + '/records',492 api_token=api_token, data=data)493 req.get = req.unavailable_api_call494 req.put = req.unavailable_api_call495 req.delete = req.unavailable_api_call496 return req497 def delete_record(self, api_token, cloud_id, zone_id, record_id):498 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +499 '/dns/zones/' + zone_id + '/records/' + record_id,500 api_token=api_token)501 req.get = req.unavailable_api_call502 req.post = req.unavailable_api_call503 req.put = req.unavailable_api_call504 return req505 #################################################506 # TUNNELS #507 #################################################508 def list_vpn_tunnels(self, api_token):509 req = MistRequests(uri=self.uri + '/api/v1/tunnels',510 api_token=api_token)511 req.post = req.unavailable_api_call512 req.delete = req.unavailable_api_call513 req.put = req.unavailable_api_call514 return req515 def add_vpn_tunnel(self, api_token, cidrs, excluded_cidrs,516 name, description=''):517 data = {518 'name': name,519 'cidrs': cidrs,520 'excluded_cidrs': excluded_cidrs,521 'description': description522 }523 payload = json.dumps(data)524 req = MistRequests(uri=self.uri + '/api/v1/tunnels', data=payload,525 api_token=api_token)526 req.get = req.unavailable_api_call527 req.put = req.unavailable_api_call528 req.delete = req.unavailable_api_call529 return req530 def del_vpn_tunnel(self, api_token, tunnel_id):531 req = MistRequests(uri=self.uri + '/api/v1/tunnel/' + tunnel_id,532 api_token=api_token)533 req.post = req.unavailable_api_call534 req.put = req.unavailable_api_call535 req.get = req.unavailable_api_call536 return req537 def del_vpn_tunnels(self, api_token, tunnel_ids):538 data = {539 'tunnel_ids': tunnel_ids540 }541 payload = json.dumps(data)542 req = MistRequests(uri=self.uri + '/api/v1/tunnels', data=payload,543 api_token=api_token)544 req.post = req.unavailable_api_call545 req.put = req.unavailable_api_call546 req.get = req.unavailable_api_call547 return req548 def edit_vpn_tunnel(self, api_token, tunnel_id, cidrs, name,549 description=''):550 data = {551 'cidrs': cidrs,552 'name': name,553 'description': description554 }555 payload = json.dumps(data)556 req = MistRequests(uri=self.uri + '/api/v1/tunnel/' + tunnel_id,557 data=payload, api_token=api_token)558 req.get = req.unavailable_api_call559 req.post = req.unavailable_api_call560 req.delete = req.unavailable_api_call561 return req562 #################################################563 # NETWORKS #564 #################################################565 def list_networks(self, cloud_id, api_token):566 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +567 '/networks', api_token=api_token)568 req.post = req.unavailable_api_call569 req.put = req.unavailable_api_call570 req.delete = req.unavailable_api_call571 return req572 def list_subnets(self, cloud_id, network_id, api_token):573 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id +574 '/networks/' + network_id + '/subnets',575 api_token=api_token)576 req.post = req.unavailable_api_call577 req.put = req.unavailable_api_call578 req.delete = req.unavailable_api_call579 return req580 def create_network(self, cloud_id, api_token, network_params=''):581 data = {}582 if network_params:583 data.update(network_params)584 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id585 + '/networks', api_token=api_token,586 data=json.dumps(data))587 req.get = req.unavailable_api_call588 req.put = req.unavailable_api_call589 req.delete = req.unavailable_api_call590 return req591 def delete_network(self, cloud_id, network_id, api_token):592 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id593 + '/networks/' + network_id, api_token=api_token)594 req.get = req.unavailable_api_call595 req.post = req.unavailable_api_call596 req.put = req.unavailable_api_call597 return req598 def create_subnet(self, cloud_id, network_id, api_token):599 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id600 + '/networks/' + network_id + '/subnets',601 api_token=api_token)602 req.get = req.unavailable_api_call603 req.put = req.unavailable_api_call604 req.delete = req.unavailable_api_call605 return req606 def delete_subnet(self, cloud_id, network_id, subnet_id, api_token):607 req = MistRequests(uri=self.uri + '/api/v1/clouds/' + cloud_id608 + '/networks/' + network_id +609 '/subnets/' + subnet_id, api_token=api_token)610 req.get = req.unavailable_api_call611 req.post = req.unavailable_api_call612 req.put = req.unavailable_api_call613 return req614 #################################################615 # USER-ACTIONS #616 #################################################617 def login(self, email, password, cookie=None):618 req = MistRequests(uri=self.uri + '/login', cookie=cookie, data={619 'email': email,620 'password': password621 })622 req.delete = req.unavailable_api_call623 req.put = req.unavailable_api_call624 return req625 def logout(self, cookie, csrf):626 req = MistRequests(uri=self.uri + '/logout', cookie=cookie, csrf=csrf)627 return req628 def check_auth(self, email, password='', api_token_name='', ttl='',629 org_id=None, api_token=None):630 data = {'email': email}631 if password:632 data.update({'password': password})633 if api_token_name:634 data.update({'name': api_token_name})635 if ttl:636 data.update({'ttl': ttl})637 if org_id:638 data.update({'org_id': org_id})639 req = MistRequests(uri=self.uri + '/api/v1/tokens', data=data,640 api_token=api_token)641 req.get = req.unavailable_api_call642 req.delete = req.unavailable_api_call643 req.put = req.unavailable_api_call644 return req645 def list_tokens(self, api_token):646 req = MistRequests(uri=self.uri + '/api/v1/tokens',647 api_token=api_token)648 req.post = req.unavailable_api_call649 req.delete = req.unavailable_api_call650 req.put = req.unavailable_api_call651 return req652 def create_token(self, email, password, api_token=None, ttl=None,653 org_id=None, new_api_token_name=None):654 data = {655 'email': email,656 'password': password,657 'ttl': ttl,658 'org_id': org_id659 }660 if new_api_token_name:661 data.update({'name': new_api_token_name})662 req = MistRequests(uri=self.uri + '/api/v1/tokens', data=data,663 api_token=api_token)664 req.get = req.unavailable_api_call665 req.delete = req.unavailable_api_call666 req.put = req.unavailable_api_call667 return req668 def revoke_token(self, api_token, api_token_id):669 req = MistRequests(uri=self.uri + '/api/v1/tokens',670 params={'id': api_token_id},671 api_token=api_token)672 req.get = req.unavailable_api_call673 req.post = req.unavailable_api_call674 req.put = req.unavailable_api_call675 return req676 def check_token(self, api_token):677 req = MistRequests(uri=self.uri + '/api/v1/ping', api_token=api_token)678 req.put = req.unavailable_api_call679 req.delete = req.unavailable_api_call680 return req681 def su(self, api_token):682 req = MistRequests(uri=self.uri + '/su', api_token=api_token)683 req.post = req.unavailable_api_call684 req.delete = req.unavailable_api_call685 req.put = req.unavailable_api_call686 return req687 #################################################688 # WHITELIST_IPS #689 #################################################690 def request_whitelist_ip(self, owner_email, api_token):691 data = {692 'email': owner_email693 }694 req = MistRequests(uri=self.uri + '/request-whitelist-ip',695 api_token=api_token, data=data)696 req.delete = req.unavailable_api_call697 req.get = req.unavailable_api_call698 req.put = req.unavailable_api_call699 return req700 def confirm_whitelist_ip(self, api_token, key=''):701 data = {702 'key': key703 }704 req = MistRequests(uri=self.uri + '/confirm-whitelist',705 api_token=api_token, data=data)706 req.delete = req.unavailable_api_call707 req.put = req.unavailable_api_call708 req.post = req.unavailable_api_call709 return req710 def whitelist_ips(self, api_token, ips=None):711 data = {712 'ips': ips713 }714 req = MistRequests(uri=self.uri + '/api/v1/whitelist',715 api_token=api_token, data=json.dumps(data))716 req.get = req.unavailable_api_call717 req.delete = req.unavailable_api_call718 req.put = req.unavailable_api_call...

Full Screen

Full Screen

core.py

Source:core.py Github

copy

Full Screen

1import json2from misttests.api.io.io import MistIoApi3from misttests.api.mistrequests import MistRequests4class MistCoreApi(MistIoApi):5 def create_org(self, api_token, name=''):6 req = MistRequests(uri=self.uri + '/api/v1/org',7 json={'name': name},8 api_token=api_token)9 req.get = req.unavailable_api_call10 req.delete = req.unavailable_api_call11 req.put = req.unavailable_api_call12 return req13 def show_user_org(self, api_token):14 req = MistRequests(uri=self.uri + '/api/v1/org',15 api_token=api_token)16 req.post = req.unavailable_api_call17 req.delete = req.unavailable_api_call18 req.put = req.unavailable_api_call19 return req20 def show_user_invitations(self, api_token):21 req = MistRequests(uri=self.uri + '/user_invitations',22 api_token=api_token)23 req.post = req.unavailable_api_call24 req.delete = req.unavailable_api_call25 req.put = req.unavailable_api_call26 return req27 def add_team(self, api_token, org_id, name='', description=None):28 data = {'name': name,29 }30 if description is not None:31 data.update({'description': description})32 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams' % org_id,33 api_token=api_token, data=data)34 req.get = req.unavailable_api_call35 req.delete = req.unavailable_api_call36 req.put = req.unavailable_api_call37 return req38 def list_teams(self, api_token, org_id):39 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams' % org_id,40 api_token=api_token)41 req.post = req.unavailable_api_call42 req.delete = req.unavailable_api_call43 req.put = req.unavailable_api_call44 return req45 def show_team(self, api_token, org_id, team_id):46 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s'47 % (org_id, team_id),48 api_token=api_token)49 req.post = req.unavailable_api_call50 req.delete = req.unavailable_api_call51 req.put = req.unavailable_api_call52 return req53 def edit_team(self, api_token, org_id, team_id, name, visibility=None,54 description=None,):55 data = {'new_name': name,56 }57 if description is not None:58 data.update({'new_description': description})59 if visibility is not None:60 data.update({'new_visible': visibility})61 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s'62 % (org_id, team_id), data=data,63 api_token=api_token)64 req.post = req.unavailable_api_call65 req.delete = req.unavailable_api_call66 req.get = req.unavailable_api_call67 return req68 def delete_team(self, api_token, org_id, team_id):69 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s'70 % (org_id, team_id),71 api_token=api_token)72 req.get = req.unavailable_api_call73 req.post = req.unavailable_api_call74 req.put = req.unavailable_api_call75 return req76 def delete_teams(self, api_token, org_id, team_ids):77 data = {'team_ids': team_ids}78 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams'79 % org_id,80 api_token=api_token, data=json.dumps(data))81 req.get = req.unavailable_api_call82 req.post = req.unavailable_api_call83 req.put = req.unavailable_api_call84 return req85 def invite_member_to_team(self, api_token, org_id, team_id, email):86 data = {'emails': email}87 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s/members' %88 (org_id, team_id),89 api_token=api_token, data=data)90 req.get = req.unavailable_api_call91 req.delete = req.unavailable_api_call92 req.put = req.unavailable_api_call93 return req94 def confirm_invitation(self, api_token, invitoken):95 req = MistRequests(uri=self.uri + '/confirm-invitation?invitoken=%s' %96 invitoken,97 api_token=api_token)98 req.post = req.unavailable_api_call99 req.delete = req.unavailable_api_call100 req.put = req.unavailable_api_call101 return req102 def delete_member_from_team(self, api_token, org_id, team_id, user_id):103 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s/members/%s'104 % (org_id, team_id, user_id),105 api_token=api_token)106 req.get = req.unavailable_api_call107 req.post = req.unavailable_api_call108 req.put = req.unavailable_api_call109 return req110 def list_team_policy(self, api_token, org_id, team_id):111 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s/policy'112 % (org_id, team_id),113 api_token=api_token)114 req.post = req.unavailable_api_call115 req.delete = req.unavailable_api_call116 req.put = req.unavailable_api_call117 return req118 def edit_team_policy_operator(self, api_token, org_id, team_id,119 policy_operator):120 data = {'policy_operator': policy_operator,121 }122 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s/policy'123 % (org_id, team_id), data=data,124 api_token=api_token)125 req.put = req.unavailable_api_call126 req.delete = req.unavailable_api_call127 req.get = req.unavailable_api_call128 return req129 def append_rule_to_policy(self, api_token, org_id, team_id, operator,130 action, rtype, rid, rtags):131 if isinstance(rtags, dict):132 rtags = json.dumps(rtags)133 data = {'operator': operator,134 'action': action,135 'rtype': rtype,136 'rid': rid,137 'rtags': rtags138 }139 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s/'140 'policy/rules''' % (org_id, team_id),141 data=data, api_token=api_token)142 req.put = req.unavailable_api_call143 req.delete = req.unavailable_api_call144 req.get = req.unavailable_api_call145 return req146 def insert_rule_to_policy(self, api_token, org_id, team_id, index_id,147 operator, action, rtype, rid, rtags):148 data = {'operator': operator,149 'action': action,150 'rtype': rtype,151 'rid': rid,152 'rtags': rtags153 }154 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s/'155 'policy/rules/%s' % (org_id, team_id, index_id),156 data=data, api_token=api_token)157 req.put = req.unavailable_api_call158 req.delete = req.unavailable_api_call159 req.get = req.unavailable_api_call160 return req161 def edit_rule_to_policy(self, api_token, org_id, team_id, index_id,162 operator,163 action, rtype, rid, rtags):164 data = {'operator': operator,165 'action': action,166 'rtype': rtype,167 'rid': rid,168 'rtags': rtags169 }170 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/'171 '%s/policy/rules/%s'172 % (org_id, team_id, index_id),173 data=data, api_token=api_token)174 req.post = req.unavailable_api_call175 req.delete = req.unavailable_api_call176 req.get = req.unavailable_api_call177 return req178 def delete_rule_from_policy(self, api_token, org_id, team_id, index_id):179 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s/'180 'policy/rules/%s' % (org_id, team_id, index_id),181 api_token=api_token)182 req.get = req.unavailable_api_call183 req.post = req.unavailable_api_call184 req.put = req.unavailable_api_call185 return req186 def edit_team_policy(self, api_token, org_id, team_id, policy):187 data = {'policy': policy}188 req = MistRequests(uri=self.uri + '/api/v1/org/%s/teams/%s/policy'189 % (org_id, team_id),190 data=json.dumps(data),191 api_token=api_token)192 req.get = req.unavailable_api_call193 req.post = req.unavailable_api_call194 req.delete = req.unavailable_api_call195 return req196 def list_orgs(self, api_token):197 req = MistRequests(uri=self.uri + '/api/v1/orgs', api_token=api_token)198 req.post = req.unavailable_api_call199 req.put = req.unavailable_api_call200 req.delete = req.unavailable_api_call201 return req202 def list_templates(self, api_token):203 req = MistRequests(uri=self.uri + '/api/v1/templates',204 api_token=api_token)205 req.post = req.unavailable_api_call206 req.put = req.unavailable_api_call207 req.delete = req.unavailable_api_call208 return req209 def add_template(self, api_token, name, location_type,210 exec_type='cloudify', **kwargs):211 payload = {212 'name': name,213 'location_type': location_type,214 'exec_type': exec_type215 }216 payload.update(kwargs)217 req = MistRequests(uri=self.uri + '/api/v1/templates',218 data=json.dumps(payload), api_token=api_token)219 req.get = req.unavailable_api_call220 req.put = req.unavailable_api_call221 req.delete = req.unavailable_api_call222 return req223 def delete_template(self, api_token, template_id):224 req = MistRequests(uri=self.uri + '/api/v1/templates/' + template_id,225 api_token=api_token)226 req.get = req.unavailable_api_call227 req.post = req.unavailable_api_call228 req.put = req.unavailable_api_call229 return req230 def edit_template(self, api_token, template_id, name,231 description='', **kwargs):232 payload = {233 'name': name,234 'description': description235 }236 payload.update(kwargs)237 req = MistRequests(uri=self.uri + '/api/v1/templates/' + template_id,238 data=payload, api_token=api_token)239 req.get = req.unavailable_api_call240 req.post = req.unavailable_api_call241 req.delete = req.unavailable_api_call242 return req243 def show_template(self, api_token, template_id):244 req = MistRequests(uri=self.uri + '/api/v1/templates/' + template_id,245 api_token=api_token)246 req.put = req.unavailable_api_call247 req.post = req.unavailable_api_call248 req.delete = req.unavailable_api_call249 return req250 def list_stacks(self, api_token):251 req = MistRequests(uri=self.uri + '/api/v1/stacks',252 api_token=api_token)253 req.post = req.unavailable_api_call254 req.put = req.unavailable_api_call255 req.delete = req.unavailable_api_call256 return req257 def create_stack(self, api_token, name, template_id,258 cloud_id='', machine_name=''):259 payload = {260 'name': name,261 'template_id': template_id,262 'workflow': 'install',263 'deploy': True,264 'inputs': {265 'mist_uri': 'https://mist.io',266 'mist_cloud': cloud_id,267 'webserver_port': 8000,268 'machine_name': machine_name,269 'mist_image': 'mist/ubuntu-14.04',270 'mist_size': 'default'271 }272 }273 req = MistRequests(uri=self.uri + '/api/v1/stacks',274 data=json.dumps(payload), api_token=api_token)275 req.delete = req.unavailable_api_call276 req.put = req.unavailable_api_call277 req.get = req.unavailable_api_call278 return req279 def delete_stack(self, api_token, stack_id):280 req = MistRequests(uri=self.uri + '/api/v1/stacks/' + stack_id,281 api_token=api_token)282 req.post = req.unavailable_api_call283 req.put = req.unavailable_api_call284 req.get = req.unavailable_api_call285 return req286 def show_stack(self, api_token, stack_id):287 req = MistRequests(uri=self.uri + '/api/v1/stacks/' + stack_id,288 api_token=api_token)289 req.post = req.unavailable_api_call290 req.put = req.unavailable_api_call291 req.delete = req.unavailable_api_call292 return req293 def run_workflow(self, api_token, stack_id, workflow=''):294 payload = {295 'workflow': workflow296 }297 req = MistRequests(uri=self.uri + '/api/v1/stacks/' + stack_id,298 data=json.dumps(payload), api_token=api_token)299 req.get = req.unavailable_api_call300 req.put = req.unavailable_api_call301 req.delete = req.unavailable_api_call...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...27 res = {'api_token': str(uuid.uuid4())}28 storage.internal.api_tokens.insert_one(res)29 res.pop('_id')30 return res31def validate_api_token(storage, api_token: str):32 query = {'api_token': api_token}33 is_found = next(storage.internal.api_tokens.find(query), None)34 if not is_found:35 raise fastapi.HTTPException(404, detail='Unknown API token')36@app.get('/api/{api_token}')37def get_resources(api_token: str, storage = Depends(get_storage)):38 validate_api_token(storage, api_token)39 return list(set(storage[api_token].collection_names()))40@app.get('/api/{api_token}/{resource}')41def get_resource_list(api_token: str, resource: str, storage = Depends(get_storage)):42 validate_api_token(storage, api_token)43 entities = list(storage[api_token][resource].find())44 for entity in entities:45 entity['_id'] = str(entity['_id'])46 return entities47@app.post('/api/{api_token}/{resource}')48def create_resource(49 api_token: str,50 resource: str,51 entity: dict = fastapi.Body(...),52 storage = Depends(get_storage),53):54 validate_api_token(storage, api_token)55 res = storage[api_token][resource].insert_one(entity)56 entity['_id'] = str(res.inserted_id)57 return entity58@app.get('/api/{api_token}/{resource}/{entity_id}')59def get_entity(60 api_token: str,61 resource: str,62 entity_id: str,63 storage = Depends(get_storage),64):65 validate_api_token(storage, api_token)66 try:67 query = {'_id': ObjectId(entity_id)}68 [entity] = list(storage[api_token][resource].find(query))69 entity['_id'] = str(entity['_id'])70 except:71 raise fastapi.HTTPException(404, detail='No entity with given id')72 return entity73@app.put('/api/{api_token}/{resource}/{entity_id}')74def put_entity(75 api_token: str,76 resource: str,77 entity_id: str,78 new_entity: dict = fastapi.Body(...),79 storage = Depends(get_storage),80):81 query = {'_id': ObjectId(entity_id)}82 storage[api_token][resource].replace_one(query, new_entity)83 return get_entity(api_token, resource, entity_id)84@app.patch('/api/{api_token}/{resource}/{entity_id}')85def patch_entity(86 api_token: str,87 resource: str,88 entity_id: str,89 patch: dict = fastapi.Body(...),90 storage = Depends(get_storage),91):92 old_entity = get_entity(api_token, resource, entity_id)93 new_entity = {**old_entity, **patch}94 res = put_entity(api_token, resource, entity_id, new_entity)95 return res96@app.delete('/api/{api_token}/{resource}/{entity_id}')97def delete_resource(98 api_token: str,99 resource: str,100 entity_id: str,101 storage = Depends(get_storage),102):103 validate_api_token(storage, api_token)104 query = {'_id': ObjectId(entity_id)}105 try:106 storage[api_token][resource].delete_one(query)107 except:108 pass109 return True110if __name__ == '__main__':111 HOST, PORT = 'localhost', 7777...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful