本文整理汇总了Python中DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient.modifyStatusElement方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceStatusClient.modifyStatusElement方法的具体用法?Python ResourceStatusClient.modifyStatusElement怎么用?Python ResourceStatusClient.modifyStatusElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient
的用法示例。
在下文中一共展示了ResourceStatusClient.modifyStatusElement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __changeSiteStatus
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import modifyStatusElement [as 别名]
def __changeSiteStatus( self, site, comment, statusType, status, printOutput = False ):
"""
Change the RSS status of the given site
"""
result = self.__checkSiteIsValid( site )
if not result['OK']:
return result
wmsAdmin = RPCClient( 'WorkloadManagement/WMSAdministrator' )
result = wmsAdmin.allowSite( site, comment )
if not result['OK']:
return result
rsc = ResourceStatusClient()
proxyInfo = getProxyInfo()
if not proxyInfo[ 'OK' ]:
return proxyInfo
userName = proxyInfo[ 'Value' ][ 'username' ]
tomorrow = datetime.utcnow().replace( microsecond = 0 ) + timedelta( days = 1 )
result = rsc.modifyStatusElement( 'Site', 'Status',
name = site,
statusType = statusType,
status = status,
reason = comment,
tokenOwner = userName,
tokenExpiration = tomorrow )
return result
示例2: ResourceStatus
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import modifyStatusElement [as 别名]
#.........这里部分代码省略.........
elementStatuses[ elementStatusType ] = value
# If there is no status defined in the CS, we add by default Read and
# Write as Active.
if elementStatuses == {}:
elementStatuses = { 'ReadAccess' : 'Active', 'WriteAccess' : 'Active' }
result[ element ] = elementStatuses
if result:
return S_OK( result )
if default is not None:
# sec check
if statusType is None:
statusType = 'none'
defList = [ [ el, statusType, default ] for el in elementName ]
return S_OK( getDictFromList( defList ) )
_msg = "StorageElement '%s', with statusType '%s' is unknown for CS."
return S_ERROR( _msg % ( elementName, statusType ) )
def __setRSSStorageElementStatus( self, elementName, statusType, status, reason, tokenOwner ):
"""
Sets on the RSS the StorageElements status
"""
expiration = datetime.datetime.utcnow() + datetime.timedelta( days = 1 )
self.seCache.acquireLock()
try:
res = self.rssClient.modifyStatusElement( 'Resource', 'Status', name = elementName,
statusType = statusType, status = status,
reason = reason, tokenOwner = tokenOwner,
tokenExpiration = expiration )
if res[ 'OK' ]:
self.seCache.refreshCache()
if not res[ 'OK' ]:
_msg = 'Error updating StorageElement (%s,%s,%s)' % ( elementName, statusType, status )
gLogger.warn( 'RSS: %s' % _msg )
return res
finally:
# Release lock, no matter what.
self.seCache.releaseLock()
def __setCSStorageElementStatus( self, elementName, statusType, status ):
"""
Sets on the CS the StorageElements status
"""
statuses = self.rssConfig.getConfigStatusType( 'StorageElement' )
if not statusType in statuses:
gLogger.error( "%s is not a valid statusType" % statusType )
return S_ERROR( "%s is not a valid statusType: %s" % ( statusType, statuses ) )
csAPI = CSAPI()
cs_path = "/Resources/StorageElements"
csAPI.setOption( "%s/%s/%s" % ( cs_path, elementName, statusType ), status )
示例3: setToken
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import modifyStatusElement [as 别名]
def setToken(user):
'''
Function that gets the user token, sets the validity for it. Gets the elements
in the database for a given name and statusType(s). Then updates the status
of all them adding a reason and the token.
'''
rssClient = ResourceStatusClient()
# This is a little bit of a nonsense, and certainly needs to be improved.
# To modify a list of elements, we have to do it one by one. However, the
# modify method does not discover the StatusTypes ( which in this script is
# an optional parameter ). So, we get them from the DB and iterate over them.
elements = rssClient.selectStatusElement(switchDict['element'], 'Status',
name=switchDict['name'],
statusType=switchDict['statusType'],
meta={'columns': ['StatusType', 'TokenOwner']})
if not elements['OK']:
return elements
elements = elements['Value']
# If there list is empty they do not exist on the DB !
if not elements:
subLogger.warn('Nothing found for %s, %s, %s' % (switchDict['element'],
switchDict['name'],
switchDict['statusType']))
return S_OK()
# If we want to release the token
if switchDict['releaseToken']:
tokenExpiration = datetime.max
newTokenOwner = 'rs_svc'
else:
tokenExpiration = datetime.utcnow().replace(microsecond=0) + timedelta(days=int(switchDict['days']))
newTokenOwner = user
subLogger.always('New token: %s --- until %s' % (newTokenOwner, tokenExpiration))
for statusType, tokenOwner in elements:
# If a user different than the one issuing the command and RSS
if tokenOwner != user and tokenOwner != 'rs_svc':
subLogger.info('%s(%s) belongs to the user: %s' % (switchDict['name'], statusType, tokenOwner))
# does the job
result = rssClient.modifyStatusElement(switchDict['element'], 'Status',
name=switchDict['name'],
statusType=statusType,
reason=switchDict['reason'],
tokenOwner=newTokenOwner,
tokenExpiration=tokenExpiration)
if not result['OK']:
return result
if tokenOwner == newTokenOwner:
msg = '(extended)'
elif newTokenOwner == 'rs_svc':
msg = '(released)'
else:
msg = '(aquired from %s)' % tokenOwner
subLogger.info('%s:%s %s' % (switchDict['name'], statusType, msg))
return S_OK()
示例4: SiteStatus
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import modifyStatusElement [as 别名]
#.........这里部分代码省略.........
>>> siteStatus.getSites()
S_OK( ['test1.test1.uk', 'test3.test3.org'] )
>>> siteStatus.getSites( 'Active' )
S_OK( ['test1.test1.uk', 'test3.test3.org'] )
>>> siteStatus.getSites( 'Banned' )
S_OK( ['test0.test0.uk', ... ] )
>>> siteStatus.getSites( 'All' )
S_OK( ['test1.test1.uk', 'test3.test3.org', 'test4.test4.org', 'test5.test5.org'...] )
>>> siteStatus.getSites( None )
S_ERROR( ... )
:Parameters:
**siteState** - `String`
state of the sites to be matched
:return: S_OK() || S_ERROR()
"""
if not siteState:
return S_ERROR(DErrno.ERESUNK, 'siteState parameter is empty')
siteStatusDictRes = self.getSiteStatuses()
if not siteStatusDictRes['OK']:
return siteStatusDictRes
if siteState.capitalize() == 'All':
# if no siteState is set return everything
siteList = list(siteStatusDictRes['Value'])
else:
# fix case sensitive string
siteState = siteState.capitalize()
allowedStateList = ['Active', 'Banned', 'Degraded', 'Probing', 'Error', 'Unknown']
if siteState not in allowedStateList:
return S_ERROR(errno.EINVAL, 'Not a valid status, parameter rejected')
siteList = [x[0] for x in siteStatusDictRes['Value'].iteritems() if x[1] == siteState]
return S_OK(siteList)
def setSiteStatus(self, site, status, comment='No comment'):
"""
Set the status of a site in the 'SiteStatus' table of RSS
examples
>>> siteStatus.banSite( 'site1.test.test' )
S_OK()
>>> siteStatus.banSite( None )
S_ERROR( ... )
:Parameters:
**site** - `String`
the site that is going to be banned
**comment** - `String`
reason for banning
:return: S_OK() || S_ERROR()
"""
if not status:
return S_ERROR(DErrno.ERESUNK, 'status parameter is empty')
# fix case sensitive string
status = status.capitalize()
allowedStateList = ['Active', 'Banned', 'Degraded', 'Probing', 'Error', 'Unknown']
if status not in allowedStateList:
return S_ERROR(errno.EINVAL, 'Not a valid status, parameter rejected')
if self.rssFlag:
result = getProxyInfo()
if result['OK']:
tokenOwner = result['Value']['username']
else:
return S_ERROR("Unable to get user proxy info %s " % result['Message'])
tokenExpiration = datetime.utcnow() + timedelta(days=1)
self.rssCache.acquireLock()
try:
result = self.rsClient.modifyStatusElement('Site', 'Status', status=status, name=site,
tokenExpiration=tokenExpiration, reason=comment,
tokenOwner=tokenOwner)
if result['OK']:
self.rssCache.refreshCache()
else:
_msg = 'Error updating status of site %s to %s' % (site, status)
gLogger.warn('RSS: %s' % _msg)
# Release lock, no matter what.
finally:
self.rssCache.releaseLock()
else:
if status in ['Active', 'Degraded']:
result = RPCClient('WorkloadManagement/WMSAdministrator').allowSite()
else:
result = RPCClient('WorkloadManagement/WMSAdministrator').banSite()
return result
示例5: setToken
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient import ResourceStatusClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceStatusClient.ResourceStatusClient import modifyStatusElement [as 别名]
def setToken(user):
"""
Function that gets the user token, sets the validity for it. Gets the elements
in the database for a given name and statusType(s). Then updates the status
of all them adding a reason and the token.
"""
rssClient = ResourceStatusClient()
# This is a little bit of a nonsense, and certainly needs to be improved.
# To modify a list of elements, we have to do it one by one. However, the
# modify method does not discover the StatusTypes ( which in this script is
# an optional parameter ). So, we get them from the DB and iterate over them.
elements = rssClient.selectStatusElement(
switchDict["element"],
"Status",
name=switchDict["name"],
statusType=switchDict["statusType"],
meta={"columns": ["StatusType", "TokenOwner"]},
)
if not elements["OK"]:
return elements
elements = elements["Value"]
# If there list is empty they do not exist on the DB !
if not elements:
subLogger.warn(
"Nothing found for %s, %s, %s" % (switchDict["element"], switchDict["name"], switchDict["statusType"])
)
return S_OK()
# If we want to release the token
if switchDict["releaseToken"] != False:
tokenExpiration = datetime.max
newTokenOwner = "rs_svc"
else:
tokenExpiration = datetime.utcnow().replace(microsecond=0) + timedelta(days=1)
newTokenOwner = user
subLogger.info("New token : %s until %s" % (newTokenOwner, tokenExpiration))
for statusType, tokenOwner in elements:
# If a user different than the one issuing the command and RSS
if tokenOwner != user and tokenOwner != "rs_svc":
subLogger.info("%s(%s) belongs to the user: %s" % (switchDict["name"], statusType, tokenOwner))
# does the job
result = rssClient.modifyStatusElement(
switchDict["element"],
"Status",
name=switchDict["name"],
statusType=statusType,
reason=switchDict["reason"],
tokenOwner=newTokenOwner,
tokenExpiration=tokenExpiration,
)
if not result["OK"]:
return result
if tokenOwner == newTokenOwner:
msg = "(extended)"
elif newTokenOwner == "rs_svc":
msg = "(released)"
else:
msg = "(aquired from %s)" % tokenOwner
subLogger.info("%s:%s %s" % (switchDict["name"], statusType, msg))
return S_OK()