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
            for switch_name, switch in self.switches.items():
                try:
                    switch.add_network(segmentation_id, network_id)
                except Exception as e:
                    LOG.error(_LE("Failed to create network %(net_id)s "
                                  "on device: %(switch)s, reason: %(exc)s"),
                              {'net_id': network_id,
                               'switch': switch_name,
                               'exc': e})
                LOG.info(_LI('Network %(net_id)s has been added on device '
                             '%(device)s'), {'net_id': network['id'],
                                             'device': switch_name})
    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
            for switch_name, switch in self.switches.items():
                try:
                    switch.del_network(segmentation_id)
                except Exception as e:
                    LOG.error(_LE("Failed to delete network %(net_id)s "
                                  "on device: %(switch)s, reason: %(exc)s"),
                              {'net_id': network['id'],
                               'switch': switch_name,
                               'exc': e})
                LOG.info(_LI('Network %(net_id)s has been deleted on device '
                             '%(device)s'), {'net_id': network['id'],
                                             'device': switch_name})
예제 #3
0
 def plug_port_to_network(self, port, segmentation_id):
     self._exec_commands(
         self.PLUG_PORT_TO_NETWORK,
         port=port,
         segmentation_id=segmentation_id)
     LOG.info(_LI("Port %(port)s has been added to vlan "
                  "%(segmentation_id)d"),
              {'port': port, 'segmentation_id': segmentation_id})
예제 #4
0
 def delete_port(self, port, segmentation_id):
     self._exec_commands(
         self.DELETE_PORT,
         port=port,
         segmentation_id=segmentation_id)
     LOG.info(_LI("Port %(port)s has been removed from vlan "
                  "%(segmentation_id)d"),
              {'port': port, 'segmentation_id': segmentation_id})
예제 #5
0
 def add_network(self, segmentation_id, network_id):
     # NOTE(zhenguo): Remove dashes from uuid as on most devices 32 chars
     # is the max length of vlan name.
     network_id = uuid.UUID(network_id).hex
     self._exec_commands(
         self.ADD_NETWORK,
         segmentation_id=segmentation_id,
         network_id=network_id)
     LOG.info(_LI('Network %s has been added'), network_id)
    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())
예제 #7
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())
    def delete_port_postcommit(self, context):
        """Delete a port.

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

        Called after the transaction completes. 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.
        """

        port = context.current
        binding_profile = port['binding:profile']
        local_link_information = binding_profile.get('local_link_information')
        vnic_type = port['binding:vnic_type']
        if vnic_type == 'baremetal' and local_link_information:
            switch_info = local_link_information[0].get('switch_info')
            if switch_info not in self.switches:
                return
            port_id = local_link_information[0].get('port_id')
            network = context.network.current
            segmentation_id = network.get('provider:segmentation_id', '1')
            LOG.debug("Deleting port {port} on {switch_info} from vlan: "
                      "{segmentation_id}".format(
                          port=port_id,
                          switch_info=switch_info,
                          segmentation_id=segmentation_id))
            try:
                self.switches[switch_info].delete_port(port_id,
                                                       segmentation_id)
            except Exception as e:
                LOG.error(_LE("Failed to delete port %(port_id)s "
                              "on device: %(switch)s from network %(net_id)s "
                              "reason: %(exc)s"),
                          {'port_id': port['id'], 'net_id': network['id'],
                           'switch': switch_info, 'exc': e})
                raise e
            LOG.info(_LI('Port %(port_id)s has been deleted from network '
                         ' %(net_id)s on device %(device)s'),
                     {'port_id': port['id'], 'net_id': network['id'],
                      'device': switch_info})
예제 #9
0
 def del_network(self, segmentation_id):
     self._exec_commands(
         self.DELETE_NETWORK,
         segmentation_id=segmentation_id)
     LOG.info(_LI('Network %s has been deleted'), segmentation_id)
예제 #10
0
 def add_network(self, segmentation_id, network_id):
     self._exec_commands(
         self.ADD_NETWORK,
         segmentation_id=segmentation_id,
         network_id=network_id)
     LOG.info(_LI('Network %s has been added'), network_id)
    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')
        vnic_type = port['binding:vnic_type']
        if vnic_type == 'baremetal' and local_link_information:
            switch_info = local_link_information[0].get('switch_info')
            if switch_info not in self.switches:
                return
            port_id = local_link_information[0].get('port_id')
            segments = context.segments_to_bind
            segmentation_id = segments[0].get('segmentation_id')
            # If segmentation ID is None, set vlan 1
            if not segmentation_id:
                segmentation_id = '1'
            provisioning_blocks.add_provisioning_component(
                context._plugin_context, port['id'], resources.PORT,
                GENERIC_SWITCH_ENTITY)
            LOG.debug("Putting port {port} on {switch_info} to vlan: "
                      "{segmentation_id}".format(
                          port=port_id,
                          switch_info=switch_info,
                          segmentation_id=segmentation_id))
            # Move port to network
            self.switches[switch_info].plug_port_to_network(port_id,
                                                            segmentation_id)
            LOG.info(_LI("Successfully bound port %(port_id)s in segment "
                         " %(segment_id)s on device %(device)s"),
                     {'port_id': port['id'], 'device': switch_info,
                      'segment_id': segmentation_id})
            context.set_binding(segments[0][driver_api.ID],
                                portbindings.VIF_TYPE_OTHER, {})
예제 #12
0
 def add_network(self, segmentation_id, network_id):
     self._exec_commands(self.ADD_NETWORK,
                         segmentation_id=segmentation_id,
                         network_id=network_id)
     LOG.info(_LI('Network %s has been added'), network_id)