1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 United States Government as represented by the
4
# Administrator of the National Aeronautics and Space Administration.
7
# Copyright 2012 Nebula, Inc.
9
# Licensed under the Apache License, Version 2.0 (the "License"); you may
10
# not use this file except in compliance with the License. You may obtain
11
# a copy of the License at
13
# http://www.apache.org/licenses/LICENSE-2.0
15
# Unless required by applicable law or agreed to in writing, software
16
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18
# License for the specific language governing permissions and limitations
22
from __future__ import absolute_import
27
from quantum import client as quantum_client
29
from horizon.api.base import url_for
30
from horizon.api import nova
33
LOG = logging.getLogger(__name__)
36
# FIXME(gabriel): Add object wrappers for Quantum client. The quantum client
37
# returns plain dicts (a la Glance) which we should wrap.
39
def quantum_api(request):
40
tenant = request.user.tenant_id
41
url = urlparse.urlparse(url_for(request, 'network'))
42
return quantum_client.Client(url.hostname, url.port, False, tenant, 'json')
45
def quantum_list_networks(request):
46
return quantum_api(request).list_networks()
49
def quantum_network_details(request, network_id):
50
return quantum_api(request).show_network_details(network_id)
53
def quantum_list_ports(request, network_id):
54
return quantum_api(request).list_ports(network_id)
57
def quantum_port_details(request, network_id, port_id):
58
return quantum_api(request).show_port_details(network_id, port_id)
61
def quantum_create_network(request, data):
62
return quantum_api(request).create_network(data)
65
def quantum_delete_network(request, network_id):
66
return quantum_api(request).delete_network(network_id)
69
def quantum_update_network(request, network_id, data):
70
return quantum_api(request).update_network(network_id, data)
73
def quantum_create_port(request, network_id):
74
return quantum_api(request).create_port(network_id)
77
def quantum_delete_port(request, network_id, port_id):
78
return quantum_api(request).delete_port(network_id, port_id)
81
def quantum_attach_port(request, network_id, port_id, data):
82
return quantum_api(request).attach_resource(network_id, port_id, data)
85
def quantum_detach_port(request, network_id, port_id):
86
return quantum_api(request).detach_resource(network_id, port_id)
89
def quantum_set_port_state(request, network_id, port_id, data):
90
return quantum_api(request).update_port(network_id, port_id, data)
93
def quantum_port_attachment(request, network_id, port_id):
94
return quantum_api(request).show_port_attachment(network_id, port_id)
97
def get_vif_ids(request):
100
# Get a list of all networks
101
networks_list = quantum_api(request).list_networks()
102
for network in networks_list['networks']:
103
ports = quantum_api(request).list_ports(network['id'])
104
# Get port attachments
105
for port in ports['ports']:
106
port_attachment = quantum_api(request).show_port_attachment(
109
if port_attachment['attachment']:
110
attached_vifs.append(
111
port_attachment['attachment']['id'].encode('ascii'))
113
instances = nova.server_list(request)
114
# Get virtual interface ids by instance
115
for instance in instances:
117
instance_vifs = nova.virtual_interfaces_list(request, id)
118
for vif in instance_vifs:
119
# Check if this VIF is already connected to any port
120
if str(vif.id) in attached_vifs:
123
'instance': instance.id,
124
'instance_name': instance.name,
129
'instance': instance.id,
130
'instance_name': instance.name,