def listOsnexusVolumes(self): try: # volumes is the flocker data type volumes = [] qs_vols = self._qsclient.list_volumes() for vol in qs_vols: #Add only the volumes starting with "flockerVol-" volUuid = self.getDataSetId(vol._name) if volUuid is None: continue #Now get the host access list for this volume to figure out if it is attached if self.isVolumeAttached(vol._id) == True: volumes.append( BlockDeviceVolume(blockdevice_id=unicode(vol._id), size=int(vol._size), attached_to=unicode( socket.gethostbyname( socket.getfqdn())), dataset_id=volUuid)) else: volumes.append( BlockDeviceVolume(blockdevice_id=unicode(vol._id), size=int(vol._size), attached_to=None, dataset_id=volUuid)) except Exception as e: self._logger.error("List volume failed with exception") raise e return volumes
def test_list_volumes_with_one_not_attached(self): self.get_vols_mapping_fake.pop(WWN2) # update the attached_to=None self.expected_list_volumes[1] = BlockDeviceVolume( blockdevice_id=unicode(WWN2), size=int(WWN2_SIZE), attached_to=None, dataset_id=UUID(UUID3_STR) ) self.assertEqual( self.driver_obj.list_volumes(), self.expected_list_volumes) self.get_vols_mapping_fake.pop(WWN1) # update the attached_to=None self.expected_list_volumes[0] = BlockDeviceVolume( blockdevice_id=unicode(WWN1), size=int(WWN1_SIZE), attached_to=None, dataset_id=UUID(UUID1_STR) ) self.assertEqual( self.driver_obj.list_volumes(), self.expected_list_volumes)
def createOsnexusVolumeWithProfile(self, dataset_id, size, profile_name): try: tier = "" if profile_name == VolumeProfiles.PROFILE_GOLD: tier = self._gold_tier elif profile_name == VolumeProfiles.PROFILE_SILVER: tier = self._silver_tier elif profile_name == VolumeProfiles.PROFILE_BRONZE: tier = self._bronze_tier elif profile_name == VolumeProfiles.PROFILE_DEFAULT: return self.createOsnexusVolume(dataset_id, size) if self._osnexusTierId == "": tier = self._qsclient.get_tier(tier) self._osnexusTierId = tier._id volName = "flockerVol-{0}".format(dataset_id) # Check the pools and pass that to qsclient.create_volume vol = self._qsclient.create_volume(volName, size, "createdbyFlocker", self._osnexusTierId) flocker_volume = BlockDeviceVolume(blockdevice_id=vol._id, size=vol._size, attached_to=None, dataset_id=dataset_id) return flocker_volume except Exception as e: self._logger.error( "Create volume with profile failed. Dataset Id '%s'", dataset_id) raise e
def test_ibm_storage_block_device_api__get_blockdevicevolume_by_vol( self, multipathing_mock): multipathing_mock.return_value = True vol_info = VolInfo('f_{}_{}'.format(UUID1_STR, UUID1_SLUG), int(GiB(16).to_Byte().value), 1111, UUID1_STR) blockdevicevolume = BlockDeviceVolume( blockdevice_id=unicode(UUID1_STR), size=int(GiB(16).to_Byte().value), attached_to=u'fake_host', dataset_id=UUID(UUID1_STR), ) self.mock_client.get_vol_mapping = MagicMock(return_value='fake_host') driver_obj = driver.IBMStorageBlockDeviceAPI( UUID(FAKE_CLUSTER_ID), self.mock_client, DRIVER_BASIC_CONF) driver_obj._is_cluster_volume = MagicMock(return_value=False) with self.assertRaises(UnknownVolume): driver_obj._get_blockdevicevolume_by_vol(vol_info) driver_obj._is_cluster_volume = MagicMock(return_value=True) self.assertEqual(blockdevicevolume, driver_obj._get_blockdevicevolume_by_vol(vol_info))
def create_volume(self, dataset_id, size): try: Message.new( Info='Creating Volume: ' + str(dataset_id), size=size, user=self._config.user, passwd=self._config.password, mgmt_addr=self._config.mgmt_addr).write(_logger) fname = str(self._cluster_id) + str(dataset_id) ai = self._api.app_instances.create(name=fname) si = ai.storage_instances.create(name=fname) volsize = size / self._allocation_unit vol = si.volumes.create(name=fname, size=volsize) Message.new( Info='Datera API Volume Created: ', fname=fname, dataset=str(dataset_id), volsize=volsize, size=size).write(_logger) blkdev_id = unicode(str(self._cluster_id + vol['uuid'])) volume = BlockDeviceVolume( size=size, attached_to=None, dataset_id=dataset_id, blockdevice_id=blkdev_id) self._vols[blkdev_id] = {'dataset_id': dataset_id, 'size': size, 'attached_to': None, 'ai_name': ai['name'], 'volume': volume} Message.new( Info='Created volume for ' + str(dataset_id)).write(_logger) except ApiError as ex: Message.new( Info='ERROR creating volume for ' + str(dataset_id), resp=ex.message).write(_logger) volume = None raise DeviceExceptionAPIError return volume
def test_ibm_storage_block_device_api__create_volume( self, multipathing_mock): size = int(GiB(16).to_Byte().value) multipathing_mock.return_value = True mock_vol_obj = MagicMock mock_vol_obj.id = 'vol-id-11111' mock_vol_obj.size = size mock_vol_obj.name = 'volfack' mock_vol_obj.wwn = '11111111111' self.mock_client.list_volumes = MagicMock( return_value=[mock_vol_obj]) self.mock_client.create_volume = MagicMock self.mock_client.handle_default_pool = MagicMock self.mock_client.handle_default_profile = MagicMock( return_value='fakepool') self.mock_client.con_info = CONF_INFO_MOCK driver_obj = driver.IBMStorageBlockDeviceAPI( UUID1, self.mock_client, DRIVER_BASIC_CONF) bdv = driver_obj.create_volume(UUID(UUID1_STR), size) expacted_blockdevicevolume = BlockDeviceVolume( blockdevice_id=unicode(mock_vol_obj.wwn), size=size, attached_to=None, dataset_id=UUID(UUID1_STR), ) self.assertEqual(bdv, expacted_blockdevicevolume)
def test_ibm_storage_block_device_api__get_device_path( self, ospathexist, multipathing_mock, check_output_mock): multipathing_mock.return_value = True ospathexist.return_value = True check_output_mock.return_value = test_host_actions.MULTIPATH_OUTPUT2 blockdevicevolume = BlockDeviceVolume( blockdevice_id=unicode(test_host_actions.MULTIPATH_OUTPUT_WWN2), size=int(GiB(16).to_Byte().value), attached_to=u'fakehost', dataset_id=UUID(UUID1_STR), ) driver_obj = driver.IBMStorageBlockDeviceAPI( UUID1, self.mock_client, DRIVER_BASIC_CONF) class VolInfoFake(object): name = 'fake_volname' driver_obj._get_volume_object = MagicMock(return_value=VolInfoFake()) driver_obj._get_blockdevicevolume_by_vol = MagicMock( return_value=blockdevicevolume) self.mock_client.backend_type = 'XIV' self.mock_client.list_volumes = MagicMock(return_value=[FAKERList]) dpath = driver_obj.get_device_path(blockdevicevolume.blockdevice_id) self.assertEqual( dpath, FilePath('{}/{}'.format( PREFIX_DEVICE_PATH, test_host_actions.WWN_PREFIX + test_host_actions.MULTIPATH_OUTPUT_WWN2, )))
def list_volumes(self): """ List all the block devices available via the back end API. :returns: A ``list`` of ``BlockDeviceVolume``s. """ volumes = [] all_volumes = [os.path.splitext(x)[0].lstrip("/") for x in self.client.list_volumes_by_path()] all_maps = self._list_maps() for blockdevice_id in all_volumes: blockdevice_id = blockdevice_id.decode() try: dataset_id = _dataset_id(blockdevice_id) except ExternalBlockDeviceId: continue object_id = \ self.client.get_object_id(str("/%s.raw" % blockdevice_id)) size = self.client.info_volume(object_id).volume_size if blockdevice_id in all_maps: attached_to = self.compute_instance_id() else: attached_to = None volumes.append(BlockDeviceVolume(blockdevice_id= unicode(blockdevice_id), size=size, attached_to= attached_to, dataset_id=dataset_id)) return volumes
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``. """ ascii_blockdevice_id = blockdevice_id.encode() self._check_exists(ascii_blockdevice_id) if self._is_already_mapped(blockdevice_id): raise AlreadyAttachedVolume(blockdevice_id) if attach_to != self.compute_instance_id(): return Blktap.Tapdisk.create(blockdevice_id) object_id = self.client.get_object_id(str("/%s.raw" % blockdevice_id)) size = self.client.info_volume(object_id).volume_size return BlockDeviceVolume(blockdevice_id=blockdevice_id, size=size, attached_to=self.compute_instance_id(), dataset_id=_dataset_id(blockdevice_id))
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``. """ # This also checks if it exists if self._is_already_mapped(blockdevice_id): raise AlreadyAttachedVolume(blockdevice_id) if attach_to != self.compute_instance_id(): # TODO log this. return self._check_output([b"rbd", b"-p", self._pool, b"map", blockdevice_id]) rbd_image = rbd.Image(self._ioctx, _rbd_blockdevice_id(blockdevice_id)) size = int(rbd_image.stat()["size"]) return BlockDeviceVolume(blockdevice_id=blockdevice_id, size=size, attached_to=self.compute_instance_id(), dataset_id=_dataset_id(blockdevice_id))
def create_volume(self, dataset_id, size, from_name): """ Create a new volume as an RBD image. :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``. """ blockdevice_id = _blockdevice_id(dataset_id) rbd_inst = rbd.RBD() all_images = rbd_inst.list(self._ioctx) if blockdevice_id in all_images: raise ImageExists(blockdevice_id) if from_name is not None: rbd_image = rbd.Image(self._ioctx, _rbd_blockdevice_id(from_name)) rbd_image.copy(self._ioctx, _rbd_blockdevice_id(blockdevice_id)) fh = open("/tmp/flocker_debug.log", "a") fh.write( str(datetime.datetime.now()) + ": " + "create_volume copy :" + from_name + "\n") fh.close else: rbd_inst.create(self._ioctx, _rbd_blockdevice_id(blockdevice_id), size, old_format=False, features=1) return BlockDeviceVolume(blockdevice_id=blockdevice_id, size=size, dataset_id=dataset_id)
def list_volumes(self): """ List all the block devices available via the back end API. :returns: A ``list`` of ``BlockDeviceVolume``s. """ rbd_inst = rbd.RBD() volumes = [] all_images = rbd_inst.list(self._ioctx) all_maps = self._list_maps() for blockdevice_id in all_images: blockdevice_id = blockdevice_id.decode() try: dataset_id = _dataset_id(blockdevice_id) except ExternalBlockDeviceId: # This is an external volume continue rbd_image = rbd.Image(self._ioctx, _rbd_blockdevice_id(blockdevice_id)) size = int(rbd_image.stat()["size"]) if blockdevice_id in all_maps: attached_to = self.compute_instance_id() else: attached_to = None volumes.append(BlockDeviceVolume(blockdevice_id=unicode(blockdevice_id), size=size, attached_to=attached_to, dataset_id=dataset_id)) return volumes
def list_volumes(self): """ List all the block devices available via the back end API. :returns: A ``list`` of ``BlockDeviceVolume``s. """ pagesProxy = PagesProxy() vdiskInfos = pagesProxy.listVDisks() tgtHost = hedvigLookupTgt('wood', self.logger_) volumes = [] for vdiskInfo in vdiskInfos: try: vDiskInfo = pagesProxy.describeVDisk(vdiskInfo.vDiskName) except Exception as e: continue try: lunnum = hedvigGetLun(tgtHost, vdiskInfo.vDiskName, self.logger_) attached_to = self._is_attached(tgtHost, lunnum) except Exception as e: attached_to = None volumes.append( BlockDeviceVolume(blockdevice_id=unicode(vdiskInfo.vDiskName), size=vdiskInfo.size, attached_to=attached_to, dataset_id=UUID(vdiskInfo.vDiskName))) return volumes
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.debug("Call create_volume, dataset_id=%s, size=%d" % (dataset_id, size)) name = str(self._cluster_id) + '.' + str(dataset_id) try: self.rest.create_lun(self.Pool, name, int(size)) except jexc.JDSSRESTException as error_message: LOG.debug(error_message) raise VolumeException(error_message) volume = BlockDeviceVolume( size=int(size), attached_to=None, dataset_id=dataset_id, blockdevice_id=unicode(name) ) return volume
def build_block_device(self, blockdevice_id, dataset_id, volume_size, attach_to=None): logger.debug( 'Building blockdevice with blockdevice_id {}, volume_size {}, dataset_id {}, attach_to {}.'.format( blockdevice_id, volume_size, dataset_id, attach_to)) return BlockDeviceVolume( size=volume_size, dataset_id=dataset_id, attached_to=attach_to, blockdevice_id=unicode(blockdevice_id))
def create_volume(self, dataset_id, size): """ Create a new volume. Creates a new vmdk volume on vSphere datastore provided in the configuration :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. :raises VolumeCreationFailure: If the volume creation fails with some error. :returns: A ``BlockDeviceVolume``. """ try: content = self._si.RetrieveContent() virtualDiskManager = content.virtualDiskManager fileBackedVirtualDiskSpec = vim.VirtualDiskManager.FileBackedVirtualDiskSpec( ) fileBackedVirtualDiskSpec.capacityKb = int( Byte(size).to_KiB().value) # Using vim enums fileBackedVirtualDiskSpec.adapterType = vim.VirtualDiskManager.VirtualDiskAdapterType.lsiLogic fileBackedVirtualDiskSpec.diskType = vim.VirtualDiskManager.VirtualDiskType.thick logging.debug("Creating VMDK capacityKb: {}; adapterType: {}; " "diskType: {}".format( str(fileBackedVirtualDiskSpec.capacityKb), fileBackedVirtualDiskSpec.adapterType, fileBackedVirtualDiskSpec.diskType)) path_name = self._flocker_volume_datastore_folder + \ str(dataset_id) + ".vmdk" new_disk = [ virtualDiskManager.CreateVirtualDisk_Task( name=path_name, datacenter=self._dc, spec=fileBackedVirtualDiskSpec) ] self._wait_for_tasks(new_disk, self._si) logging.debug("VMDK {} created successfully".format(path_name)) uuid = virtualDiskManager.QueryVirtualDiskUuid(name=path_name, datacenter=self._dc) logging.debug("VMDK {} UUID: {}".format(path_name, str(uuid))) except Exception as e: logging.error("Cannot create volume because of exception : " + str(e)) raise VolumeCreationFailure(e) # normalizing uuid uuid = self._normalize_uuid(uuid) logging.debug("VMDK {} UUID normalized {}".format(path_name, uuid)) # creating flocker block device volume volume = BlockDeviceVolume(size=size, dataset_id=dataset_id, blockdevice_id=unicode(uuid)) logging.debug("vSphere Block Device Volume ID {}".format( volume.blockdevice_id)) return volume
def setUp(self): self.list_volumes_fake = [ VolInfo('f_{}_{}'.format(UUID1_STR, UUID1_SLUG), WWN1_SIZE, '28d4e218f01647', WWN1), VolInfo('f_{}_{}'.format(UUID3_STR, UUID1_SLUG), WWN2_SIZE, '28d4e218f01647', WWN2), # and one with different clusterid VolInfo('f_{}_{}'.format(UUID3_STR, '666'), WWN2_SIZE, '28d4e218f01647', WWN2), ] self.get_vols_mapping_fake = {WWN1: HOST_ID, WWN2: HOST_ID} self.get_hosts_fake = {HOST_ID: HOST, 99: 99, 98: 98} self.expected_list_volumes = [ BlockDeviceVolume( blockdevice_id=unicode(WWN1), size=int(WWN1_SIZE), attached_to=unicode(HOST), dataset_id=UUID(UUID1_STR) ), BlockDeviceVolume( blockdevice_id=unicode(WWN2), size=int(WWN2_SIZE), attached_to=unicode(HOST), dataset_id=UUID(UUID3_STR) ), ] mock_client = MagicMock mock_client.list_volumes = \ MagicMock(return_value=self.list_volumes_fake) mock_client.get_vols_mapping = \ MagicMock(return_value=self.get_vols_mapping_fake) mock_client.get_hosts = \ MagicMock(return_value=self.get_hosts_fake) mock_client.backend_type = messages.SCBE_STRING mock_client.con_info.debug_level = DEFAULT_DEBUG_LEVEL mock_client.con_info.credential = dict(username='******') with patch(IS_MULTIPATH_EXIST) as multipathing_mock: multipathing_mock.return_value = True self.driver_obj = driver.IBMStorageBlockDeviceAPI( UUID1, mock_client, DRIVER_BASIC_CONF)
def test_volume_to_block_device(self, mock_volume): mock_volume = self._populate_volume('1234', base_volume=mock_volume) block_device = self._api._to_block_device_volume(mock_volume) self.assertEqual( BlockDeviceVolume( blockdevice_id=six.text_type('1234'), size=107374182400, attached_to=six.text_type('42'), dataset_id=uuid.UUID('0ff66359-4f63-47c8-a950-ff5de6f6225e')), block_device, 'correct conversion from do volume to BlockDeviceVolume')
def test_list_volumes_with_incomplete_attach(self): self.get_hosts_fake.pop(HOST_ID) # update the attached_to=None self.expected_list_volumes[0] = BlockDeviceVolume( blockdevice_id=unicode(WWN1), size=int(WWN1_SIZE), attached_to=None, dataset_id=UUID(UUID1_STR) ) # update the attached_to=None self.expected_list_volumes[1] = BlockDeviceVolume( blockdevice_id=unicode(WWN2), size=int(WWN2_SIZE), attached_to=None, dataset_id=UUID(UUID3_STR) ) self.assertEqual( self.driver_obj.list_volumes(), self.expected_list_volumes)
def _blockdevicevolume_from_azure_volume(self, label, size, attached_to_name): # azure will report the disk size excluding the 512 byte footer # however flocker expects the exact value it requested for disk size # so offset the reported size to flocker by 512 bytes return BlockDeviceVolume( blockdevice_id=unicode(label), size=int(size), attached_to=attached_to_name, dataset_id=self._dataset_id_for_disk_label( label)) # disk labels are formatted as flocker-<data_set_id>
def blockdevice_from_segment(self, segment): blockdevice_id, size, snapshots, status, permission, connections, t = segment dataset_id = uuid.UUID("-".join(blockdevice_id.split("-")[1:])) attach_to = None if (int(connections) > 0): attach_to = self.fetch_connections(blockdevice_id) return BlockDeviceVolume( size=int(re.findall(r'^\d+', size)[-1]), attached_to=attach_to, dataset_id=dataset_id, blockdevice_id=u'{0}'.format(blockdevice_id))
def _list_vsphere_volumes(self): """ Lists vsphere volumes in configured datastore only. :return: """ datastore = self._find_datastore() vms = datastore.vm logging.debug('Found {} VMs'.format(len(vms))) searchResults = self._find_virtual_disks() content = self._si.RetrieveContent() virtualDiskManager = content.virtualDiskManager vol_list = {} for result in searchResults: for file in result.file: volume_path = result.folderPath + file.path disk_uuid = virtualDiskManager.QueryVirtualDiskUuid( name=volume_path, datacenter=self._dc) disk_uuid = self._normalize_uuid(disk_uuid) str_dataset_id = file.path str_dataset_id = str_dataset_id[:-5] # logging.debug(str_dataset_id) dataset_id = uuid.UUID(str_dataset_id) # logging.debug(dataset_id) volume = BlockDeviceVolume(size=int( KiB(file.capacityKb).to_Byte().value), dataset_id=dataset_id, blockdevice_id=unicode(disk_uuid)) vsphere_volume = VsphereBlockDeviceVolume( blockDeviceVolume=volume, path=volume_path) for vm in vms: if isinstance(vm, vim.VirtualMachine) and \ hasattr(vm.config, 'hardware'): devices = vm.config.hardware.device for device in devices: if hasattr(device.backing, 'diskMode'): device_disk_uuid = device.backing.uuid device_disk_uuid = self._normalize_uuid( device_disk_uuid) if device_disk_uuid == disk_uuid: volume = volume.set( 'attached_to', unicode(vm.config.instanceUuid)) vsphere_volume.blockDeviceVolume = volume vsphere_volume.vm = vm vsphere_volume.uuid = vm.config.instanceUuid vsphere_volume.device = device break vol_list[unicode(disk_uuid)] = vsphere_volume logging.debug("Found {} vSphere volumes: {}".format( len(vol_list), '.'.join(vol_list.keys()))) return vol_list
def attach_volume(self, blockdevice_id, attach_to): """ Attach ``blockdevice_id`` to ``host``. :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 ``host`` attribute set to ``host``. """ volName = str(blockdevice_id) vdiskInfo = findVDisk(volName) if (vdiskInfo == None): raise UnknownVolume(blockdevice_id) computeHost = socket.getfqdn(attach_to) try: tgtHost = hedvigLookupTgt('wood', self.logger_) lunnum = hedvigGetLun(tgtHost, volName, self.logger_) except: raise Exception("Failed to get Lun number") if lunnum == -1: self.logger_.error("failed to add vDiskName:%s:tgtHost:%s", volName, tgtHost) raise Exception("Failed to add Lun") if (self._is_attached(tgtHost, lunnum) != None): raise AlreadyAttachedVolume(blockdevice_id) try: hedvigAddAccess(tgtHost, lunnum, socket.gethostbyname(socket.getfqdn(computeHost)), self.logger_) hedvigAddAccess(tgtHost, lunnum, socket.gethostbyname(socket.getfqdn()), self.logger_) targetName, portal = hedvigDoIscsiDiscovery( tgtHost, lunnum, self.logger_) except Exception as e: self.logger_.exception( "volume assignment to connector failed :volume:%s:connector:%s", volName, attach_to) return None return BlockDeviceVolume(blockdevice_id=unicode(blockdevice_id), size=vdiskInfo.size, attached_to=attach_to, dataset_id=UUID(blockdevice_id))
def list_volumes(self): """ List all the block devices available via the back end API. :returns: A ``list`` of ``BlockDeviceVolume``s. """ LOG.debug("Call list_volumes") volumes = [] vols = self.rest.get_luns(self.Pool) targets = [targ['name'] for targ in self.rest.get_targets(self.Pool)] for volume in vols: if str(self._cluster_id) in volume['name']: for targ_name in targets: if volume['name'] in targ_name: if self.rest.is_target_lun(self.Pool, targ_name, volume['name']): volumes.append(BlockDeviceVolume( size=int(volume['volsize']), attached_to=targ_name.split(':')[1].split( '.')[-1], dataset_id=UUID(volume['name'].split('.')[-1]), blockdevice_id=unicode(volume['name']))) break else: try: self.rest.delete_target(self.Pool, targ_name) except Exception as error_message: LOG.debug(error_message) else: volumes.append(BlockDeviceVolume( size=int(volume['volsize']), attached_to=None, dataset_id=UUID(volume['name'].split('.')[1]), blockdevice_id=unicode(volume['name']))) LOG.debug('Volumes: {}'.format(volumes)) return volumes
def _blockdevicevolume_from_vmax_volume(blockdevice_id, volume): """ :param unicode blockdevice_id: An opaque identifier for the volume :param volume: a VMAX device Id :returns: ``BlockDeviceVolume``` """ size = int(volume['actual_size']) attached_to = volume['attach_to'] # Return a ``BlockDeviceVolume`` return BlockDeviceVolume(blockdevice_id=blockdevice_id, size=size, attached_to=attached_to, dataset_id=UUID(volume['id']))
def create_volume_with_profile(self, dataset_id, size, profile_name): """Create a new volume with profile on the SolidFire Cluster. :param dataset_id: The Flocker dataset UUID for the volume. :param size: The size of the new volume in bytes (int). :param profile_name: The name of the storage profile for this volume. :return: A ``BlockDeviceVolume`` """ with startTask(logger, "SFAgent:create_volume_with_profile", datasetID=unicode(dataset_id), volSize=unicode(size), profile=unicode(profile_name)): # NOTE(jdg): dataset_id is unique so we use it as the # volume name on the cluster. We then use the resultant # solidfire vol ID as the blockdevice_id vname = '%s%s' % (self.volume_prefix, dataset_id) profile = self._process_profile(profile_name) params = {'name': vname, 'accountID': self.account_id, 'sliceCount': 1, 'totalSize': int(size), 'enable512e': True, 'attributes': {}} if profile: # We set these keys explicity from the profile, rather # than slurping in a dict inentionally, this handles # cases where there may be extra/invalid keys in the # profile. More importantly alows us to extend the # usage of profiles beyond QoS later. params['qos'] = {'minIOPS': profile['minIOPS'], 'maxIOPS': profile['maxIOPS'], 'burstIOPS': profile['burstIOPS']} result = self.client.issue_request('CreateVolume', params) params = {} params['volumeAccessGroupID'] = self.vag_id params['volumes'] = [int(result['volumeID'])] self.client.issue_request('AddVolumesToVolumeAccessGroup', params, version='7.0') return BlockDeviceVolume( blockdevice_id=unicode(result['volumeID']), size=size, attached_to=None, dataset_id=uuid.UUID(dataset_id))
def test_ibm_storage_block_device_api___destroy_volume_exist(self): self.mock_client.delete_volume = Mock() driver_obj = driver.IBMStorageBlockDeviceAPI( UUID1, self.mock_client, DRIVER_BASIC_CONF) expacted_blockdevicevolume = BlockDeviceVolume( blockdevice_id=unicode('999'), size=10, attached_to=None, dataset_id=UUID(UUID1_STR), ) driver_obj._get_volume = \ MagicMock(return_value=expacted_blockdevicevolume) driver_obj.destroy_volume(unicode(UUID(UUID1_STR)))
def _create_hedvig_volume_with_profile(self, vDiskInfo, dataset_id): """ """ try: hedvigCreateVirtualDisk(vDiskInfo, self.logger_) except Exception as e: self.logger_.exception("error creating volume:name:%s", vDiskInfo.vDiskName) raise e return BlockDeviceVolume(blockdevice_id=unicode(dataset_id), size=vDiskInfo.size, attached_to=None, dataset_id=dataset_id)
def _blockdevicevolume_from_vmax_volume(blockdevice_id, volume): """ Convert volume dictionary into BlockDeviceVolume object :param unicode blockdevice_id: An opaque identifier for the volume :param volume: a VMAX volume data dictionary :returns: ``BlockDeviceVolume``` """ size = int(volume['actual_size']) attached_to = volume['attach_to'] # Return a ``BlockDeviceVolume`` return BlockDeviceVolume(blockdevice_id=blockdevice_id, size=size, attached_to=attached_to, dataset_id=UUID(blockdevice_id))
def _blockdevicevolume_from_azure_volume(self, label, size, attached_to_name): # azure will report the disk size including the 512 byte footer # however flocker expects the exact value it requested for disk size # so remove the offset when reportint the size to flocker by 512 bytes if (size % self.allocation_unit()) == 512: size = size - 512 return BlockDeviceVolume( blockdevice_id=unicode(label), size=int(size), attached_to=attached_to_name, dataset_id=self._dataset_id_for_disk_label(label) ) # disk labels are formatted as flocker-<data_set_id>