def index(self, req): tenant_id = urlparse.parse_qs(req.environ["QUERY_STRING"]).get("tenant_id", [None])[0] context = req.environ["engine.context"] LOG.audit(_("Getting networks for project %s"), tenant_id or "<all>") if context.is_admin and not tenant_id: networks = db.network_get_all(context) elif tenant_id: networks = db.project_get_networks(context, tenant_id, associate=False) else: raise exc.HTTPNotFound() result = [network_dict(net_ref) for net_ref in networks] return {"networks": result}
def get_project_and_global_net_ids(self, context, project_id): """Fetches all networks associated with this project, or that are "global" (i.e., have no project set). Returns list sorted by 'priority'. """ admin_context = context.elevated() networks = db.project_get_networks(admin_context, project_id, False) networks.extend(self.get_global_networks(admin_context)) id_priority_map = {} net_list = [] for n in networks: net_id = n['uuid'] net_list.append((net_id, n["project_id"])) id_priority_map[net_id] = n['priority'] return sorted(net_list, key=lambda x: id_priority_map[x[0]])
def index(self, req): tenant_id = urlparse.parse_qs(req.environ['QUERY_STRING']).get( 'tenant_id', [None])[0] context = req.environ['engine.context'] LOG.audit(_("Getting networks for project %s"), tenant_id or '<all>') if context.is_admin and not tenant_id: networks = db.network_get_all(context) elif tenant_id: networks = db.project_get_networks(context, tenant_id, associate=False) else: raise exc.HTTPNotFound() result = [network_dict(net_ref) for net_ref in networks] return {'networks': result}
def _setup_networking(instance_id, ip='1.2.3.4', flo_addr='1.2.1.2'): ctxt = context.get_admin_context() network_ref = db.project_get_networks(ctxt, 'fake', associate=True)[0] vif = {'address': '56:12:12:12:12:12', 'network_id': network_ref['id'], 'instance_id': instance_id} vif_ref = db.virtual_interface_create(ctxt, vif) fixed_ip = {'address': ip, 'network_id': network_ref['id'], 'virtual_interface_id': vif_ref['id'], 'allocated': True, 'instance_id': instance_id} db.fixed_ip_create(ctxt, fixed_ip) fix_ref = db.fixed_ip_get_by_address(ctxt, ip) db.floating_ip_create(ctxt, {'address': flo_addr, 'fixed_ip_id': fix_ref['id']})
def get_project_vpn_data(project): """Gets vpn ip and port for project @type project: Project or project_id @param project: Project from which to get associated vpn data @rvalue: tuple of (str, str) @return: A tuple containing (ip, port) or None, None if vpn has not been allocated for user. """ networks = db.project_get_networks(context.get_admin_context(), Project.safe_id(project), False) if not networks: return (None, None) # TODO(tr3buchet): not sure what you guys plan on doing with this # but it's possible for a project to have multiple sets of vpn data # for now I'm just returning the first one network = networks[0] return (network['vpn_public_address'], network['vpn_public_port'])
def _setup_networking(instance_id, ip='1.2.3.4', flo_addr='1.2.1.2'): ctxt = context.get_admin_context() network_ref = db.project_get_networks(ctxt, 'fake', associate=True)[0] vif = { 'address': '56:12:12:12:12:12', 'network_id': network_ref['id'], 'instance_id': instance_id } vif_ref = db.virtual_interface_create(ctxt, vif) fixed_ip = { 'address': ip, 'network_id': network_ref['id'], 'virtual_interface_id': vif_ref['id'], 'allocated': True, 'instance_id': instance_id } db.fixed_ip_create(ctxt, fixed_ip) fix_ref = db.fixed_ip_get_by_address(ctxt, ip) db.floating_ip_create(ctxt, { 'address': flo_addr, 'fixed_ip_id': fix_ref['id'] })
def get_global_networks(self, admin_context): return db.project_get_networks(admin_context, None, False)