Skip to content

Commit

Permalink
feat(device): accepts feature config in toggle_features
Browse files Browse the repository at this point in the history
The toggle_features method now accepts additional feature config that
allows us to invoke the patch device daemons API with daemon config.

Usage:
    >>> from rapyuta_io import Client
    >>> client = Client(auth_token='auth_token', project='project_guid')
    >>> client.toggle_features('device-id', [('vpn', True), ('tracing', False)], config={'vpn': {'advertise_routes': True}})
  • Loading branch information
pallabpain committed Nov 17, 2023
1 parent 7483d89 commit c16e246
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rapyuta_io/rio_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,20 +485,22 @@ def delete_device(self, device_id):
raise InvalidParameterException('device_id needs to be a non empty string')
return self._dmClient.delete_device(device_id)

def toggle_features(self, device_id, features):
def toggle_features(self, device_id, features, config=None):
"""
Patch a device on rapyuta.io platform.
:param device_id: Device ID
:type device_id: str
:param features: A tuple of featues and their states
:type features: list<tuple>
:param config: A dict of additional feature configuration
:type config: dict
Following example demonstrates how to toggle features a device.
>>> from rapyuta_io import Client
>>> client = Client(auth_token='auth_token', project='project_guid')
>>> client.toggle_features('device-id', [('vpn', True), ('tracing', False)])
>>> client.toggle_features('device-id', [('vpn', True), ('tracing', False)], config={'vpn': {'advertise_routes': True}})
"""
if not device_id or not isinstance(device_id, six.string_types):
raise InvalidParameterException('device_id needs to be a non empty string')
Expand All @@ -510,6 +512,9 @@ def toggle_features(self, device_id, features):
feature, state = entry
data[feature] = state

if config is not None:
data['config'] = config

return self._dmClient.patch_daemons(device_id, data)

def create_package_from_manifest(self, manifest_filepath, retry_limit=0):
Expand Down

0 comments on commit c16e246

Please sign in to comment.