Add per-network service models
[osm/N2VC.git] / modules / libjuju / juju / client / client.py
1 '''Replace auto-generated classes with our own, where necessary.
2 '''
3
4 from . import _client, _definitions, overrides # isort:skip
5
6 for o in overrides.__all__:
7 if "Facade" not in o:
8 # Override stuff in _definitions, which is all imported
9 # into _client. We Monkey patch both the original class and
10 # the ref in _client (import shenanigans are fun!)
11 setattr(_definitions, o, getattr(overrides, o))
12 setattr(_client, o, getattr(overrides, o))
13 # We shouldn't be overriding Facades!
14 else:
15 raise ValueError(
16 "Cannot override a versioned Facade class -- you must patch "
17 "it instead.")
18
19 for o in overrides.__patches__:
20 # Patch a versioned Facade.
21 for client_version in _client.CLIENTS.values():
22 try:
23 c_type = getattr(client_version, o)
24 except AttributeError:
25 # Not all the _client<version> modules may have the
26 # facade. That's okay -- we just skip over them.
27 continue
28 o_type = getattr(overrides, o)
29 for a in dir(o_type):
30 if not a.startswith('_'):
31 setattr(c_type, a, getattr(o_type, a))
32
33 from ._client import * # noqa, isort:skip