本文整理汇总了Python中DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient.getTokens方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceStatusClient.getTokens方法的具体用法?Python ResourceStatusClient.getTokens怎么用?Python ResourceStatusClient.getTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient
的用法示例。
在下文中一共展示了ResourceStatusClient.getTokens方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TokenAgent
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import getTokens [as 别名]
class TokenAgent( AgentModule ):
'''
TokenAgent is in charge of checking tokens assigned on resources.
Notifications are sent to those users owning expiring tokens.
'''
# Too many public methods
# pylint: disable-msg=R0904
def initialize( self ):
'''
TokenAgent initialization
'''
# Attribute defined outside __init__
# pylint: disable-msg=W0201
self.notifyHours = self.am_getOption( 'notifyHours', 10 )
try:
self.rsClient = ResourceStatusClient()
self.rmClient = ResourceManagementClient()
self.noClient = NotificationClient()
return S_OK()
except Exception:
errorStr = "TokenAgent initialization"
self.log.exception( errorStr )
return S_ERROR( errorStr )
def execute( self ):
'''
The main TokenAgent execution method.
Checks for tokens owned by users that are expiring, and notifies those users.
Calls rsClient.setToken() to set 'RS_SVC' as owner for those tokens that expired.
'''
adminMail = ''
try:
reason = 'Out of date token'
#reAssign the token to RS_SVC
#for g in self.ELEMENTS:
validElements = RssConfiguration.getValidElements()
for granularity in validElements:
tokensExpired = self.rsClient.getTokens( granularity,
tokenExpiration = datetime.datetime.utcnow() )
if tokensExpired[ 'Value' ]:
adminMail += '\nLIST OF EXPIRED %s TOKENS\n' % granularity
adminMail += '%s|%s|%s\n' % ( 'user'.ljust(20), 'name'.ljust(15), 'status type')
for token in tokensExpired[ 'Value' ]:
name = token[ 1 ]
stype = token[ 2 ]
user = token[ 9 ]
self.rsClient.setToken( granularity, name, stype, reason, 'RS_SVC',
datetime.datetime( 9999, 12, 31, 23, 59, 59 ) )
adminMail += ' %s %s %s\n' %( user.ljust(20), name.ljust(15), stype )
#notify token owners
inNHours = datetime.datetime.utcnow() + datetime.timedelta( hours = self.notifyHours )
#for g in self.ELEMENTS:
for granularity in validElements:
tokensExpiring = self.rsClient.getTokens( granularity, tokenExpiration = inNHours )
if tokensExpiring[ 'Value' ]:
adminMail += '\nLIST OF EXPIRING %s TOKENS\n' % granularity
adminMail += '%s|%s|%s\n' % ( 'user'.ljust(20),'name'.ljust(15),'status type')
for token in tokensExpiring[ 'Value' ]:
name = token[ 1 ]
stype = token[ 2 ]
user = token[ 9 ]
adminMail += '\n %s %s %s\n' %( user.ljust(20), name.ljust(15), stype )
#If user is RS_SVC, we ignore this, whenever the token is out, this
#agent will set again the token to RS_SVC
if user == 'RS_SVC':
continue
pdp = PDP( granularity = granularity, name = name, statusType = stype )
decision = pdp.takeDecision()
pcresult = decision[ 'PolicyCombinedResult' ]
spresult = decision[ 'SinglePolicyResults' ]
expiration = token[ 10 ]
mailMessage = "The token for %s %s ( %s )" % ( granularity, name, stype )
mailMessage = mailMessage + " will expire on %s\n\n" % expiration
#.........这里部分代码省略.........