networking_generic_switch package

Subpackages

Submodules

networking_generic_switch.batching module

exception networking_generic_switch.batching.ShutdownTimeout

Bases: Exception

Exception raised when shutdown timeout is exceeded.

class networking_generic_switch.batching.SwitchBatch(switch_name, etcd_url=None, switch_queue=None)

Bases: object

do_batch(device, cmd_set, timeout=300)

Batch up switch configuration commands to reduce overheads.

We collect together the iterables in the cmd_set, and execute them toegether in a single larger batch.

Parameters:
  • device – a NetmikoSwitch device object

  • cmd_set – an iterable of commands

Returns:

output string generated by this command set

class networking_generic_switch.batching.SwitchQueue(switch_name, etcd_client)

Bases: object

EXEC_LOCK = '/ngs/batch/%s/execute_lock'
INPUT_ITEM_KEY = '/ngs/batch/%s/input/%s'
INPUT_PREFIX = '/ngs/batch/%s/input/'
RESULT_ITEM_KEY = '/ngs/batch/%s/output/%s'
acquire_worker_lock(item, acquire_timeout=300, lock_ttl=120, wait=None)

Wait for lock needed to call record_result.

This blocks until the work queue is empty of the switch lock is acquired. If we timeout waiting for the lock we raise an exception.

add_batch(cmds)

Clients add batch, given key events.

Each batch is given an uuid that is used to generate both and input and result key in etcd.

First we watch for any results, second we write the input in a location that the caller of get_batches will be looking.

No locks are required when calling this function to send work to the workers, and start waiting for results.

Parameters:

cmds – an iterable of commands

Returns:

a SwitchQueueItem object

get_batches(item=None)

Return a list of the event dicts written in wait for result.

This is called both with or without getting a lock to get the latest list of work that has send to the per switch queue in etcd.

Parameters:

item – Optional SwitchQueueItem object. If provided, only batches added up to and including this item are returned.

record_result(batch)

Record the result from executing given command set.

We assume that a lock is held before getting a fresh list of batches, executing them, and then calling this record results function, before finally dropping the lock.

wait_for_result(item, timeout)

Wait for the result of a command batch.

Parameters:
  • item – SwitchQueueItem object returned by add_batch

  • timeout – wait timeout in seconds

Returns:

output string generated by this command set

Raises:

Exception if waiting times out or the command batch was unsuccessful

class networking_generic_switch.batching.SwitchQueueItem(uuid, create_revision)

Bases: object

An item in the queue.

networking_generic_switch.config module

networking_generic_switch.config.get_devices()

Parse supplied config files and fetch defined supported devices.

networking_generic_switch.exceptions module

exception networking_generic_switch.exceptions.GenericSwitchBatchError(**kwargs)

Bases: GenericSwitchException

message = 'Batching error: %(device)s, error: %(error)s'
exception networking_generic_switch.exceptions.GenericSwitchConfigException(**kwargs)

Bases: NeutronException

message = '%(option)s must be one of: %(allowed_options)s'
exception networking_generic_switch.exceptions.GenericSwitchEntrypointLoadError(**kwargs)

Bases: GenericSwitchException

message = 'Failed to load entrypoint %(ep)s: %(err)s'
exception networking_generic_switch.exceptions.GenericSwitchException(**kwargs)

Bases: NeutronException

message = '%(method)s failed.'
exception networking_generic_switch.exceptions.GenericSwitchNetmikoConfigError(**kwargs)

Bases: GenericSwitchException

message = 'Netmiko configuration error: %(config)s, error: %(error)s'
exception networking_generic_switch.exceptions.GenericSwitchNetmikoConnectError(**kwargs)

Bases: GenericSwitchException

message = 'Netmiko connection error: %(config)s, error: %(error)s'
exception networking_generic_switch.exceptions.GenericSwitchNetmikoMethodError(**kwargs)

Bases: GenericSwitchException

message = 'Can not parse arguments: commands %(cmds)s, args %(args)s'
exception networking_generic_switch.exceptions.GenericSwitchNetmikoNotSupported(**kwargs)

Bases: GenericSwitchException

message = 'Netmiko does not support device type %(device_type)s'
exception networking_generic_switch.exceptions.GenericSwitchNetworkNameFormatInvalid(**kwargs)

Bases: GenericSwitchException

message = "Invalid value for 'ngs_network_name_format': %(name_format)s. Valid format options include 'network_id' and 'segmentation_id'"

networking_generic_switch.generic_switch_mech module

class networking_generic_switch.generic_switch_mech.GenericSwitchDriver

Bases: MechanismDriver

bind_port(context)

Attempt to bind a port.

Parameters:

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.

create_network_postcommit(context)

Create a network.

Parameters:

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.

create_network_precommit(context)

Allocate resources for a new network.

Parameters:

context – NetworkContext instance describing the new network.

Create a new network, allocating resources as necessary in the database. Called inside transaction context on session. Call cannot block. Raising an exception will result in a rollback of the current transaction.

create_port_postcommit(context)

Create a port.

Parameters:

context – PortContext instance describing the port.

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

create_port_precommit(context)

Allocate resources for a new port.

Parameters:

context – PortContext instance describing the port.

Create a new port, allocating resources as necessary in the database. Called inside transaction context on session. Call cannot block. Raising an exception will result in a rollback of the current transaction.

create_subnet_postcommit(context)

Create a subnet.

Parameters:

context – SubnetContext instance describing the new subnet.

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.

create_subnet_precommit(context)

Allocate resources for a new subnet.

Parameters:

context – SubnetContext instance describing the new subnet.

rt = context.current device_id = port[‘device_id’] device_owner = port[‘device_owner’] Create a new subnet, allocating resources as necessary in the database. Called inside transaction context on session. Call cannot block. Raising an exception will result in a rollback of the current transaction.

delete_network_postcommit(context)

Delete a network.

Parameters:

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.

delete_network_precommit(context)

Delete resources for a network.

Parameters:

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

Delete network resources previously allocated by this mechanism driver for a network. Called inside transaction context on session. Runtime errors are not expected, but raising an exception will result in rollback of the transaction.

delete_port_postcommit(context)

Delete a port.

Parameters:

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.

delete_port_precommit(context)

Delete resources of a port.

Parameters:

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

Called inside transaction context on session. Runtime errors are not expected, but raising an exception will result in rollback of the transaction.

delete_subnet_postcommit(context)

Delete a subnet.

Parameters:

context – SubnetContext instance describing the current state of the subnet, 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.

delete_subnet_precommit(context)

Delete resources for a subnet.

Parameters:

context – SubnetContext instance describing the current state of the subnet, prior to the call to delete it.

Delete subnet resources previously allocated by this mechanism driver for a subnet. Called inside transaction context on session. Runtime errors are not expected, but raising an exception will result in rollback of the transaction.

initialize()

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.

update_network_postcommit(context)

Update a network.

Parameters:

context – NetworkContext instance describing the new state of the network, as well as the original state prior to the update_network call.

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.

update_network_postcommit is called for all changes to the network state. It is up to the mechanism driver to ignore state or state changes that it does not know or care about.

update_network_precommit(context)

Update resources of a network.

Parameters:

context – NetworkContext instance describing the new state of the network, as well as the original state prior to the update_network call.

Update values of a network, updating the associated resources in the database. Called inside transaction context on session. Raising an exception will result in rollback of the transaction.

update_network_precommit is called for all changes to the network state. It is up to the mechanism driver to ignore state or state changes that it does not know or care about.

update_port_postcommit(context)

Update a port.

Parameters:

context – PortContext instance describing the new state of the port, as well as the original state prior to the update_port call.

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

update_port_postcommit is called for all changes to the port state. It is up to the mechanism driver to ignore state or state changes that it does not know or care about.

update_port_precommit(context)

Update resources of a port.

Parameters:

context – PortContext instance describing the new state of the port, as well as the original state prior to the update_port call.

Called inside transaction context on session to complete a port update as defined by this mechanism driver. Raising an exception will result in rollback of the transaction.

update_port_precommit is called for all changes to the port state. It is up to the mechanism driver to ignore state or state changes that it does not know or care about.

update_subnet_postcommit(context)

Update a subnet.

Parameters:

context – SubnetContext instance describing the new state of the subnet, as well as the original state prior to the update_subnet call.

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.

update_subnet_postcommit is called for all changes to the subnet state. It is up to the mechanism driver to ignore state or state changes that it does not know or care about.

update_subnet_precommit(context)

Update resources of a subnet.

Parameters:

context – SubnetContext instance describing the new state of the subnet, as well as the original state prior to the update_subnet call.

Update values of a subnet, updating the associated resources in the database. Called inside transaction context on session. Raising an exception will result in rollback of the transaction.

update_subnet_precommit is called for all changes to the subnet state. It is up to the mechanism driver to ignore state or state changes that it does not know or care about.

networking_generic_switch.locking module

class networking_generic_switch.locking.PoolLock(coordinator, locks_pool_size=1, locks_prefix='ngs-', timeout=0)

Bases: object

Tooz lock wrapper for pools of locks

If tooz coordinator is provided, it will attempt to grab any lock from a predefined set of names, with configurable set size (lock pool), and keep attempting for until given timeout is reached.

Module contents