Beispiel #1
0
    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)
Beispiel #2
0
# along with this library.  If not, see <http://www.gnu.org/licenses/>.


import libnetvirt
info = libnetvirt.libnetvirt_init(libnetvirt.DRIVER_OF_NOX)
for num in range(1,10000):
	libnetvirt.libnetvirt_connect(info, "127.0.0.1",2000) 
fns_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
	<description xmlns=\"http://www.sail-project.eu/fns\">\
	<fns name=\"two-fns\" uuid=\"1\">\
		<endpoint uuid=\"3\"> <swId>3</swId> <port>2</port> </endpoint>\
		<endpoint uuid=\"2\"> <swId>2</swId><port>2</port> </endpoint>\
		<endpoint uuid=\"4\"> <swId>4</swId><port>1</port> </endpoint>\
	</fns>\
	</description>"
fns = libnetvirt.parse_fns_Mem(fns_xml,len(fns_xml))
#fns = libnetvirt.parse_fns("fns.xml")
libnetvirt.libnetvirt_create_fns(info,fns)

fns1 = libnetvirt.create_local_fns(20,2,"fns_api")
ep1 = libnetvirt.add_local_epoint(fns1,0,10,3,2,10,0)
ep2 = libnetvirt.add_local_epoint(fns1,1,20,2,2,20,0)
#print ep1

libnetvirt.printFNS(fns1)
libnetvirt.libnetvirt_create_fns(info,fns1)
libnetvirt.libnetvirt_remove_fns(info,fns1)

libnetvirt.libnetvirt_disconnect(info)

Beispiel #3
0
    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)