def create(self, entity): ''' Create an entity (Resource or Link) ''' logger.debug('The create operation of the libnetvirt_backend') # Check if the mixin is libnetvirt if str(entity.mixins[0]['term']) != 'libnetvirt': logger.debug('Wrong mixin') return # Initialize and connect libnetvirt type = self.getType(entity.ocni_libnetvirt_service_type) info = self.init_libnetvirt(type, entity) if info < 0: logger.error ("Error while connecting to driver") return # Create FNS fns = libnetvirt.create_local_fns(int(entity.ocni_libnetvirt_uuid), len(entity.ocni_libnetvirt_endpoint), entity.occi_core_id, type) # Loop with all the endpoints index = 0 for ep in entity.ocni_libnetvirt_endpoint: ep = self.ep_check(ep) if type == libnetvirt.LIBNETVIRT_FORWARDING_L2: libnetvirt.add_local_epoint(fns, index, long(ep.ocni_libnetvirt_endpoint_uuid), int(ep.ocni_libnetvirt_endpoint_swid), int(ep.ocni_libnetvirt_endpoint_port), int(ep.ocni_libnetvirt_endpoint_vlan), int(ep.ocni_libnetvirt_endpoint_mpls)) else: libnetvirt.add_local_epoint_l3(fns, index, long(ep.ocni_libnetvirt_endpoint_uuid), int(ep.ocni_libnetvirt_endpoint_swid), int(ep.ocni_libnetvirt_endpoint_port), int(ep.ocni_libnetvirt_endpoint_vlan), ep.ocni_libnetvirt_endpoint_address+'/'+ep.ocni_libnetvirt_endpoint_mask) index = index + 1 # Send command libnetvirt.libnetvirt_create_fns(info,fns) # Stop communication libnetvirt.libnetvirt_stop(info)
def delete(self, entity): ''' Delete an Entity ''' logger.debug('The delete operation of the libnetvirt_backend') # Check if the mixin is libnetvirt if entity == None: logger.error('Error. Entity is none') return if str(entity.mixins[0]['term']) != 'libnetvirt': logger.error('Entity is not libnetvirt mixin') return # Initialize and connect libnetvirt type = self.getType(entity.ocni_libnetvirt_service_type) info = self.init_libnetvirt(type, entity) if info < 0: return fns = libnetvirt.create_local_fns(int(entity.ocni_libnetvirt_uuid), len(entity.ocni_libnetvirt_endpoint), entity.occi_core_id,type) index = 0 if type == libnetvirt.LIBNETVIRT_FORWARDING_L3VPN: for ep in entity.ocni_libnetvirt_endpoint: ep = self.ep_check(ep) libnetvirt.add_local_epoint_l3(fns, index, long(ep.ocni_libnetvirt_endpoint_uuid), int(ep.ocni_libnetvirt_endpoint_swid), int(ep.ocni_libnetvirt_endpoint_port), int(ep.ocni_libnetvirt_endpoint_vlan), ep.ocni_libnetvirt_endpoint_address+'/'+ep.ocni_libnetvirt_endpoint_mask) index = index + 1 # Send command libnetvirt.libnetvirt_remove_fns(info,fns); logger.debug('Removing fns sent') # Stop communication libnetvirt.libnetvirt_stop(info)
def update(self, old_entity, new_entity): ''' Update an Entity's information ''' logger.debug('The update operation of the libnetvirt_backend') if old_entity == None: self.create(new_entity) return # Find the difference ep_add, ep_rem = self.diff(old_entity.ocni_libnetvirt_endpoint, new_entity.ocni_libnetvirt_endpoint) #ep_rem = self.diff(new_entity.ocni_libnetvirt_endpoint, # old_entity.ocni_libnetvirt_endpoint) # Nothing to be change if len(ep_add) == 0 and len(ep_rem) == 0: return # Initialize and connect libnetvirt type = self.getType(new_entity.ocni_libnetvirt_service_type) info = self.init_libnetvirt(type, new_entity) if info < 0: return if len(ep_add) > 0: # Modify add logger.debug('Adding endpoint to FNS') logger.debug(ep_add) fns = libnetvirt.create_local_fns(int(new_entity.ocni_libnetvirt_uuid), len(ep_add), new_entity.occi_core_id,type) # Loop with all the endpoints index = 0 for ep in ep_add: ep = self.ep_check(ep) if type == libnetvirt.LIBNETVIRT_FORWARDING_L2: libnetvirt.add_local_epoint(fns, index, long(ep.ocni_libnetvirt_endpoint_uuid), int(ep.ocni_libnetvirt_endpoint_swid), int(ep.ocni_libnetvirt_endpoint_port), int(ep.ocni_libnetvirt_endpoint_vlan), int(ep.ocni_libnetvirt_endpoint_mpls)) else: libnetvirt.add_local_epoint_l3(fns, index, long(ep.ocni_libnetvirt_endpoint_uuid), int(ep.ocni_libnetvirt_endpoint_swid), int(ep.ocni_libnetvirt_endpoint_port), int(ep.ocni_libnetvirt_endpoint_vlan), ep.ocni_libnetvirt_endpoint_address+'/'+ep.ocni_libnetvirt_endpoint_mask) index = index + 1 libnetvirt.libnetvirt_modify_fns_add(info,fns); if len(ep_rem) > 0: # Modify remove logger.debug('Removing endpoints to FNS') logger.debug(ep_rem) fns = libnetvirt.create_local_fns(int(new_entity.ocni_libnetvirt_uuid), len(ep_rem), new_entity.occi_core_id,type) # Loop with all the endpoints index = 0 for ep in ep_rem: ep = self.ep_check(ep) if type == libnetvirt.LIBNETVIRT_FORWARDING_L2: libnetvirt.add_local_epoint(fns, index, long(ep.ocni_libnetvirt_endpoint_uuid), int(ep.ocni_libnetvirt_endpoint_swid), int(ep.ocni_libnetvirt_endpoint_port), int(ep.ocni_libnetvirt_endpoint_vlan), int(ep.ocni_libnetvirt_endpoint_mpls)) else: libnetvirt.add_local_epoint_l3(fns, index, long(ep.ocni_libnetvirt_endpoint_uuid), int(ep.ocni_libnetvirt_endpoint_swid), int(ep.ocni_libnetvirt_endpoint_port), int(ep.ocni_libnetvirt_endpoint_vlan), ep.ocni_libnetvirt_endpoint_address+'/'+ep.ocni_libnetvirt_endpoint_mask) index = index + 1 libnetvirt.libnetvirt_modify_fns_del(info,fns); # Stop communication libnetvirt.libnetvirt_stop(info)