def _get_sfaccount(self, project_id): sf_account_name = self._get_sf_account_name(project_id) sfaccount = self._get_sfaccount_by_name(sf_account_name) if sfaccount is None: raise exception.SfAccountNotFound(account_name=sf_account_name) return sfaccount
def delete_volume(self, volume, is_snapshot=False): """Delete SolidFire Volume from device. SolidFire allows multipe volumes with same name, volumeID is what's guaranteed unique. """ LOG.debug(_("Enter SolidFire delete_volume...")) sf_account_name = socket.gethostname() + '-' + volume['project_id'] sfaccount = self._get_sfaccount_by_name(sf_account_name) if sfaccount is None: raise exception.SfAccountNotFound(account_name=sf_account_name) params = {'accountID': sfaccount['accountID']} data = self._issue_api_request('ListVolumesForAccount', params) if 'result' not in data: raise exception.SolidFireAPIDataException(data=data) if is_snapshot: seek = 'OS-SNAPID-%s' % (volume['id']) else: seek = 'OS-VOLID-%s' % volume['id'] #params = {'name': 'OS-VOLID-:%s' % volume['id'], found_count = 0 volid = -1 for v in data['result']['volumes']: if v['name'] == seek: found_count += 1 volid = v['volumeID'] if found_count == 0: raise exception.VolumeNotFound(volume_id=volume['id']) if found_count > 1: LOG.debug(_("Deleting volumeID: %s"), volid) raise exception.DuplicateSfVolumeNames(vol_name=volume['id']) params = {'volumeID': volid} data = self._issue_api_request('DeleteVolume', params) if 'result' not in data: raise exception.SolidFireAPIDataException(data=data) LOG.debug(_("Leaving SolidFire delete_volume"))
def _do_create_snapshot(self, snapshot, snapshot_name): """Creates a snapshot.""" LOG.debug(_("Enter SolidFire create_snapshot...")) sf_account_name = socket.gethostname() + '-' + snapshot['project_id'] sfaccount = self._get_sfaccount_by_name(sf_account_name) if sfaccount is None: raise exception.SfAccountNotFound(account_name=sf_account_name) params = {'accountID': sfaccount['accountID']} data = self._issue_api_request('ListVolumesForAccount', params) if 'result' not in data: raise exception.SolidFireAPIDataException(data=data) found_count = 0 volid = -1 for v in data['result']['volumes']: if v['name'] == 'OS-VOLID-%s' % snapshot['volume_id']: found_count += 1 volid = v['volumeID'] if found_count == 0: raise exception.VolumeNotFound(volume_id=snapshot['volume_id']) if found_count != 1: raise exception.DuplicateSfVolumeNames(vol_name='OS-VOLID-%s' % snapshot['volume_id']) params = { 'volumeID': int(volid), 'name': snapshot_name, 'attributes': { 'OriginatingVolume': volid } } data = self._issue_api_request('CloneVolume', params) if 'result' not in data: raise exception.SolidFireAPIDataException(data=data) return (data, sfaccount)