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 back VMs and other modules #753

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions src/freebox_api/aiofreepybox.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from freebox_api.api.airmedia import Airmedia
from freebox_api.api.call import Call
from freebox_api.api.connection import Connection
from freebox_api.api.contact import Contact
from freebox_api.api.dhcp import Dhcp
from freebox_api.api.download import Download
from freebox_api.api.freeplug import Freeplug
Expand All @@ -32,6 +33,7 @@
from freebox_api.api.netshare import Netshare
from freebox_api.api.notifications import Notifications
from freebox_api.api.parental import Parental
from freebox_api.api.profile import Profile
from freebox_api.api.phone import Phone
from freebox_api.api.player import Player
from freebox_api.api.remote import Remote
Expand All @@ -42,6 +44,8 @@
from freebox_api.api.tv import Tv
from freebox_api.api.upnpav import Upnpav
from freebox_api.api.upnpigd import Upnpigd
from freebox_api.api.vm import Vm
from freebox_api.api.vpn import Vpn
from freebox_api.api.wifi import Wifi
from freebox_api.exceptions import AuthorizationError
from freebox_api.exceptions import InvalidTokenError
Expand Down Expand Up @@ -104,12 +108,16 @@ def __init__(
self.download: Download
self.home: Home
self.parental: Parental
self.profile: Profile
self.netshare: Netshare
self.notifications: Notifications
self.remote: Remote
self.rrd: Rrd
self.upnpav: Upnpav
self.upnpigd: Upnpigd
self.contact: Contact
self.vm: Vm
self.vpn: Vpn

async def open(self, host: str, port: str) -> None:
"""
Expand Down Expand Up @@ -161,6 +169,10 @@ async def open(self, host: str, port: str) -> None:
self.rrd = Rrd(self._access)
self.upnpav = Upnpav(self._access)
self.upnpigd = Upnpigd(self._access)
self.contact = Contact(self._access)
self.profile = Profile(self._access)
self.vm = Vm(self._access)
self.vpn = Vpn(self._access)

async def close(self) -> None:
"""
Expand Down
62 changes: 62 additions & 0 deletions src/freebox_api/api/contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
class Contact:
"""
API to manage contacts, partially implemented : missing photo, url, addresses, emails
"""

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

contact_write_parms = {'display_name': 'text', 'first_name': 'text', 'last_name': 'text', 'company': 'text' }
contact_write_numbers = { 'number': 'text', 'type': 'text', 'is_default': 'bool' }
contact_number_type = [ 'fixed', 'mobile', 'work', 'fax', 'other' ]
contact_number_schema = { 'number': '0', 'type': contact_number_type[0], 'contact_id': 0, 'is_default': False }
contact_configuration_schema = { 'display_name': 'Batman', 'first_name': 'Bruce', 'last_name': 'Wayne','company': 'DC Comics' }

async def get_contact_list(self):
"""
Returns the collection of all contact entries
"""
return await self._access.get('contact/')

async def get_contact(self, id):
"""
Gets contact #id
"""
return await self._access.get('contact/{0}'.format(id))

async def add_contact(self, conf):
"""
Adds a contact
"""
return await self._access.post('contact/', payload=conf)

async def del_contact(self, id):
"""
Removes a contact
"""
return await self._access.delete('contact/{0}'.format(id))

async def update_contact(self, id, conf):
"""
Updates a contact
"""
return await self._access.put('contact/{0}'.format(id), payload=conf)

async def add_number(self, id, conf):
"""
Adds a number for a contact
"""
conf['contact_id'] = id
return await self._access.post('number/', payload=conf)

async def del_number(self, id):
"""
Deletes a number
"""
return await self._access.delete('number/{0}'.format(id))

async def update_number(self, id, conf):
"""
Updates a number
"""
return await self._access.put('number/{0}'.format(id), payload=conf)
127 changes: 127 additions & 0 deletions src/freebox_api/api/profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
class Profile:
"""
(The new) API to manage network profiles
"""
def __init__(self, access):
self._access = access

profile_write_parms = { 'name': 'text', 'icon': 'text' }
profile_data_schema = { 'name': '', 'icon': '/resources/images/profile/profile_01.png' }
netcontrol_modes = [ 'allowed', 'denied', 'webonly' ]
cday_values = [ ':fr_bank_holidays', ':fr_school_holidays_a', ':fr_school_holidays_b', ':fr_school_holidays_c', ':fr_school_holidays_corse' ]
netcontrol_write_parms = { 'override_mode': 'text', 'macs': 'list', 'cdayranges': 'list' }
netcontrol_data_schema = { 'override_mode': netcontrol_modes[2], 'macs': [], 'cdayranges': [] }
rule_write_parms = { 'name': 'text', 'mode': 'text', 'start_time': 'int', 'end_time': 'int', 'enabled': 'bool', 'weekdays': 'list' }
rule_data_schema = { 'name': '', 'mode': netcontrol_modes[1], 'start_time': 0, 'end_time': 0, 'enabled': True, 'weekdays': [] }

async def get_profiles(self):
"""
Gets all profiles
"""
return await self._access.get('profile/')

async def get_profile(self, profile_id):
"""
Gets all profiles
"""
return await self._access.get(f"profile/{profile_id}")

async def add_profile(self, new_profile):
"""
Adds a profile
"""
return await self._access.post('profile/', new_profile)

async def del_profile(self, profile_id):
"""
Deletes a profile
"""
return await self._access.delete(f"profile/{profile_id}")

async def set_profile(self, profile_id, data):
"""
Configures a profile
"""
return await self._access.put(f"profile/{profile_id}", payload=data)

async def get_netcontrols(self):
"""
Gets network control for all profiles
"""
return await self._access.get('network_control/')

async def get_netcontrol(self, profile_id):
"""
Gets network control for a profile
"""
return await self._access.get(f"network_control/{profile_id}")

async def set_netcontrol(self, profile_id, data):
"""
Sets network control for a profile
"""
return await self._access.put(f"network_control/{profile_id}", payload=data)

async def override(self, profile_id, duration=0):
"""
Switch to override mode for the specified duration
"""
oldconf = self.get_netcontrol(profile_id)
return await self._access.put(f"network_control/{profile_id}", { 'override': True, 'override_until': duration, 'macs': oldconf['macs'] })

async def back(self, profile_id):
"""
Switch to standard mode
"""
oldconf = self.get_netcontrol(profile_id)
return await self._access.put(f"network_control/{profile_id}", { 'override': False, 'macs': oldconf['macs'] })

async def get_migration_status(self):
"""
Gets migration status
"""
return await self._access.get('network_control/migrate')

async def migrate(self):
"""
Migrates to new version
"""
return await self._access.post('network_control/migrate', payload=None)

async def get_netcontrol_rules(self, profile_id):
"""
Gets all rules for a network control profile
"""
return await self._access.get(f"network_control/{profile_id}/rules/")

async def get_netcontrol_rule(self, profile_id, rule_id):
"""
Gets a rule for a network control profile
"""
return await self._access.get(f"network_control/{profile_id}/rules/{rule_id}")

async def add_netcontrol_rule(self, profile_id, new_profile):
"""
Adds a rule for a network control profile
"""
if 'weekdays' in new_profile:
newlist = []
for day in new_profile['weekdays']: newlist.append(day == 'True')
new_profile['weekdays'] = newlist
return await self._access.post(f"network_control/{profile_id}/rules/", new_profile)

async def set_netcontrol_rule(self, profile_id, rule_id, data):
"""
Sets a rule for a network control profile
"""
if 'weekdays' in data:
newlist = []
for day in data['weekdays']: newlist.append(day == 'True')
data['weekdays'] = newlist
return await self._access.put(f"network_control/{profile_id}/rules/{rule_id}", data)

async def del_netcontrol_rule(self, profile_id, rule_id):
"""
Deletes a profile
"""
return await self._access.delete(f"network_control/{profile_id}/rules/{rule_id}")
9 changes: 9 additions & 0 deletions src/freebox_api/api/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,12 @@ async def get_raids(self):
Get raids list
"""
return await self._access.get("storage/raid/")

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

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