Skip to content

Commit 8f05333

Browse files
committed
Generate code to use _2_9_clients along with _clients
1 parent 3a7922e commit 8f05333

3 files changed

Lines changed: 96 additions & 13 deletions

File tree

juju/client/_client.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,26 @@
33

44
from juju.client._definitions import *
55

6-
from juju.client import _client2, _client1, _client3, _client4, _client5, _client8, _client7, _client9, _client10, _client6, _client12, _client11, _client13, _client15, _client16, _client17, _client18
6+
from juju.client.old_clients import _client2 as _2_9_client2
7+
from juju.client.old_clients import _client1 as _2_9_client1
8+
from juju.client.old_clients import _client3 as _2_9_client3
9+
from juju.client.old_clients import _client4 as _2_9_client4
10+
from juju.client.old_clients import _client5 as _2_9_client5
11+
from juju.client.old_clients import _client8 as _2_9_client8
12+
from juju.client.old_clients import _client7 as _2_9_client7
13+
from juju.client.old_clients import _client9 as _2_9_client9
14+
from juju.client.old_clients import _client10 as _2_9_client10
15+
from juju.client.old_clients import _client6 as _2_9_client6
16+
from juju.client.old_clients import _client12 as _2_9_client12
17+
from juju.client.old_clients import _client11 as _2_9_client11
18+
from juju.client.old_clients import _client13 as _2_9_client13
19+
from juju.client.old_clients import _client15 as _2_9_client15
20+
from juju.client.old_clients import _client16 as _2_9_client16
21+
from juju.client.old_clients import _client17 as _2_9_client17
22+
from juju.client.old_clients import _client18 as _2_9_client18
23+
from juju.client.old_clients import _client14 as _2_9_client14
24+
25+
from juju.client import _client2, _client1, _client3, _client4, _client5, _client8, _client7, _client9, _client10, _client6, _client12, _client11, _client13, _client15, _client16, _client17, _client18, _client14
726

827

928
CLIENTS = {
@@ -23,20 +42,43 @@
2342
"15": _client15,
2443
"16": _client16,
2544
"17": _client17,
26-
"18": _client18
45+
"18": _client18,
46+
"14": _client14
2747
}
2848

2949

50+
OLD_CLIENTS = {
51+
"2": _2_9_client2,
52+
"1": _2_9_client1,
53+
"3": _2_9_client3,
54+
"4": _2_9_client4,
55+
"5": _2_9_client5,
56+
"8": _2_9_client8,
57+
"7": _2_9_client7,
58+
"9": _2_9_client9,
59+
"10": _2_9_client10,
60+
"6": _2_9_client6,
61+
"12": _2_9_client12,
62+
"11": _2_9_client11,
63+
"13": _2_9_client13,
64+
"15": _2_9_client15,
65+
"16": _2_9_client16,
66+
"17": _2_9_client17,
67+
"18": _2_9_client18,
68+
"14": _2_9_client14
69+
}
70+
3071

31-
def lookup_facade(name, version):
72+
def lookup_facade(name, version, is_2_9=False):
3273
"""
3374
Given a facade name and version, attempt to pull that facade out
3475
of the correct client<version>.py file.
3576
3677
"""
3778
for _version in range(int(version), 0, -1):
3879
try:
39-
facade = getattr(CLIENTS[str(_version)], name)
80+
client_directory = OLD_CLIENTS if is_2_9 else CLIENTS
81+
facade = getattr(client_directory[str(_version)], name)
4082
return facade
4183
except (KeyError, AttributeError):
4284
continue
@@ -45,7 +87,6 @@ def lookup_facade(name, version):
4587
"{}".format(name))
4688

4789

48-
4990
class TypeFactory:
5091
@classmethod
5192
def from_connection(cls, connection):
@@ -66,7 +107,8 @@ def from_connection(cls, connection):
66107
raise Exception('No facade {} in facades {}'.format(facade_name,
67108
connection.facades))
68109

69-
c = lookup_facade(cls.__name__, version)
110+
server_version = connection.info['server-version']
111+
c = lookup_facade(cls.__name__, version, server_version.startswith('2.9'))
70112
c = c()
71113
c.connect(connection)
72114

juju/client/_definitions.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9408,6 +9408,30 @@ def __init__(self, actions=None, operation=None, **unknown_fields):
94089408

94099409

94109410

9411+
class EnqueuedActionsV2(Type):
9412+
_toSchema = {'actions': 'actions', 'operation': 'operation'}
9413+
_toPy = {'actions': 'actions', 'operation': 'operation'}
9414+
def __init__(self, actions=None, operation=None, **unknown_fields):
9415+
'''
9416+
actions : typing.Sequence[~ActionResult]
9417+
operation : str
9418+
'''
9419+
actions_ = [ActionResult.from_json(o) for o in actions or []]
9420+
operation_ = operation
9421+
9422+
# Validate arguments against known Juju API types.
9423+
if actions_ is not None and not isinstance(actions_, (bytes, str, list)):
9424+
raise Exception("Expected actions_ to be a Sequence, received: {}".format(type(actions_)))
9425+
9426+
if operation_ is not None and not isinstance(operation_, (bytes, str)):
9427+
raise Exception("Expected operation_ to be a str, received: {}".format(type(operation_)))
9428+
9429+
self.actions = actions_
9430+
self.operation = operation_
9431+
self.unknown_fields = unknown_fields
9432+
9433+
9434+
94119435
class Entities(Type):
94129436
_toSchema = {'entities': 'entities'}
94139437
_toPy = {'entities': 'entities'}
@@ -28161,10 +28185,10 @@ class ValidateModelUpgradeParams(Type):
2816128185
def __init__(self, force=None, model=None, **unknown_fields):
2816228186
'''
2816328187
force : bool
28164-
model : typing.Sequence[~ValidateModelUpgradeParam]
28188+
model : typing.Sequence[~ModelParam]
2816528189
'''
2816628190
force_ = force
28167-
model_ = [ValidateModelUpgradeParam.from_json(o) for o in model or []]
28191+
model_ = [ModelParam.from_json(o) for o in model or []]
2816828192

2816928193
# Validate arguments against known Juju API types.
2817028194
if force_ is not None and not isinstance(force_, bool):

juju/client/facade.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,23 @@
4444

4545
# Classes and helper functions that we'll write to _client.py
4646
LOOKUP_FACADE = '''
47-
def lookup_facade(name, version):
47+
def lookup_facade(name, version, is_2_9=False):
4848
"""
4949
Given a facade name and version, attempt to pull that facade out
5050
of the correct client<version>.py file.
5151
5252
"""
5353
for _version in range(int(version), 0, -1):
5454
try:
55-
facade = getattr(CLIENTS[str(_version)], name)
55+
client_directory = OLD_CLIENTS if is_2_9 else CLIENTS
56+
facade = getattr(client_directory[str(_version)], name)
5657
return facade
5758
except (KeyError, AttributeError):
5859
continue
5960
else:
6061
raise ImportError("No supported version for facade: "
6162
"{}".format(name))
6263
63-
6464
'''
6565

6666
TYPE_FACTORY = '''
@@ -84,7 +84,8 @@ def from_connection(cls, connection):
8484
raise Exception('No facade {} in facades {}'.format(facade_name,
8585
connection.facades))
8686
87-
c = lookup_facade(cls.__name__, version)
87+
server_version = connection.info['server-version']
88+
c = lookup_facade(cls.__name__, version, server_version.startswith('2.9'))
8889
c = c()
8990
c.connect(connection)
9091
@@ -112,6 +113,13 @@ def best_facade_version(cls, connection):
112113
{clients}
113114
}}
114115
116+
'''
117+
118+
119+
OLD_CLIENTS_TABLE = '''
120+
OLD_CLIENTS = {{
121+
{old_clients}
122+
}}
115123
116124
'''
117125

@@ -874,9 +882,18 @@ def write_client(captures, options):
874882
f.write(HEADER)
875883
f.write("from juju.client._definitions import *\n\n")
876884
clients = ", ".join("_client{}".format(v) for v in captures)
877-
f.write("from juju.client import " + clients + "\n\n")
885+
# from juju.client.old_clients import _client{} as _2_9_client{}
886+
for v in captures:
887+
pre = "from juju.client.old_clients import "
888+
f.write(pre + "_client{num} as _2_9_client{num}\n".format(num=v))
889+
# from juju.client import _client2, _client1, _client3 ...
890+
f.write("\nfrom juju.client import " + clients + "\n\n")
891+
# CLIENTS = { ....
878892
f.write(CLIENT_TABLE.format(clients=",\n ".join(
879893
['"{}": _client{}'.format(v, v) for v in captures])))
894+
# OLD_CLIENTS = { ....
895+
f.write(OLD_CLIENTS_TABLE.format(old_clients=",\n ".join(
896+
['"{}": _2_9_client{}'.format(v, v) for v in captures])))
880897
f.write(LOOKUP_FACADE)
881898
f.write(TYPE_FACTORY)
882899
for key in sorted([k for k in factories.keys() if "Facade" in k]):

0 commit comments

Comments
 (0)