Table Of Contents

Previous topic

Service object related examples

Next topic

SWRelease object related examples

Site Status Examples

This section provides a set of examples illustrated how to retrieve or set site status for specific activity.

Retrieving defined site state for specific activity

agis.objects.SiteStatusActivity object is used to store information about site state associated with given activity.

state and autostate properties introduced to define site status for an activity.

AStateTypes class describes possible values for state property:

  • AStateTypes.ON
  • AStateTypes.OFF
  • AStateTypes.AUTO

state attribute describes primary value to be used. If it set to AStateTypes.AUTO value, then the value of autostate property is used as final site status.

AStateValues class describes possible values for autostate property:

  • AStateTypes.ON
  • AStateTypes.OFF

agis.objects.SiteStatusActivity.get_status function should be used to retrive final site status.

To retrieve sites states list_sites_status function can be used.

>>> # initialize AGIS
>>> from agis.api.AGIS import AGIS
>>> a=AGIS(hostp='atlas-agis-api-dev.cern.ch:80')
>>> r=a.list_sites_status()
>>> r
{u'RRC-KI': [{'state_update': None, 'autostate_update': datetime.datetime(2011, 7, 17, 10, 50), 'site': u'RRC-KI', 'autostate': u'0',
'state': u'AUTO', 'activity': u'DDMFT', 'autostate_comment': u'disabled because of active downtime', 'state_comment': u''}] }
>>> obj=r.values()[0][0]
>>> print obj.site, obj.activity, obj.state, obj.autostate, obj.state_update, obj.autostate_update, obj.autostate_comment, obj.state_comment
RRC-KI DDMFT AUTO 0 None 2011-07-17 10:50:00 disabled because of active downtime
>>> print obj.get_status()
(u'0', u'disabled because of active downtime', datetime.datetime(2011, 7, 17, 10, 50))

Various filters could be applied:

>>> r=a.list_sites_status(cloud='IT', tier_level=2) # filter by cloud + tier_level
>>> r=a.list_sites_status(activity='DDMFT') # filter by activity
>>> from agis.objects import ObjectStateTypes
>>> # retrieve site states for any sites even for globally DISABLED one
>>> r=a.list_sites_status(site_state=ObjectStateTypes.ANY) # filter by global site state

Show only explicitly defined site states to ON value:

>>> from agis.objects import AStateTypes, AStateValues
>>> r=a.list_sites_status(state=AStateTypes.ON, activity='DDMFT')

Filter by final status value:

>>> r=a.list_sites_status(status=AStateValues.ON, activity='DDMFT')
# show all finally excluded sites for an activity
>>> r=a.list_sites_status(status=AStateValues.OFF)

groupby parameter could be used to group output by specific field:

  • site (default)
  • ddmsite
  • activity
>>> r=a.list_sites_status(groupby='activity')
>>> r.keys()
[u'DDMFT']

agis-list-sites-status tool exposed list_sites_status functionality to CLI usage.

For example:

$ agis-list-sites-status --help
$ agis-list-sites-status --server=atlas-agis-api-dev.cern.ch --status=1 --activity=DDMFT --cloud=US

Setting site state for specific activity

agis.api.AGIS.AGIS.set_site_status function or related CLI agis-set-site-status tool should be used to update SiteStatus activity related information.

If SiteStatusActivity object is not exist for related Site and Activity it will be automatically created and updated with passed values.

>>> # initialize AGIS
>>> from agis.api.AGIS import AGIS
>>> a=AGIS(hostp='atlas-agis-api-dev.cern.ch:80')

Following example set autostate value of ‘RRC-KI’ site to OFF status for DDMFT activity

>>> from agis.objects import AStateTypes, AStateValues
>>> a.set_site_status(site='RRC-KI', activity='DDMFT',  autostate=AStateValues.OFF, autostate_comment='Disabled because of active down
time.')
True # updated successfully
>>> # try to do it again
>>> a.set_site_status(site='RRC-KI', activity='DDMFT',  autostate=AStateValues.OFF, autostate_comment='Disabled because of active down
time.')
False # db values is up-to-date

Next example shows how to set or update state and autostate values together:

>>> from agis.objects import AStateTypes, AStateValues
>>> a.set_site_status(site='AGLT2', state=AStateTypes.OFF, autostate=AStateValues.ON, state_comment='temporary deactivated', autostate_comment='AUTO state ALT2 comment', activity='DDMFT')
True

Enable the site again:

>>> a.set_site_status(site='AGLT2', state=AStateTypes.AUTO, state_comment='site is online again', activity='DDMFT')
True

agis-set-site-status tool mirrors set_site_status functionality for CLI usage.

For example:

$ agis-set-site-status --help
$ agis-set-site-status --server=atlas-agis-api-dev.cern.ch --site=GRIF --activity=DDMFT --state=AUTO --state-comment="comment" --autostate=0 --autostate-comment="auto disabled"