tuskar-ui/horizon/api/quantum.py
Gabriel Hurley 052aa55d34 Unifies the project packaging into one set of modules.
There are no longer two separate projects living inside the horizon
repository. There is a single project now with a single setup.py,
single README, etc.

The openstack-dashboard/dashboard django project is now named
"openstack_dashboard" and lives as an example project in the
topmost horizon directory.

The "horizon/horizon" directory has been bumped up a level and now
is directly on the path when the root horizon directory is on
your python path.

Javascript media which the horizon module directly relies upon
now ships in the horizon/static dir rather than
openstack-dashboard/dashboard/static.

All the corresponding setup, installation, build, and env scripts
have been updated accordingly.

Implements blueprint unified-packaging.

Change-Id: Ieed8e3c777432cd046c3e0298869a9428756ab62
2012-02-29 00:20:13 -08:00

133 lines
4.3 KiB
Python

# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Copyright 2012 Nebula, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import logging
import urlparse
from quantum import client as quantum_client
from horizon.api.base import url_for
from horizon.api import nova
LOG = logging.getLogger(__name__)
# FIXME(gabriel): Add object wrappers for Quantum client. The quantum client
# returns plain dicts (a la Glance) which we should wrap.
def quantum_api(request):
tenant = request.user.tenant_id
url = urlparse.urlparse(url_for(request, 'network'))
return quantum_client.Client(url.hostname, url.port, False, tenant, 'json')
def quantum_list_networks(request):
return quantum_api(request).list_networks()
def quantum_network_details(request, network_id):
return quantum_api(request).show_network_details(network_id)
def quantum_list_ports(request, network_id):
return quantum_api(request).list_ports(network_id)
def quantum_port_details(request, network_id, port_id):
return quantum_api(request).show_port_details(network_id, port_id)
def quantum_create_network(request, data):
return quantum_api(request).create_network(data)
def quantum_delete_network(request, network_id):
return quantum_api(request).delete_network(network_id)
def quantum_update_network(request, network_id, data):
return quantum_api(request).update_network(network_id, data)
def quantum_create_port(request, network_id):
return quantum_api(request).create_port(network_id)
def quantum_delete_port(request, network_id, port_id):
return quantum_api(request).delete_port(network_id, port_id)
def quantum_attach_port(request, network_id, port_id, data):
return quantum_api(request).attach_resource(network_id, port_id, data)
def quantum_detach_port(request, network_id, port_id):
return quantum_api(request).detach_resource(network_id, port_id)
def quantum_set_port_state(request, network_id, port_id, data):
return quantum_api(request).update_port(network_id, port_id, data)
def quantum_port_attachment(request, network_id, port_id):
return quantum_api(request).show_port_attachment(network_id, port_id)
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