コード例 #1
0
ファイル: impl_zmq.py プロジェクト: v12aml/raksha
    def consume_in_thread(self):
        """Runs the ZmqProxy service"""
        ipc_dir = CONF.rpc_zmq_ipc_dir
        consume_in = "tcp://%s:%s" % \
            (CONF.rpc_zmq_bind_address,
             CONF.rpc_zmq_port)
        consumption_proxy = InternalContext(None)

        if not os.path.isdir(ipc_dir):
            try:
                utils.execute('mkdir', '-p', ipc_dir, run_as_root=True)
                utils.execute('chown', "%s:%s" % (os.getuid(), os.getgid()),
                              ipc_dir, run_as_root=True)
                utils.execute('chmod', '750', ipc_dir, run_as_root=True)
            except utils.ProcessExecutionError:
                with excutils.save_and_reraise_exception():
                    LOG.error(_("Could not create IPC directory %s") %
                              (ipc_dir, ))

        try:
            self.register(consumption_proxy,
                          consume_in,
                          zmq.PULL,
                          out_bind=True)
        except zmq.ZMQError:
            with excutils.save_and_reraise_exception():
                LOG.error(_("Could not create ZeroMQ receiver daemon. "
                            "Socket may already be in use."))

        super(ZmqProxy, self).consume_in_thread()
コード例 #2
0
ファイル: manager.py プロジェクト: DPaaS-Raksha/raksha
    def backupjob_create(self, context, backupjob_id):
        """
        Create a scheduled backup job in the backup job scheduler
        """
        try:
            backupjob = self.db.backupjob_get(context, backupjob_id)
            #TODO(gbasava): Change it to list of VMs when we support multiple VMs
            vm = self.db.backupjob_vms_get(context, backupjob_id)

            LOG.info(_('create_backupjob started, %s:' %backupjob_id))
            self.db.backupjob_update(context, backupjob_id, {'host': self.host,
                                     'service': FLAGS.vault_service})

            schjob = self.scheduler.add_interval_job(context, backupjob_callback, hours=24,
                                     name=backupjob['display_name'], args=[backupjob_id], 
                                     backupjob_id=backupjob_id)
            LOG.info(_('scheduled backup job: %s'), schjob.id)
        except Exception as err:
            with excutils.save_and_reraise_exception():
                self.db.backupjob_update(context, backupjob_id,
                                      {'status': 'error',
                                       'fail_reason': unicode(err)})

        self.db.backupjob_update(context, backupjob_id, {'status': 'available',
                                                         'availability_zone': self.az,
                                                         'schedule_job_id':schjob.id})
        LOG.info(_('create_backupjob finished. backup: %s'), backupjob_id)
コード例 #3
0
ファイル: manager.py プロジェクト: DPaaS-Raksha/raksha
    def create_volume(self, context, topic, volume_id, snapshot_id=None,
                      image_id=None, request_spec=None,
                      filter_properties=None):
        try:
            if request_spec is None:
                # For RPC version < 1.2 backward compatibility
                request_spec = {}
                volume_ref = db.volume_get(context, volume_id)
                size = volume_ref.get('size')
                availability_zone = volume_ref.get('availability_zone')
                volume_type_id = volume_ref.get('volume_type_id')
                vol_type = db.volume_type_get(context, volume_type_id)
                volume_properties = {'size': size,
                                     'availability_zone': availability_zone,
                                     'volume_type_id': volume_type_id}
                request_spec.update(
                    {'volume_id': volume_id,
                     'snapshot_id': snapshot_id,
                     'image_id': image_id,
                     'volume_properties': volume_properties,
                     'volume_type': dict(vol_type).iteritems()})

            self.driver.schedule_create_volume(context, request_spec,
                                               filter_properties)
        except exception.NoValidHost as ex:
            volume_state = {'volume_state': {'status': 'error'}}
            self._set_volume_state_and_notify('create_volume',
                                              volume_state,
                                              context, ex, request_spec)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                volume_state = {'volume_state': {'status': 'error'}}
                self._set_volume_state_and_notify('create_volume',
                                                  volume_state,
                                                  context, ex, request_spec)
コード例 #4
0
ファイル: utils.py プロジェクト: DPaaS-Raksha/raksha
def remove_path_on_error(path):
    """Protect code that wants to operate on PATH atomically.
    Any exception will cause PATH to be removed.
    """
    try:
        yield
    except Exception:
        with excutils.save_and_reraise_exception():
            delete_if_exists(path)
コード例 #5
0
def remove_path_on_error(path):
    """Protect code that wants to operate on PATH atomically.
    Any exception will cause PATH to be removed.
    """
    try:
        yield
    except Exception:
        with excutils.save_and_reraise_exception():
            delete_if_exists(path)
コード例 #6
0
ファイル: utils.py プロジェクト: DPaaS-Raksha/raksha
def logging_error(message):
    """Catches exception, write message to the log, re-raise.
    This is a common refinement of save_and_reraise that writes a specific
    message to the log.
    """
    try:
        yield
    except Exception as error:
        with excutils.save_and_reraise_exception():
            LOG.exception(message)
コード例 #7
0
def logging_error(message):
    """Catches exception, write message to the log, re-raise.
    This is a common refinement of save_and_reraise that writes a specific
    message to the log.
    """
    try:
        yield
    except Exception as error:
        with excutils.save_and_reraise_exception():
            LOG.exception(message)
コード例 #8
0
ファイル: utils.py プロジェクト: DPaaS-Raksha/raksha
    def rollback_and_reraise(self, msg=None, **kwargs):
        """Rollback a series of actions then re-raise the exception.

        .. note:: (sirp) This should only be called within an
                  exception handler.
        """
        with excutils.save_and_reraise_exception():
            if msg:
                LOG.exception(msg, **kwargs)

            self._rollback()
コード例 #9
0
ファイル: impl_zmq.py プロジェクト: v12aml/raksha
def _serialize(data):
    """
    Serialization wrapper
    We prefer using JSON, but it cannot encode all types.
    Error if a developer passes us bad data.
    """
    try:
        return jsonutils.dumps(data, ensure_ascii=True)
    except TypeError:
        with excutils.save_and_reraise_exception():
            LOG.error(_("JSON serialization failed."))
コード例 #10
0
    def rollback_and_reraise(self, msg=None, **kwargs):
        """Rollback a series of actions then re-raise the exception.

        .. note:: (sirp) This should only be called within an
                  exception handler.
        """
        with excutils.save_and_reraise_exception():
            if msg:
                LOG.exception(msg, **kwargs)

            self._rollback()
コード例 #11
0
ファイル: amqp.py プロジェクト: DPaaS-Raksha/raksha
 def __iter__(self):
     """Return a result until we get a 'None' response from consumer"""
     if self._done:
         raise StopIteration
     while True:
         try:
             self._iterator.next()
         except Exception:
             with excutils.save_and_reraise_exception():
                 self.done()
         if self._got_ending:
             self.done()
             raise StopIteration
         result = self._result
         if isinstance(result, Exception):
             self.done()
             raise result
         yield result
コード例 #12
0
ファイル: amqp.py プロジェクト: v12aml/raksha
 def __iter__(self):
     """Return a result until we get a 'None' response from consumer"""
     if self._done:
         raise StopIteration
     while True:
         try:
             self._iterator.next()
         except Exception:
             with excutils.save_and_reraise_exception():
                 self.done()
         if self._got_ending:
             self.done()
             raise StopIteration
         result = self._result
         if isinstance(result, Exception):
             self.done()
             raise result
         yield result
コード例 #13
0
ファイル: manager.py プロジェクト: v12aml/raksha
    def create_volume(self,
                      context,
                      topic,
                      volume_id,
                      snapshot_id=None,
                      image_id=None,
                      request_spec=None,
                      filter_properties=None):
        try:
            if request_spec is None:
                # For RPC version < 1.2 backward compatibility
                request_spec = {}
                volume_ref = db.volume_get(context, volume_id)
                size = volume_ref.get('size')
                availability_zone = volume_ref.get('availability_zone')
                volume_type_id = volume_ref.get('volume_type_id')
                vol_type = db.volume_type_get(context, volume_type_id)
                volume_properties = {
                    'size': size,
                    'availability_zone': availability_zone,
                    'volume_type_id': volume_type_id
                }
                request_spec.update({
                    'volume_id': volume_id,
                    'snapshot_id': snapshot_id,
                    'image_id': image_id,
                    'volume_properties': volume_properties,
                    'volume_type': dict(vol_type).iteritems()
                })

            self.driver.schedule_create_volume(context, request_spec,
                                               filter_properties)
        except exception.NoValidHost as ex:
            volume_state = {'volume_state': {'status': 'error'}}
            self._set_volume_state_and_notify('create_volume', volume_state,
                                              context, ex, request_spec)
        except Exception as ex:
            with excutils.save_and_reraise_exception():
                volume_state = {'volume_state': {'status': 'error'}}
                self._set_volume_state_and_notify('create_volume',
                                                  volume_state, context, ex,
                                                  request_spec)
コード例 #14
0
ファイル: amqp.py プロジェクト: DPaaS-Raksha/raksha
 def __iter__(self):
     """Return a result until we get a reply with an 'ending" flag"""
     if self._done:
         raise StopIteration
     while True:
         try:
             data = self._dataqueue.get(timeout=self._timeout)
             result = self._process_data(data)
         except queue.Empty:
             self.done()
             raise rpc_common.Timeout()
         except Exception:
             with excutils.save_and_reraise_exception():
                 self.done()
         if self._got_ending:
             self.done()
             raise StopIteration
         if isinstance(result, Exception):
             self.done()
             raise result
         yield result
コード例 #15
0
ファイル: amqp.py プロジェクト: v12aml/raksha
 def __iter__(self):
     """Return a result until we get a reply with an 'ending" flag"""
     if self._done:
         raise StopIteration
     while True:
         try:
             data = self._dataqueue.get(timeout=self._timeout)
             result = self._process_data(data)
         except queue.Empty:
             self.done()
             raise rpc_common.Timeout()
         except Exception:
             with excutils.save_and_reraise_exception():
                 self.done()
         if self._got_ending:
             self.done()
             raise StopIteration
         if isinstance(result, Exception):
             self.done()
             raise result
         yield result
コード例 #16
0
    def backupjob_create(self, context, backupjob_id):
        """
        Create a scheduled backup job in the backup job scheduler
        """
        try:
            backupjob = self.db.backupjob_get(context, backupjob_id)
            #TODO(gbasava): Change it to list of VMs when we support multiple VMs
            vm = self.db.backupjob_vms_get(context, backupjob_id)

            LOG.info(_('create_backupjob started, %s:' % backupjob_id))
            self.db.backupjob_update(context, backupjob_id, {
                'host': self.host,
                'service': FLAGS.vault_service
            })

            schjob = self.scheduler.add_interval_job(
                context,
                backupjob_callback,
                hours=24,
                name=backupjob['display_name'],
                args=[backupjob_id],
                backupjob_id=backupjob_id)
            LOG.info(_('scheduled backup job: %s'), schjob.id)
        except Exception as err:
            with excutils.save_and_reraise_exception():
                self.db.backupjob_update(context, backupjob_id, {
                    'status': 'error',
                    'fail_reason': unicode(err)
                })

        self.db.backupjob_update(
            context, backupjob_id, {
                'status': 'available',
                'availability_zone': self.az,
                'schedule_job_id': schjob.id
            })
        LOG.info(_('create_backupjob finished. backup: %s'), backupjob_id)