本文整理汇总了Python中DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient.getUserRegistryCache方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceManagementClient.getUserRegistryCache方法的具体用法?Python ResourceManagementClient.getUserRegistryCache怎么用?Python ResourceManagementClient.getUserRegistryCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient
的用法示例。
在下文中一共展示了ResourceManagementClient.getUserRegistryCache方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Synchronizer
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient import getUserRegistryCache [as 别名]
#.........这里部分代码省略.........
continue
if siteInGOCDB == []:
gLogger.warn("%s is not in GOCDB!!!" % srm)
continue
siteInGOCDB = siteInGOCDB[ 0 ][ 'SITENAME' ]
#Utils.protect2(self.rsClient.addOrModifyStorageElement, SE, srm, siteInGOCDB )
res = self.rsClient.addOrModifyStorageElement( SE, srm, siteInGOCDB )
if not res[ 'OK' ]:
gLogger.error( res[ 'Message' ] )
return res
################################################################################
def _syncServices(self):
"""This function is in charge of cleaning the Service table in DB
in case of obsolescence."""
# services in the DB now
#servicesInDB = Utils.unpack(self.rsClient.getService())
servicesInDB = self.rsClient.getService()
if not servicesInDB[ 'OK' ]:
gLogger.error( servicesInDB[ 'Message' ] )
return servicesInDB
servicesInDB = servicesInDB[ 'Value' ]
for service_name, service_type, site_name in servicesInDB:
if not service_type in ["VO-BOX", "CondDB", "VOMS", "Storage"]:
#if Utils.unpack(self.rsClient.getResource(siteName=site_name, serviceType=service_type)) == []:
resource = self.rsClient.getResource( siteName = site_name, serviceType = service_type )
if not resource[ 'OK' ]:
gLogger.error( resource[ 'Message' ] )
return resource
if resource[ 'Value' ] == []:
gLogger.info("Deleting Service %s since it has no corresponding resources." % service_name)
#Utils.protect2(self.rsClient.removeElement, "Service", service_name)
res = self.rsClient.removeElement( "Service", service_name )
if not res[ 'OK' ]:
gLogger.error( res[ 'Message' ] )
return res
elif service_type == "Storage":
res = self.rsClient.getSite( siteName = site_name, meta = { 'columns' : 'GridSiteName'} )
if res[ 'OK' ]:
res = res[ 'Value' ]
else:
res = []
if res:
if self.rsClient.getResource( gridSiteName = res[0], serviceType = service_type ) == []:
gLogger.info("Deleting Service %s since it has no corresponding resources." % service_name)
#Utils.protect2(self.rsClient.removeElement, "Service", service_name)
res = self.rsClient.removeElement( "Service", service_name )
if not res[ 'OK' ]:
gLogger.error( res[ 'Message' ] )
return res
def _syncRegistryUsers(self):
users = CS.getTypedDictRootedAt("Users", root= "/Registry")
usersInCS = set(users.keys())
#usersInDB = set((u[0] for u in Utils.unpack(self.rmClient.getUserRegistryCache())))
usersInCache = self.rmClient.getUserRegistryCache()
if not usersInCache[ 'OK' ]:
gLogger.error( usersInCache[ 'Message' ] )
return usersInCache
usersInDB = set( [ userInCache[ 0 ] for userInCache in usersInCache[ 'Value' ] ] )
usersToAdd = usersInCS - usersInDB
usersToDel = usersInDB - usersInCS
gLogger.info("Updating Registry Users: + %d, - %d" % (len(usersToAdd), len(usersToDel)))
if len(usersToAdd) > 0:
gLogger.debug(str(usersToAdd))
if len(usersToDel) > 0:
gLogger.debug(str(usersToDel))
for u in usersToAdd:
if type(users[u]['DN']) == list:
users[u]['DN'] = users[u]['DN'][0]
if type(users[u]['Email']) == list:
users[u]['Email'] = users[u]['Email'][0]
users[u]['DN'] = users[u]['DN'].split('=')[-1]
#Utils.unpack(self.rmClient.addOrModifyUserRegistryCache( u, users[u]['DN'], users[u]['Email'].lower()))
res = self.rmClient.addOrModifyUserRegistryCache( u, users[u]['DN'], users[u]['Email'].lower() )
if not res[ 'OK' ]:
gLogger.error( res[ 'Message' ] )
return res
for u in usersToDel:
#Utils.protect2(self.rmClient.deleteUserRegistryCache, u)
res = self.rmClient.deleteUserRegistryCache( u )
if not res[ 'OK' ]:
gLogger.error( res[ 'Message' ] )
return res
################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
示例2: TokenAgent
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient import getUserRegistryCache [as 别名]
#.........这里部分代码省略.........
'''
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
mailMessage = mailMessage + "You can renew it with command 'dirac-rss-renew-token'.\n"
mailMessage = mailMessage + "If you don't take any action, RSS will take control of the resource.\n\n"
policyMessage = ''
if pcresult[ 'Action' ]:
policyMessage += " Policies applied will set status to %s.\n" % pcresult[ 'Status' ]
for spr in spresult:
policyMessage += " %s Status->%s\n" % ( spr[ 'PolicyName' ].ljust(25), spr[ 'Status' ] )
mailMessage += policyMessage
adminMail += policyMessage
self.noClient.sendMail( self.rmClient.getUserRegistryCache( user )[ 'Value' ][ 0 ][ 2 ],
'Token for %s is expiring' % name, mailMessage )
if adminMail != '':
#FIXME: 'ubeda' is not generic ;p
self.noClient.sendMail( self.rmClient.getUserRegistryCache( 'ubeda' )[ 'Value' ][ 0 ][ 2 ],
"Token's summary", adminMail )
return S_OK()
except Exception:
errorStr = "TokenAgent execution"
self.log.exception( errorStr )
return S_ERROR( errorStr )
################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
示例3: AlarmAction
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient import getUserRegistryCache [as 别名]
class AlarmAction( ActionBase ):
def __init__(self, granularity, name, status_type, pdp_decision, **kw):
ActionBase.__init__( self, granularity, name, status_type, pdp_decision, **kw )
try: self.rsClient = self.kw["Clients"][ 'ResourceStatusClient' ]
except KeyError: self.rsClient = ResourceStatusClient()
try: self.rmClient = self.kw["Clients"][ 'ResourceManagementClient' ]
except KeyError: self.rmClient = ResourceManagementClient()
def _getUsersToNotify(self):
groups = CS.getTypedDictRootedAtOperations("AssigneeGroups/" + CS.getSetup()).values()
concerned_groups = [g for g in groups if Utils.dictMatch(self.kw["Params"], g)]
return [{'Users':g['Users'],
'Notifications':g['Notifications']} for g in concerned_groups]
def run(self):
""" Do actions required to notify users.
Mandatory keyword arguments:
- Granularity
Optional keyword arguments:
- SiteType
- ServiceType
- ResourceType
"""
# Initializing variables
nc = NotificationClient()
# raise alarms, right now makes a simple notification
if 'Granularity' not in self.kw['Params'].keys():
raise ValueError, "You have to provide a argument Granularity = <desired_granularity>"
if self.new_status['Action']:
notif = "%s %s is perceived as" % (self.granularity, self.name)
notif = notif + " %s. Reason: %s." % (self.new_status['Status'], self.new_status['Reason'])
users_to_notify = self._getUsersToNotify()
for notif in users_to_notify:
for user in notif['Users']:
if 'Web' in notif['Notifications']:
gLogger.info("Sending web notification to user %s" % user)
nc.addNotificationForUser(user, notif)
if 'Mail' in notif['Notifications']:
gLogger.info("Sending mail notification to user %s" % user)
was = self.rsClient.getElementHistory( self.granularity,
elementName = self.name,
statusType = self.status_type,
meta = {"order": "DESC", 'limit' : 1,
"columns": ['Status', 'Reason', 'DateEffective']})#[0]
if not was[ 'OK' ]:
gLogger.error( was[ 'Message' ] )
continue
was = was[ 'Value' ][ 0 ]
mailMessage = """ ---TESTING---
--------------------------------------------------------------------------------
RSS changed the status of the following resource:
Granularity:\t%s
Name:\t\t%s
New status:\t%s
Reason:\t\t%s
Was:\t\t%s (%s) since %s
Setup:\t\t%s
If you think RSS took the wrong decision, please set the status manually:
Use: dirac-rss-set-status -g <granularity> -n <element_name> -s <desired_status> [-t status_type]
(if you omit the optional last part of the command, all status types are matched.)
This notification has been sent according to those parameters:
%s
""" % (self.granularity, self.name, self.new_status['Status'],
self.new_status['Reason'], was[0], was[1], was[2], CS.getSetup(), str(users_to_notify))
# Actually send the mail!
resUser = self.rmClient.getUserRegistryCache( user )
if not resUser[ 'OK' ]:
gLogger.error( resUser[ 'Message' ] )
continue
resUser = resUser[ 'Value' ][ 0 ][ 2 ]
nc.sendMail(resUser,
'[RSS][%s][%s] %s -> %s'
% (self.granularity, self.name, self.new_status['Status'], was[0]), mailMessage)
################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
示例4: ResourceManagementClient
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient import getUserRegistryCache [as 别名]
gLogger.error( "Failed to get proxy information", res['Message'] )
DIRAC.exit( 2 )
userName = res['Value']['username']
if not params.has_key( 'k' ):
params[ 'k' ] = userName
validElements = RssConfiguration.getValidElements()
if not params[ 'g' ] in validElements:
gLogger.error( '"%s" is not a valid granularity' % params[ 'g' ] )
DIRAC.exit( 2 )
if params[ 'k' ] != 'RS_SVC':
rmc = ResourceManagementClient()
u = rmc.getUserRegistryCache( login = params[ 'k' ] )
if not u[ 'OK' ] or not u[ 'Value' ]:
gLogger.error( '"%s" is not a known user' % params[ 'k' ] )
DIRAC.exit( 2 )
if not params.has_key( 't' ):
params[ 't' ] = None
if not params.has_key( 'r' ):
params[ 'r' ] = 'Status set by %s' % userName
if not params.has_key( 'u' ):
params[ 'u' ] = DEFAULT_DURATION
else:
if not isintance( params[ 'u' ], int ):