def __get_volume(self, volume_id, config=None): """ Returns: Volume object Raises: VolumeDoesNotExist """ if config is None: config = self.__read_cache_file() try: size, storageAdapter, adapterVolume, persistent, shared = \ config.get(self.VOLUME_SECTION_NAME, volume_id).split() return Volume(volume_id=volume_id.lower(), size=int(size), storageAdapter=storageAdapter, adapterVolume=adapterVolume, persistent=persistent.lower() == 'true', shared=shared.lower() == 'true') except (configparser.NoOptionError, configparser.NoSectionError): raise VolumeDoesNotExist('Volume [%s] does not exist' % (volume_id)) except ValueError: raise VolumeDoesNotExist('Volume [%s] entry malformed' % (volume_id))
def addStorageVolume(self, nodeName, volume, isDirect="DEFAULT"): """ Raises: VolumeDoesNotExist UnsupportedOperation """ node = self.getNode(nodeName, {'hardwareprofile': True}) # Only allow persistent volumes to be attached... vol = self._san.getVolume(volume) if vol is None: raise VolumeDoesNotExist('Volume [%s] does not exist' % (volume)) if not vol.getPersistent(): raise UnsupportedOperation( 'Only persistent volumes can be attached') api = resourceAdapterFactory.getApi( node.getHardwareProfile().getResourceAdapter().getName()) if isDirect == "DEFAULT": return api.addVolumeToNode(node, volume) return api.addVolumeToNode(node, volume, isDirect)
def __getVolumeHelper(self, queryVolume=None): """ Returns a list of 0 or more volumes if 'queryVolume' is None, otherwise returns a list containing the requested volume. Raises exception if 'queryVolume' is set and no volumes match. Raises: VolumeDoesNotExist """ config = self.__read_cache_file() volumes = TortugaObjectList() if not config.has_section(self.VOLUME_SECTION_NAME): return volumes for item in config.items(self.VOLUME_SECTION_NAME): volume = item[0] volinfo = self.__get_volume(volume, config) if queryVolume: if volume == queryVolume.lower(): volumes.append(volinfo) break else: volumes.append(volinfo) if not volumes and queryVolume is not None: raise VolumeDoesNotExist('Volume [%s] does not exist' % (queryVolume.lower())) return volumes
def removeStorageVolume(self, nodeName, volume): """ Raises: VolumeDoesNotExist UnsupportedOperation """ node = self.getNode(nodeName, {'hardwareprofile': True}) api = resourceAdapterFactory.getApi( node.getHardwareProfile().getResourceAdapter().getName()) vol = self._san.getVolume(volume) if vol is None: raise VolumeDoesNotExist('The volume [%s] does not exist' % (volume)) if not vol.getPersistent(): raise UnsupportedOperation( 'Only persistent volumes can be detached') return api.removeVolumeFromNode(node, volume)