From 55ae2c120ce031f57ac210f3d7bd203db739f1e9 Mon Sep 17 00:00:00 2001 From: Tim Van Steenburgh Date: Tue, 1 Nov 2016 15:48:44 -0400 Subject: [PATCH] Add get_config() and get_constraints() for Application --- examples/config.py | 41 +++++++++++++++++++++++++++++++++++++++++ examples/relate.py | 2 +- juju/application.py | 24 ++++++++++++++++++------ juju/model.py | 3 --- 4 files changed, 60 insertions(+), 10 deletions(-) create mode 100644 examples/config.py diff --git a/examples/config.py b/examples/config.py new file mode 100644 index 0000000..616c780 --- /dev/null +++ b/examples/config.py @@ -0,0 +1,41 @@ +""" +This example: + +1. Connects to the current model +2. Resets it +3. Deploys a charm and prints its config and constraints + +""" +import asyncio +import logging + +from juju.model import Model + + +async def run(): + model = Model() + await model.connect_current() + await model.reset(force=True) + + ubuntu_app = await model.deploy( + 'mysql', + service_name='mysql', + series='trusty', + channel='stable', + constraints={ + 'mem': 512 * 1024 * 1024 + }, + ) + print(await ubuntu_app.get_config()) + print(await ubuntu_app.get_constraints()) + + await model.disconnect() + model.loop.stop() + +logging.basicConfig(level=logging.DEBUG) +ws_logger = logging.getLogger('websockets.protocol') +ws_logger.setLevel(logging.INFO) +loop = asyncio.get_event_loop() +loop.set_debug(False) +loop.create_task(run()) +loop.run_forever() diff --git a/examples/relate.py b/examples/relate.py index aeb320d..8e42bab 100644 --- a/examples/relate.py +++ b/examples/relate.py @@ -93,6 +93,6 @@ logging.basicConfig(level=logging.DEBUG) ws_logger = logging.getLogger('websockets.protocol') ws_logger.setLevel(logging.INFO) loop = asyncio.get_event_loop() -loop.set_debug(False) +loop.set_debug(True) loop.create_task(run()) loop.run_forever() diff --git a/juju/application.py b/juju/application.py index c12af85..42dae71 100644 --- a/juju/application.py +++ b/juju/application.py @@ -171,17 +171,29 @@ class Application(model.ModelEntity): return await app_facade.Expose(self.name) - def get_config(self): - """Return the configuration settings for this application. + async def get_config(self): + """Return the configuration settings dict for this application. """ - pass + app_facade = client.ApplicationFacade() + app_facade.connect(self.connection) + + log.debug( + 'Getting config for %s', self.name) + + return (await app_facade.Get(self.name)).config - def get_constraints(self): - """Return the machine constraints for this application. + async def get_constraints(self): + """Return the machine constraints dict for this application. """ - pass + app_facade = client.ApplicationFacade() + app_facade.connect(self.connection) + + log.debug( + 'Getting constraints for %s', self.name) + + return vars((await app_facade.Get(self.name)).constraints) def get_actions(self, schema=False): """Get actions defined for this application. diff --git a/juju/model.py b/juju/model.py index 26611fc..52721a7 100644 --- a/juju/model.py +++ b/juju/model.py @@ -759,9 +759,6 @@ class Model(object): - series is required; how do we pick a default? """ - if constraints: - constraints = client.Value(**constraints) - if to: placement = [ client.Placement(**p) for p in to -- 2.17.1