Skip to content

Commit 573a756

Browse files
Deploy add charm
The following adds the ability to add a charm based on the charm facade. The client facade is deprecated and shouldn't be used if the charms facade is located.
1 parent eed19e4 commit 573a756

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

juju/model.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,8 +1433,6 @@ async def deploy(
14331433
include_stats=False)
14341434
entity_id = entity['Id']
14351435

1436-
client_facade = client.ClientFacade.from_connection(self.connection())
1437-
14381436
is_bundle = ((is_local and
14391437
(entity_id.endswith('.yaml') and entity_path.exists()) or
14401438
bundle_path.exists()) or
@@ -1463,7 +1461,8 @@ async def deploy(
14631461
application_name = entity['Meta']['charm-metadata']['Name']
14641462
if not series:
14651463
series = self._get_series(entity_url, entity)
1466-
await client_facade.AddCharm(channel=channel, url=entity_id, force=False)
1464+
1465+
self._add_charm(channel, entity_id)
14671466
# XXX: we're dropping local resources here, but we don't
14681467
# actually support them yet anyway
14691468
resources = await self._add_store_resources(application_name,
@@ -1506,6 +1505,17 @@ async def deploy(
15061505
devices=devices,
15071506
)
15081507

1508+
async def _add_charm(self, channel, entity_id):
1509+
# client facade is deprecated with in Juju, and smaller, more focused
1510+
# facades have been created and we'll use that if it's available.
1511+
charms_cls = client.CharmsFacade
1512+
if charms_cls.best_facade_version(self.connection()) > 2:
1513+
charms_facade = charms_cls.from_connection(self.connection())
1514+
return await charms_facade.AddCharm(channel=channel, url=entity_id, force=False)
1515+
1516+
client_facade = client.ClientFacade.from_connection(self.connection())
1517+
await client_facade.AddCharm(channel=channel, url=entity_id, force=False)
1518+
15091519
async def _add_store_resources(self, application, entity_url,
15101520
overrides=None, entity=None):
15111521
if not entity:

0 commit comments

Comments
 (0)