def _resource_and_snap_data_from_snapshot(self, snapshot, empty_ok=False):
        """Find the DRBD Resource and the snapshot name
        from the snapshot ID.
        """
        s_uuid = snapshot["id"]
        res, rs = self.call_or_reconnect(
            self.odm.list_snapshots,
            self.empty_list,
            self.empty_list,
            dm_utils.dict_to_aux_props({CINDER_AUX_PROP_id: s_uuid}),
            self.empty_list,
        )
        self._check_result(res)

        if (not rs) or (len(rs) == 0):
            if empty_ok:
                return None
            else:
                raise exception.VolumeBackendAPIException(data=_("no snapshot with id %s found in drbdmanage") % s_uuid)
        if len(rs) > 1:
            raise exception.VolumeBackendAPIException(data=_("multiple resources with snapshot ID %s found") % s_uuid)

        (r_name, snaps) = rs[0]
        if len(snaps) != 1:
            raise exception.VolumeBackendAPIException(data=_("not exactly one snapshot with id %s") % s_uuid)

        (s_name, s_props) = snaps[0]

        LOG.debug("snapshot %s is %s/%s" % (s_uuid, r_name, s_name))

        return r_name, s_name, s_props
Пример #2
0
    def _resource_and_snap_data_from_snapshot(self, snapshot, empty_ok=False):
        """Find DRBD resource and snapshot name from the snapshot ID."""
        s_uuid = snapshot['id']
        res, rs = self.call_or_reconnect(self.odm.list_snapshots,
                                         self.empty_dict,
                                         self.empty_dict,
                                         0,
                                         dm_utils.dict_to_aux_props(
                                             {AUX_PROP_CINDER_VOL_ID: s_uuid}),
                                         self.empty_dict)
        self._check_result(res)

        if not rs:
            if empty_ok:
                return None
            else:
                raise exception.VolumeBackendAPIException(
                    data=_("no snapshot with id %s found in drbdmanage") %
                    s_uuid)
        if len(rs) > 1:
            raise exception.VolumeBackendAPIException(
                data=_("multiple resources with snapshot ID %s found") %
                s_uuid)

        (r_name, snaps) = rs[0]
        if len(snaps) != 1:
            raise exception.VolumeBackendAPIException(
                data=_("not exactly one snapshot with id %s") % s_uuid)

        (s_name, s_props) = snaps[0]

        LOG.debug("snapshot %(uuid)s is %(res)s/%(snap)s",
                  {'uuid': s_uuid, 'res': r_name, 'snap': s_name})

        return r_name, s_name, s_props
Пример #3
0
    def _resource_and_snap_data_from_snapshot(self, snapshot, empty_ok=False):
        """Find DRBD resource and snapshot name from the snapshot ID."""
        s_uuid = snapshot['id']
        res, rs = self.call_or_reconnect(self.odm.list_snapshots,
                                         self.empty_dict,
                                         self.empty_dict,
                                         0,
                                         dm_utils.dict_to_aux_props(
                                             {AUX_PROP_CINDER_VOL_ID: s_uuid}),
                                         self.empty_dict)
        self._check_result(res)

        if (not rs) or (len(rs) == 0):
            if empty_ok:
                return None
            else:
                raise exception.VolumeBackendAPIException(
                    data=_("no snapshot with id %s found in drbdmanage") %
                    s_uuid)
        if len(rs) > 1:
            raise exception.VolumeBackendAPIException(
                data=_("multiple resources with snapshot ID %s found") %
                s_uuid)

        (r_name, snaps) = rs[0]
        if len(snaps) != 1:
            raise exception.VolumeBackendAPIException(
                data=_("not exactly one snapshot with id %s") % s_uuid)

        (s_name, s_props) = snaps[0]

        LOG.debug("snapshot %(uuid)s is %(res)s/%(snap)s",
                  {'uuid': s_uuid, 'res': r_name, 'snap': s_name})

        return r_name, s_name, s_props
Пример #4
0
    def _resource_and_snap_data_from_snapshot(self, snapshot, empty_ok=False):
        """Find the DRBD Resource and the snapshot name
        from the snapshot ID.
        """
        s_uuid = snapshot['id']
        res, rs = self.call_or_reconnect(
            self.odm.list_snapshots, self.empty_list, self.empty_list,
            dm_utils.dict_to_aux_props({CINDER_AUX_PROP_id: s_uuid}),
            self.empty_list)
        self._check_result(res)

        if (not rs) or (len(rs) == 0):
            if empty_ok:
                return None
            else:
                raise exception.VolumeBackendAPIException(
                    data=_("no snapshot with id %s found in drbdmanage") %
                    s_uuid)
        if len(rs) > 1:
            raise exception.VolumeBackendAPIException(
                data=_("multiple resources with snapshot ID %s found") %
                s_uuid)

        (r_name, snaps) = rs[0]
        if len(snaps) != 1:
            raise exception.VolumeBackendAPIException(
                data=_("not exactly one snapshot with id %s") % s_uuid)

        (s_name, s_props) = snaps[0]

        LOG.debug("snapshot %s is %s/%s" % (s_uuid, r_name, s_name))

        return r_name, s_name, s_props
Пример #5
0
    def _res_and_vl_data_for_volume(self, volume, empty_ok=False):
        """Find DRBD resource and volume ID.

        A DRBD resource might consist of several "volumes"
        (think consistency groups).
        So we have to find the number of the volume within one resource.
        Returns resource name, volume number, and resource
        and volume properties.
        """

        # If we get a string, use it as-is.
        # Else it's a dictionary; then get the ID.
        if isinstance(volume, six.string_types):
            v_uuid = volume
        else:
            v_uuid = volume['id']

        res, rl = self.call_or_reconnect(
            self.odm.list_volumes, self.empty_dict, 0,
            dm_utils.dict_to_aux_props({AUX_PROP_CINDER_VOL_ID: v_uuid}),
            self.empty_dict)
        self._check_result(res)

        if (not rl) or (len(rl) == 0):
            if empty_ok:
                LOG.debug("No volume %s found.", v_uuid)
                return None, None, None, None
            raise exception.VolumeBackendAPIException(
                data=_("volume %s not found in drbdmanage") % v_uuid)
        if len(rl) > 1:
            raise exception.VolumeBackendAPIException(
                data=_("multiple resources with name %s found by drbdmanage") %
                v_uuid)

        (r_name, r_props, vols) = rl[0]
        if len(vols) != 1:
            raise exception.VolumeBackendAPIException(
                data=_("not exactly one volume with id %s") % v_uuid)

        (v_nr, v_props) = vols[0]

        LOG.debug(
            "volume %(uuid)s is %(res)s/%(nr)d; %(rprop)s, %(vprop)s", {
                'uuid': v_uuid,
                'res': r_name,
                'nr': v_nr,
                'rprop': dict(r_props),
                'vprop': dict(v_props)
            })

        return r_name, v_nr, r_props, v_props
Пример #6
0
    def _res_and_vl_data_for_volume(self, volume, empty_ok=False):
        """Find DRBD resource and volume ID.

        A DRBD resource might consist of several "volumes"
        (think consistency groups).
        So we have to find the number of the volume within one resource.
        Returns resource name, volume number, and resource
        and volume properties.
        """

        # If we get a string, use it as-is.
        # Else it's a dictionary; then get the ID.
        if isinstance(volume, six.string_types):
            v_uuid = volume
        else:
            v_uuid = volume['id']

        res, rl = self.call_or_reconnect(self.odm.list_volumes,
                                         self.empty_dict,
                                         0,
                                         dm_utils.dict_to_aux_props(
                                             {AUX_PROP_CINDER_VOL_ID: v_uuid}),
                                         self.empty_dict)
        self._check_result(res)

        if (not rl) or (len(rl) == 0):
            if empty_ok:
                LOG.debug("No volume %s found.", v_uuid)
                return None, None, None, None
            raise exception.VolumeBackendAPIException(
                data=_("volume %s not found in drbdmanage") % v_uuid)
        if len(rl) > 1:
            raise exception.VolumeBackendAPIException(
                data=_("multiple resources with name %s found by drbdmanage") %
                v_uuid)

        (r_name, r_props, vols) = rl[0]
        if len(vols) != 1:
            raise exception.VolumeBackendAPIException(
                data=_("not exactly one volume with id %s") %
                v_uuid)

        (v_nr, v_props) = vols[0]

        LOG.debug("volume %(uuid)s is %(res)s/%(nr)d; %(rprop)s, %(vprop)s",
                  {'uuid': v_uuid, 'res': r_name, 'nr': v_nr,
                   'rprop': dict(r_props), 'vprop': dict(v_props)})

        return r_name, v_nr, r_props, v_props
Пример #7
0
    def terminate_connection(self, volume, connector,
                             force=False, **kwargs):
        d_res_name, d_vol_nr = self._resource_name_volnr_for_volume(
            volume, empty_ok=True)
        if not d_res_name:
            return

        nodename = connector["host"]

        # If the DRBD volume is diskless on that node, we remove it;
        # if it has local storage, we keep it.
        res, data = self.call_or_reconnect(
            self.odm.list_assignments,
            [nodename], [d_res_name], 0,
            self.empty_list, self.empty_list)
        self._check_result(res, ignore=[dm_exc.DM_ENOENT])

        if len(data) < 1:
            # already removed?!
            LOG.info(_LI('DRBD connection for %s already removed'),
                     volume['id'])
        elif len(data) == 1:
            __, __, props, __ = data[0]
            my_props = dm_utils.dict_to_aux_props(props)
            diskless = getattr(props,
                               dm_const.FLAG_DISKLESS,
                               dm_const.BOOL_FALSE)
            temp_cli = getattr(my_props,
                               AUX_PROP_TEMP_CLIENT,
                               dm_const.BOOL_FALSE)
            # If diskless assigned,
            if ((diskless == dm_const.BOOL_TRUE) and
                    (temp_cli == dm_const.BOOL_TRUE)):
                # remove the assignment

                # TODO(pm): does it make sense to relay "force" here?
                #           What are the semantics?

                # TODO(pm): consistency groups shouldn't really
                #           remove until *all* volumes are detached

                res = self.call_or_reconnect(self.odm.unassign,
                                             nodename, d_res_name, force)
                self._check_result(res, ignore=[dm_exc.DM_ENOENT])
        else:
            # more than one assignment?
            LOG.error(_LE("DRBDmanage: too many assignments returned."))
        return
Пример #8
0
    def terminate_connection(self, volume, connector,
                             force=False, **kwargs):
        d_res_name, d_vol_nr = self._resource_name_volnr_for_volume(
            volume, empty_ok=True)
        if not d_res_name:
            return

        nodename = connector["host"]

        # If the DRBD volume is diskless on that node, we remove it;
        # if it has local storage, we keep it.
        res, data = self.call_or_reconnect(
            self.odm.list_assignments,
            [nodename], [d_res_name], 0,
            self.empty_list, self.empty_list)
        self._check_result(res, ignore=[dm_exc.DM_ENOENT])

        if len(data) < 1:
            # already removed?!
            LOG.info('DRBD connection for %s already removed',
                     volume['id'])
        elif len(data) == 1:
            __, __, props, __ = data[0]
            my_props = dm_utils.dict_to_aux_props(props)
            diskless = getattr(props,
                               dm_const.FLAG_DISKLESS,
                               dm_const.BOOL_FALSE)
            temp_cli = getattr(my_props,
                               AUX_PROP_TEMP_CLIENT,
                               dm_const.BOOL_FALSE)
            # If diskless assigned,
            if ((diskless == dm_const.BOOL_TRUE) and
                    (temp_cli == dm_const.BOOL_TRUE)):
                # remove the assignment

                # TODO(pm): does it make sense to relay "force" here?
                #           What are the semantics?

                # TODO(pm): consistency groups shouldn't really
                #           remove until *all* volumes are detached

                res = self.call_or_reconnect(self.odm.unassign,
                                             nodename, d_res_name, force)
                self._check_result(res, ignore=[dm_exc.DM_ENOENT])
        else:
            # more than one assignment?
            LOG.error("DRBDmanage: too many assignments returned.")
        return
    def _res_and_vl_data_for_volume(self, volume, empty_ok=False):
        """A DRBD resource might consist of several "volumes"
        (think consistency groups).
        So we have to find the number of the volume within one resource.
        Returns resource name, volume number, and resource
        and volume properties.
        """

        # If we get a string, use it as-is.
        # Else it's a dictionary; then get the ID.
        if type(volume) is str or type(volume) is unicode:
            v_uuid = volume
        else:
            v_uuid = volume.name_id

        res, rl = self.call_or_reconnect(self.odm.list_volumes,
                                         self.empty_list,
                                         0,
                                         dm_utils.dict_to_aux_props(
                                             {CINDER_AUX_PROP_id: v_uuid}),
                                         self.empty_list)
        self._check_result(res)

        if (not rl) or (len(rl) == 0):
            if empty_ok:
                LOG.debug("No volume %s found." % v_uuid)
                return None, None, None, None
            raise exception.VolumeBackendAPIException(
                data=_("volume %s not found in drbdmanage") % v_uuid)
        if len(rl) > 1:
            raise exception.VolumeBackendAPIException(
                data=_("multiple resources with name %s found by drbdmanage") %
                v_uuid)

        (r_name, r_props, vols) = rl[0]
        if len(vols) != 1:
            raise exception.VolumeBackendAPIException(
                data=_("not exactly one volume with id %s") %
                v_uuid)

        (v_nr, v_props) = vols[0]

        LOG.debug("volume %s is %s/%d; %s, %s" %
                  (v_uuid, r_name, v_nr, r_props, v_props))

        return r_name, v_nr, r_props, v_props
Пример #10
0
    def _res_and_vl_data_for_volume(self, volume, empty_ok=False):
        """A DRBD resource might consist of several "volumes"
        (think consistency groups).
        So we have to find the number of the volume within one resource.
        Returns resource name, volume number, and resource
        and volume properties.
        """

        # If we get a string, use it as-is.
        # Else it's a dictionary; then get the ID.
        if type(volume) is str or type(volume) is unicode:
            v_uuid = volume
        else:
            v_uuid = volume['id']

        res, rl = self.call_or_reconnect(
            self.odm.list_volumes, self.empty_list, 0,
            dm_utils.dict_to_aux_props({CINDER_AUX_PROP_id: v_uuid}),
            self.empty_list)
        self._check_result(res)

        if (not rl) or (len(rl) == 0):
            if empty_ok:
                LOG.debug("No volume %s found." % v_uuid)
                return None, None, None, None
            raise exception.VolumeBackendAPIException(
                data=_("volume %s not found in drbdmanage") % v_uuid)
        if len(rl) > 1:
            raise exception.VolumeBackendAPIException(
                data=_("multiple resources with name %s found by drbdmanage") %
                v_uuid)

        (r_name, r_props, vols) = rl[0]
        if len(vols) != 1:
            raise exception.VolumeBackendAPIException(
                data=_("not exactly one volume with id %s") % v_uuid)

        (v_nr, v_props) = vols[0]

        LOG.debug("volume %s is %s/%d; %s, %s" %
                  (v_uuid, r_name, v_nr, r_props, v_props))

        return r_name, v_nr, r_props, v_props
 def _priv_hash_from_volume(self, volume):
     return dm_utils.dict_to_aux_props({CINDER_AUX_PROP_id: volume.name_id})
Пример #12
0
 def _priv_hash_from_volume(self, volume):
     return dm_utils.dict_to_aux_props({
         AUX_PROP_CINDER_VOL_ID: volume['id'],
     })
Пример #13
0
 def _priv_hash_from_volume(self, volume):
     return dm_utils.dict_to_aux_props({
         AUX_PROP_CINDER_VOL_ID: volume['id'],
     })
 def _priv_hash_from_volume(self, volume):
     return dm_utils.dict_to_aux_props({
         CINDER_AUX_PROP_id: volume.name_id,
     })