2
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4
# Copyright 2012 Cisco Systems, Inc.
5
# Copyright 2012 NTT MCL, Inc.
8
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9
# not use this file except in compliance with the License. You may obtain
10
# a copy of the License at
12
# http://www.apache.org/licenses/LICENSE-2.0
14
# Unless required by applicable law or agreed to in writing, software
15
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17
# License for the specific language governing permissions and limitations
21
# Performs per host Linux Bridge configuration for Quantum.
22
# Based on the structure of the OpenVSwitch agent in the
23
# Quantum OpenVSwitch Plugin.
24
# @author: Sumit Naiksatam, Cisco Systems, Inc.
30
from sqlalchemy.ext.sqlsoup import SqlSoup
32
from quantum.openstack.common import cfg
33
from quantum.common import config as logging_config
34
from quantum.common import constants
35
from quantum.plugins.linuxbridge.common import config
36
import quantum.plugins.linuxbridge.agent.linuxbridge_quantum_agent as lb
38
from quantum.agent.linux import utils
41
LOG = logging.getLogger(__name__)
43
BRIDGE_NAME_PREFIX = "brq"
44
VLAN_BINDINGS = "vlan_bindings"
45
PORT_BINDINGS = "port_bindings"
48
class MetaLinuxBridgeQuantumAgent(lb.LinuxBridgeQuantumAgent):
50
def manage_networks_on_host(self, db,
55
flavor_key = db.flavors.network_id
56
vlan_key = db.vlan_bindings.network_id
57
query = db.session.query(db.vlan_bindings)
58
joined = query.join((db.flavors,
59
flavor_key == vlan_key))
60
where = db.flavors.flavor == 'linuxbridge'
61
vlan_binds = joined.filter(where).all()
62
except Exception as e:
63
LOG.info("Unable to get vlan bindings! Exception: %s" % e)
64
self.db_connected = False
65
return {VLAN_BINDINGS: {},
69
for bind in vlan_binds:
70
entry = {'network_id': bind.network_id, 'vlan_id': bind.vlan_id}
71
vlan_bindings[bind.network_id] = entry
72
vlans_string = "%s %s" % (vlans_string, entry)
76
flavor_key = db.flavors.network_id
77
port_key = db.ports.network_id
78
query = db.session.query(db.ports)
79
joined = query.join((db.flavors,
80
flavor_key == port_key))
81
where = db.flavors.flavor == 'linuxbridge'
82
port_binds = joined.filter(where).all()
83
except Exception as e:
84
LOG.info("Unable to get port bindings! Exception: %s" % e)
85
self.db_connected = False
86
return {VLAN_BINDINGS: {},
90
for bind in port_binds:
92
if self.target_v2_api:
93
all_bindings[bind.id] = bind
94
entry = {'network_id': bind.network_id,
96
'status': bind.status,
97
'interface_id': bind.id}
98
append_entry = bind.admin_state_up
100
all_bindings[bind.uuid] = bind
101
entry = {'network_id': bind.network_id, 'state': bind.state,
102
'op_status': bind.op_status, 'uuid': bind.uuid,
103
'interface_id': bind.interface_id}
104
append_entry = bind.state == constants.PORT_STATUS_ACTIVE
106
port_bindings.append(entry)
108
plugged_interfaces = []
110
for pb in port_bindings:
111
ports_string = "%s %s" % (ports_string, pb)
113
interface_id = pb['interface_id']
115
vlan_id = str(vlan_bindings[pb['network_id']]['vlan_id'])
116
if self.process_port_binding(port_id,
120
if self.target_v2_api:
121
all_bindings[port_id].status = constants.PORT_STATUS_ACTIVE
123
all_bindings[port_id].op_status = (
124
constants.PORT_STATUS_ACTIVE)
126
plugged_interfaces.append(interface_id)
128
if old_port_bindings != port_bindings:
129
LOG.debug("Port-bindings: %s" % ports_string)
131
self.process_unplugged_interfaces(plugged_interfaces)
133
if old_vlan_bindings != vlan_bindings:
134
LOG.debug("VLAN-bindings: %s" % vlans_string)
136
self.process_deleted_networks(vlan_bindings)
140
except Exception as e:
141
LOG.info("Unable to update database! Exception: %s" % e)
146
return {VLAN_BINDINGS: vlan_bindings,
147
PORT_BINDINGS: port_bindings}
151
cfg.CONF(args=sys.argv, project='quantum')
153
# (TODO) - swap with common logging
154
logging_config.setup_logging(cfg.CONF)
156
br_name_prefix = BRIDGE_NAME_PREFIX
157
physical_interface = cfg.CONF.LINUX_BRIDGE.physical_interface
158
polling_interval = cfg.CONF.AGENT.polling_interval
159
reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
160
root_helper = cfg.CONF.AGENT.root_helper
161
'Establish database connection and load models'
162
db_connection_url = cfg.CONF.DATABASE.sql_connection
163
plugin = MetaLinuxBridgeQuantumAgent(br_name_prefix, physical_interface,
164
polling_interval, reconnect_interval,
166
cfg.CONF.AGENT.target_v2_api)
167
LOG.info("Agent initialized successfully, now running... ")
168
plugin.daemon_loop(db_connection_url)
172
if __name__ == "__main__":