|
15 | 15 | from pathlib import Path |
16 | 16 |
|
17 | 17 | import yaml |
18 | | - |
19 | | -import theblues.charmstore |
20 | | -import theblues.errors |
21 | 18 | import websockets |
22 | 19 |
|
23 | 20 | from . import provisioner, tag, utils |
24 | 21 | from .annotationhelper import _get_annotations, _set_annotations |
25 | 22 | from .bundle import BundleHandler, get_charm_series |
26 | 23 | from .charmhub import CharmHub |
| 24 | +from .charmstore import CharmStore |
27 | 25 | from .client import client, connector |
28 | 26 | from .client.client import ConfigValue, Value |
29 | 27 | from .client.overrides import Caveat, Macaroon |
@@ -461,6 +459,8 @@ def __init__( |
461 | 459 | self._watch_stopped = asyncio.Event(loop=self._connector.loop) |
462 | 460 | self._watch_received = asyncio.Event(loop=self._connector.loop) |
463 | 461 | self._watch_stopped.set() |
| 462 | + |
| 463 | + self._charmhub = CharmHub(self) |
464 | 464 | self._charmstore = CharmStore(self._connector.loop) |
465 | 465 |
|
466 | 466 | def is_connected(self): |
@@ -783,7 +783,11 @@ def charmhub(self): |
783 | 783 | the charm-hub-url model config. |
784 | 784 |
|
785 | 785 | """ |
786 | | - return CharmHub(self) |
| 786 | + return self._charmhub |
| 787 | + |
| 788 | + @property |
| 789 | + def charmstore(self): |
| 790 | + return self._charmstore |
787 | 791 |
|
788 | 792 | async def get_info(self): |
789 | 793 | """Return a client.ModelInfo object for this Model. |
@@ -1968,10 +1972,6 @@ def upload_backup(self, archive_path): |
1968 | 1972 | """ |
1969 | 1973 | raise NotImplementedError() |
1970 | 1974 |
|
1971 | | - @property |
1972 | | - def charmstore(self): |
1973 | | - return self._charmstore |
1974 | | - |
1975 | 1975 | async def get_metrics(self, *tags): |
1976 | 1976 | """Retrieve metrics. |
1977 | 1977 |
|
@@ -2186,38 +2186,6 @@ def _create_consume_args(offer, macaroon, controller_info): |
2186 | 2186 | return arg |
2187 | 2187 |
|
2188 | 2188 |
|
2189 | | -class CharmStore: |
2190 | | - """ |
2191 | | - Async wrapper around theblues.charmstore.CharmStore |
2192 | | - """ |
2193 | | - def __init__(self, loop, cs_timeout=20): |
2194 | | - self.loop = loop |
2195 | | - self._cs = theblues.charmstore.CharmStore(timeout=cs_timeout) |
2196 | | - |
2197 | | - def __getattr__(self, name): |
2198 | | - """ |
2199 | | - Wrap method calls in coroutines that use run_in_executor to make them |
2200 | | - async. |
2201 | | - """ |
2202 | | - attr = getattr(self._cs, name) |
2203 | | - if not callable(attr): |
2204 | | - wrapper = partial(getattr, self._cs, name) |
2205 | | - setattr(self, name, wrapper) |
2206 | | - else: |
2207 | | - async def coro(*args, **kwargs): |
2208 | | - method = partial(attr, *args, **kwargs) |
2209 | | - for attempt in range(1, 4): |
2210 | | - try: |
2211 | | - return await self.loop.run_in_executor(None, method) |
2212 | | - except theblues.errors.ServerError: |
2213 | | - if attempt == 3: |
2214 | | - raise |
2215 | | - await asyncio.sleep(1, loop=self.loop) |
2216 | | - setattr(self, name, coro) |
2217 | | - wrapper = coro |
2218 | | - return wrapper |
2219 | | - |
2220 | | - |
2221 | 2189 | class CharmArchiveGenerator: |
2222 | 2190 | """ |
2223 | 2191 | Create a Zip archive of a local charm directory for upload to a controller. |
|
0 commit comments