Add get_config() and get_constraints() for Application
authorTim Van Steenburgh <tvansteenburgh@gmail.com>
Tue, 1 Nov 2016 19:48:44 +0000 (15:48 -0400)
committerTim Van Steenburgh <tvansteenburgh@gmail.com>
Tue, 1 Nov 2016 19:48:44 +0000 (15:48 -0400)
examples/config.py [new file with mode: 0644]
examples/relate.py
juju/application.py
juju/model.py

diff --git a/examples/config.py b/examples/config.py
new file mode 100644 (file)
index 0000000..616c780
--- /dev/null
@@ -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()
index aeb320d..8e42bab 100644 (file)
@@ -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()
index c12af85..42dae71 100644 (file)
@@ -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.
index 26611fc..52721a7 100644 (file)
@@ -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