Ejemplo n.º 1
0
 def test_get_devices(self):
     device_list = config.get_devices()
     self.assertEqual(set(device_list), set(['foo', 'bar']))
     self.assertEqual({"device_type": "foo_device", "spam": "eggs"},
                      device_list['foo'])
     self.assertEqual({"device_type": "bar_device", "ham": "vikings"},
                      device_list['bar'])
    def test_get_devices(self, m_get_config):
        # get_config array
        m_get_config.return_value = [  # parsed_file dict
            {  # parsed_item str
                'genericswitch:foo':  # device_tag
                {  # parsed_file[device].items() dict
                    'device_type': ['foo_device'],  # {k: v[0] for k, v
                    'spam': ['eggs']
                },
                'genericswitch:bar':  # device_tag
                {  # parsed_file[device].items() dict
                    'device_type': ['bar_device'],  # {k: v[0] for k, v
                    'ham': ['vikings']
                }
            },
            {
                'other_driver:bar': {}
            }

        ]
        device_list = config.get_devices()
        m_get_config.assert_called_with()
        self.assertEqual(set(device_list), set(['foo', 'bar']))
        self.assertEqual({"device_type": "foo_device", "spam": "eggs"},
                         device_list['foo'])
        self.assertEqual({"device_type": "bar_device", "ham": "vikings"},
                         device_list['bar'])
Ejemplo n.º 3
0
 def test_get_devices(self, m_get_config):
     # get_config array
     m_get_config.return_value = [  # parsed_file dict
         {  # parsed_item str
             'genericswitch:foo':  # device_tag
             {  # parsed_file[device].items() dict
                 'device_type': ['foo_device'],  # {k: v[0] for k, v
                 'spam': ['eggs']
             },
             'genericswitch:bar':  # device_tag
             {  # parsed_file[device].items() dict
                 'device_type': ['bar_device'],  # {k: v[0] for k, v
                 'ham': ['vikings']
             }
         },
         {
             'other_driver:bar': {}
         }
     ]
     device_list = config.get_devices()
     m_get_config.assert_called_with()
     self.assertEqual(set(device_list), set(['foo', 'bar']))
     self.assertEqual({
         "device_type": "foo_device",
         "spam": "eggs"
     }, device_list['foo'])
     self.assertEqual({
         "device_type": "bar_device",
         "ham": "vikings"
     }, device_list['bar'])
Ejemplo n.º 4
0
    def initialize(self):
        """Perform driver initialization.

        Called after all drivers have been loaded and the database has
        been initialized. No abstract methods defined below will be
        called prior to this method being called.
        """
        LOG.info("PRUTH: GenericSwitchDriver")
        self.vfcHost = None

        gsw_devices = gsw_conf.get_devices()
        self.switches = {}
        for switch_info, device_cfg in gsw_devices.items():
            switch = devices.device_manager(device_cfg)
            if hasattr(devices, 'corsa_devices') and isinstance(
                    switch, devices.corsa_devices.corsa2100.CorsaDP2100):
                device_cfg['name'] = switch_info
            self.switches[switch_info] = switch
            if 'VFCHost' in device_cfg and device_cfg['VFCHost'] == 'True':
                self.vfcHost = switch
            if 'sharedNonByocVFC' in device_cfg:
                self.sharedNonByocVFC = device_cfg['sharedNonByocVFC']
            if 'sharedNonByocVLAN' in device_cfg:
                self.sharedNonByocVLAN = device_cfg['sharedNonByocVLAN']
            if 'sharedNonByocProvider' in device_cfg:
                self.sharedNonByocProvider = device_cfg[
                    'sharedNonByocProvider']

        LOG.info('Devices %s have been loaded', self.switches.keys())
        if not self.switches:
            LOG.error('No devices have been loaded')
    def initialize(self):
        """Perform driver initialization.

        Called after all drivers have been loaded and the database has
        been initialized. No abstract methods defined below will be
        called prior to this method being called.
        """

        gsw_devices = gsw_conf.get_devices()
        self.switches = {}
        for switch_info, device_cfg in gsw_devices.items():
            switch = devices.device_manager(device_cfg)
            self.switches[switch_info] = switch
        LOG.info(_LI('Devices %s have been loaded'), self.switches.keys())
Ejemplo n.º 6
0
    def initialize(self):
        """Perform driver initialization.

        Called after all drivers have been loaded and the database has
        been initialized. No abstract methods defined below will be
        called prior to this method being called.
        """

        gsw_devices = gsw_conf.get_devices()
        self.switches = {}
        for switch_info, device_cfg in gsw_devices.items():
            switch = devices.device_manager(device_cfg)
            self.switches[switch_info] = switch
        LOG.info(_LI('Devices %s have been loaded'), self.switches.keys())
Ejemplo n.º 7
0
    def delete_network_postcommit(self, context):
        """Delete a network.

        :param context: NetworkContext instance describing the current
        state of the network, prior to the call to delete it.

        Called after the transaction commits. Call can block, though
        will block the entire process so care should be taken to not
        drastically affect performance. Runtime errors are not
        expected, and will not prevent the resource from being
        deleted.
        """
        network = context.current
        provider_type = network['provider:network_type']
        segmentation_id = network['provider:segmentation_id']

        if provider_type == 'vlan' and segmentation_id:
            # Delete vlan on all switches from this driver
            gsw_devices = gsw_conf.get_devices()
            for device_cfg in gsw_devices.values():
                switch = devices.device_manager(device_cfg)
                switch.del_network(segmentation_id)
    def delete_network_postcommit(self, context):
        """Delete a network.

        :param context: NetworkContext instance describing the current
        state of the network, prior to the call to delete it.

        Called after the transaction commits. Call can block, though
        will block the entire process so care should be taken to not
        drastically affect performance. Runtime errors are not
        expected, and will not prevent the resource from being
        deleted.
        """
        network = context.current
        provider_type = network['provider:network_type']
        segmentation_id = network['provider:segmentation_id']

        if provider_type == 'vlan' and segmentation_id:
            # Delete vlan on all switches from this driver
            gsw_devices = gsw_conf.get_devices()
            for device_cfg in gsw_devices.values():
                switch = devices.device_manager(device_cfg)
                switch.del_network(segmentation_id)
Ejemplo n.º 9
0
    def initialize(self):
        """Perform driver initialization.

        Called after all drivers have been loaded and the database has
        been initialized. No abstract methods defined below will be
        called prior to this method being called.
        """

        gsw_devices = gsw_conf.get_devices()
        self.switches = {}
        for switch_info, device_cfg in gsw_devices.items():
            switch = devices.device_manager(device_cfg)
            self.switches[switch_info] = switch
        LOG.info('Devices %s have been loaded', self.switches.keys())
        if not self.switches:
            LOG.error('No devices have been loaded')
        self.warned_del_network = False

        registry.subscribe(self.add_subports_to_trunk, constants.SUBPORTS,
                           events.PRECOMMIT_CREATE)

        registry.subscribe(self.remove_subports_from_trunk, constants.SUBPORTS,
                           events.PRECOMMIT_DELETE)
Ejemplo n.º 10
0
    def create_network_postcommit(self, context):
        """Create a network.

        :param context: NetworkContext instance describing the new
        network.

        Called after the transaction commits. Call can block, though
        will block the entire process so care should be taken to not
        drastically affect performance. Raising an exception will
        cause the deletion of the resource.
        """

        network = context.current
        network_id = network['id']
        provider_type = network['provider:network_type']
        segmentation_id = network['provider:segmentation_id']

        if provider_type == 'vlan' and segmentation_id:
            # Create vlan on all switches from this driver
            gsw_devices = gsw_conf.get_devices()
            for device_cfg in gsw_devices.values():
                switch = devices.device_manager(device_cfg)
                switch.add_network(segmentation_id, network_id)
    def create_network_postcommit(self, context):
        """Create a network.

        :param context: NetworkContext instance describing the new
        network.

        Called after the transaction commits. Call can block, though
        will block the entire process so care should be taken to not
        drastically affect performance. Raising an exception will
        cause the deletion of the resource.
        """

        network = context.current
        network_id = network['id']
        provider_type = network['provider:network_type']
        segmentation_id = network['provider:segmentation_id']

        if provider_type == 'vlan' and segmentation_id:
            # Create vlan on all switches from this driver
            gsw_devices = gsw_conf.get_devices()
            for device_cfg in gsw_devices.values():
                switch = devices.device_manager(device_cfg)
                switch.add_network(segmentation_id, network_id)
Ejemplo n.º 12
0
    def bind_port(self, context):
        """Attempt to bind a port.

        :param context: PortContext instance describing the port

        This method is called outside any transaction to attempt to
        establish a port binding using this mechanism driver. Bindings
        may be created at each of multiple levels of a hierarchical
        network, and are established from the top level downward. At
        each level, the mechanism driver determines whether it can
        bind to any of the network segments in the
        context.segments_to_bind property, based on the value of the
        context.host property, any relevant port or network
        attributes, and its own knowledge of the network topology. At
        the top level, context.segments_to_bind contains the static
        segments of the port's network. At each lower level of
        binding, it contains static or dynamic segments supplied by
        the driver that bound at the level above. If the driver is
        able to complete the binding of the port to any segment in
        context.segments_to_bind, it must call context.set_binding
        with the binding details. If it can partially bind the port,
        it must call context.continue_binding with the network
        segments to be used to bind at the next lower level.

        If the binding results are committed after bind_port returns,
        they will be seen by all mechanism drivers as
        update_port_precommit and update_port_postcommit calls. But if
        some other thread or process concurrently binds or updates the
        port, these binding results will not be committed, and
        update_port_precommit and update_port_postcommit will not be
        called on the mechanism drivers with these results. Because
        binding results can be discarded rather than committed,
        drivers should avoid making persistent state changes in
        bind_port, or else must ensure that such state changes are
        eventually cleaned up.

        Implementing this method explicitly declares the mechanism
        driver as having the intention to bind ports. This is inspected
        by the QoS service to identify the available QoS rules you
        can use with ports.
        """

        port = context.current
        binding_profile = port['binding:profile']
        local_link_information = binding_profile.get('local_link_information',
                                                     False)
        vnic_type = port['binding:vnic_type']
        if vnic_type == 'baremetal' and local_link_information:
            gsw_devices = gsw_conf.get_devices()
            switch_info = local_link_information[0].get('switch_info')
            if switch_info not in gsw_devices:
                raise exc.GenericSwitchConfigError(switch=switch_info)
            port_id = local_link_information[0].get('port_id')
            segments = context.segments_to_bind
            segmentation_id = segments[0]['segmentation_id']
            # If segmentation ID is None, set vlan 1
            if not segmentation_id:
                segmentation_id = '1'
            LOG.debug("Putting port {port} on {switch_info} to vlan: "
                      "{segmentation_id}".format(
                          port=port_id,
                          switch_info=switch_info,
                          segmentation_id=segmentation_id))
            switch = devices.device_manager(gsw_devices[switch_info])
            # Move port to network
            switch.plug_port_to_network(port_id, segmentation_id)
            context.set_binding(segments[0][driver_api.ID],
                                portbindings.VIF_TYPE_OTHER, {},
                                status=const.PORT_STATUS_ACTIVE)
    def bind_port(self, context):
        """Attempt to bind a port.

        :param context: PortContext instance describing the port

        This method is called outside any transaction to attempt to
        establish a port binding using this mechanism driver. Bindings
        may be created at each of multiple levels of a hierarchical
        network, and are established from the top level downward. At
        each level, the mechanism driver determines whether it can
        bind to any of the network segments in the
        context.segments_to_bind property, based on the value of the
        context.host property, any relevant port or network
        attributes, and its own knowledge of the network topology. At
        the top level, context.segments_to_bind contains the static
        segments of the port's network. At each lower level of
        binding, it contains static or dynamic segments supplied by
        the driver that bound at the level above. If the driver is
        able to complete the binding of the port to any segment in
        context.segments_to_bind, it must call context.set_binding
        with the binding details. If it can partially bind the port,
        it must call context.continue_binding with the network
        segments to be used to bind at the next lower level.

        If the binding results are committed after bind_port returns,
        they will be seen by all mechanism drivers as
        update_port_precommit and update_port_postcommit calls. But if
        some other thread or process concurrently binds or updates the
        port, these binding results will not be committed, and
        update_port_precommit and update_port_postcommit will not be
        called on the mechanism drivers with these results. Because
        binding results can be discarded rather than committed,
        drivers should avoid making persistent state changes in
        bind_port, or else must ensure that such state changes are
        eventually cleaned up.

        Implementing this method explicitly declares the mechanism
        driver as having the intention to bind ports. This is inspected
        by the QoS service to identify the available QoS rules you
        can use with ports.
        """

        port = context.current
        binding_profile = port['binding:profile']
        local_link_information = binding_profile.get('local_link_information',
                                                     False)
        vnic_type = port['binding:vnic_type']
        if vnic_type == 'baremetal' and local_link_information:
            gsw_devices = gsw_conf.get_devices()
            switch_info = local_link_information[0].get('switch_info')
            if switch_info not in gsw_devices:
                raise exc.GenericSwitchConfigError(switch=switch_info)
            port_id = local_link_information[0].get('port_id')
            segments = context.segments_to_bind
            segmentation_id = segments[0]['segmentation_id']
            # If segmentation ID is None, set vlan 1
            if not segmentation_id:
                segmentation_id = '1'
            LOG.debug("Putting port {port} on {switch_info} to vlan: "
                      "{segmentation_id}".format(
                          port=port_id,
                          switch_info=switch_info,
                          segmentation_id=segmentation_id))
            switch = devices.device_manager(gsw_devices[switch_info])
            # Move port to network
            switch.plug_port_to_network(port_id, segmentation_id)
            context.set_binding(segments[0][driver_api.ID],
                                portbindings.VIF_TYPE_OTHER, {},
                                status=const.PORT_STATUS_ACTIVE)