Skip to content

Commit 1a0dc2f

Browse files
Allow the deploying of a charm
There was some issue with adding a charm, but that was easily resolved.
1 parent 8ffa708 commit 1a0dc2f

1 file changed

Lines changed: 29 additions & 18 deletions

File tree

juju/model.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from .offerendpoints import parse_local_endpoint, parse_offer_url
3838
from .placement import parse as parse_placement
3939
from .tag import application as application_tag
40+
from .url import URL, Schema
4041

4142
log = logging.getLogger(__name__)
4243

@@ -1416,27 +1417,37 @@ async def deploy(
14161417
if trust and (self.info.agent_version < client.Number.from_json('2.4.0')):
14171418
raise NotImplementedError("trusted is not supported on model version {}".format(self.info.agent_version))
14181419

1419-
entity_url = str(entity_url) # allow for pathlib.Path objects
1420-
entity_path = Path(entity_url.replace('local:', ''))
1421-
bundle_path = entity_path / 'bundle.yaml'
1422-
metadata_path = entity_path / 'metadata.yaml'
14231420

1424-
is_local = (
1425-
entity_url.startswith('local:') or
1426-
entity_path.is_dir() or
1427-
entity_path.is_file()
1428-
)
1429-
if is_local:
1430-
entity_id = entity_url.replace('local:', '')
1431-
else:
1432-
entity = await self.charmstore.entity(entity_url, channel=channel,
1421+
# Attempt to resolve a charm or bundle based on the URL.
1422+
# In an ideal world this should be moved to the controller, and we
1423+
# wouldn't have to deal with this at all.
1424+
is_local = False
1425+
is_bundle = False
1426+
identifier = None
1427+
url = URL.parse(str(entity_url))
1428+
if url.schema.matches(Schema.Local):
1429+
entity_url = url.path()
1430+
entity_path = Path(entity_url)
1431+
bundle_path = entity_path / 'bundle.yaml'
1432+
1433+
identifier = entity_url
1434+
is_local = (
1435+
entity_path.is_dir() or
1436+
entity_path.is_file()
1437+
)
1438+
is_bundle = (
1439+
(entity_url.endswith(".yaml") and entity_path.exists()) or
1440+
bundle_path.exists()
1441+
)
1442+
elif url.schema.matches(Schema.CHARM_STORE):
1443+
charm = await self.charmstore.entity(str(url), channel=channel,
14331444
include_stats=False)
1434-
entity_id = entity['Id']
1445+
identifier = charm['Id']
1446+
is_bundle = url.series == "bundle"
1447+
elif url.schema.matches(Schema.CHARM_HUB):
1448+
# TODO (stickupkid): request to get the charm id.
1449+
14351450

1436-
is_bundle = ((is_local and
1437-
(entity_id.endswith('.yaml') and entity_path.exists()) or
1438-
bundle_path.exists()) or
1439-
(not is_local and 'bundle/' in entity_id))
14401451

14411452
if is_bundle:
14421453
handler = BundleHandler(self, trusted=trust, forced=force)

0 commit comments

Comments
 (0)