Skip to content

Commit cc2dbee

Browse files
committed
Defer importing client bindings only when needed
1 parent e210cce commit cc2dbee

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

juju/client/jujudata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
import pathlib
55

6-
import juju.client.client as jujuclient
6+
from juju.client import client as jujuclient
77
import yaml
88
from juju import tag
99
from juju.client.gocookies import GoCookieJar

juju/model.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from .charmhub import CharmHub
2626
from .charmstore import CharmStore
2727
from .client import client, connector
28-
from .client.client import ConfigValue, Value
2928
from .client.overrides import Caveat, Macaroon
3029
from .constraints import parse as parse_constraints
3130
from .controller import Controller, ConnectedController
@@ -2003,7 +2002,7 @@ async def get_config(self):
20032002
result = await config_facade.ModelGet()
20042003
config = result.config
20052004
for key, value in config.items():
2006-
config[key] = ConfigValue.from_json(value)
2005+
config[key] = client.ConfigValue.from_json(value)
20072006
return config
20082007

20092008
async def get_constraints(self):
@@ -2027,7 +2026,7 @@ async def get_constraints(self):
20272026
# set.
20282027
if result.constraints:
20292028
constraint_types = [a for a in dir(result.constraints)
2030-
if a in Value._toSchema.keys()]
2029+
if a in client.Value._toSchema.keys()]
20312030
for constraint in constraint_types:
20322031
value = getattr(result.constraints, constraint)
20332032
if value is not None:
@@ -2121,7 +2120,7 @@ async def set_config(self, config):
21212120

21222121
new_conf = {}
21232122
for key, value in config.items():
2124-
if isinstance(value, ConfigValue):
2123+
if isinstance(value, client.ConfigValue):
21252124
new_conf[key] = value.value
21262125
elif isinstance(value, str):
21272126
new_conf[key] = value
@@ -2134,8 +2133,12 @@ async def set_constraints(self, constraints):
21342133
21352134
:param dict config: Mapping of model constraints
21362135
"""
2137-
client_facade = client.ModelConfigFacade.from_connection(self.connection())
2138-
await client_facade.SetModelConstraints(
2136+
facade_cls = client.ModelConfigFacade
2137+
if facade_cls.best_facade_version(self.connection()) <= 2:
2138+
facade_cls = client.ClientFacade
2139+
facade = facade_cls.from_connection(self.connection())
2140+
2141+
await facade.SetModelConstraints(
21392142
application='',
21402143
constraints=constraints)
21412144

0 commit comments

Comments
 (0)