add current-apps script

This commit is contained in:
Chris MacNaughton
2017-12-04 17:38:16 +01:00
parent c3e5adcb4d
commit 895fbbad57
2 changed files with 37 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ from setuptools.command.test import test as TestCommand
version = "0.0.1.dev1"
install_require = [
'juju'
]
tests_require = [
@@ -71,6 +72,7 @@ setup(
],
entry_points={
'console_scripts': [
'current-apps = zaza.model:main',
'tempest-config = zaza.tempest_config:main',
]
},

35
zaza/model.py Normal file
View File

@@ -0,0 +1,35 @@
import logging
import sys
from juju import loop
from juju.model import Model
async def deployed(filter=None):
# Create a Model instance. We need to connect our Model to a Juju api
# server before we can use it.
model = Model()
# Connect to the currently active Juju model
await model.connect_current()
try:
# list currently deploeyd services
return list(model.applications.keys())
finally:
# Disconnect from the api server and cleanup.
await model.disconnect()
def main():
# logging.basicConfig(level=logging.INFO)
# # If you want to see everything sent over the wire, set this to DEBUG.
# ws_logger = logging.getLogger('websockets.protocol')
# ws_logger.setLevel(logging.INFO)
# Run the deploy coroutine in an asyncio event loop, using a helper
# that abstracts loop creation and teardown.
print("Current applications: {}".format( ", ".join(loop.run(deployed()))))
if __name__ == '__main__':
main()