Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resources support #191

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ EOR

if [[ $JUJU_VERSION == 2 ]]; then
sudo add-apt-repository -y ppa:juju/stable
sudo add-apt-repository -y ppa:ubuntu-lxc/lxd-stable
JUJU_PKGS="juju lxd"
else
sudo add-apt-repository -y ppa:juju/1.25
JUJU_PKGS="juju juju-local"
fi

sudo apt-get update
sudo apt-get install -y bzr $JUJU_PKGS
sudo apt-get install -t trusty-backports -y bzr $JUJU_PKGS

if [[ $JUJU_VERSION == 2 ]]; then
echo User: $USER
Expand Down
47 changes: 45 additions & 2 deletions amulet/deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ def load(self, deploy_cfg, deployment_name=None):
constraints=constraints,
placement=service_config.get('to', None),
series=self.series,
storage=service_config.get('storage')
storage=service_config.get('storage'),
resources=service_config.get('resources')
)

if service_config.get('options'):
Expand All @@ -171,7 +172,8 @@ def add(self, service_name,
branch=None,
placement=None,
series=None,
storage=None):
storage=None,
resources=None):
"""Add a new service to the deployment schema.

:param service_name: Name of the service to deploy.
Expand All @@ -189,6 +191,8 @@ def add(self, service_name,
:param series: Series of charm to deploy, e.g. precise, trusty, xenial
:param storage: Storage configuration as a dictionary with key the
label and value being the pool,size,count string used by Juju.
:param resources: Resources configuration as a dictionary with key the
resource name and value the local path to the file

Example::

Expand All @@ -198,6 +202,8 @@ def add(self, service_name,
d.add('second-wp', charm='wordpress')
d.add('personal-wp', charm='~marcoceppi/wordpress', units=2)
d.add('postgresql', storage={'pgdata', 'rootfs,50M'})
d.add('etcd', resources={'snapshot': './snapshot.tgz',
'etcd': 'etcd.snap'})

"""
if self.deployed:
Expand All @@ -214,6 +220,11 @@ def add(self, service_name,
raise ValueError('Storage must be specified as a dict')
service['storage'] = storage

if resources is not None:
if not isinstance(resources, dict):
raise ValueError('Resources must be specified as a dict')
service['resources'] = resources

charm = self.charm_cache.fetch(
service_name, charm, branch=branch, series=service['series'])

Expand Down Expand Up @@ -546,6 +557,38 @@ def configure(self, service, options):
else:
self.services[service]['options'].update(options)

def attach(self, service, resources):
"""Attaches resources to a service (deployed or not).

:param service: Name of the service to hold the attachments
:param resources: Dictionary of resources to attach

Example:

import amulet
d = amulet.Deployment()
d.add('etcd')
d.attach('etc', {'snapshot': 'snapshot.tgz'})

"""
if JUJU_VERSION.major == 1:
raise NotImplementedError(
'Resources feature not implemented in this juju version')

if self.deployed:
args = ['attach', service]
for k, v in resources.items():
args.append("%s=%s" % (k, v))
return juju(args)

if service not in self.services:
raise ValueError('Service has not yet been described')

if 'resources' not in self.services[service]:
self.services[service]['resources'] = resources
else:
self.services[service]['resources'].update(resources)

def expose(self, service):
"""Expose a service.

Expand Down
2 changes: 2 additions & 0 deletions tests/test_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def test_load(self):
placement=None,
series='raring',
storage={"wp-data": "rootfs,100M"},
resources=None,
units=1,
branch='lp:~charmers/charms/precise/wordpress/trunk',
constraints=None,
Expand All @@ -73,6 +74,7 @@ def test_load(self):
placement=None,
series='raring',
storage=None,
resources=None,
units=1,
branch='lp:~charmers/charms/precise/mysql/trunk',
constraints={'mem': '2G', 'cpu-cores': '2'},
Expand Down