switchmng.database package

Submodules

switchmng.database.add module

switchmng.database.add.add_connector(session, **kwargs)

Create a new connector and add it to the database.

Parameters

kwargs – Parameters for new connector. Possible parameters are public attributes of Connector object but in a json compatible representation (as nested dict structure)

Return type

Connector

Returns

The newly added connector

switchmng.database.add.add_network_protocol(session, **kwargs)

Create a new network protocol and add it to the database.

Parameters

kwargs – Parameters for new network protocol. Possible parameters are public attributes of NetworkProtocol object but in a json compatible representation (as nested dict structure)

Return type

NetworkProtocol

Returns

The newly added network protocol

switchmng.database.add.add_port_model(session, switch_model_resource_id, **kwargs)

Add a new port model to a switch model and add it to the database.

Parameters
  • switch_model_resource_id (str) – Resource identifier uniquely identifying the switch model to add the new port model to. (See SwitchModel for what attribute is the resource identifier)

  • kwargs – Parameters for new port model. Possible parameters are public attributes of PortModel object but in a json compatible representation (as nested dict structure)

Return type

PortModel

Returns

The newly added port model

switchmng.database.add.add_switch(session, **kwargs)

Create a new switch and add it to the database.

Parameters

kwargs – Parameters for new switch. Possible parameters are public attributes of Switch object but in a json compatible representation (as nested dict structure)

Return type

Switch

Returns

The newly added switch

switchmng.database.add.add_switch_model(session, **kwargs)

Create a new switch model and add it to the database.

Parameters

kwargs – Parameters for new switch model. Possible parameters are public attributes of SwitchModel object but in a json compatible representation (as nested dict structure)

Return type

SwitchModel

Returns

The newly added switch model

switchmng.database.add.add_vlan(session, **kwargs)

Create a new vlan and add it to the database.

Parameters

kwargs – Parameters for new vlan. Possible parameters are public attributes of Vlan object but in a json compatible representation (as nested dict structure)

Return type

Vlan

Returns

The newly added vlan

switchmng.database.delete module

switchmng.database.delete.delete_connector(session, resource_id)

Delete a connector from the database.

Can only delete a connector from the database if it is not still in use by a port of a switch model. Will only delete connector if there is not still a switch model which uses the given connector on one of its ports.

Parameters

resource_id (str) – Resource identifier uniquely identifying the connector to delete. (See Connector for what attribute is the resource identifier)

Return type

None

switchmng.database.delete.delete_network_protocol(session, resource_id)

Delete a network protocol from the database.

Can only delete a network protocol from the database if it is not still in use by a port of a switch model. Will only delete network protocol if there is not still a switch model which uses the given network protocol on one of its ports.

Parameters

resource_id (str) – Resource identifier uniquely identifying the network protocol to delete. (See NetworkProtocol for what attribute is the resource identifier)

Return type

None

switchmng.database.delete.delete_port_model(session, switch_model_resource_id, port_model_resource_id)

Delete a port model from a switch model from the database.

Parameters
  • switch_model_resource_id (str) – Resource identifier uniquely identifying the switch model containing the port model to delete. (See SwitchModel for what attribute is the resource identifier)

  • port_model_resource_id (str) – Resource identifier together with switch model uniquely identifying the port model to delete. (See PortModel for what attribute is the resource identifier)

Return type

None

switchmng.database.delete.delete_switch(session, resource_id)

Delete a switch from the database.

Parameters

resource_id (str) – Resource identifier uniquely identifying the switch to delete. (See Switch for what attribute is the resource identifier)

Return type

None

switchmng.database.delete.delete_switch_model(session, resource_id)

Delete a switch model from the database.

Can only delete a switch model from the database if it is not still in use by a switch. Will only delete switch model if there is not still a switch which uses the given switch model as its model.

Parameters

resource_id (str) – Resource identifier uniquely identifying the switch model to delete. (See SwitchModel for what attribute is the resource identifier)

Return type

None

switchmng.database.delete.delete_vlan(session, resource_id)

Delete a vlan from the database.

Can only delete a vlan from the database if it is not still in use by a port of a switch. Will only delete vlan if there is not still a switch which uses the given vlan on one of its ports.

Parameters

resource_id (str) – Resource identifier uniquely identifying the vlan to delete. (See Vlan for what attribute is the resource identifier)

Return type

None

switchmng.database.helper module

switchmng.database.helper.port_model_from_dict(session, **kwargs)

Create port model.

Return type

PortModel

switchmng.database.helper.port_models_from_dict(session, ports)

Convert port models from list of dict of strings to list of port model objects.

Return type

List[PortModel]

Parameters

ports (List[dict]) –

switchmng.database.helper.ports_from_dict(session, ports)

Convert ports from list of dict of strings to list of port objects.

Return type

List[Port]

Parameters

ports (List[dict]) –

switchmng.database.modify module

switchmng.database.modify.modify_connector(session, resource_id, **kwargs)

Modify a Connector object in the database.

All given attributes of connector will be modified. Attributes not given will not be changed and will keep their current state.

Parameters
  • resource_id (str) – Resource identifier uniquely identifying the connector to modify

  • kwargs – Attributes of connector to change. Possible parameters are public attributes of Connector object but in a json compatible representation (as nested dict structure)

Return type

Connector

Returns

The modified connector object

switchmng.database.modify.modify_network_protocol(session, resource_id, **kwargs)

Modify a NetworkProtocol object in the database.

All given attributes of network protocol will be modified. Attributes not given will not be changed and will keep their current state.

Parameters
  • resource_id (str) – Resource identifier uniquely identifying the network protocol to modify. (See NetworkProtocol for what attribute is the resource identifier)

  • kwargs – Attributes of network protocol to change. Possible parameters are public attributes of NetworkProtocol object but in a json compatible representation (as nested dict structure)

Return type

NetworkProtocol

Returns

The modified network protocol object

switchmng.database.modify.modify_port(session, switch_resource_id, port_resource_id, **kwargs)

Modify a Port object in the database.

All given attributes of port will be modified. Attributes not given will not be changed and will keep their current state.

Parameters
  • switch_resource_id (str) – Resource identifier uniquely identifying the switch containing the port to modify. (See Switch for what attribute is the resource identifier)

  • port_resource_id (str) – Resource identifier together with switch uniquely identifying the port to modify. (See Port for what attribute is the resource identifier)

  • kwargs – Attributes of port to change. Possible parameters are public attributes of Port object but in a json compatible representation (as nested dict structure)

Return type

Port

Returns

The modified port

switchmng.database.modify.modify_port_model(session, switch_model_resource_id, port_model_resource_id, **kwargs)

Modify a PortModel object in the database.

All given attributes of port model will be modified. Attributes not given will not be changed and will keep their current state.

Parameters
  • switch_model_resource_id (str) – Resource identifier uniquely identifying the switch model containing the port model to modify. (See SwitchModel for what attribute is the resource identifier)

  • port_model_resource_id (str) – Resource identifier together with switch model uniquely identifying the port model to modify. (See PortModel for what attribute is the resource identifier)

  • kwargs – Attributes of port model to change. Possible parameters are public attributes of PortModel object but in a json compatible representation (as nested dict structure)

Return type

PortModel

Returns

The modified port model

switchmng.database.modify.modify_switch(session, resource_id, **kwargs)

Modify a Switch object in the database.

All given attributes of switch will be modified. Attributes not given will not be changed and will keep their current state.

Parameters
  • resource_id (str) – Resource identifier uniquely identifying the switch to modify. (See Switch for what attribute is the resource identifier)

  • kwargs – Attributes of switch to change. Possible parameters are public attributes of Switch object but in a json compatible representation (as nested dict structure)

Return type

Switch

Returns

The modified switch

switchmng.database.modify.modify_switch_model(session, resource_id, **kwargs)

Modify a SwitchModel object in the database.

All given attributes of switch model will be modified. Attributes not given will not be changed and will keep their current state.

Parameters
  • resource_id (str) – Resource identifier uniquely identifying the switch model to modify. (See SwitchModel for what attribute is the resource identifier)

  • kwargs – Attributes of switch model to change. Possible parameters are public attributes of SwitchModel object but in a json compatible representation (as nested dict structure)

Return type

SwitchModel

Returns

The modified switch model

switchmng.database.modify.modify_vlan(session, resource_id, **kwargs)

Modify a Vlan object in the database.

All given attributes of vlan will be modified. Attributes not given will not be changed and will keep their current state.

Parameters
  • resource_id (str) – Resource identifier uniquely identifying the vlan to modify. (See Vlan for what attribute is the resource identifier)

  • kwargs – Attributes of vlan to change. Possible parameters are public attributes of Vlan object but in a json compatible representation (as nested dict structure)

Return type

Vlan

Returns

The modified vlan object

switchmng.database.query module

switchmng.database.query.query_connector(session, resource_id)

Retrieve Connector object from database.

Query the database for a Connector object with given resource identifier and return it.

Parameters

resource_id (str) – Resource identifier uniquely identifying the connector to return. (See Connector for what attribute is the resource identifier)

Return type

Optional[Connector]

Returns

The connector object matching the given resource identifier or None if no matching connector resource was found.

switchmng.database.query.query_connectors(session, **kwargs)

Retrieve multiple Connector objects from database.

# TODO: Implement and document query_connectors() correctly

switchmng.database.query.query_network_protocol(session, resource_id)

Retrieve NetworkProtocol object from database.

Query the database for a NetworkProtocol object with given resource identifier and return it.

Parameters

resource_id (str) – Resource identifier uniquely identifying the network protocol to return. (See NetworkProtocol for what attribute is the resource identifier)

Return type

Optional[NetworkProtocol]

Returns

The network protocol object matching the given resource identifier or None if no matching network protocol resource was found.

switchmng.database.query.query_network_protocols(session, **kwargs)

Retrieve multiple NetworkProtocol objects from database.

# TODO: Implement and document query_network_protocols() correctly

switchmng.database.query.query_port(session, switch_resource_id, port_resource_id)

Retrieve Port object from database.

Query the database for a Port object with given resource identifier on switch with given resource identifier and return it.

Parameters
  • switch_resource_id (str) – Resource identifier uniquely identifying the switch containing the port to return. (See Switch for what attribute is the resource identifier)

  • port_resource_id (str) – Resource identifier together with switch uniquely identifying the port to return. (See Port for what attribute is the resource identifier)

Return type

Optional[Port]

Returns

The port object matching the given resource identifiers or None if no matching port resource was found.

switchmng.database.query.query_port_model(session, switch_model_resource_id, port_model_resource_id)

Retrieve PortModel object from database.

Query the database for a PortModel object with given resource identifier on switch model with given resource identifier and return it.

Parameters
  • switch_model_resource_id (str) – Resource identifier uniquely identifying the switch model containing the port model to return. (See SwitchModel for what attribute is the resource identifier)

  • port_model_resource_id (str) – Resource identifier together with switch model uniquely identifying the port model to return. (See PortModel for what attribute is the resource identifier)

Return type

Optional[PortModel]

Returns

The port model object matching the given resource identifiers or None if no matching port model resource was found.

switchmng.database.query.query_port_models(session, switch_model_resource_id, **kwargs)

Retrieve multiple PortModel objects from database.

switch_model_resource_id is optional

# TODO: Implement and document query_port_models() correctly

switchmng.database.query.query_ports(session, switch_resource_id, **kwargs)

Retrieve multiple Port objects from database.

switch_resource_id is optional

# TODO: Implement and document query_ports() correctly

switchmng.database.query.query_switch(session, resource_id)

Retrieve Switch object from database.

Query the database for a Switch object with given resource identifier and return it.

Parameters

resource_id (str) – Resource identifier uniquely identifying the switch to return. (See Switch for what attribute is the resource identifier)

Return type

Optional[Switch]

Returns

The switch object matching the given resource identifier or None if no matching switch resource was found.

switchmng.database.query.query_switch_model(session, resource_id)

Retrieve SwitchModel object from database.

Query the database for a SwitchModel object with given resource identifier and return it.

Parameters

resource_id (str) – Resource identifier uniquely identifying the switch model to return. (See SwitchModel for what attribute is the resource identifier)

Return type

Optional[SwitchModel]

Returns

The switch model object matching the given resource identifier or None if no matching switch model resource was found.

switchmng.database.query.query_switch_models(session, **kwargs)

Retrieve multiple SwitchModel objects from database.

# TODO: Implement and document query_switch_models() correctly

switchmng.database.query.query_switches(session, **kwargs)

Retrieve multiple Switch objects from database.

# TODO: Implement and document query_switches() correctly

switchmng.database.query.query_vlan(session, resource_id)

Retrieve Vlan object from database.

Query the database for a Vlan object with given resource identifier and return it.

Parameters

resource_id (str) – Resource identifier uniquely identifying the vlan to return. (See Vlan for what attribute is the resource identifier)

Return type

Optional[Vlan]

Returns

The vlan object matching the given resource identifier or None if no matching vlan resource was found.

switchmng.database.query.query_vlans(session, **kwargs)

Retrieve multiple Vlan objects from database.

# TODO: Implement and document query_vlans() correctly

switchmng.database.set module

switchmng.database.set.set_connector(session, resource_id, **kwargs)

Set a Connector in the database to a given state.

Connector identified by given resource identifier may already exist. If it does not already exist it will be created.

All attributes of connector will be set to given values. Attributes not given but present in already existing Connector will be set to None or [] or other representation of “not set”.

Parameters
  • resource_id (Optional[str]) – Resource identifier uniquely identifying the connector to modify. (See Connector for what attribute is the resource identifier)

  • kwargs – Attributes of connector to change. Possible parameters are public attributes of Connector object but in a json compatible representation (as nested dict structure)

Return type

Connector

Returns

The modified or created connector

switchmng.database.set.set_network_protocol(session, resource_id, **kwargs)

Set a NetworkProtocol in the database to a given state.

NetworkProtocol identified by given resource identifier may already exist. If it does not already exist it will be created.

All attributes of network protocol will be set to given values. Attributes not given but present in already existing NetworkProtocol will be set to None or [] or other representation of “not set”.

Parameters
  • resource_id (Optional[str]) – Resource identifier uniquely identifying the network protocol to modify. (See NetworkProtocol for what attribute is the resource identifier)

  • kwargs – Attributes of network protocol to change. Possible parameters are public attributes of NetworkProtocol object but in a json compatible representation (as nested dict structure)

Return type

NetworkProtocol

Returns

The modified or created network protocol

switchmng.database.set.set_port(session, switch_resource_id, port_resource_id, **kwargs)

Set a Port in the database to a given state.

Port identified by given resource identifier on switch identified by given resource identifier may already exist. If it does not already exist it will be created.

All attributes of port will be set to given values. Attributes not given but present in already existing Port will be set to None or [] or other representation of “not set”.

Parameters
  • switch_resource_id (str) – Resource identifier uniquely identifying the switch containing the port to modify. (See Switch for what attribute is the resource identifier)

  • port_resource_id (str) – Resource identifier together with switch uniquely identifying the port to modify. (See Port for what attribute is the resource identifier)

  • kwargs – Attributes of port to change. Possible parameters are public attributes of Port object but in a json compatible representation (as nested dict structure)

Return type

Port

Returns

The modified or created port

switchmng.database.set.set_port_model(session, switch_model_resource_id, port_model_resource_id, **kwargs)

Set a PortModel in the database to a given state.

PortModel identified by given resource identifier on switch model identified by given resource identifier may already exist. If it does not already exist it will be created.

All attributes of port model will be set to given values. Attributes not given but present in already existing PortModel will be set to None or [] or other representation of “not set”.

Parameters
  • switch_model_resource_id (str) – Resource identifier uniquely identifying the switch model containing the port model to modify. (See SwitchModel for what attribute is the resource identifier)

  • port_model_resource_id (str) – Resource identifier together with switch model uniquely identifying the port model to modify. (See PortModel for what attribute is the resource identifier)

  • kwargs – Attributes of port model to change. Possible parameters are public attributes of PortModel object but in a json compatible representation (as nested dict structure)

Return type

PortModel

Returns

The modified or created port model

switchmng.database.set.set_switch(session, resource_id, **kwargs)

Set a Switch corresponding to a given resource identifier to a given state.

Switch identified by given resource identifier may already exist. If it does not already exist it will be created.

All attributes of switch will be set to given values. Attributes not given but present in already existing Switch will be set to None or [] or other representation of “not set”.

Parameters
  • resource_id (Optional[str]) – Resource identifier uniquely identifying the switch to modify. (See Switch for what attribute is the resource identifier)

  • kwargs – Attributes of switch to change. Possible parameters are public attributes of Switch object but in a json compatible representation (as nested dict structure)

Return type

Switch

Returns

The modified or created switch

switchmng.database.set.set_switch_model(session, resource_id, **kwargs)

Set a SwitchModel in the database to a given state.

SwitchModel identified by given resource identifier may already exist. If it does not already exist it will be created.

All attributes of switch model will be set to given values. Attributes not given but present in already existing SwitchModel will be set to None or [] or other representation of “not set”.

Parameters
  • resource_id (Optional[str]) – Resource identifier uniquely identifying the switch model to modify. (See SwitchModel for what attribute is the resource identifier)

  • kwargs – Attributes of switch model to change. Possible parameters are public attributes of SwitchModel object but in a json compatible representation (as nested dict structure)

Return type

SwitchModel

Returns

The modified or created switch model

switchmng.database.set.set_vlan(session, resource_id, **kwargs)

Set a Vlan in the database to a given state.

Vlan identified by given resource identifier may already exist. If it does not already exist it will be created.

All attributes of vlan will be set to given values. Attributes not given but present in already existing Vlan will be set to None or [] or other representation of “not set”.

Parameters
  • resource_id (Optional[str]) – Resource identifier uniquely identifying the vlan to modify. (See Vlan for what attribute is the resource identifier)

  • kwargs – Attributes of vlan to change. Possible parameters are public attributes of Vlan object but in a json compatible representation (as nested dict structure)

Return type

Vlan

Returns

The modified or created vlan

Module contents

class switchmng.database.DatabaseConnection(db_type, db_str, db_verbose, base)

Bases: object