SiteStatus
SiteStatus helper
Module that acts as a helper for knowing the status of a site. It takes care of switching between the CS and the RSS. The status is kept in the RSSCache object, which is a small wrapper on top of DictCache
- class DIRAC.ResourceStatusSystem.Client.SiteStatus.SiteStatus(*args, **kwargs)
Bases:
object
RSS helper to interact with the ‘Site’ family on the DB. It provides the most demanded functions and a cache to avoid hitting the server too often.
It provides four methods to interact with the site statuses: * getSiteStatuses * isUsableSite * getUsableSites * getSites
- __init__()
Constructor, initializes the rssClient.
- getSiteStatuses(siteNames=None)
Method that queries the database for status of the sites in a given list. A single string site name may also be provides as “siteNames” If the input is None, it is interpreted as * ( all ).
If match is positive, the output looks like:
{ 'test1.test1.org': 'Active', 'test2.test2.org': 'Banned', }
Examples:
>>> siteStatus.getSiteStatuses( ['test1.test1.uk', 'test2.test2.net', 'test3.test3.org'] ) S_OK( { 'test1.test1.org': 'Active', 'test2.test2.net': 'Banned', 'test3.test3.org': 'Active' } ) >>> siteStatus.getSiteStatuses( 'NotExists') S_ERROR( ... )) >>> siteStatus.getSiteStatuses( None ) S_OK( { 'test1.test1.org': 'Active', 'test2.test2.net': 'Banned', }, ... } )
- getSites(siteState='Active')
By default, it gets the currently active site list
- examples
>>> 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
- Returns:
S_OK() || S_ERROR()
- getUsableSites(siteNames=None)
Returns all sites that are usable if their statusType is either Active or Degraded; in a list.
- examples
>>> siteStatus.getUsableSites( ['test1.test1.uk', 'test2.test2.net', 'test3.test3.org'] ) S_OK( ['test1.test1.uk', 'test3.test3.org'] ) >>> siteStatus.getUsableSites( None ) S_OK( ['test1.test1.uk', 'test3.test3.org', 'test4.test4.org', 'test5.test5.org', ...] ) >>> siteStatus.getUsableSites( 'NotExists' ) S_ERROR( ... )
- Parameters:
- siteNames - List or str
name(s) of the sites to be matched
- Returns:
S_OK() || S_ERROR()
- instance = None
- setSiteStatus(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
- Returns:
S_OK() || S_ERROR()
- DIRAC.ResourceStatusSystem.Client.SiteStatus.getCacheDictFromRawData(rawList)
Formats the raw data list, which we know it must have tuples of four elements. ( element1, element2 ) into a dictionary of tuples with the format { ( element1 ): element2 )}. The resulting dictionary will be the new Cache.
- It happens that element1 is elementName,
element4 is status.
- Parameters:
- rawList - list
list of three element tuples [( element1, element2 ),… ]
- Returns:
dict of the form { ( elementName ) : status, … }