1
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2
# not use this file except in compliance with the License. You may obtain
3
# a copy of the License at
5
# http://www.apache.org/licenses/LICENSE-2.0
7
# Unless required by applicable law or agreed to in writing, software
8
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
# License for the specific language governing permissions and limitations
17
from seamicroclient import base
20
class Interface(base.Resource):
23
def shutdown(self, **kwargs):
24
return self.manager.shutdown(self, **kwargs)
26
def no_shutdown(self, **kwargs):
27
return self.manager.no_shutdown(self, **kwargs)
29
def add_tagged_vlan(self, vlan_id, **kwargs):
30
return self.manager.add_tagged_vlan(self, vlan_id, **kwargs)
32
def remove_tagged_vlan(self, vlan_id, **kwargs):
33
return self.manager.remove_tagged_vlan(self, vlan_id, **kwargs)
35
def add_untagged_vlan(self, vlan_id, **kwargs):
36
return self.manager.add_untagged_vlan(self, vlan_id, **kwargs)
38
def remove_untagged_vlan(self, vlan_id, **kwargs):
39
return self.manager.remove_untagged_vlan(self, vlan_id, **kwargs)
42
class InterfaceManager(base.ManagerWithFind):
43
resource_class = Interface
45
def get(self, interface):
49
:param interface: ID of the :class:`Interface` to get.
50
:rtype: :class:`Interface`
52
return self._get(base.getid(interface),
53
"/interfaces/%s" % base.getid(interface))
55
def list(self, filters=None):
57
Get a list of interfaces.
59
:rtype: list of :class:`Interface`
61
return self._list("/interfaces", filters=filters)
63
def shutdown(self, interface, **kwargs):
65
Shutdown the specified network Interface
67
url = "/interfaces/%s/shutdown" % base.getid(interface)
68
body = {'value': True}
69
return self.api.client.put(url, body=body)
71
def no_shutdown(self, interface, **kwargs):
73
Start the specified network Interface
75
url = "/interfaces/%s/shutdown" % base.getid(interface)
76
body = {'value': False}
77
return self.api.client.put(url, body=body)
79
def add_tagged_vlan(self, interface, vlan_id, **kwargs):
81
Add tagged vlan for the given Interface
83
url = '/interfaces/%s/vlans/taggedVlans' % base.getid(interface)
84
if isinstance(vlan_id, list):
85
vlan_id = map(lambda x: str(x), vlan_id)
86
body = {'add': ','.join(vlan_id)}
88
body = {'add': str(vlan_id)}
89
return self.api.client.put(url, body=body)
91
def remove_tagged_vlan(self, interface, vlan_id, **kwargs):
93
Remove tagged vlan for the given Interface
95
url = '/interfaces/%s/vlans/taggedVlans' % base.getid(interface)
96
body = {'remove': str(vlan_id)}
97
return self.api.client.put(url, body=body)
99
def add_untagged_vlan(self, interface, vlan_id, **kwargs):
101
Add untagged vlan for the given Interface
103
url = '/interfaces/%s/vlans/untaggedVlans' % base.getid(interface)
104
body = {'add': str(vlan_id)}
105
return self.api.client.put(url, body=body)
107
def remove_untagged_vlan(self, interface, vlan_id, **kwargs):
109
Remove untagged vlan for the given Interface
111
url = '/interfaces/%s/vlans/untaggedVlans' % base.getid(interface)
112
body = {'remove': str(vlan_id)}
113
return self.api.client.put(url, body=body)