def create_new_user(): switch_mode(user='******', password='******') clear_session() user_data = json.dumps({ 'full_name': 'test-user-1', 'is_active': True, 'password': '******', 'username': '******', 'access': [{ 'role_ref': "/api/role/?name=System-Admin", 'tenant_ref': "/api/tenant/?name=admin" }], 'default_tenant_ref': "/api/tenant/?name=admin" }) rest.post('user', data=user_data) clear_session() yield clear_session(all_sessions=True) switch_mode(user='******', password='******') rest.delete('user', name='test-user-1')
def create_microservice_group(msg_name, ms_name=[], **kwargs): """ :param msg_name: :param ms_name: :param kwargs: :return: """ tenant = infra_utils.get_config().get_mode(key='tenant') msg = { 'name': msg_name, 'tenant_uuid': rest.get_uuid_by_name('tenant', tenant), 'service_uuids': [] } for ms in ms_name: msg['service_uuids'].append(rest.get_uuid_by_name('microservice', ms)) try: rest.post('microservicegroup', name=msg_name, data=msg) # REVIEW why was this tenant_uuid? except Exception as e: if 'Micro service group with this Name and Tenant ref ' \ 'already exists' in str(e): logger.info('microservice group already exists, ignoring error') else: raise return msg_name
def import_key_and_certificate(data, name=None, key_file=None, cert_file=None, user_session='default_session', should_pass=True, slug=None, tenant='admin'): path = 'sslkeyandcertificate/importkeyandcertificate' headers = {} if slug: headers = {'slug': slug} if not data: if not name: logger_utils.fail('name must be specified if data is not') if not key_file and not cert_file: logger_utils.fail('key and/or cert file must be specified if data is not') key_s = '' cert_s = '' try: if key_file: with open(key_file, 'r') as f: key_s = f.read() except Exception as e: logger_utils.fail('Failed to read key file %s: %s' %(key_file, str(e))) try: if cert_file: with open(cert_file, 'r') as f: cert_s = f.read() except Exception as e: logger_utils.fail('Failed to read certificate file %s: %s' %(cert_file, str(e))) data = {} data['name'] = name if cert_s: data['certificate'] = cert_s if key_s: data['key'] = key_s rest.post(path, data=data)
def create_healthmonitor(template, hm_name, hm_template_name, **kwargs): """ :param template: :param hm_name: :param kwargs: :return: """ hm = load_hm_template(template, hm_template_name) hm['name'] = hm_name http_request = kwargs.get('http_request', None) if http_request: hm['http_monitor'] = {'http_request': http_request} rest.post('healthmonitor', name=hm_name, data=hm) validate_healthmonitor('healthmonitor', hm_name)
def reboot_clean(update_admin_info=True, **kwargs): post('cluster', path='reboot', data=json.dumps({'mode': 'REBOOT_CLEAN'})) asleep(msg="Sleep before cluster wait check", delay=120) wait_until_cluster_ready() set_sysadmin_public_key() set_systemconfiguration() set_ha_mode_best_effort() if update_admin_info: config = AviConfig.get_instance() mode = config.get_mode() logger.debug("Current Default Mode %s" % mode) username = mode['user'] password = '******' mode["password"] = '******' update_admin_user(username=username, password=password) switch_mode(**mode)
def network_create(name, configured_subnet, static_range_list=None, check_status_code=True): """ :param name: :param configured_subnet: :param static_range_list: :param check_status_code: :return: """ if not configured_subnet: logger_utils.fail('Must specify configured subnet') network_data = {} network_data['name'] = name network_data['uuid'] = name network_data['configured_subnets'] = [] if static_range_list: static_ips = [] for static_range in static_range_list: static_ips.append({'type': 'V4', 'addr': static_range}) configured_subnet = { 'prefix': configured_subnet, 'static_ips': static_ips } network_data['configured_subnets'].append(configured_subnet) return rest.post('network', data=json.dumps(network_data), check_status_code=check_status_code)
def test_crud_demo(self): """ Create, Read, Update and Delete SE Group """ sg_name = 'demo_sg_group' # Create se_group = {} se_group['name'] = sg_name rest.post('serviceenginegroup', name=sg_name, data=json.dumps(se_group)) # Read _, resp = rest.get('serviceenginegroup', name=sg_name) # Update se_group = {} se_group['vs_host_redundancy'] = False _, resp = rest.update('serviceenginegroup', name=sg_name, **se_group) # Delete rest.delete('serviceenginegroup', name=sg_name)
def ssl_import_key_and_certificate(cert_data): """ cert_name: Name of Certificate cert_type: Type of certificate - CA/VIRTUALSERVICE/SYSTEM cert: Certificate to Import Type of ssl cert (pb): SSLKeyAndCertificate API called: api/sslkeyandcertificate """ data = cert_data for k,v in cert_data.iteritems(): if k == 'certificate': data['certificate'] = {k:v} data['type'] = 'SSL_CERTIFICATE_TYPE_VIRTUALSERVICE' rest.post('sslkeyandcertificate', data=data) return
def create_vrf(name): try: data={"uuid": "uuid", "name": name} datas= json.dumps(data) resp, code = rest.post("vrfcontext", name=name, data=datas) return resp except Exception: logger_utils.fail("Unable to create VRF! ...")
def tenant_create(name, tenant_vrf=False): """ :param name: :param kwargs: :return: """ import avi_objects.rest as rest json_tenant_data = { 'uuid': name, 'name': name } if tenant_vrf: json_tenant_data['config_settings'] = { 'tenant_vrf' : tenant_vrf } rest.post('tenant', data=json.dumps(json_tenant_data))
def create_basic_ipam_profile(name, ipam_type, **kwargs): """ :param name: :param ipam_type: :param kwargs: :return: """ if ipam_type not in IpamDnsType.keys(): e_str = "%s: not in one of %s" % (ipam_type, IpamDnsType.keys()) logger.info(e_str) logger_utils.fail(e_str) tenant = kwargs.get('tenant', infra_utils.get_mode()['tenant']) ipam_data = {'name': name, 'type': IpamDnsType.Value(ipam_type)} rest.post('ipamdnsproviderprofile', data=json.dumps(ipam_data), tenant=tenant)
def manual_autoscale(pool_name, action): """ :param pool_name: pool name for which autoscaling is requested :param action: SCALEOUT or SCALEIN """ obj_data = {'reason': 'test'} rc, rsp = rest.post('pool', name=pool_name, path=action.lower(), data=obj_data) logger.info('%s %s returned %s' % (action, rc, rsp))
def create_ip_addr_group(name, ip, prefix, **kwargs): ''' Creates IP address group :param name: :param ip: :param kwargs: :return: ''' ip_addr = {} ip_addr['name'] = name ip_addr['prefixes'] = [] for each_ip in ip: new_ip_addr = {} new_ip_addr['addr'] = each_ip new_ip_addr['type'] = 0 #For type V4 ip_addr['prefixes'].append({ 'ip_addr': new_ip_addr, 'mask': int(prefix) }) # TODO need to check for mask to IP address group ip_addr['description'] = "Created for testing" rest.post('ipaddrgroup', data=ip_addr)
def set_sysadmin_public_key(enable_basic_auth=True, **kwargs): sysadmin_public_key_path = '/test/robot/new/lib/tools/id_sysadmin.pub' sysadmin_priv_key_path = '/test/robot/new/lib/tools/id_sysadmin' config = AviConfig.get_instance() controller_obj = config.get_vm_of_type('controller')[0].ip # first enable basic auth and then use REST API. if enable_basic_auth: enable_controller_basic_authentication() logger.info('Finish updating controller to allow basic auth') logger.info('-- set_sysadmin_public_key -- %s\n' % (controller_obj)) data = {} data['action'] = 'create' workspace = suite_vars.workspace key_path = workspace + sysadmin_public_key_path key_str = None try: with open(key_path, 'r') as f: key_str = f.read() except: raise Exception('Could not ready sysadmin pub key') data['key'] = key_str logger.info('Data after: %s---' % data) try: # Try with 'adminkey' config = AviConfig.get_instance() current_password = config.get_mode()['password'] config.switch_mode(password='******') r = post('adminkey', data=json.dumps(data)) except Exception as e: # Try with 'resetsysadminkey' logger.info("Got Exception %s with adminkey. Trying with resetsysadminkey" % e) r = post('resetsysadminkey', data=json.dumps(data)) config.switch_mode(password=current_password)
def create_vsvip(vsvip_name, dns_info_list=None, vip_list=None, network=None, auto_allocate_ip=False, auto_allocate_network=None, auto_allocate_subnet=None, vrf_context=None, check_status_code=True): vsvip_data = {} vsvip_data['name'] = vsvip_name vsvip_data['uuid'] = vsvip_name if dns_info_list: vsvip_data['dns_info'] = dns_info_list if vrf_context: vsvip_data[ 'vrf_context_ref'] = '/api/vrfcontext/?name=%s' % vrf_context vsvip_data['vip'] = [] # TODO: handle auto_allocate_ips, auto_allocate_networks plural forms if auto_allocate_ip: vip_data = {} vip_data['auto_allocate_ip'] = True vip_data['avi_allocated_vip'] = True subnet_uuid = get_testbed_variable(variable='subnet_uuid') if subnet_uuid: vip_data['subnet_uuid'] = subnet_uuid vsvip_data['vip'].append(vip_data) if network: # REVIEW do we need this? we don't actually use the value vsvip_data['ipam_network_subnet'] = {} if auto_allocate_network: vsvip_data['ipam_network_subnet'][ 'network_ref'] = '/api/network/?name=%s' % auto_allocate_network if auto_allocate_subnet: vsvip_data['ipam_network_subnet'][ 'subnet'] = auto_allocate_subnet elif vip_list: vsvip_data['vip'] = vip_list else: # TODO pass return post('vsvip', data=json.dumps(vsvip_data), check_status_code=check_status_code)
def clear_dispatcher_stat(vs_name): se_uuids = get_se_uuids_from_vs_name(vs_name) for se_uuid in se_uuids: rest.post('serviceengine', uuid=se_uuid, path='flowtablestat/clear')
def clear_cltrack(vs_name, **kwargs): status_code, data = rest.post('virtualservice', name=vs_name, path='/cltrack/clear')