From: Tim Van Steenburgh Date: Tue, 1 Nov 2016 19:48:44 +0000 (-0400) Subject: Add get_config() and get_constraints() for Application X-Git-Tag: 0.1.0~60 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=55ae2c120ce031f57ac210f3d7bd203db739f1e9;p=osm%2FN2VC.git Add get_config() and get_constraints() for Application --- 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