Debian Codegraph @

seamicroclient/v2/scards.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 Scard interface.
15 """
16
17 from seamicroclient import base
18
19
20 class Scard(base.Resource):
21 HUMAN_ID = True
22
23 def set_management_mode(self, mode, force=False, **kwargs):
24 return self.manager.set_management_mode(self, mode, force, **kwargs)
25
26 def volume_mode(self, value, **kwargs):
27 if value:
28 return self.manager.set_management_mode(self, 'volume', **kwargs)
29 else:
30 return self.manager.set_management_mode(self, 'disk', **kwargs)
31
32
33 class ScardManager(base.ManagerWithFind):
34 resource_class = Scard
35
36 def list(self, filters=None):
37 """
38 Get a list of scard properties.
39
40 :rtype: list of :class:`Scard`
41 """
42 return self._list("/chassis/scards", filters=filters)
43
44 def get(self, scard, **kwargs):
45 """
46 Get a specific scard.
47
48 :rtype: Instance of :class:`Scard`
49 """
50 return self._get(base.getid(scard),
51 '/chassis/scard/%s' % base.getid(scard))
52
53 def set_management_mode(self, scard, mode, force=False, **kwargs):
54 """
55 Set management mode of the specified scard
56 """
57 url = "/chassis/scard/%s/mgmtMode" % base.getid(scard)
58 body = {'value': mode}
59 return self.api.client.put(url, body=body)