Exemplo n.º 1
0
def disk_space_avail(dn, timeout=5):
    def _disk_space_avail():
        if os.path.exists(dn):
            try:
                stat_info = os.statvfs(dn)
                return stat_info.f_bavail * stat_info.f_bsize / 1024**2
            except Exception:
                import ctypes
                free_bytes = ctypes.c_ulonglong(0)
                ctypes.windll.kernel32.GetDiskFreeSpaceExW(
                    ctypes.c_wchar_p(dn), None, None,
                    ctypes.pointer(free_bytes))
                return free_bytes.value / 1024**2
        return -1

    try:
        return hang_protection(_disk_space_avail, timeout)
    except TimeoutException:
        logging.getLogger('console').critical(
            'Unable to get free disk space for directory %s after waiting for %d sec!\n'
            % (dn, timeout) +
            'The file system is probably hanging or corrupted' +
            ' - try to check the free disk space manually. ' +
            'Refer to the documentation to disable checking the free disk space - at your own risk'
        )
        exit_without_cleanup(os.EX_OSERR)
Exemplo n.º 2
0
    def __init__(self):
        # Collect host / user / installation specific config files
        def resolve_hostname():
            import socket
            host = socket.gethostname()
            try:
                return socket.gethostbyaddr(host)[0]
            except Exception:
                return host

        try:
            host = hang_protection(resolve_hostname, timeout=5)
            hostCfg = lmap(
                lambda c: utils.pathPKG('../config/%s.conf' % host.split(
                    '.', c)[-1]), irange(host.count('.') + 1, -1, -1))
        except TimeoutException:
            sys.stderr.write('System call to resolve hostname is hanging!\n')
            sys.stderr.flush()
            hostCfg = []
        defaultCfg = [
            '/etc/grid-control.conf', '~/.grid-control.conf',
            utils.pathPKG('../config/default.conf')
        ]
        if os.environ.get('GC_CONFIG'):
            defaultCfg.append('$GC_CONFIG')
        log = logging.getLogger('config.default')
        log.log(logging.DEBUG1, 'Possible default config files: %s',
                str.join(', ', defaultCfg))
        fqConfigFiles = lmap(lambda p: utils.resolvePath(p, mustExist=False),
                             hostCfg + defaultCfg)
        FileConfigFiller.__init__(self,
                                  lfilter(os.path.exists, fqConfigFiles),
                                  addSearchPath=False)
Exemplo n.º 3
0
	def __init__(self):
		# Collect host / user / installation specific config files
		def _resolve_hostname():
			import socket
			host = socket.gethostname()
			return ignore_exception(Exception, host, lambda: socket.gethostbyaddr(host)[0])

		try:
			hostname = hang_protection(_resolve_hostname, timeout=5)
		except TimeoutException:
			clear_current_exception()
			hostname = None
			logging.getLogger('console').warning('System call to resolve hostname is hanging!')

		def _get_default_config_fn_iter():  # return possible default config files
			if hostname:  # host / domain specific
				for part_idx in irange(hostname.count('.') + 1, -1, -1):
					yield get_path_pkg('../config/%s.conf' % hostname.split('.', part_idx)[-1])
			yield '/etc/grid-control.conf'  # system specific
			yield '~/.grid-control.conf'  # user specific
			yield get_path_pkg('../config/default.conf')  # installation specific
			if os.environ.get('GC_CONFIG'):
				yield '$GC_CONFIG'  # environment specific

		config_fn_list = list(_get_default_config_fn_iter())
		log = logging.getLogger('config.sources.default')
		log.log(logging.DEBUG1, 'Possible default config files: %s', str.join(', ', config_fn_list))
		config_fn_iter = imap(lambda fn: resolve_path(fn, must_exist=False), config_fn_list)
		FileConfigFiller.__init__(self, lfilter(os.path.exists, config_fn_iter), add_search_path=False)
Exemplo n.º 4
0
def freeSpace(dn, timeout = 5):
	def freeSpace_int():
		if os.path.exists(dn):
			try:
				stat_info = os.statvfs(dn)
				return stat_info.f_bavail * stat_info.f_bsize / 1024**2
			except Exception:
				import ctypes
				free_bytes = ctypes.c_ulonglong(0)
				ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(dn), None, None, ctypes.pointer(free_bytes))
				return free_bytes.value / 1024**2
		return -1

	try:
		return hang_protection(freeSpace_int, timeout)
	except TimeoutException:
		sys.stderr.write('Unable to get free disk space for directory %s after waiting for %d sec!' % (dn, timeout))
		sys.stderr.write('The file system is probably hanging or corrupted - try to check the free disk space manually.')
		sys.stderr.write('Refer to the documentation to disable checking the free disk space - at your own risk')
		exit_without_cleanup(os.EX_OSERR)
Exemplo n.º 5
0
    def __init__(self):
        # Collect host / user / installation specific config files
        def _resolve_hostname():
            import socket
            host = socket.gethostname()
            return ignore_exception(Exception, host,
                                    lambda: socket.gethostbyaddr(host)[0])

        try:
            hostname = hang_protection(_resolve_hostname, timeout=5)
        except TimeoutException:
            clear_current_exception()
            hostname = None
            logging.getLogger('console').warning(
                'System call to resolve hostname is hanging!')

        def _get_default_config_fn_iter(
        ):  # return possible default config files
            if hostname:  # host / domain specific
                for part_idx in irange(hostname.count('.') + 1, -1, -1):
                    yield get_path_pkg('../config/%s.conf' %
                                       hostname.split('.', part_idx)[-1])
            yield '/etc/grid-control.conf'  # system specific
            yield '~/.grid-control.conf'  # user specific
            yield get_path_pkg(
                '../config/default.conf')  # installation specific
            if os.environ.get('GC_CONFIG'):
                yield '$GC_CONFIG'  # environment specific

        config_fn_list = list(_get_default_config_fn_iter())
        log = logging.getLogger('config.sources.default')
        log.log(logging.DEBUG1, 'Possible default config files: %s',
                str.join(', ', config_fn_list))
        config_fn_iter = imap(lambda fn: resolve_path(fn, must_exist=False),
                              config_fn_list)
        FileConfigFiller.__init__(self,
                                  lfilter(os.path.exists, config_fn_iter),
                                  add_search_path=False)
Exemplo n.º 6
0
	def __init__(self):
		# Collect host / user / installation specific config files
		def resolve_hostname():
			import socket
			host = socket.gethostname()
			try:
				return socket.gethostbyaddr(host)[0]
			except Exception:
				return host
		try:
			host = hang_protection(resolve_hostname, timeout = 5)
			hostCfg = lmap(lambda c: utils.pathPKG('../config/%s.conf' % host.split('.', c)[-1]), irange(host.count('.') + 1, -1, -1))
		except TimeoutException:
			sys.stderr.write('System call to resolve hostname is hanging!\n')
			sys.stderr.flush()
			hostCfg = []
		defaultCfg = ['/etc/grid-control.conf', '~/.grid-control.conf', utils.pathPKG('../config/default.conf')]
		if os.environ.get('GC_CONFIG'):
			defaultCfg.append('$GC_CONFIG')
		log = logging.getLogger('config.default')
		log.log(logging.DEBUG1, 'Possible default config files: %s', str.join(', ', defaultCfg))
		fqConfigFiles = lmap(lambda p: utils.resolvePath(p, mustExist = False), hostCfg + defaultCfg)
		FileConfigFiller.__init__(self, lfilter(os.path.exists, fqConfigFiles), addSearchPath = False)
Exemplo n.º 7
0
def disk_space_avail(dn, timeout=5):
	def _disk_space_avail():
		if os.path.exists(dn):
			try:
				stat_info = os.statvfs(dn)
				return stat_info.f_bavail * stat_info.f_bsize / 1024 ** 2
			except Exception:
				import ctypes
				free_bytes = ctypes.c_ulonglong(0)
				ctypes.windll.kernel32.GetDiskFreeSpaceExW(
					ctypes.c_wchar_p(dn), None, None, ctypes.pointer(free_bytes))
				return free_bytes.value / 1024 ** 2
		return -1

	try:
		return hang_protection(_disk_space_avail, timeout)
	except TimeoutException:
		logging.getLogger('console').critical(
			'Unable to get free disk space for directory %s after waiting for %d sec!\n' % (dn, timeout) +
			'The file system is probably hanging or corrupted' +
			' - try to check the free disk space manually. ' +
			'Refer to the documentation to disable checking the free disk space - at your own risk')
		time.sleep(1)  # give GUI report the possibility to log its output
		exit_without_cleanup(os.EX_OSERR)