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

« back to all changes in this revision

Viewing changes to deployer/service.py

  • Committer: Kapil Thangavelu
  • Date: 2015-01-22 15:22:18 UTC
  • Revision ID: kapil@canonical.com-20150122152218-vapvthnijvphdag4
support maas name and zone for placement

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
 
51
51
class ServiceUnitPlacement(object):
52
52
 
53
 
    def __init__(self, service, deployment, status):
 
53
    def __init__(self, service, deployment, status, arbitrary_machines=False):
54
54
        self.service = service
55
55
        self.deployment = deployment
56
56
        self.status = status
 
57
        self.arbitrary_machines = arbitrary_machines
57
58
 
58
59
    @staticmethod
59
60
    def _format_placement(machine, container=None):
84
85
                            self.service.name, unit_placement[idx]))
85
86
            if '=' in p:
86
87
                p, u_idx = p.split("=")
 
88
                if p in ('maas', 'zone'):
 
89
                    continue
87
90
                if not u_idx.isdigit():
88
91
                    feedback.error(
89
92
                        "Invalid service:%s placement: %s" % (
90
93
                        self.service.name, unit_placement[idx]))
91
 
            if p.isdigit() and p == '0':
92
 
                continue
93
 
            elif p.isdigit():
94
 
                feedback.error(
95
 
                    "Service placement to machine not supported %s to %s" % (
96
 
                    self.service.name, unit_placement[idx]))
 
94
            if p.isdigit():
 
95
                if self.arbitrary_machines:
 
96
                    continue
 
97
                elif p == '0':
 
98
                    continue
 
99
                else:
 
100
                    feedback.error(
 
101
                        ("Service placement to machine"
 
102
                         "not supported %s to %s") % (
 
103
                             self.service.name, unit_placement[idx]))
97
104
            elif p in services:
98
105
                if services[p].unit_placement:
99
106
                    feedback.error(
124
131
        if '=' in placement:
125
132
            placement, u_idx = placement.split("=")
126
133
 
127
 
        if placement.isdigit() and placement == "0":
128
 
            return self._format_placement(placement, container)
 
134
        if placement.isdigit():
 
135
            if self.arbitrary_machines or placement == '0':
 
136
                return self._format_placement(placement, container)
 
137
        if placement == 'maas':
 
138
            return u_idx
 
139
        elif placement == "zone":
 
140
            return "zone=%s" % u_idx
129
141
 
130
142
        with_service = status['services'].get(placement)
131
143
        if with_service is None: