def create_volume(self, dataset_id, size):
        """
        Create a new volume.

        When called by ``IDeployer``, the supplied size will be
        rounded up to the nearest ``IBlockDeviceAPI.allocation_unit()``

        :param UUID dataset_id: The Flocker dataset ID of the dataset on this
            volume.
        :param int size: The size of the new volume in bytes.
        :returns: A ``BlockDeviceVolume``.
        """
        LOG.info("Call create_volume, dataset_id=%s, size=%d"
                 % (dataset_id, size))
        name = huawei_utils.encode_name(dataset_id, self._cluster_id)
        parameters = huawei_utils.get_lun_conf_params(self.xml_file_path)
        if parameters is None:
            raise VolumeException
        pool_name = huawei_utils.get_pools(self.xml_file_path)
        if pool_name is None:
            raise VolumeException
        pools = self.restclient.find_all_pools()
        pool_info = self.restclient.find_pool_info(pool_name,
                                                   pools)

        lun_param = {"TYPE": '11',
                     "NAME": name,
                     "PARENTTYPE": '216',
                     "PARENTID": pool_info['ID'],
                     "ALLOCTYPE": parameters['LUNType'],
                     "CAPACITY": str((size/512)),
                     "WRITEPOLICY": parameters['WriteType'],
                     "MIRRORPOLICY": parameters['MirrorSwitch'],
                     "PREFETCHPOLICY": parameters['PrefetchType'],
                     "PREFETCHVALUE": parameters['PrefetchValue'],
                     "DATATRANSFERPOLICY": parameters['policy'],
                     "READCACHEPOLICY": parameters['readcachepolicy'],
                     "WRITECACHEPOLICY": parameters['writecachepolicy']}

        url = "/lun"
        data = json.dumps(lun_param)
        result = self.restclient.call(url, data)
        lun_info = result['data']
        volume = BlockDeviceVolume(
            size=int(lun_info['CAPACITY'])*512,
            attached_to=None,
            dataset_id=huawei_utils.decode_name(lun_info['NAME'],
                                                self._cluster_id),
            blockdevice_id=unicode(lun_info['ID'])
        )
        return volume
    def attach_volume(self, blockdevice_id, attach_to):
        """
        Attach ``blockdevice_id`` to the node indicated by ``attach_to``.

        :param unicode blockdevice_id: The unique identifier for the block
            device being attached.
        :param unicode attach_to: An identifier like the one returned by the
            ``compute_instance_id`` method indicating the node to which to
            attach the volume.

        :raises UnknownVolume: If the supplied ``blockdevice_id`` does not
            exist.
        :raises AlreadyAttachedVolume: If the supplied ``blockdevice_id`` is
            already attached.

        :returns: A ``BlockDeviceVolume`` with a ``attached_to`` attribute set
            to ``attach_to``.
        """

        LOG.info("Call attach_volume blockdevice_id=%s, attach_to=%s"
                 % (blockdevice_id, attach_to))

        try:
            lun_info = self.restclient.get_lun_info(blockdevice_id)
        except Exception:
            raise UnknownVolume(blockdevice_id)

        if lun_info['EXPOSEDTOINITIATOR'].lower() == 'true':
            raise AlreadyAttachedVolume(blockdevice_id)

        self.initialize_connection()

        self.restclient.do_mapping(blockdevice_id, self._hostgroup_id,
                                   self._host_id)

        huawei_utils.rescan_scsi()

        lun_info = self.restclient.get_lun_info(blockdevice_id)

        attached_volume = BlockDeviceVolume(
            size=int(lun_info['CAPACITY'])*512,
            attached_to=unicode(attach_to),
            dataset_id=huawei_utils.decode_name(
                lun_info['NAME'], self._cluster_id),
            blockdevice_id=blockdevice_id)
        return attached_volume
    def list_volumes(self):
        """
        List all the block devices available via the back end API.

        :returns: A ``list`` of ``BlockDeviceVolume``s.
        """
        LOG.info("Call list_volumes")
        volumes = []
        url = "/lun?range=[0-65535]"
        result = self.restclient.call(url, None, "GET")

        if 'data' in result:
            for item in result['data']:
                if huawei_utils.is_cluster_volume(
                        item['NAME'], self._cluster_id):
                    volume = BlockDeviceVolume(
                        size=int(item['CAPACITY'])*512,
                        attached_to=self.get_attached_to(item),
                        dataset_id=huawei_utils.decode_name(
                            item['NAME'], self._cluster_id),
                        blockdevice_id=unicode(item['ID'])
                    )
                    volumes.append(volume)
        return volumes