@staticmethod
    def add_leases(xml, leases, channels):
        
        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
        
        # group the leases by slice and timeslots
        grouped_leases = []

        while leases:
             slice_id = leases[0]['slice_id']
             start_time = leases[0]['start_time']
             duration = leases[0]['duration']
             group = []
             
             for lease in leases:
                  if slice_id == lease['slice_id'] and start_time == lease['start_time'] and duration == lease['duration']:
                      group.append(lease)

             grouped_leases.append(group)

             for lease1 in group:
                  leases.remove(lease1)
         
        lease_elems = []       
        for lease in grouped_leases:
            #lease_fields = ['lease_id', 'component_id', 'slice_id', 'start_time', 'duration']
            lease_fields = ['slice_id', 'start_time', 'duration']
            lease_elem = network_elem.add_instance('lease', lease[0], lease_fields)
            lease_elems.append(lease_elem)

            # add nodes of this lease
            for node in lease:
                 lease_elem.add_instance('node', node, ['component_id'])

            # add reserved channels of this lease
            #channels = [{'channel_id': 1}, {'channel_id': 2}]
            for channel in channels:
                 if channel['slice_id'] == lease[0]['slice_id'] and channel['start_time'] == lease[0]['start_time'] and channel['duration'] == lease[0]['duration']:
                     lease_elem.add_instance('channel', channel, ['channel_num'])
dataset/ETHPy150Open fp7-ofelia/ocf/ofam/src/src/foam/sfa/rspecs/elements/versions/nitosv1Lease.py/NITOSv1Lease.add_leases/original