CERNServiceXML

travis-ci badge coveralls.io badge

CERNServiceXML is a small library to generate a CERN XSLS Service XML.

Installation

The CERNServiceXML package is on PyPI so all you need is:

$ pip install cernservicexml

Usage

Creation of XSLS service documents.

Usage:

>>> from cernservicexml import ServiceDocument, Status
>>> doc = ServiceDocument('zenodo', status=Status.available)
>>> doc.add_numericvalue('users', 1000, desc="Number of users")
>>> xml = doc.to_xml()

Publishing of service documents.

Usage:

>>> from cernservicexml import ServiceDocument, XSLSPublisher
>>> doc = ServiceDocument('myserviceid')
>>> XSLSPublisher.send(doc)
<Response [200]>

API

class cernservicexml.document.ServiceDocument(service_id, status=None, timestamp=None, availabilitydesc=None, contact=None, webpage=None, availabilityinfo=None, availability=None)

XSLS Service Document class.

Parameters:
  • service_id – A unique service id.
  • availability – An integer 0-100 indicating availability of service (deprecated, use status instead). Default: 100.
  • status – Status of the service. Allowed values: available, degraded or unavailable. Default: available.
  • timestamp – Timestamp when the availability was calculated. Must be a datetime object. Default: now.
  • availabilitydesc – Information about the availability.
  • contact – Service contacts a string.
  • webpage – Service website (any URI)
  • availabilityinfo – Information about the service. Can contain HTML.

Changed in version 0.2: Added status parameter. Deprecated availability parameter.

STATUSES = [u'available', u'degraded', u'unavailable']

Allowed status values.

add_numericvalue(name, value, desc=None)

Add a numeric value metric.

Parameters:
  • name – Numeric value id.
  • value – An integer, float or Decimal object.
  • desc – A description.
availability

Get status as legacy availability percentage.

Deprecated since version 0.2: Use of availability as percentage is deprecated. Please use status instead. Attribute will be removed in v0.3.

to_xml()

Serialize service document to XML.

class cernservicexml.publisher.XSLSPublisher

Publish a service document to an XSLS service.

classmethod send(document, api_url=u'http://xsls.cern.ch')

Send service document to XSLS.

Changes

Version 0.2.1 (released 2015-07-24)

  • Relaxes Requests library version requirement from v2.3 to v1.1 to support CERN SLC6/CentOS 7 distributions. Note, Python 3.4 requires Requests v2+.
  • Adds Travis test matrix to test multiple versions of the Requests library.
  • Standardises software name (CERNServiceXML) and package name (cernservicexml) following usual inveniosoftware practices.
  • Fixes reST headline formatting in RELEASE-NOTES.rst.

Version 0.2.0 (released 2015-07-16)

  • Adds support for service status parameter in ServiceDocument.
  • Deprecates use of service availability percentage in ServiceDocument. Please use service status parameter instead.
  • Changes documentation theme to the standard non-Flask RTD one.
  • Initial release of Docker configuration suitable for local developments. docker-compose build rebuilds the image, docker-compose run –rm web python setup.py test runs the test suite.

Version 0.1.2 (released 2015-06-17)

  • Adds support for long (Python 2) integers.

Version 0.1.1 (released 2015-06-17)

  • Fixes issues with POST request for sending the service XML to XSLS.
  • Adds doctests to ensure documentation examples works.
  • Adds XML validation tests according to XSD Schema.

Version 0.1.0 (released 2015-06-16)

  • Initial public release.

Contributing

Bug reports, feature requests, and other contributions are welcome. If you find a demonstrable problem that is caused by the code of this library, please:

  1. Search for already reported problems.
  2. Check if the issue has been fixed or is still reproducible on the latest master branch.
  3. Create an issue with a test case.

If you create a feature branch, you can run the tests to ensure everything is operating correctly:

$ ./run-tests.sh

You can also test your feature branch using Docker:

$ docker-compose build
$ docker-compose run --rm web /code/run-tests.sh

License

CERNServiceXML is free software; you can redistribute it and/or modify it under the terms of the Revised BSD License quoted below.

Copyright (C) 2015 CERN.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction.

Authors

Contact us at info@inveniosoftware.org