~lutostag/juju-deployer/populate-first+test-fixes

« back to all changes in this revision

Viewing changes to deployer/service.py

  • Committer: Ryan Harper
  • Date: 2015-02-11 22:01:37 UTC
  • Revision ID: ryan.harper@canonical.com-20150211220137-bm4gf29wfmer44y0
Add placement_first cli option.  This allocates machines in maas placement first to ensure no other services use the targetted machine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from feedback import Feedback
 
2
import time
2
3
 
3
4
 
4
5
class Service(object):
100
101
                    feedback.error(
101
102
                        ("Service placement to machine"
102
103
                         "not supported %s to %s") % (
103
 
                             self.service.name, unit_placement[idx]))
 
104
                            self.service.name, unit_placement[idx]))
104
105
            elif p in services:
105
106
                if services[p].unit_placement:
106
107
                    feedback.error(
112
113
                        self.service.name, unit_placement[idx]))
113
114
        return feedback
114
115
 
115
 
    def get(self, unit_number):
 
116
    def get(self, unit_number, env=None):
116
117
        status = self.status
117
118
        svc = self.service
118
119
 
135
136
            if self.arbitrary_machines or placement == '0':
136
137
                return self._format_placement(placement, container)
137
138
        if placement == 'maas':
138
 
            return u_idx
 
139
            # find the machine id that matches the target machine
 
140
            # unlike juju status output, the dns-name is one of the
 
141
            # many values returned from our env.status()
 
142
            mid = [x for x in status['machines'].keys()
 
143
                   if u_idx in
 
144
                   [v.get('Value') for v in
 
145
                    status['machines'][x]['addresses']]]
 
146
            self.deployment.log.info('mid=%s' % mid)
 
147
            if mid:
 
148
                m = mid.pop()
 
149
                self.deployment.log.debug(
 
150
                    'Found juju machine (%s) matching placement: %s', m, u_idx)
 
151
                return m
 
152
            else:
 
153
                self.deployment.log.info(
 
154
                    'No match in juju machines for: %s', u_idx)
 
155
                uuid = env.get_env_config()['Config']['uuid']
 
156
                mid = env.add_machine(scope=uuid, directive=u_idx)
 
157
                self.deployment.log.debug(
 
158
                    'Waiting for machine to show up in status.')
 
159
                m = mid.get('Machine')
 
160
                while True:
 
161
                    if m in status['machines'].keys():
 
162
                        s = [x for x in status['machines'].keys()
 
163
                             if u_idx in
 
164
                             [v.get('Value') for v in
 
165
                              status['machines'][x]['addresses']]]
 
166
                        self.deployment.log.debug('addresses: %s' % s)
 
167
                        if m in s:
 
168
                            break
 
169
                    else:
 
170
                        self.deployment.log.debug(
 
171
                            'Machine %s not in status yet' % m)
 
172
                    time.sleep(1)
 
173
                    status = env.status()
 
174
                self.deployment.log.debug('Machine %s up!' % m)
 
175
                return mid.get('Machine')
139
176
        elif placement == "zone":
140
177
            return "zone=%s" % u_idx
141
178