from jujuclient.juju2.environment import Environment
log = logging.getLogger(__name__)
# Constants, change these for your environment
API_SERVER = '10.0.4.52'
USER = 'user-admin'
PASSWORD = 'd7247825e7df512140005cb2b6aab925'
CHARM_DIR = '/home/tvansteenburgh/src/charms/trusty/ubuntu'
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
# Login to default model
models = controller.models.list()
for m in models['user-models']:
if m['model']['name'] == 'default': model_endpoint = '{}/model/{}/api'.format( endpoint, m['model']['uuid'])
model = Environment(model_endpoint) model.login(PASSWORD, user=USER)
# Workaround for certificatge failure (hack)
ssl._create_default_https_context = ssl._create_unverified_context
# Upload a local charm to the model
res = model.add_local_charm_dir(CHARM_DIR, "trusty")
log.debug("Added local charm: %s", res)
# Turn on rpc debugging so we can see raw api calls
model._debug = True
# Deploy the uploaded charm
res = model.deploy('mycharm', res['charm-url'])
log.debug("Deploy response: %s", res)
And here's the output of running it. As you can see, the local charm is uploaded successfully and we get a charm-url back, but then when we try to deploy the charm using that url, it doesn't work:
Here's a python script to repro. You'll need the latest lp:python-jujuclient, which you can install from source or from ppa:tvansteenbu rgh/ppa.
tvansteenburgh@ xenial- vm:~/python- jujuclient⟫ cat deploy_test.py
#!/usr/bin/env python3
import logging
import ssl
from jujuclient. juju2.environme nt import Environment
log = logging. getLogger( __name_ _)
# Constants, change these for your environment 2140005cb2b6aab 925' tvansteenburgh/ src/charms/ trusty/ ubuntu'
API_SERVER = '10.0.4.52'
USER = 'user-admin'
PASSWORD = 'd7247825e7df51
CHARM_DIR = '/home/
if __name__ == "__main__": basicConfig( level=logging. DEBUG)
logging.
# Login to controller endpoint) login(PASSWORD, user=USER)
endpoint = 'wss://%s:17070' % (API_SERVER)
controller = Environment(
controller.
# Login to default model models. list() 'user-models' ]:
model_ endpoint = '{}/model/ {}/api' .format(
endpoint, m['model']['uuid']) model_endpoint)
model. login(PASSWORD, user=USER)
models = controller.
for m in models[
if m['model']['name'] == 'default':
model = Environment(
# Workaround for certificatge failure (hack) _create_ default_ https_context = ssl._create_ unverified_ context
ssl.
# Upload a local charm to the model local_charm_ dir(CHARM_ DIR, "trusty") debug(" Added local charm: %s", res)
res = model.add_
log.
# Turn on rpc debugging so we can see raw api calls
model._debug = True
# Deploy the uploaded charm 'mycharm' , res['charm-url']) debug(" Deploy response: %s", res)
res = model.deploy(
log.
And here's the output of running it. As you can see, the local charm is uploaded successfully and we get a charm-url back, but then when we try to deploy the charm using that url, it doesn't work:
tvansteenburgh@ xenial- vm:~/python- jujuclient⟫ .tox/py27/ bin/python deploy_test.py _main__ :Added local charm: {u'charm-url': u'local: trusty/ ubuntu- 3'} t.rpc:rpc request:
"placement" : [],
"num-units" : 1,
"application" : "mycharm",
"charm- url": "local: trusty/ ubuntu- 3",
"constraints" : {} t.rpc:rpc response:
"message" : "charm \"local: trusty/ ubuntu- 3\" not found", _main__ :Deploy response: {u'results': [{u'error': {u'message': u'charm "local: trusty/ ubuntu- 3" not found', u'code': u'not found'}}]}
DEBUG:_
DEBUG:jujuclien
{
"params": {
"applications": [
{
"config": {},
}
]
},
"request-id": 2,
"version": 1,
"request": "Deploy",
"type": "Application"
}
DEBUG:jujuclien
{
"request-id": 2,
"response": {
"results": [
{
"error": {
"code": "not found"
}
}
]
}
}
DEBUG:_