def setup_mtz_simple(cmgr, x_name, **kwargs): x_name = x_name or data_utils.rand_name('mtz-i') wait4server_active = kwargs.pop('wait4servers', True) tenant_cmgr = kwargs.pop('for_tenant', None) if tenant_cmgr: # in this condition, cmgr must have admin privilege tenant_id = tenant_cmgr.manager.credentials.tenant_id else: tenant_cmgr = cmgr tenant_id = kwargs.pop('tenant_id', None) if tenant_id: msg = "tenant_id not supported, use for_tenant=tenant_cmgr" raise exceptions.NotImplementedError(msg) router_type = kwargs.pop('router_type', 'shared') scope_id_list = kwargs.pop('scope_id_list', []) mtz_ip = netaddr.IPNetwork(kwargs.pop('cidr', '10.199.1.0/24')) mask_bits = kwargs.pop('mask_bits', (mtz_ip.prefixlen + 3)) cidr_list = [x for x in mtz_ip.subnet(mask_bits)] net_list = [] for ix, scope_id in enumerate(scope_id_list): subnet_cidr = str(cidr_list[ix]) name = x_name + ("-%d" % (ix + 1)) network_subnet = create_mtz_networks(cmgr, scope_id, subnet_cidr, name=name, tenant_id=tenant_id, **kwargs) net_list.append(network_subnet) # server_create does not accept tenant_id, always use tenant_cmgr router = NET.create_router_and_add_interfaces(tenant_cmgr, x_name + "-router", net_list, router_type=router_type, tenant_id=tenant_id) sg = NET.create_security_group_loginable(tenant_cmgr, x_name, tenant_id=tenant_id) security_group_id = sg['id'] net_id_servers = {} for ix, (network, subnet) in enumerate(net_list): net_id = network['id'] vm = NET.create_server_on_network( tenant_cmgr, net_id, security_group_name_or_id=security_group_id, server_name=network['name']) net_id_servers[net_id] = dict(server=vm, network=network, subnet=subnet) if wait4server_active: try: wait_for_servers_active(cmgr, net_id_servers) except Exception: # if servers failed to be ACTIVE, we want to examine them pass return (router, net_id_servers, sg)
def create_networks(cmgr, network_name, cidr, **kwargs): try: router = cmgr.qsvc('router-show', network_name) network = cmgr.qsvc('net-show', network_name) subnet = cmgr.qsvc('subnet-show', network_name) except: router_type = kwargs.pop('router_type', 'shared') public_network_id = kwargs.pop('public_network_id', None) network, subnet = NET.create_mtz_networks(cmgr, cidr, name=network_name, **kwargs) net_list = [(network, subnet)] router = NET.create_router_and_add_interfaces( cmgr, network_name, net_list, public_network_id=public_network_id, router_type=router_type) return (router, network, subnet)