Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the storage API #27

Merged
merged 7 commits into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aiofreepybox/aiofreepybox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from aiofreepybox.api.dhcp import Dhcp
from aiofreepybox.api.switch import Switch
from aiofreepybox.api.lan import Lan
from aiofreepybox.api.storage import Storage
from aiofreepybox.api.lcd import Lcd
from aiofreepybox.api.wifi import Wifi
from aiofreepybox.api.phone import Phone
Expand Down Expand Up @@ -81,6 +82,7 @@ async def open(self, host, port):
self.dhcp = Dhcp(self._access)
self.switch = Switch(self._access)
self.lan = Lan(self._access)
self.storage = Storage(self._access)
self.lcd = Lcd(self._access)
self.wifi = Wifi(self._access)
self.phone = Phone(self._access)
Expand Down
85 changes: 85 additions & 0 deletions aiofreepybox/api/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
class Storage:
"""
Storage
"""

def __init__(self, access):
self._access = access

eject_schema = {"state": "disabled"}

async def check_partition(self, id):
"""
Check partition

id : `int`
"""
return await self._access.put(f"storage/partition/{id}/check")

async def eject_disk(self, disk_id, eject_data=None):
"""
Eject storage disk

disk_id : `int`
eject_data : `dict`
"""
if eject_data is None:
eject_data = self.eject_schema
return await self._access.put(f"storage/disk/{disk_id}", eject_data)

async def format_partition(self, id, format_data):
"""
Format partition

id : `int`
format_data : `dict`
"""
return await self._access.put(f"storage/partition/{id}/format", format_data)

async def get_config(self):
"""
Get storage configuration
"""
return await self._access.get("storage/config/")

async def get_disk(self, id):
"""
Get disk

id : `int`
"""
return await self._access.get(f"storage/disk/{id}")

async def get_disks(self):
"""
Get disks list
"""
return await self._access.get("storage/disk/")

async def get_partition(self, id):
"""
Get partition

id : `int`
"""
return await self._access.get(f"storage/partition/{id}")

async def get_partitions(self):
"""
Get partitions list
"""
return await self._access.get("storage/partition/")

async def get_raid(self, id):
"""
Get raid

id : `int`
"""
return await self._access.get(f"storage/raid/{id}")

async def get_raids(self):
"""
Get raids list
"""
return await self._access.get("storage/raid/")