Exemplo n.º 1
0
def _convert_timestamps_to_datetimes(image_meta):
    """Returns image with timestamp fields converted to datetime objects."""
    for attr in ['created_at', 'updated_at', 'deleted_at']:
        if image_meta.get(attr):
            image_meta[attr] = timeutils.parse_isotime(image_meta[attr])
    return image_meta
Exemplo n.º 2
0
def _convert_timestamps_to_datetimes(image_meta):
    """Returns image with timestamp fields converted to datetime objects."""
    for attr in ['created_at', 'updated_at', 'deleted_at']:
        if image_meta.get(attr):
            image_meta[attr] = timeutils.parse_isotime(image_meta[attr])
    return image_meta
Exemplo n.º 3
0
    def _heal_volume_status(self, context):

        TIME_SHIFT_TOLERANCE = 3

        heal_interval = CONF.volume_sync_interval

        if not heal_interval:
            return

        curr_time = time.time()
        LOG.info(_('Cascade info: last volume update time:%s'),
                 self._last_info_volume_state_heal)
        LOG.info(_('Cascade info: heal interval:%s'), heal_interval)
        LOG.info(_('Cascade info: curr_time:%s'), curr_time)

        if self._last_info_volume_state_heal + heal_interval > curr_time:
            return
        self._last_info_volume_state_heal = curr_time

        cinderClient = self._get_cinder_cascaded_admin_client()

        try:
            if self._change_since_time is None:
                search_opt = {'all_tenants': True}
                volumes = cinderClient.volumes.list(search_opts=search_opt)
                volumetypes = cinderClient.volume_types.list()
                LOG.info(_('Cascade info: change since time is none,'
                           'volumes:%s'), volumes)
            else:
                change_since_isotime = \
                    timeutils.parse_isotime(self._change_since_time)
                changesine_timestamp = change_since_isotime - \
                    datetime.timedelta(seconds=TIME_SHIFT_TOLERANCE)
                timestr = time.mktime(changesine_timestamp.timetuple())
                new_change_since_isotime = \
                    timeutils.iso8601_from_timestamp(timestr)

                search_op = {'all_tenants': True,
                             'changes-since': new_change_since_isotime}
                volumes = cinderClient.volumes.list(search_opts=search_op)
                volumetypes = cinderClient.volume_types.list()
                LOG.info(_('Cascade info: search time is not none,'
                           'volumes:%s'), volumes)

            self._change_since_time = timeutils.isotime()

            if len(volumes) > 0:
                LOG.debug(_('Updated the volumes %s'), volumes)

            for volume in volumes:
                volume_id = volume._info['metadata']['logicalVolumeId']
                volume_status = volume._info['status']
                if volume_status == "in-use":
                    self.db.volume_update(context, volume_id,
                                          {'status': volume._info['status'],
                                           'attach_status': 'attached',
                                           'attach_time': timeutils.strtime()
                                           })
                elif volume_status == "available":
                    self.db.volume_update(context, volume_id,
                                          {'status': volume._info['status'],
                                           'attach_status': 'detached',
                                           'instance_uuid': None,
                                           'attached_host': None,
                                           'mountpoint': None,
                                           'attach_time': None
                                           })
                else:
                    self.db.volume_update(context, volume_id,
                                          {'status': volume._info['status']})
                LOG.info(_('Cascade info: Updated the volume  %s status from'
                           'cinder-proxy'), volume_id)

            vol_types = self.db.volume_type_get_all(context, inactive=False)
            for volumetype in volumetypes:
                volume_type_name = volumetype._info['name']
                if volume_type_name not in vol_types.keys():
                    extra_specs = volumetype._info['extra_specs']
                    self.db.volume_type_create(
                        context,
                        dict(name=volume_type_name, extra_specs=extra_specs))

        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.error(_('Failed to sys volume status to db.'))