class Root(base.Resource): """Softboxen REST API service root. :param connector: A RestClient instance :param path: sub-URI path to the resource. """ description = base.Field('description') """Service description.""" def __init__(self, connector, path='/softboxen/v1'): super(Root, self).__init__(connector, path=path) @property def boxen(self): """Return a `BoxCollection` object.""" return box.BoxCollection( self._conn, base.get_sub_resource_path_by(self, 'boxen')) def get_box(self, identity): """Return `Box` object by identity. :param identity: The identity of the Box resource. :raises: `UnknownDefaultError` if default box can't be determined. :returns: The Box object """ return box.Box(self._conn, identity)
class Port(base.Resource): """Represent physical port resource.""" name = base.Field('name') description = base.Field('description') mode = base.Field('mode') shutdown = base.Field('shutdown') speed = base.Field('speed') auto_negotiation = base.Field('auto_negotiation') mtu = base.Field('mtu') @property def access_vlan(self): """Return `VlanPort` object for access VLAN.""" return vlan_port.VlanPort( self._conn, base.get_sub_resource_path_by(self, 'access_vlan')) @property def trunk_vlans(self): """Return `VlanPortCollection` object for trunk VLANs.""" return vlan_port.VlanPortCollection( self._conn, base.get_sub_resource_path_by(self, 'trunk_vlans')) @property def trunk_native_vlan(self): """Return `VlanPort` object for trunk native VLAN.""" return vlan_port.VlanPort( self._conn, base.get_sub_resource_path_by(self, 'trunk_native_vlan')) def add_access_vlan(self, **fields): """Add new access VLAN.""" vlan_port.VlanPort.create(self._conn, os.path.join(self.path, 'access_vlan'), **fields) def add_trunk_vlan(self, **fields): """Add new trunk VLAN.""" vlan_port.VlanPort.create(self._conn, os.path.join(self.path, 'trunk_vlans'), **fields) def add_trunk_native_vlan(self, **fields): """Add new trunk native VLAN.""" vlan_port.VlanPort.create(self._conn, os.path.join(self.path, 'trunk_native_vlan'), **fields)
class Box(base.Resource): """Represent a network device (AKA box). :param connection: A RestClient instance :param identity: The identity of the System resource """ vendor = base.Field('vendor', required=True) """Network device vendor e.g. cisco""" model = base.Field('model', required=True) """Network device model e.g. 5300""" version = base.Field('version', required=True) """Network device model version e.g. 1.2.3""" uuid = base.Field('uuid', required=True) """Network device unique instance ID""" description = base.Field('description') """The description of this box""" hostname = base.Field('hostname') """Network device model e.g. 5300""" mgmt_address = base.Field('mgmt_address') """Management IP address""" @property def credentials(self): """Return `CredentialsCollection` object.""" return credentials.CredentialsCollection( self._conn, base.get_sub_resource_path_by( self, 'credentials')) @property def routes(self): """Return `RouteCollection` object.""" return route.RouteCollection( self._conn, base.get_sub_resource_path_by(self, 'routes')) @property def ports(self): """Return `PortCollection` object.""" return port.PortCollection( self._conn, base.get_sub_resource_path_by(self, 'ports'))
class VlanPort(base.Resource): """Represent VLAN port resource.""" vlan_num = base.Field('vlan_num') name = base.Field('name') description = base.Field('description') role = base.Field('role') shutdown = base.Field('shutdown') mtu = base.Field('mtu') access_group_in = base.Field('access_group_in') access_group_out = base.Field('access_group_out') ip_redirect = base.Field('ip_redirect') ip_proxy_arp = base.Field('ip_proxy_arp') unicast_reverse_path_forwarding = base.Field( 'unicast_reverse_path_forwarding') load_interval = base.Field('load_interval') mpls_ip = base.Field('mpls_ip') @property def port(self): return port.Port(self._conn, base.get_sub_resource_path_by(self, 'port')) @property def ports(self): """Return `VlanPortCollection` object.""" return VlanPortCollection(self._conn, base.get_sub_resource_path_by(self, 'ports'))
class Vlan(base.Resource): """Represent a VLAN resource.""" number = base.Field('number') name = base.Field('name') description = base.Field('description')
class Route(base.Resource): """Represent network routing entry resource.""" dst = base.Field('dst') gw = base.Field('gw') metric = base.Field('metric')
class Credentials(base.Resource): """Represent user credentials.""" protocol = base.Field('protocol') user = base.Field('user') password = base.Field('password')
class FullResource(base.Resource): string = base.Field('String', required=True) integer = base.Field('Integer', converter=int) collection_field = TestCollectionField('CollectionField') enumeration_field = base.EnumerationField('Enumeration', MAPPING)
class TestCollectionField(base.CollectionField): string = base.Field('String', required=True) integer = base.Field('Integer', converter=int)