lambda delta, old_unit, new_unit, model:
print('Unit removed: {}'.format(old_unit.entity_id))
))
+ unit_a, unit_b = await ubuntu_app.add_units(count=2)
+ unit_a.on_change(asyncio.coroutine(
+ lambda delta, old_unit, new_unit, model:
+ print('Unit changed: {}'.format(new_unit.entity_id))
+ ))
await model.deploy(
'nrpe',
service_name='nrpe',
+import asyncio
import logging
from . import model
"""
pass
- def add_unit(self, count=1, to=None):
+ async def add_unit(self, count=1, to=None):
"""Add one or more units to this service.
:param int count: Number of units to add
If None, a new machine is provisioned.
"""
- pass
+ app_facade = client.ApplicationFacade()
+ app_facade.connect(self.connection)
+
+ log.debug(
+ 'Adding %s unit%s to %s',
+ count, '' if count == 1 else 's', self.name)
+
+ result = await app_facade.AddUnits(
+ application=self.name,
+ placement=to,
+ num_units=count,
+ )
+
+ return await asyncio.gather(*[
+ asyncio.ensure_future(self.model._wait_for_new('unit', unit_id))
+ for unit_id in result.units
+ ])
+
add_units = add_unit
def allocate(self, budget, value):
# doesn't, so we're not bothering, either
unit_name = self._units_by_app[application].pop()
log.debug('Reusing unit %s for %s', unit_name, application)
- return unit_name
- log.debug('Adding unit of %s%s',
- application,
- (' to %s' % placement) if placement else '')
- result = await self.app_facade.AddUnits(
- application=application,
- placement=placement,
- num_units=1,
+ return self.model.units[unit_name]
+
+ return await self.model.applications[application].add_unit(
+ count=1,
+ to=placement,
)
- return result.units[0]
async def expose(self, application):
"""