コード例 #1
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
            for switch in self.switches.values():
                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.config['ip'],
                               'exc': e})
コード例 #2
0
def _load_failure_hook(manager, entrypoint, exception):
    LOG.error(_LE("Driver manager %(manager)s failed to load device plugin "
                  "%(entrypoint)s: %(exp)s"),
              {'manager': manager, 'entrypoint': entrypoint, 'exp': exception})
    raise gsw_exc.GenericSwitchEntrypointLoadError(
        ep=entrypoint,
        err=exception)
コード例 #3
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
            for switch in self.switches.values():
                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.config['ip'],
                               'exc': e})
コード例 #4
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
            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})
コード例 #5
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
            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})
コード例 #6
0
def _load_failure_hook(manager, entrypoint, exception):
    LOG.error(
        _LE("Driver manager %(manager)s failed to load device plugin "
            "%(entrypoint)s: %(exp)s"), {
                'manager': manager,
                'entrypoint': entrypoint,
                'exp': exception
            })
    raise gsw_exc.GenericSwitchEntrypointLoadError(ep=entrypoint,
                                                   err=exception)
コード例 #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())
        if not self.switches:
            LOG.error(_LE('No devices have been loaded'))
コード例 #8
0
    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})