예제 #1
0
	def load(self, preset_type):
		'''
		@rtype: Preset
		@raise OSError: When cannot read preset file
		@raise MetaconfError: When experience problems with preset file parsing
		'''
		self._logger.debug('Loading %s %s preset' % (preset_type, self.service_name))
		ini = Configuration('ini')
		ini.read(self._filename(preset_type))
		
		return CnfPreset(ini.get('general/name'), dict(ini.items('settings/'))) 
예제 #2
0
    def load(self, preset_type):
        '''
        @rtype: Preset
        @raise OSError: When cannot read preset file
        @raise MetaconfError: When experience problems with preset file parsing
        '''
        self._logger.debug('Loading %s %s preset' %
                           (preset_type, self.service_name))
        ini = Configuration('ini')
        ini.read(self._filename(preset_type))

        return CnfPreset(ini.get('general/name'), dict(ini.items('settings/')))
예제 #3
0
	def __init__(self, manifest_path):
		self._options = []
		ini = Configuration('ini')
		ini.read(manifest_path)
		try:
			self._defaults = dict(ini.items('__defaults__'))
		except NoPathError:
			self._defaults = dict()
		
		for name in ini.sections("./"):
			if name == '__defaults__':
				continue
			self._options.append(_OptionSpec.from_ini(ini, name, self._defaults))
예제 #4
0
    def __init__(self, manifest_path):
        self._options = []
        ini = Configuration('ini')
        ini.read(manifest_path)
        try:
            self._defaults = dict(ini.items('__defaults__'))
        except NoPathError:
            self._defaults = dict()

        for name in ini.sections("./"):
            if name == '__defaults__':
                continue
            self._options.append(
                _OptionSpec.from_ini(ini, name, self._defaults))
예제 #5
0
    def download_and_restore(self, volume, snapshot, tranzit_path):
        # Load manifest
        clear_queue(self._writer_queue)
        clear_queue(self._download_queue)
        self._download_finished.clear()
        transfer = self._transfer_cls()
        mnf_path = transfer.download(snapshot.path, tranzit_path)
        mnf = Configuration('ini')
        mnf.read(mnf_path)

        volume.fs_created = False
        volume.mkfs(snapshot.fstype)

        remote_path = os.path.dirname(snapshot.path)
        # Get links with md5 sums
        links = [(os.path.join(remote_path, chunk[0]), chunk[1])
                 for chunk in mnf.items('chunks')]
        links.sort()

        # Download 2 first chunks
        for link in links[:2]:
            transfer.download(link[0], tranzit_path)
            chunk_path = os.path.join(tranzit_path, os.path.basename(link[0]))
            if self._md5sum(chunk_path) != link[1]:
                raise Exception("md5sum of chunk %s is not correct." %
                                chunk_path)
            self._writer_queue.put(chunk_path)

        if hasattr(snapshot,
                   'snap_strategy') and snapshot.snap_strategy == 'data':
            restore_strategy = DataRestoreStrategy(self._logger)
        else:
            restore_strategy = DeviceRestoreStrategy(self._logger)

        writer = threading.Thread(target=restore_strategy.restore,
                                  name='writer',
                                  args=(self._writer_queue, volume,
                                        self._download_finished))
        writer.start()

        # Add remaining files to download queue
        for link in links[2:]:
            self._download_queue.put(link)

        downloader = threading.Thread(name="Downloader",
                                      target=self._downloader,
                                      args=(tranzit_path, ))
        downloader.start()
        downloader.join()
        writer.join()
예제 #6
0
파일: eph.py 프로젝트: notbrain/scalarizr
    def download_and_restore(self, volume, snapshot, tranzit_path):
        # Load manifest
        clear_queue(self._writer_queue)
        clear_queue(self._download_queue)
        self._download_finished.clear()
        transfer = self._transfer_cls()
        mnf_path = transfer.download(snapshot.path, tranzit_path)
        mnf = Configuration('ini')
        mnf.read(mnf_path)

        volume.fs_created = False
        volume.mkfs(snapshot.fstype)

        remote_path = os.path.dirname(snapshot.path)
        # Get links with md5 sums
        links = [(os.path.join(remote_path, chunk[0]), chunk[1]) for chunk in mnf.items('chunks')]
        links.sort()

        # Download 2 first chunks
        for link in links[:2]:
            transfer.download(link[0], tranzit_path)
            chunk_path = os.path.join(tranzit_path, os.path.basename(link[0]))
            if self._md5sum(chunk_path) != link[1]:
                raise Exception("md5sum of chunk %s is not correct." % chunk_path)
            self._writer_queue.put(chunk_path)

        if hasattr(snapshot, 'snap_strategy') and snapshot.snap_strategy == 'data':
            restore_strategy = DataRestoreStrategy(self._logger)
        else:
            restore_strategy = DeviceRestoreStrategy(self._logger)

        writer = threading.Thread(target=restore_strategy.restore, name='writer',
                                                        args=(self._writer_queue, volume, self._download_finished))
        writer.start()

        # Add remaining files to download queue
        for link in links[2:]:
            self._download_queue.put(link)

        downloader = threading.Thread(name="Downloader", target=self._downloader,
                                                                  args=(tranzit_path,))
        downloader.start()
        downloader.join()
        writer.join()