def _get_cib_version(cib, attribute, regexp, none_if_missing=False): version = cib.get(attribute) if version is None: if none_if_missing: return None raise LibraryError( reports.cib_load_error_invalid_format( "the attribute '{0}' of the element 'cib' is missing".format( attribute))) match = regexp.match(version) if not match: raise LibraryError( reports.cib_load_error_invalid_format( ("the attribute '{0}' of the element 'cib' has an invalid" " value: '{1}'").format(attribute, version))) return Version(int(match.group("major")), int(match.group("minor")), int(match.group("rev")) if match.group("rev") else None)
def get_pacemaker_version_by_which_cib_was_validated(cib): """ Return version of pacemaker which validated specified cib as tree. Version is returned as tuple of integers: (<major>, <minor>, <revision>). Raises LibraryError on any failure. cib -- cib etree """ version = cib.get("validate-with") if version is None: raise LibraryError(reports.cib_load_error_invalid_format()) regexp = re.compile( r"pacemaker-(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<rev>\d+))?") match = regexp.match(version) if not match: raise LibraryError(reports.cib_load_error_invalid_format()) return (int(match.group("major")), int(match.group("minor")), int(match.group("rev") or 0))
def get_pacemaker_version_by_which_cib_was_validated(cib): """ Return version of pacemaker which validated specified cib as tree. Version is returned as tuple of integers: (<major>, <minor>, <revision>). Raises LibraryError on any failure. cib -- cib etree """ version = cib.get("validate-with") if version is None: raise LibraryError(reports.cib_load_error_invalid_format()) regexp = re.compile( r"pacemaker-(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<rev>\d+))?" ) match = regexp.match(version) if not match: raise LibraryError(reports.cib_load_error_invalid_format()) return ( int(match.group("major")), int(match.group("minor")), int(match.group("rev") or 0) )
def _get_cib_version(cib, attribute, regexp, none_if_missing=False): version = cib.get(attribute) if version is None: if none_if_missing: return None raise LibraryError(reports.cib_load_error_invalid_format( "the attribute '{0}' of the element 'cib' is missing".format( attribute ) )) match = regexp.match(version) if not match: raise LibraryError(reports.cib_load_error_invalid_format( ( "the attribute '{0}' of the element 'cib' has an invalid" " value: '{1}'" ).format(attribute, version) )) return Version( int(match.group("major")), int(match.group("minor")), int(match.group("rev")) if match.group("rev") else None )
def get_cib(xml): try: return etree.fromstring(xml) except (etree.XMLSyntaxError, etree.DocumentInvalid): raise LibraryError(reports.cib_load_error_invalid_format())
def get_cib(xml): try: return parse_cib_xml(xml) except (etree.XMLSyntaxError, etree.DocumentInvalid): raise LibraryError(reports.cib_load_error_invalid_format())
def get_cib(xml): try: return parse_cib_xml(xml) except (etree.XMLSyntaxError, etree.DocumentInvalid) as e: raise LibraryError(reports.cib_load_error_invalid_format(str(e)))