diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2013-07-17 12:32:55 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2013-07-17 14:15:05 +0900 |
commit | 66b0c290be07ef48d8c892d3555458f688342495 (patch) | |
tree | 585749f4a6bb63658ab7abdb50f75fd91c9b0085 | |
parent | 9746e523e906cc468368a9e5104d554fcf905840 (diff) |
app/quantum_adapter: Lazily initialize neutron client
When ryu starts up, related openstack components (keystone and neutron)
might not be running. They might be during start up process.
In that case, quantum_adapter results in exception as follows.
So in order to avoid ordering of starting up, lazily initialize neutoron
api.
> hub: uncaught exception: Traceback (most recent call last):
> File "/ryu/lib/hub.py", line 48, in _launch
> func(*args, **kwargs)
> File "/ryu/base/app_manager.py", line 173, in _event_loop
> handler(ev)
> File "/ryu/app/quantum_adapter.py", line 398, in dp_handler
> ovs_switch = self._get_ovs_switch(dpid)
> File "/ryu/app/quantum_adapter.py", line 381, in _get_ovs_switch
> ovs_switch = OVSSwitch(dpid, self.nw, self.ifaces, self.logger)
> File "/ryu/app/quantum_adapter.py", line 167, in __init__
> token = _get_auth_token(logger)
> File "/ryu/app/quantum_adapter.py", line 90, in _get_auth_token
> httpclient.authenticate()
> File "/neutronclient/client.py", line 211, in authenticate
> content_type="application/json")
> File "/neutronclient/client.py", line 141, in _cs_request
> raise exceptions.ConnectionFailed(reason=e)
> ConnectionFailed: Connection to neutron failed: [Errno 111] ECONNREFUSED
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/app/quantum_adapter.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/ryu/app/quantum_adapter.py b/ryu/app/quantum_adapter.py index b6ea8b80..f6b267d0 100644 --- a/ryu/app/quantum_adapter.py +++ b/ryu/app/quantum_adapter.py @@ -132,16 +132,11 @@ class OVSPort(object): class OVSSwitch(object): def __init__(self, dpid, nw, ifaces, logger): # TODO: clean up - token = None - if CONF.neutron_auth_strategy: - token = _get_auth_token(logger) - q_api = _get_quantum_client(token) - self.dpid = dpid self.network_api = nw self.ifaces = ifaces self.logger = logger - self.q_api = q_api + self._q_api = None # lazy initialization self.ctrl_addr = CONF.neutron_controller_addr if not self.ctrl_addr: raise ValueError('option neutron_controler_addr must be speicfied') @@ -154,6 +149,15 @@ class OVSSwitch(object): super(OVSSwitch, self).__init__() + @property + def q_api(self): + if self._q_api is None: + token = None + if CONF.neutron_auth_strategy: + token = _get_auth_token(self.logger) + self._q_api = _get_quantum_client(token) + return self._q_api + def set_ovsdb_addr(self, dpid, ovsdb_addr): # easy check if the address format valid self.logger.debug('set_ovsdb_addr dpid %s ovsdb_addr %s', |