~rbanffy/+junk/python3-seamicroclient

« back to all changes in this revision

Viewing changes to python-seamicroclient-0.2.1/seamicroclient/v2/interfaces.py

  • Committer: Ricardo Bánffy
  • Date: 2015-12-15 21:36:41 UTC
  • Revision ID: rbanffy@gmail.com-20151215213641-l6rxowkaerz02467
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
#
 
5
#         http://www.apache.org/licenses/LICENSE-2.0
 
6
#
 
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
 
11
#    under the License.
 
12
 
 
13
"""
 
14
Interfaces object.
 
15
"""
 
16
 
 
17
from seamicroclient import base
 
18
 
 
19
 
 
20
class Interface(base.Resource):
 
21
    HUMAN_ID = True
 
22
 
 
23
    def shutdown(self, **kwargs):
 
24
        return self.manager.shutdown(self, **kwargs)
 
25
 
 
26
    def no_shutdown(self, **kwargs):
 
27
        return self.manager.no_shutdown(self, **kwargs)
 
28
 
 
29
    def add_tagged_vlan(self, vlan_id, **kwargs):
 
30
        return self.manager.add_tagged_vlan(self, vlan_id, **kwargs)
 
31
 
 
32
    def remove_tagged_vlan(self, vlan_id, **kwargs):
 
33
        return self.manager.remove_tagged_vlan(self, vlan_id, **kwargs)
 
34
 
 
35
    def add_untagged_vlan(self, vlan_id, **kwargs):
 
36
        return self.manager.add_untagged_vlan(self, vlan_id, **kwargs)
 
37
 
 
38
    def remove_untagged_vlan(self, vlan_id, **kwargs):
 
39
        return self.manager.remove_untagged_vlan(self, vlan_id, **kwargs)
 
40
 
 
41
 
 
42
class InterfaceManager(base.ManagerWithFind):
 
43
    resource_class = Interface
 
44
 
 
45
    def get(self, interface):
 
46
        """
 
47
        Get a interface.
 
48
 
 
49
        :param interface: ID of the :class:`Interface` to get.
 
50
        :rtype: :class:`Interface`
 
51
        """
 
52
        return self._get(base.getid(interface),
 
53
                         "/interfaces/%s" % base.getid(interface))
 
54
 
 
55
    def list(self, filters=None):
 
56
        """
 
57
        Get a list of interfaces.
 
58
 
 
59
        :rtype: list of :class:`Interface`
 
60
        """
 
61
        return self._list("/interfaces", filters=filters)
 
62
 
 
63
    def shutdown(self, interface, **kwargs):
 
64
        """
 
65
        Shutdown the specified network Interface
 
66
        """
 
67
        url = "/interfaces/%s/shutdown" % base.getid(interface)
 
68
        body = {'value': True}
 
69
        return self.api.client.put(url, body=body)
 
70
 
 
71
    def no_shutdown(self, interface, **kwargs):
 
72
        """
 
73
        Start the specified network Interface
 
74
        """
 
75
        url = "/interfaces/%s/shutdown" % base.getid(interface)
 
76
        body = {'value': False}
 
77
        return self.api.client.put(url, body=body)
 
78
 
 
79
    def add_tagged_vlan(self, interface, vlan_id, **kwargs):
 
80
        """
 
81
        Add tagged vlan for the given Interface
 
82
        """
 
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)}
 
87
        else:
 
88
            body = {'add': str(vlan_id)}
 
89
        return self.api.client.put(url, body=body)
 
90
 
 
91
    def remove_tagged_vlan(self, interface, vlan_id, **kwargs):
 
92
        """
 
93
        Remove tagged vlan for the given Interface
 
94
        """
 
95
        url = '/interfaces/%s/vlans/taggedVlans' % base.getid(interface)
 
96
        body = {'remove': str(vlan_id)}
 
97
        return self.api.client.put(url, body=body)
 
98
 
 
99
    def add_untagged_vlan(self, interface, vlan_id, **kwargs):
 
100
        """
 
101
        Add untagged vlan for the given Interface
 
102
        """
 
103
        url = '/interfaces/%s/vlans/untaggedVlans' % base.getid(interface)
 
104
        body = {'add': str(vlan_id)}
 
105
        return self.api.client.put(url, body=body)
 
106
 
 
107
    def remove_untagged_vlan(self, interface, vlan_id, **kwargs):
 
108
        """
 
109
        Remove untagged vlan for the given Interface
 
110
        """
 
111
        url = '/interfaces/%s/vlans/untaggedVlans' % base.getid(interface)
 
112
        body = {'remove': str(vlan_id)}
 
113
        return self.api.client.put(url, body=body)