Debian Codegraph @

seamicroclient/v2/system.py

raw
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 System interface.
15 """
16
17 from seamicroclient import base
18
19
20 class System(base.Resource):
21 HUMAN_ID = True
22
23 def switchover(self, mxcard=None, **kwargs):
24 return self.manager.switchover(self, mxcard, **kwargs)
25
26 def writemem(self, **kwargs):
27 return self.manager.writemem(self, **kwargs)
28
29 def add_segment(self, vlan_id, **kwargs):
30 return self.manager.add_segment(self, vlan_id, **kwargs)
31
32 def remove_segment(self, vlan_id, **kwargs):
33 return self.manager.remove_segment(self, vlan_id, **kwargs)
34
35 class SystemManager(base.ManagerWithFind):
36 resource_class = System
37
38 def list(self, filters=None):
39 """
40 Get a list of system properties.
41
42 :rtype: list of :class:`System`
43 """
44 return self._list("/chassis/system", filters=filters)
45
46 def switchover(self, system, mxcard=None, **kwargs):
47 """
48 Switchover system to different mxcard
49 """
50 url = "/chassis/system/switchover"
51 body = {}
52 if mxcard is not None:
53 body = {'newActive': mxcard}
54 return self.api.client.put(url, body=body)
55
56 def writemem(self, system, **kwargs):
57 """
58 Write current system config to flash memory
59 This will persist even after reboot of chassis
60 """
61 url = "/chassis/system/writeMem"
62 return self.api.client.put(url, body={})
63
64 def reload(self, system, **kwargs):
65 """
66 Reload the chassis and start the boot image
67 """
68 url = "/chassis/system/reload"
69 return self.api.client.put(url, body={})
70
71 def add_segment(self, system, vlan_id, **kwargs):
72 """
73 Create Global Network
74 """
75 url = "/chassis/system/vlans"
76 if vlan_id is not None:
77 action_params = {}
78 action_params.update({'add': vlan_id})
79 self.run_hooks('modify_body_for_action', action_params, **kwargs)
80 return self.api.client.put(url, body=action_params)
81
82 def remove_segment(self, system, vlan_id, **kwargs):
83 """
84 Remove Global Network
85 """
86 url = "/chassis/system/vlans"
87 if vlan_id is not None:
88 action_params = {}
89 action_params.update({'remove': vlan_id})
90 self.run_hooks('modify_body_for_action', action_params, **kwargs)
91 return self.api.client.put(url, body=action_params)