~makyo/juju-deployer/machines-and-placement

« back to all changes in this revision

Viewing changes to deployer/service.py

  • Committer: Madison Scott-Clary
  • Date: 2015-03-03 01:17:55 UTC
  • Revision ID: matthew.scott@canonical.com-20150303011755-5i00rtpsb32xtdh5
Checkpoint - first passing functional tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
115
115
                        self.service.name, unit_placement[idx]))
116
116
        return feedback
117
117
 
118
 
    def get(self, unit_number):
 
118
    def get(self, unit_number, machines_map=None):
119
119
        status = self.status
120
120
        svc = self.service
121
121
 
202
202
        replicated to fill it. If there are no elements (or To is omitted),
203
203
        "new" is replicated."""
204
204
        unit_mapping = self.service.unit_placement
205
 
        unit_count = self.service.get('num_units', 0)
 
205
        unit_count = self.service.num_units
206
206
        if not unit_mapping:
207
207
            self.service['to'] = ['new' for r in range(unit_count)]
208
208
            return
238
238
 
239
239
        services = dict([(s.name, s) for s in self.deployment.get_services()])
240
240
        machines = self.deployment.get_machines()
 
241
        container = None
241
242
 
242
243
        for idx, p in enumerate(unit_placement):
243
244
            # (<containertype>:)?(<unit>|<machine>|new)
246
247
            if '/' in p:
247
248
                p, unit_number = p.split('/')
248
249
 
249
 
            if container not in ('lxc', 'kvm'):
 
250
            if container and container not in ('lxc', 'kvm'):
250
251
                feedback.error(
251
252
                    "Invalid service:%s placement: %s" % (
252
253
                        self.service.name, unit_placement[idx]))
265
266
                    continue
266
267
                else:
267
268
                    feedback.error(
268
 
                        ("Service placement to machine"
 
269
                        ("Service placement to machine "
269
270
                         "not supported %s to %s") % (
270
271
                             self.service.name, unit_placement[idx]))
271
272
            # Specify a particular service for colocation.
305
306
                new_machine_count += 1
306
307
        return new_machine_count
307
308
 
308
 
    def get(self, unit_number):
 
309
    def get(self, unit_number, machines_map=None):
309
310
        status = self.status
310
311
        svc = self.service
311
312
 
323
324
        if '/' in placement:
324
325
            placement, u_idx = placement.split("/")
325
326
 
326
 
        if placement.isdigit() and self.has_machine_spec:
 
327
        if placement.isdigit() and not self.has_machine_spec:
327
328
            if self.arbitrary_machines or placement == '0':
328
329
                return self._format_placement(placement, container)
329
330
 
 
331
        if self.has_machine_spec and placement in machines_map:
 
332
            return self._format_placement(machines_map[placement]['Machine'],
 
333
                                          container)
 
334
 
 
335
        # Handle <container_type>:new
 
336
        if placement == 'new':
 
337
            # XXX get new machine created
 
338
            return None
 
339
            # return self._format_placement(machines_map['_new%d' % some_digit']['Machine'], container)
 
340
 
330
341
        with_service = status['services'].get(placement)
331
342
        if with_service is None:
332
343
            # Should be caught in validate relations but sanity check