From: Sandrine Avakian Date: Thu, 5 Jul 2012 15:04:20 +0000 (+0200) Subject: Addind leases for Slab Rspecs. X-Git-Tag: sfa-2.1-24~3^2~133 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=9e10015fde2d9affa3b04506642a72bfb0751f12;hp=-c;p=sfa.git Addind leases for Slab Rspecs. --- 9e10015fde2d9affa3b04506642a72bfb0751f12 diff --git a/sfa/rspecs/elements/versions/slabv1Lease.py b/sfa/rspecs/elements/versions/slabv1Lease.py new file mode 100644 index 00000000..a9663469 --- /dev/null +++ b/sfa/rspecs/elements/versions/slabv1Lease.py @@ -0,0 +1,61 @@ +from sfa.util.sfalogging import logger +from sfa.util.xml import XpathFilter +from sfa.util.xrn import Xrn + +from sfa.rspecs.elements.element import Element +from sfa.rspecs.elements.node import Node +from sfa.rspecs.elements.sliver import Sliver +from sfa.rspecs.elements.location import Location +from sfa.rspecs.elements.hardware_type import HardwareType + + + + +from sfa.rspecs.elements.versions.slabv1Sliver import Slabv1Sliver +#from sfa.rspecs.elements.versions.sfav1PLTag import SFAv1PLTag +#from sfa.rspecs.elements.versions.pgv2Services import PGv2Services +from sfa.rspecs.elements.lease import Lease + +from sfa.planetlab.plxrn import xrn_to_hostname + +class Slabv1Lease: + + @staticmethod + def add_leases(xml, leases): + + network_elems = xml.xpath('//network') + if len(network_elems) > 0: + network_elem = network_elems[0] + elif len(leases) > 0: + network_urn = Xrn(leases[0]['component_id']).get_authority_urn().split(':')[0] + network_elem = xml.add_element('network', name = network_urn) + else: + network_elem = xml + + lease_elems = [] + for lease in leases: + lease_fields = ['lease_id', 'component_id', 'slice_id', 't_from', 't_until'] + lease_elem = network_elem.add_instance('lease', lease, lease_fields) + lease_elems.append(lease_elem) + + + @staticmethod + def get_leases(xml, filter={}): + xpath = '//lease%s | //default:lease%s' % (XpathFilter.xpath(filter), XpathFilter.xpath(filter)) + lease_elems = xml.xpath(xpath) + return Slabv1Lease.get_lease_objs(lease_elems) + + @staticmethod + def get_lease_objs(lease_elems): + leases = [] + for lease_elem in lease_elems: + lease = Lease(lease_elem.attrib, lease_elem) + if lease.get('lease_id'): + lease['lease_id'] = lease_elem.attrib['lease_id'] + lease['component_id'] = lease_elem.attrib['component_id'] + lease['slice_id'] = lease_elem.attrib['slice_id'] + lease['t_from'] = lease_elem.attrib['t_from'] + lease['t_until'] = lease_elem.attrib['t_until'] + + leases.append(lease) + return leases \ No newline at end of file