def init_vio_tempest_env(cli_mgr, vio_net_conf, conf_conf, conf_defaults=None, **kwargs): xnet_name = kwargs.pop('public_net_name', 'public') use_internal_dns = kwargs.pop('use_internal_dns', True) img_name = kwargs.pop('image_name', 'cirros-0.3.3-x86_64-disk') from_template = kwargs.pop('tempest_sample', 'itempest/etc/tempest-internal.conf.sample') tempest_conf = kwargs.pop('tempest_conf', 'itempest/etc/itempest-internal.conf') dns_nameservers = ( vio_net_conf['nameservers_internal'] if use_internal_dns else vio_net_conf['nameservers']) net, subnet = show_or_create_external_network( cli_mgr, xnet_name, cidr=vio_net_conf['cidr'], gateway_ip=vio_net_conf['gateway'], dns_nameservers=dns_nameservers, allocation_pools=vio_net_conf['alloc_pools']) try: img = U.fgrep(cli_mgr.nova('image-list'), name=img_name)[0] except Exception: img = cli_mgr.nova('image-list')[0] vio_iconf = copy.deepcopy(conf_conf) vio_iconf['compute']['image_ref'] = img['id'] vio_iconf['compute']['image_ref_alt'] = img['id'] vio_iconf['network']['public_network_id'] = net['id'] conf_name = build_tempest_conf(tempest_conf, from_template, conf_defaults, **vio_iconf) net = cli_mgr.qsvc('net-list', name=xnet_name)[0] return (conf_name, net)
def create_solaris(adm, os_auth_url, halt=False, password="******"): if halt: import pdb; pdb.set_trace() # get-or-create Sun solaris system's admin Sun try: tenant = utils.fgrep(adm.keys('tenant-list'), name=r'^Sun$') if len(tenant) < 1: Sun = icreds.create_admin_project('Sun', password) sun = utils.get_mimic_manager_cli(os_auth_url, 'Sun', password) except Exception: tb_str = traceback.format_exc() mesg = ("ERROR creating/retriving Admin user[%s]:\n%s" % ( 'Sun', tb_str)) utils.log_msg(mesg) # our solar system has 8 planets' sun_planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Satun', 'Uranus', 'Neptune'] dwarf_planets = ["Haumea", "Eris", "Ceres", "Pluto", "Makemake"] tenants = {} for planet in sun_planets + dwarf_planets + ["Moon"]: tenant = utils.fgrep(adm.keys('tenant-list'), name=planet) if len(tenant) < 1: # tenant not exist, create it; default password=itempest tenant = icreds.create_primary_project(planet, password) try: tenant = adm.keys('tenant_get_by_name', planet) tenants[planet] = tenant # by default tenant can only have instances=10 adm.nova('quota-update', tenant['id'], instances=tenant_max_instances) adm.qsvc('quota-incr-by', tenant['id'], 2) except Exception: pass else: tenants[planet] = tenant[0] return tenants
def show_or_create_vmdk_image(cli_mgr, img_name=None, img_file=None): img_name = img_name if img_name else DEFAULT_IMAGE_NAME img_file = img_file if img_file else DEFAULT_IMAGE_FILE try: img = utils.fgrep(cli_mgr.nova('image-list'), name=img_name)[0] except Exception: property = dict(vmware_disktype='sparse', vmware_adaptertype='ide', hw_vif_model='e1000') img = cli_mgr.nova('image-create', img_name, file=img_file, container_format='bare', disk_format='vmdk', is_public=True, property=property) return cli_mgr.nova('image-show', img['id'])
def create_image(glance, img_name, **create_kwargs): exact_img_name = r"\^%s\$" % img_name imgs = U.fgrep(glance('image-list'), name=exact_img_name) if len(imgs) > 0: return imgs[0] container_format = create_kwargs.pop('container_format', 'bare') # TODO(akang): properies are wrong, how to get correct values? disk_format = create_kwargs.pop('disk_format', 'raw') if disk_format == 'vmdk': create_kwargs['property'] = dict( vmware_disktype='sparse', vmware_adaptertype='ide', hw_vif_model='e1000') img = glance('image-create', img_name, container_format, disk_format, **create_kwargs) return img
def show_toplogy(cli_mgr, return_topo=False, prefix=None, router_id=None, delete_resources=False): tenant_name = cli_mgr.manager.credentials.tenant_name FMT_ROUTER = "%s>> {router_type} router: {name} {id}" % (' ' * 2) FMT_ROUTER_O = "%s>> router: {name} {id}" % (' ' * 2) FMT_X_GW1 = "%sGW: snat_enabled: {enable_snat}" % (' ' * 5) FMT_X_GW2 = "%sfixed_ip: {external_fixed_ips}" % (' ' * (5 + 4)) FMT_X_ROUT = "%sroutes: {routes}" % (' ' * (5 + 4)) FMT_INTERFACE = "%s>> interface: {name} {id}" % (' ' * 6) # FMT_SUBNETS = "%s subnets: {subnets}" % (' ' * 8) FMT_SNET_ADDR = "%s subnet: {id} {name} cidr={cidr} gw={gateway_ip}" % ( ' ' * 8) FMT_SERVER = "%s>> server: {name} {id}" % (' ' * 10) FMT_SERV_ADDR = "%s>> network: %s " topo = [] topo_line = ["\nNetwork topology of tenant[%s]" % tenant_name] s_list = cli_mgr.nova('server-list-with-detail') if router_id: router_list = cli_mgr.qsvc('router-list', id=router_id) else: router_list = cli_mgr.qsvc('router-list') if prefix: ser_name = "^%s" % prefix s_list = utils.fgrep(s_list, name=ser_name) router_list = utils.fgrep(router_list, name=ser_name) sorted(router_list, key=itemgetter('name')) for router in router_list: rtr = _g_by_attr(router, ('id', 'name', 'router_type', 'distributed')) rtr['_networks'] = [] if 'distributed' in router and router['distributed']: rtr['router_type'] = 'distributed' try: topo_line.append(FMT_ROUTER.format(**rtr)) except: topo_line.append(FMT_ROUTER_O.format(**rtr)) if type(router['external_gateway_info']) is dict: xnet_info = router['external_gateway_info'] rtr['gateway'] = xnet_info topo_line.append(FMT_X_GW1.format(**xnet_info)) try: topo_line.append(FMT_X_GW2.format(**xnet_info)) except: utils.log_msg("GW does not have external_fixed_ips: %s" % xnet_info) rtr['routes'] = router['routes'] if (type(router['routes']) in [list, tuple] and len(router['routes']) > 0): topo_line.append(FMT_X_ROUT.format(**router)) rp_list = cli_mgr.qsvc('router-port-list', router['id']) for rp in rp_list: network = cli_mgr.qsvc('net-show', rp['network_id']) netwk = _g_by_attr(network, ('name', 'id')) subnet_list = network['subnets'] netwk['port_id'] = rp['id'] netwk['_servers'] = [] topo_line.append(FMT_INTERFACE.format(**netwk)) netwk['subnets'] = [] for subnet_id in subnet_list: subnet = cli_mgr.qsvc('subnet-show', subnet_id) subnet = _g_by_attr(subnet, ('id', 'cidr', 'gateway_ip', 'allocation_pools', 'name')) topo_line.append(FMT_SNET_ADDR.format(**subnet)) netwk['subnets'].append(subnet) if_name = network['name'] if_servers = [s for s in s_list if if_name in s['addresses']] for s in if_servers: addr_dict = mdata.get_server_address(s) no_if = len(addr_dict) serv = _g_by_attr(s, ('name', 'id')) serv['#interface'] = no_if topo_line.append( FMT_SERVER.format(**s) + " #interface=%s" % no_if) if if_name in addr_dict: serv['interface'] = addr_dict[if_name] topo_line.append( FMT_SERV_ADDR % (' ' * 14, addr_dict[if_name])) netwk['_servers'].append(serv) rtr['_networks'].append(netwk) topo.append(rtr) print("\n".join(topo_line)) if delete_resources: _delete_topology(cli_mgr, topo) return topo if return_topo else {}