switchmng.schema package¶
Submodules¶
switchmng.schema.base module¶
switchmng.schema.base_resource module¶
-
class
switchmng.schema.base_resource.
BaseResource
(**kwargs)¶ Bases:
object
Represents the base for all REST resources.
This class only provides the skeleton for other resources and cannot be instantiated. Every implementing class should overwrite _Attributes and ResourceIdentifier.
-
ResourceIdentifier
= 'name'¶ Name of the attribute that is this resource’s identifier
-
classmethod
check_param
(key, val)¶ Check given parameter.
Check if given parameter has the correct type and is a valid attribute for this resource.
These checks get executed when trying to assign a value to a resource attribute but can be called when needing to check parameters before making changes.
- Raises
TypeError – When type of given parameter does not match expectation
ValueError – When value of given parameter does not match expectation
- Return type
None
-
classmethod
check_params
(**kwargs)¶ Check all given parameter.
Check if given parameters have the correct type and are valid attributes for this resource.
These checks get executed when trying to assign a value to a resource attribute but can be called when needing to check multiple parameters at once in order to prevent inconistent states.
- Raises
TypeError – When type of given parameter does not match expectation
ValueError – When value of given parameter does not match expectation
- Return type
None
-
jsonify
()¶ Represent this resource as a json-ready dict.
That is a dict which completely consists of json-compatible structures like:
dict
list
string
int
bool
None / null
- Return type
Dict
[str
,Union
[str
,int
,None
,Dict
[str
,Any
],List
[Any
],Dict
[str
,Union
[str
,int
,None
,Dict
[str
,Any
],List
[Any
]]],List
[Union
[str
,int
,None
,Dict
[str
,Any
],List
[Any
]]]]]
-
switchmng.schema.connector module¶
-
class
switchmng.schema.connector.
Connector
(**kwargs)¶ Bases:
switchmng.schema.base_resource.BaseResource
,sqlalchemy.ext.declarative.api.Base
Represents a physical port connector.
This resource is uniquely identified by its name.
- Parameters
name (str) – Name uniquely identifying this port connector
-
ResourceIdentifier
= 'name'¶ Name of the attribute that is this resource’s identifier
switchmng.schema.network_protocol module¶
-
class
switchmng.schema.network_protocol.
NetworkProtocol
(**kwargs)¶ Bases:
switchmng.schema.base_resource.BaseResource
,sqlalchemy.ext.declarative.api.Base
Represents a network protocol resource.
This resource is uniquely identified by its name.
- Parameters
name (str) – Name uniquely identifying this network protocol
speed (int) – Maximum possible speed of this network protocol in Mb/s
-
ResourceIdentifier
= 'name'¶ Name of the attribute that is this resource’s identifier
switchmng.schema.port module¶
-
class
switchmng.schema.port.
Port
(**kwargs)¶ Bases:
switchmng.schema.base_resource.BaseResource
,sqlalchemy.ext.declarative.api.Base
Represents a port of a switch.
That is a concrete port of a concrete switch. This resource is uniquely identified by the switch (See
Switch
) containing it in combination with its name.- Parameters
name (str) – The identifier of this port. Must be unique for the containing
Switch
.vlans (list) – A list of vlans that are active on this port
target (str) – Host that is connected to this port
-
ResourceIdentifier
= 'name'¶ Name of the attribute that is this resource’s identifier
switchmng.schema.port_model module¶
-
class
switchmng.schema.port_model.
PortModel
(**kwargs)¶ Bases:
switchmng.schema.base_resource.BaseResource
,sqlalchemy.ext.declarative.api.Base
Represents a port model resource.
This resource is uniquely identified by the switch model (See
SwitchModel
) containing it in combination with its name.- Parameters
name (str) – The identifier of this port. Must be unique for the containing
SwitchModel
.network_protocols (list) – List of possible network protocols of this port
connector (
Connector
) – Physical connector of this port
-
ResourceIdentifier
= 'name'¶ Name of the attribute that is this resource’s identifier
switchmng.schema.switch module¶
-
class
switchmng.schema.switch.
Switch
(**kwargs)¶ Bases:
switchmng.schema.base_resource.BaseResource
,sqlalchemy.ext.declarative.api.Base
Represents a switch resource.
This resource is uniquely identified by its name.
- Parameters
name (str) – Name uniquely identifying this switch
model (
SwitchModel
) – Model of this switchports (list) – Ports associated with this switch
location (int) – Location of this switch in server rack
ip (str) – IP Address of this switch
-
ResourceIdentifier
= 'name'¶ Name of the attribute that is this resource’s identifier
-
port
(resource_id)¶ Return port of this switch identified by resource identifier
Returns the port for the given resource identifier or None if this switch does not contain a matching port.
- Parameters
resource_id (str) – The resource id of the port to return object of
- Return type
Optional
[Port
]- Returns
The
Port
object identified by given resource id
-
sync_ports_from_model
()¶ Synchronize ports from switch model.
All ports that have a name that does not exist in switch model will get removed. All ports from switch model that do not exist in this object will be added.
- Return type
None
switchmng.schema.switch_model module¶
-
class
switchmng.schema.switch_model.
SwitchModel
(**kwargs)¶ Bases:
switchmng.schema.base_resource.BaseResource
,sqlalchemy.ext.declarative.api.Base
Represents a switch model resource.
This resource is uniquely identified by its name.
- Parameters
name (str) – Name uniquely identifying this switch model Acts as resource identifier.
ports (list) – Ports associated with this switch model
size (int) – Size (number of rack units) this switch takes up in server rack
-
ResourceIdentifier
= 'name'¶ Name of the attribute that is this resource’s identifier
-
port
(resource_id)¶ Return port of this switch model identified by resource identifier.
Returns the port for the given resource identifier or None if this switch model does not contain a matching port.
- Parameters
resource_id (str) – The resource id of the port to return object of
- Return type
Optional
[PortModel
]- Returns
The
PortModel
object identified by given resource id
-
refresh_switches
()¶ Refresh ports of all switches using this switch model.
- Return type
None
switchmng.schema.vlan module¶
-
class
switchmng.schema.vlan.
Vlan
(**kwargs)¶ Bases:
switchmng.schema.base_resource.BaseResource
,sqlalchemy.ext.declarative.api.Base
Represents a VLAN resource.
This resource is uniquely identified by its vlan tag.
- Parameters
tag (int) – Tag uniquely identifying this VLAN
description (str) – Description of this VLAN
-
ResourceIdentifier
= 'tag'¶