Skip to content

Commit d88756e

Browse files
committed
Clear out charmstore in juju/model and juju/bundle
1 parent d7e0811 commit d88756e

2 files changed

Lines changed: 11 additions & 153 deletions

File tree

juju/bundle.py

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def __init__(self, model, trusted=False, forced=False):
3434
self.overlays = []
3535
self.overlay_removed_charms = set()
3636

37-
self.charmstore = model.charmstore
3837
self.plan = []
3938
self.references = {}
4039
self._units_by_app = {}
@@ -235,11 +234,7 @@ async def fetch_plan(self, charm_url, origin, overlays=[]):
235234
bundle_yaml = (Path(entity_id) / "bundle.yaml").read_text()
236235
bundle_dir = Path(entity_id)
237236

238-
if Schema.CHARM_STORE.matches(charm_url.schema):
239-
bundle_yaml = await self.charmstore.files(entity_id,
240-
filename='bundle.yaml',
241-
read_file=True)
242-
elif Schema.CHARM_HUB.matches(charm_url.schema):
237+
if Schema.CHARM_HUB.matches(charm_url.schema):
243238
bundle_yaml = await self._download_bundle(charm_url, origin)
244239

245240
if not bundle_yaml:
@@ -361,8 +356,6 @@ async def _resolve_charms(self):
361356
channel = Channel.parse(spec['channel'])
362357
track, risk = channel.track, channel.risk
363358

364-
# if not track and series:
365-
# track = utils.get_series_version(series)
366359
if self.charms_facade is not None:
367360
if cons is not None and cons['arch'] != '':
368361
architecture = cons['arch']
@@ -379,9 +372,7 @@ async def _resolve_charms(self):
379372
charm_url, charm_origin, _ = await self.model._resolve_charm(charm_url, origin)
380373
spec['charm'] = str(charm_url)
381374
else:
382-
results = await self.model.charmstore.entity(str(charm_url))
383-
charm_url = results.get('Id', charm_url)
384-
charm_origin = client.CharmOrigin(source="charm-store",
375+
charm_origin = client.CharmOrigin(source="charm-hub",
385376
risk=risk,
386377
track=track)
387378

@@ -596,9 +587,7 @@ async def run(self, context):
596587

597588
# set the channel to the default value if not specified
598589
if not self.channel:
599-
if Schema.CHARM_STORE.matches(url.schema):
600-
self.channel = "stable"
601-
elif Schema.CHARM_HUB.matches(url.schema):
590+
if Schema.CHARM_HUB.matches(url.schema):
602591
self.channel = "latest/stable"
603592
else: # for local charms
604593
self.channel = ""
@@ -616,17 +605,13 @@ async def run(self, context):
616605
if origin is None:
617606
raise JujuError("expected origin to be valid for application {} and charm {} with channel {}".format(self.application, str(url), str(channel)))
618607

619-
if self.series is None or self.series == "":
608+
if not self.series:
620609
self.series = context.bundle.get("series", None)
621610

622-
if Schema.CHARM_STORE.matches(url.schema):
623-
resources = await context.model._add_store_resources(
624-
self.application, charm, overrides=self.resources)
625-
elif Schema.CHARM_HUB.matches(url.schema):
611+
resources = context.bundle.get("applications", {}).get(self.application, {}).get("resources", {})
612+
if Schema.CHARM_HUB.matches(url.schema):
626613
resources = await context.model._add_charmhub_resources(
627614
self.application, charm, origin, overrides=self.resources)
628-
else:
629-
resources = context.bundle.get("applications", {}).get(self.application, {}).get("resources", {})
630615

631616
await context.model._deploy(
632617
charm_url=charm,
@@ -723,13 +708,6 @@ async def run(self, context):
723708
if Schema.LOCAL.matches(url.schema):
724709
return self.charm
725710

726-
if Schema.CHARM_STORE.matches(url.schema):
727-
entity_id = await context.charmstore.entityId(self.charm, channel=self.channel)
728-
log.debug('Adding %s', entity_id)
729-
await context.charms_facade.AddCharm(channel=self.channel, url=entity_id, force=False)
730-
identifier = entity_id
731-
origin = client.CharmOrigin(source="charm-store", risk="stable")
732-
733711
if Schema.CHARM_HUB.matches(url.schema):
734712
ch = Channel('latest', 'stable')
735713
if self.channel:

juju/model.py

Lines changed: 5 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from .annotationhelper import _get_annotations, _set_annotations
2424
from .bundle import BundleHandler, get_charm_series, is_local_charm
2525
from .charmhub import CharmHub
26-
from .charmstore import CharmStore
2726
from .client import client, connector
2827
from .client.overrides import Caveat, Macaroon
2928
from .constraints import parse as parse_constraints
@@ -484,52 +483,6 @@ async def resolve(self, url, architecture, app_name=None, channel=None, series=N
484483
is_bundle=is_bundle,
485484
)
486485

487-
488-
class CharmStoreDeployType:
489-
"""CharmStoreDeployType defines a class for resolving and deploying charm
490-
store charms and bundle.
491-
"""
492-
493-
def __init__(self, charmstore, get_series):
494-
self.charmstore = charmstore
495-
self.get_series = get_series
496-
497-
@staticmethod
498-
def _default_app_name(meta):
499-
suggested_name = meta.get('charm-metadata', {}).get('Name')
500-
return suggested_name or meta.get('id', {}).get('Name')
501-
502-
async def resolve(self, url, architecture, app_name=None, channel=None, series=None, entity_url=None):
503-
"""resolve attempts to resolve charmstore charms or bundles. A request
504-
to the charmstore is required to get more information about the
505-
underlying identifier.
506-
"""
507-
508-
result = await self.charmstore.entity(str(url),
509-
channel=channel,
510-
include_stats=False)
511-
512-
identifier = result['Id']
513-
is_bundle = url.series == "bundle" or url.parse(identifier).series == "bundle"
514-
if not series:
515-
series = "bundle" if is_bundle else self.get_series(entity_url, result)
516-
517-
if app_name is None and not is_bundle:
518-
app_name = self._default_app_name(result['Meta'])
519-
520-
origin = client.CharmOrigin(source="charm-store",
521-
architecture=architecture,
522-
risk=channel,
523-
series=series)
524-
525-
return DeployTypeResult(
526-
identifier=identifier,
527-
app_name=app_name,
528-
origin=origin,
529-
is_bundle=is_bundle,
530-
)
531-
532-
533486
class CharmhubDeployType:
534487
"""CharmhubDeployType defines a class for resolving and deploying charmhub
535488
charms and bundles.
@@ -618,11 +571,9 @@ def __init__(
618571
self._watch_stopped.set()
619572

620573
self._charmhub = CharmHub(self)
621-
self._charmstore = CharmStore()
622574

623575
self.deploy_types = {
624576
"local": LocalDeployType(),
625-
"cs": CharmStoreDeployType(self._charmstore, self._get_series),
626577
"ch": CharmhubDeployType(self._resolve_charm),
627578
}
628579

@@ -1107,10 +1058,6 @@ def charmhub(self):
11071058
"""
11081059
return self._charmhub
11091060

1110-
@property
1111-
def charmstore(self):
1112-
return self._charmstore
1113-
11141061
@property
11151062
def name(self):
11161063
"""Return the name of this model
@@ -1653,21 +1600,6 @@ async def debug_log(
16531600
}
16541601
await self.connect(debug_log_conn=target, debug_log_params=params)
16551602

1656-
def _get_series(self, entity_url, entity):
1657-
# try to get the series from the provided charm URL
1658-
parts = entity_url.split('/')
1659-
1660-
if len(parts) > 1:
1661-
# series was specified in the URL
1662-
return parts[0]
1663-
# series was not supplied at all, so use the newest
1664-
# supported series according to the charm store
1665-
ss = entity['Meta'].get('supported-series')
1666-
if not ss:
1667-
log.error("Entity {} has no 'supported-series' in {}".format(entity_url, entity))
1668-
raise JujuError("Unable to determine series for {}".format(entity_url))
1669-
return ss['SupportedSeries'][0]
1670-
16711603
async def deploy(
16721604
self, entity_url, application_name=None, bind=None,
16731605
channel=None, config=None, constraints=None, force=False,
@@ -1733,7 +1665,7 @@ async def deploy(
17331665
architecture = await self._resolve_architecture(url)
17341666

17351667
if str(url.schema) not in self.deploy_types:
1736-
raise JujuError("unknown deploy type {}, expected charmhub, charmstore or local".format(url.schema))
1668+
raise JujuError("unknown deploy type {}, expected charmhub or local".format(url.schema))
17371669

17381670
res = await self.deploy_types[str(url.schema)].resolve(url, architecture, application_name, channel, series, entity_url)
17391671

@@ -1782,9 +1714,6 @@ async def deploy(
17821714
raise JujuError("cannot use num_units with subordinate application")
17831715
num_units = 0
17841716

1785-
if Schema.CHARM_STORE.matches(url.schema):
1786-
resources = await self._add_store_resources(res.app_name,
1787-
identifier)
17881717
else:
17891718
# We have a local charm dir that needs to be uploaded
17901719
charm_dir = os.path.abspath(os.path.expanduser(identifier))
@@ -1869,18 +1798,11 @@ async def _resolve_charm(self, url, origin):
18691798
# origin should be set (including the base) before calling this,
18701799
# though all tests need to run (in earlier versions too) before
18711800
# committing to make sure there's no regression
1872-
if Schema.CHARM_STORE.matches(url.schema):
1873-
source = "charm-store"
1874-
else:
1875-
source = "charm-hub"
1801+
source = "charm-hub"
18761802

1877-
resolve_origin = {
1878-
'source': source,
1879-
'architecture': origin.architecture,
1880-
'track': origin.track,
1881-
'risk': origin.risk,
1882-
}
1883-
resolve_origin['base'] = origin.base
1803+
resolve_origin = {'source': source, 'architecture': origin.architecture,
1804+
'track': origin.track, 'risk': origin.risk,
1805+
'base': origin.base}
18841806

18851807
resp = await charms_facade.ResolveCharms(resolve=[{
18861808
'reference': str(url),
@@ -1951,48 +1873,6 @@ async def _add_charmhub_resources(self, application,
19511873

19521874
return resource_map
19531875

1954-
async def _add_store_resources(self, application, entity_url,
1955-
overrides=None):
1956-
entity = await self.charmstore.entity(entity_url,
1957-
include_stats=False)
1958-
resources = [
1959-
{
1960-
'description': resource['Description'],
1961-
'fingerprint': resource['Fingerprint'],
1962-
'name': resource['Name'],
1963-
'path': resource['Path'],
1964-
'revision': resource['Revision'],
1965-
'size': resource['Size'],
1966-
'type_': resource['Type'],
1967-
'origin': 'store',
1968-
} for resource in entity['Meta'].get('resources', [])
1969-
]
1970-
1971-
if overrides:
1972-
names = {r['name'] for r in resources}
1973-
unknown = overrides.keys() - names
1974-
if unknown:
1975-
raise JujuError('Unrecognized resource{}: {}'.format(
1976-
's' if len(unknown) > 1 else '',
1977-
', '.join(unknown)))
1978-
for resource in resources:
1979-
if resource['name'] in overrides:
1980-
resource['revision'] = overrides[resource['name']]
1981-
1982-
if not resources:
1983-
return None
1984-
1985-
resources_facade = client.ResourcesFacade.from_connection(
1986-
self.connection())
1987-
response = await resources_facade.AddPendingResources(
1988-
application_tag=tag.application(application),
1989-
charm_url=entity_url,
1990-
resources=[client.CharmResource(**resource) for resource in resources])
1991-
resource_map = {resource['name']: pid
1992-
for resource, pid
1993-
in zip(resources, response.pending_ids)}
1994-
return resource_map
1995-
19961876
async def add_local_resources(self, application, entity_url, metadata, resources):
19971877
if not resources:
19981878
return None

0 commit comments

Comments
 (0)