def get_vif_ids(request): vifs = [] attached_vifs = [] # Get a list of all networks networks_list = quantum_api(request).list_networks() for network in networks_list['networks']: ports = quantum_api(request).list_ports(network['id']) # Get port attachments for port in ports['ports']: port_attachment = quantum_api(request).show_port_attachment( network['id'], port['id']) if port_attachment['attachment']: attached_vifs.append( port_attachment['attachment']['id'].encode('ascii')) # Get all instances instances = nova.server_list(request) # Get virtual interface ids by instance for instance in instances: id = instance.id instance_vifs = nova.virtual_interfaces_list(request, id) for vif in instance_vifs: # Check if this VIF is already connected to any port if str(vif.id) in attached_vifs: vifs.append({ 'id': vif.id, 'instance': instance.id, 'instance_name': instance.name, 'available': False }) else: vifs.append({ 'id': vif.id, 'instance': instance.id, 'instance_name': instance.name, 'available': True }) return vifs
def get_vif_ids(request): vifs = [] attached_vifs = [] # Get a list of all networks networks_list = quantum_api(request).list_networks() for network in networks_list['networks']: ports = quantum_api(request).list_ports(network['id']) # Get port attachments for port in ports['ports']: port_attachment = quantum_api(request).show_port_attachment( network['id'], port['id']) if port_attachment['attachment']: attached_vifs.append( port_attachment['attachment']['id'].encode('ascii')) # Get all instances instances = nova.server_list(request) # Get virtual interface ids by instance for instance in instances: id = instance.id instance_vifs = extras_api(request).virtual_interfaces.list(id) for vif in instance_vifs: # Check if this VIF is already connected to any port if str(vif.id) in attached_vifs: vifs.append({ 'id': vif.id, 'instance': instance.id, 'instance_name': instance.name, 'available': False}) else: vifs.append({ 'id': vif.id, 'instance': instance.id, 'instance_name': instance.name, 'available': True}) return vifs
def get_instances(request): return [(item.id, item.name) for item in server_list(request)]