~tr3buchet/nova/lock

« back to all changes in this revision

Viewing changes to nova/compute/manager.py

  • Committer: Vishvananda Ishaya
  • Date: 2010-12-22 20:59:53 UTC
  • mto: This revision was merged to the branch mainline in revision 482.
  • Revision ID: vishvananda@gmail.com-20101222205953-j2j5t0qjwlcd0t2s
merge trunk and upgrade to cheetah templating

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
        context = context.elevated()
94
94
        instance_ref = self.db.instance_get(context, instance_id)
95
95
        if instance_ref['name'] in self.driver.list_instances():
96
 
            raise exception.Error("Instance has already been created")
97
 
        logging.debug("instance %s: starting...", instance_id)
 
96
            raise exception.Error(_("Instance has already been created"))
 
97
        logging.debug(_("instance %s: starting..."), instance_id)
98
98
        self.network_manager.setup_compute_network(context, instance_id)
99
99
        self.db.instance_update(context,
100
100
                                instance_id,
113
113
                                    instance_id,
114
114
                                    {'launched_at': now})
115
115
        except Exception:  # pylint: disable-msg=W0702
116
 
            logging.exception("instance %s: Failed to spawn",
 
116
            logging.exception(_("instance %s: Failed to spawn"),
117
117
                              instance_ref['name'])
118
118
            self.db.instance_set_state(context,
119
119
                                       instance_id,
125
125
    def terminate_instance(self, context, instance_id):
126
126
        """Terminate an instance on this machine."""
127
127
        context = context.elevated()
128
 
        logging.debug("instance %s: terminating", instance_id)
 
128
        logging.debug(_("instance %s: terminating"), instance_id)
129
129
 
130
130
        instance_ref = self.db.instance_get(context, instance_id)
131
131
        volumes = instance_ref.get('volumes', []) or []
133
133
            self.detach_volume(context, instance_id, volume['id'])
134
134
        if instance_ref['state'] == power_state.SHUTOFF:
135
135
            self.db.instance_destroy(context, instance_id)
136
 
            raise exception.Error('trying to destroy already destroyed'
137
 
                                  ' instance: %s' % instance_id)
 
136
            raise exception.Error(_('trying to destroy already destroyed'
 
137
                                    ' instance: %s') % instance_id)
138
138
        self.driver.destroy(instance_ref)
139
139
 
140
140
        # TODO(ja): should we keep it in a terminated state for a bit?
148
148
        self._update_state(context, instance_id)
149
149
 
150
150
        if instance_ref['state'] != power_state.RUNNING:
151
 
            logging.warn('trying to reboot a non-running '
152
 
                         'instance: %s (state: %s excepted: %s)',
 
151
            logging.warn(_('trying to reboot a non-running '
 
152
                           'instance: %s (state: %s excepted: %s)'),
153
153
                         instance_ref['internal_id'],
154
154
                         instance_ref['state'],
155
155
                         power_state.RUNNING)
156
156
 
157
 
        logging.debug('instance %s: rebooting', instance_ref['name'])
 
157
        logging.debug(_('instance %s: rebooting'), instance_ref['name'])
158
158
        self.db.instance_set_state(context,
159
159
                                   instance_id,
160
160
                                   power_state.NOSTATE,
168
168
        context = context.elevated()
169
169
        instance_ref = self.db.instance_get(context, instance_id)
170
170
 
171
 
        logging.debug('instance %s: rescuing',
 
171
        logging.debug(_('instance %s: rescuing'),
172
172
                      instance_ref['internal_id'])
173
173
        self.db.instance_set_state(context,
174
174
                                   instance_id,
183
183
        context = context.elevated()
184
184
        instance_ref = self.db.instance_get(context, instance_id)
185
185
 
186
 
        logging.debug('instance %s: unrescuing',
 
186
        logging.debug(_('instance %s: unrescuing'),
187
187
                      instance_ref['internal_id'])
188
188
        self.db.instance_set_state(context,
189
189
                                   instance_id,
192
192
        self.driver.unrescue(instance_ref)
193
193
        self._update_state(context, instance_id)
194
194
 
 
195
    @staticmethod
 
196
    def _update_state_callback(self, context, instance_id, result):
 
197
        """Update instance state when async task completes."""
 
198
        self._update_state(context, instance_id)
 
199
 
 
200
    @exception.wrap_exception
 
201
    def pause_instance(self, context, instance_id):
 
202
        """Pause an instance on this server."""
 
203
        context = context.elevated()
 
204
        instance_ref = self.db.instance_get(context, instance_id)
 
205
 
 
206
        logging.debug('instance %s: pausing',
 
207
                      instance_ref['internal_id'])
 
208
        self.db.instance_set_state(context,
 
209
                                   instance_id,
 
210
                                   power_state.NOSTATE,
 
211
                                   'pausing')
 
212
        self.driver.pause(instance_ref,
 
213
            lambda result: self._update_state_callback(self,
 
214
                                                       context,
 
215
                                                       instance_id,
 
216
                                                       result))
 
217
 
 
218
    @exception.wrap_exception
 
219
    def unpause_instance(self, context, instance_id):
 
220
        """Unpause a paused instance on this server."""
 
221
        context = context.elevated()
 
222
        instance_ref = self.db.instance_get(context, instance_id)
 
223
 
 
224
        logging.debug('instance %s: unpausing',
 
225
                      instance_ref['internal_id'])
 
226
        self.db.instance_set_state(context,
 
227
                                   instance_id,
 
228
                                   power_state.NOSTATE,
 
229
                                   'unpausing')
 
230
        self.driver.unpause(instance_ref,
 
231
            lambda result: self._update_state_callback(self,
 
232
                                                       context,
 
233
                                                       instance_id,
 
234
                                                       result))
 
235
 
195
236
    @exception.wrap_exception
196
237
    def get_console_output(self, context, instance_id):
197
238
        """Send the console output for an instance."""
198
239
        context = context.elevated()
199
 
        logging.debug("instance %s: getting console output", instance_id)
 
240
        logging.debug(_("instance %s: getting console output"), instance_id)
200
241
        instance_ref = self.db.instance_get(context, instance_id)
201
242
 
202
243
        return self.driver.get_console_output(instance_ref)
205
246
    def attach_volume(self, context, instance_id, volume_id, mountpoint):
206
247
        """Attach a volume to an instance."""
207
248
        context = context.elevated()
208
 
        logging.debug("instance %s: attaching volume %s to %s", instance_id,
 
249
        logging.debug(_("instance %s: attaching volume %s to %s"), instance_id,
209
250
            volume_id, mountpoint)
210
251
        instance_ref = self.db.instance_get(context, instance_id)
211
252
        dev_path = self.volume_manager.setup_compute_volume(context,
222
263
            # NOTE(vish): The inline callback eats the exception info so we
223
264
            #             log the traceback here and reraise the same
224
265
            #             ecxception below.
225
 
            logging.exception("instance %s: attach failed %s, removing",
 
266
            logging.exception(_("instance %s: attach failed %s, removing"),
226
267
                              instance_id, mountpoint)
227
268
            self.volume_manager.remove_compute_volume(context,
228
269
                                                      volume_id)
234
275
    def detach_volume(self, context, instance_id, volume_id):
235
276
        """Detach a volume from an instance."""
236
277
        context = context.elevated()
237
 
        logging.debug("instance %s: detaching volume %s",
 
278
        logging.debug(_("instance %s: detaching volume %s"),
238
279
                      instance_id,
239
280
                      volume_id)
240
281
        instance_ref = self.db.instance_get(context, instance_id)
241
282
        volume_ref = self.db.volume_get(context, volume_id)
242
283
        if instance_ref['name'] not in self.driver.list_instances():
243
 
            logging.warn("Detaching volume from unknown instance %s",
 
284
            logging.warn(_("Detaching volume from unknown instance %s"),
244
285
                         instance_ref['name'])
245
286
        else:
246
287
            self.driver.detach_volume(instance_ref['name'],