Esempio n. 1
0
	def _parseTickets(self, cached = True):
		# Return cached results if requested
		if cached and self._cache:
			return self._cache
		# Call klist and parse results
		proc = LocalProcess(self._klistExec)
		self._cache = {}
		try:
			for line in proc.stdout.iter(timeout = 10):
				if line.count('@') and (line.count(':') > 1):
					issued_expires, principal = rsplit(line, '  ', 1)
					issued_expires = issued_expires.replace('/', ' ').split()
					assert(len(issued_expires) % 2 == 0)
					issued_str = str.join(' ', issued_expires[:int(len(issued_expires) / 2)])
					expires_str = str.join(' ', issued_expires[int(len(issued_expires) / 2):])
					parseDate = lambda value, format: time.mktime(time.strptime(value, format))
					if expires_str.count(' ') == 3:
						if len(expires_str.split()[2]) == 2:
							expires = parseDate(expires_str, '%m %d %y %H:%M:%S')
						else:
							expires = parseDate(expires_str, '%m %d %Y %H:%M:%S')
					elif expires_str.count(' ') == 2: # year information is missing
						currentYear = int(time.strftime('%Y'))
						expires = parseDate(expires_str + ' %d' % currentYear, '%b %d %H:%M:%S %Y')
						issued = parseDate(issued_str + ' %d' % currentYear, '%b %d %H:%M:%S %Y')
						if expires < issued: # wraparound at new year
							expires = parseDate(expires_str + ' %d' % (currentYear + 1), '%b %d %H:%M:%S %Y')
					self._cache.setdefault('tickets', {})[principal] = expires
				elif line.count(':') == 1:
					key, value = lmap(str.strip, line.split(':', 1))
					self._cache[key.lower()] = value
		except Exception:
			raise AccessTokenError('Unable to parse kerberos ticket information!')
		proc.status_raise(timeout = 0)
		return self._cache
Esempio n. 2
0
 def _list_endpoint_all(self):
     result = []
     proc = LocalProcess(self._lcg_infosites_exec, 'wms')
     for line in proc.stdout.iter(timeout=10):
         result.append(line.strip())
     proc.status_raise(timeout=0)
     random.shuffle(result)
     return result
Esempio n. 3
0
	def _list_endpoint_all(self):
		result = []
		proc = LocalProcess(self._lcg_infosites_exec, 'wms')
		for line in proc.stdout.iter(timeout=10):
			result.append(line.strip())
		proc.status_raise(timeout=0)
		random.shuffle(result)
		return result
Esempio n. 4
0
	def discover(self):
		proc = LocalProcess(self._exec)
		for line in proc.stdout.iter(timeout=self._timeout):
			if not line.startswith(' ') and len(line) > 1:
				node = line.strip()
			if ('state = ' in line) and ('down' not in line) and ('offline' not in line):
				yield {'name': node}
		proc.status_raise(timeout=0)
Esempio n. 5
0
	def listWMS_all(self):
		result = []
		proc = LocalProcess(self._exeLCGInfoSites, 'wms')
		for line in proc.stdout.iter(timeout = 10):
			result.append(line.strip())
		proc.status_raise(timeout = 0)
		random.shuffle(result)
		return result
Esempio n. 6
0
 def discover(self):
     proc = LocalProcess(self._exec)
     for line in proc.stdout.iter(timeout=10):
         if not line.startswith(' ') and len(line) > 1:
             node = line.strip()
         if ('state = ' in line) and ('down' not in line) and ('offline'
                                                               not in line):
             yield {'name': node}
     proc.status_raise(timeout=0)
Esempio n. 7
0
	def getNodes(self):
		result = []
		proc = LocalProcess(self._nodesExec)
		for line in proc.stdout.iter():
			if not line.startswith(' ') and len(line) > 1:
				node = line.strip()
			if ('state = ' in line) and ('down' not in line) and ('offline' not in line):
				result.append(node)
		proc.status_raise(timeout = 0)
		if len(result) > 0:
			return result
Esempio n. 8
0
	def getNodes(self):
		result = []
		proc = LocalProcess(self._nodesExec)
		for line in proc.stdout.iter():
			if not line.startswith(' ') and len(line) > 1:
				node = line.strip()
			if ('state = ' in line) and ('down' not in line) and ('offline' not in line):
				result.append(node)
		proc.status_raise(timeout = 0)
		if len(result) > 0:
			return result
Esempio n. 9
0
 def discover(self):
     nodes = set()
     proc = LocalProcess(self._configExec, '-shgrpl')
     for group in proc.stdout.iter(timeout=10):
         yield {'name': group.strip()}
         proc_g = LocalProcess(self._configExec, '-shgrp_resolved', group)
         for host_list in proc_g.stdout.iter(timeout=10):
             nodes.update(host_list.split())
         proc_g.status_raise(timeout=0)
     for host in sorted(nodes):
         yield {'name': host.strip()}
     proc.status_raise(timeout=0)
	def getNodes(self):
		result = set()
		proc = LocalProcess(self._configExec, '-shgrpl')
		for group in proc.stdout.iter(timeout = 10):
			result.add(group.strip())
			proc_g = LocalProcess(self._configExec, '-shgrp_resolved %s' % group)
			for host in proc_g.stdout.iter(timeout = 10):
				result.update(host.split())
			proc_g.status_raise(timeout = 0)
		proc.status_raise(timeout = 0)
		if len(result) > 0:
			return list(result)
Esempio n. 11
0
	def getNodes(self):
		result = set()
		proc = LocalProcess(self._configExec, '-shgrpl')
		for group in proc.stdout.iter(timeout = 10):
			result.add(group.strip())
			proc_g = LocalProcess(self._configExec, '-shgrp_resolved %s' % group)
			for host in proc_g.stdout.iter(timeout = 10):
				result.update(host.split())
			proc_g.status_raise(timeout = 0)
		proc.status_raise(timeout = 0)
		if len(result) > 0:
			return list(result)
Esempio n. 12
0
	def discover(self):
		nodes = set()
		proc = LocalProcess(self._configExec, '-shgrpl')
		for group in proc.stdout.iter(timeout = 10):
			yield {'name': group.strip()}
			proc_g = LocalProcess(self._configExec, '-shgrp_resolved', group)
			for host_list in proc_g.stdout.iter(timeout = 10):
				nodes.update(host_list.split())
			proc_g.status_raise(timeout = 0)
		for host in sorted(nodes):
			yield {'name': host.strip()}
		proc.status_raise(timeout = 0)
Esempio n. 13
0
    def _parse_tickets(self, cached=True):
        # Return cached results if requested
        if cached and self._cache:
            return self._cache
        # Call klist and parse results
        proc = LocalProcess(self._klist_exec)
        self._cache = {}
        try:
            for line in proc.stdout.iter(timeout=10):
                if line.count('@') and (line.count(':') > 1):
                    issued_expires, principal = rsplit(line, '  ', 1)
                    issued_expires = issued_expires.replace('/', ' ').split()
                    assert len(issued_expires) % 2 == 0
                    issued_str = str.join(
                        ' ', issued_expires[:int(len(issued_expires) / 2)])
                    expires_str = str.join(
                        ' ', issued_expires[int(len(issued_expires) / 2):])

                    if expires_str.count(' ') == 3:
                        if len(expires_str.split()[2]) == 2:
                            expires = _parse_date(expires_str,
                                                  '%m %d %y %H:%M:%S')
                        elif len(expires_str.split()[2]) == 4:
                            expires = _parse_date(expires_str,
                                                  '%m %d %Y %H:%M:%S')  # here
                        else:
                            # On NAF, we get an entirely different format now: Sep 2 12:31:34 2021
                            expires = _parse_date(expires_str,
                                                  '%b %d %H:%M:%S %Y')
                    elif expires_str.count(
                            ' ') == 2:  # year information is missing
                        cur_year = int(time.strftime('%Y'))
                        expires = _parse_date(expires_str + ' %d' % cur_year,
                                              '%b %d %H:%M:%S %Y')
                        issued = _parse_date(issued_str + ' %d' % cur_year,
                                             '%b %d %H:%M:%S %Y')
                        if expires < issued:  # wraparound at new year
                            expires = _parse_date(
                                expires_str + ' %d' % (cur_year + 1),
                                '%b %d %H:%M:%S %Y')
                    self._cache.setdefault('tickets', {})[principal] = expires
                elif line.count(':') == 1:
                    (key, value) = lmap(str.strip, line.split(':', 1))
                    self._cache[key.lower()] = value
        except Exception:
            raise AccessTokenError(
                'Unable to parse kerberos ticket information!')
        proc.status_raise(timeout=0)
        return self._cache
Esempio n. 14
0
    def discover(self):
        tags = ['h_vmem', 'h_cpu', 's_rt']
        reqs = dict(izip(tags, [WMS.MEMORY, WMS.CPUTIME, WMS.WALLTIME]))
        parser = dict(izip(tags, [int, parseTime, parseTime]))

        proc = LocalProcess(self._configExec, '-sql')
        for queue in imap(str.strip, proc.stdout.iter(timeout=10)):
            proc_q = LocalProcess(self._configExec, '-sq', queue)
            queueInfo = {'name': queue}
            for line in proc_q.stdout.iter(timeout=10):
                attr, value = lmap(str.strip, line.split(' ', 1))
                if (attr in tags) and (value != 'INFINITY'):
                    queueInfo[reqs[attr]] = parser[attr](value)
            proc_q.status_raise(timeout=0)
            yield queueInfo
        proc.status_raise(timeout=0)
Esempio n. 15
0
	def discover(self):
		tags = ['h_vmem', 'h_cpu', 's_rt']
		reqs = dict(izip(tags, [WMS.MEMORY, WMS.CPUTIME, WMS.WALLTIME]))
		parser = dict(izip(tags, [int, parseTime, parseTime]))

		proc = LocalProcess(self._configExec, '-sql')
		for queue in imap(str.strip, proc.stdout.iter(timeout = 10)):
			proc_q = LocalProcess(self._configExec, '-sq', queue)
			queueInfo = {'name': queue}
			for line in proc_q.stdout.iter(timeout = 10):
				attr, value = lmap(str.strip, line.split(' ', 1))
				if (attr in tags) and (value != 'INFINITY'):
					queueInfo[reqs[attr]] = parser[attr](value)
			proc_q.status_raise(timeout = 0)
			yield queueInfo
		proc.status_raise(timeout = 0)
	def getQueues(self):
		queues = {}
		tags = ['h_vmem', 'h_cpu', 's_rt']
		reqs = dict(izip(tags, [WMS.MEMORY, WMS.CPUTIME, WMS.WALLTIME]))
		parser = dict(izip(tags, [int, parseTime, parseTime]))

		proc = LocalProcess(self._configExec, '-sql')
		for queue in imap(str.strip, proc.stdout.iter(timeout = 10)):
			queues[queue] = dict()
			proc_q = LocalProcess(self._configExec, '-sq %s' % queue)
			for line in proc_q.stdout.iter(timeout = 10):
				attr, value = lmap(str.strip, line.split(' ', 1))
				if (attr in tags) and (value != 'INFINITY'):
					queues[queue][reqs[attr]] = parser[attr](value)
			proc_q.status_raise(timeout = 0)
		proc.status_raise(timeout = 0)
		return queues
Esempio n. 17
0
	def discover(self):
		active = False
		keys = [WMS.MEMORY, WMS.CPUTIME, WMS.WALLTIME]
		parser = dict(izip(keys, [int, parse_time, parse_time]))
		proc = LocalProcess(self._exec, '-q')
		for line in proc.stdout.iter(timeout=10):
			if line.startswith('-'):
				active = True
			elif line.startswith(' '):
				active = False
			elif active:
				fields = lmap(str.strip, line.split()[:4])
				queue_dict = {'name': fields[0]}
				for key, value in ifilter(lambda k_v: not k_v[1].startswith('-'), izip(keys, fields[1:])):
					queue_dict[key] = parser[key](value)
				yield queue_dict
		proc.status_raise(timeout=0)
Esempio n. 18
0
    def getQueues(self):
        queues = {}
        tags = ['h_vmem', 'h_cpu', 's_rt']
        reqs = dict(izip(tags, [WMS.MEMORY, WMS.CPUTIME, WMS.WALLTIME]))
        parser = dict(izip(tags, [int, parseTime, parseTime]))

        proc = LocalProcess(self._configExec, '-sql')
        for queue in imap(str.strip, proc.stdout.iter(timeout=10)):
            queues[queue] = dict()
            proc_q = LocalProcess(self._configExec, '-sq %s' % queue)
            for line in proc_q.stdout.iter(timeout=10):
                attr, value = lmap(str.strip, line.split(' ', 1))
                if (attr in tags) and (value != 'INFINITY'):
                    queues[queue][reqs[attr]] = parser[attr](value)
            proc_q.status_raise(timeout=0)
        proc.status_raise(timeout=0)
        return queues
Esempio n. 19
0
	def getQueues(self):
		(queues, active) = ({}, False)
		keys = [WMS.MEMORY, WMS.CPUTIME, WMS.WALLTIME]
		parser = dict(izip(keys, [int, parseTime, parseTime]))
		proc = LocalProcess(self.statusExec, '-q')
		for line in proc.stdout.iter(timeout = 10):
			if line.startswith('-'):
				active = True
			elif line.startswith(' '):
				active = False
			elif active:
				fields = lmap(str.strip, line.split()[:4])
				queueInfo = {}
				for key, value in ifilter(lambda k_v: not k_v[1].startswith('-'), izip(keys, fields[1:])):
					queueInfo[key] = parser[key](value)
				queues[fields[0]] = queueInfo
		proc.status_raise(timeout = 0)
		return queues
Esempio n. 20
0
	def getQueues(self):
		(queues, active) = ({}, False)
		keys = [WMS.MEMORY, WMS.CPUTIME, WMS.WALLTIME]
		parser = dict(izip(keys, [int, parseTime, parseTime]))
		proc = LocalProcess(self.statusExec, '-q')
		for line in proc.stdout.iter(timeout = 10):
			if line.startswith('-'):
				active = True
			elif line.startswith(' '):
				active = False
			elif active:
				fields = lmap(str.strip, line.split()[:4])
				queueInfo = {}
				for key, value in ifilter(lambda k_v: not k_v[1].startswith('-'), izip(keys, fields[1:])):
					queueInfo[key] = parser[key](value)
				queues[fields[0]] = queueInfo
		proc.status_raise(timeout = 0)
		return queues
Esempio n. 21
0
 def discover(self):
     active = False
     keys = [WMS.MEMORY, WMS.CPUTIME, WMS.WALLTIME]
     parser = dict(izip(keys, [int, parseTime, parseTime]))
     proc = LocalProcess(self._exec, '-q')
     for line in proc.stdout.iter(timeout=10):
         if line.startswith('-'):
             active = True
         elif line.startswith(' '):
             active = False
         elif active:
             fields = lmap(str.strip, line.split()[:4])
             queueInfo = {'name': fields[0]}
             for key, value in ifilter(
                     lambda k_v: not k_v[1].startswith('-'),
                     izip(keys, fields[1:])):
                 queueInfo[key] = parser[key](value)
             yield queueInfo
     proc.status_raise(timeout=0)