|
37 | 37 | from .offerendpoints import parse_local_endpoint, parse_offer_url |
38 | 38 | from .placement import parse as parse_placement |
39 | 39 | from .tag import application as application_tag |
| 40 | +from .url import URL, Schema |
40 | 41 |
|
41 | 42 | log = logging.getLogger(__name__) |
42 | 43 |
|
@@ -1416,27 +1417,37 @@ async def deploy( |
1416 | 1417 | if trust and (self.info.agent_version < client.Number.from_json('2.4.0')): |
1417 | 1418 | raise NotImplementedError("trusted is not supported on model version {}".format(self.info.agent_version)) |
1418 | 1419 |
|
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' |
1423 | 1420 |
|
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, |
1433 | 1444 | 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 | + |
1435 | 1450 |
|
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)) |
1440 | 1451 |
|
1441 | 1452 | if is_bundle: |
1442 | 1453 | handler = BundleHandler(self, trusted=trust, forced=force) |
|
0 commit comments