Debian Codegraph @

seamicroclient/v2/disks.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 Disks interface.
15 """
16
17 from seamicroclient import base
18
19
20 class Disk(base.Resource):
21 HUMAN_ID = True
22
23 def power_on(self, **kwargs):
24 return self.manager.power_on(self, **kwargs)
25
26 def power_off(self, **kwargs):
27 return self.manager.power_off(self, **kwargs)
28
29 def active_led(self, **kwargs):
30 return self.manager.active_led(self, **kwargs)
31
32 def deactivate_led(self, **kwargs):
33 return self.manager.deactivate_led(self, **kwargs)
34
35
36 class DiskManager(base.ManagerWithFind):
37 resource_class = Disk
38
39 def get(self, disk):
40 """
41 Get a disk.
42
43 :param disk: ID of the :class:`Disk` to get.
44 :rtype: :class:`Disk`
45 """
46 return self._get(base.getid(disk),
47 "/storage/disks/%s" % base.getid(disk))
48
49 def list(self, filters=None):
50 """
51 Get a list of disks.
52
53 :rtype: list of :class:`Disk`
54 """
55 return self._list("/storage/disks", filters=filters)
56
57 def power_off(self, disk, **kwargs):
58 """
59 Power off the specified Disk
60 """
61 url = "/storage/disks/%s" % base.getid(disk)
62 body = {'action': 'power-off'}
63 return self.api.client.put(url, body=body)
64
65 def power_on(self, disk, **kwargs):
66 """
67 Power on the specified Disk
68 """
69 url = "/storage/disks/%s" % base.getid(disk)
70 body = {'action': 'power-on'}
71 return self.api.client.put(url, body=body)
72
73 def activate_led(self, disk, **kwargs):
74 """
75 Activate LED of the specified Disk
76 """
77 url = "/storage/disks/%s" % base.getid(disk)
78 body = {'action': 'activate-led'}
79 return self.api.client.put(url, body=body)
80
81 def deactivate_led(self, disk, **kwargs):
82 """
83 De-activate LED of the specified Disk
84 """
85 url = "/storage/disks/%s" % base.getid(disk)
86 body = {'action': 'deactivate-led'}
87 return self.api.client.put(url, body=body)