Device module¶
A device is a rapyuta.io resource representing any physical device that typically lives at a client location and is registered on rapyuta.io. The resource encapsulates information about the device, its architecture, runtime, user-provided metadata. Once a particular piece of hardware is successfully on-boarded to rapyuta.io this entity is responsible for providing the necessary mechanics and communication channels to manage and interact with the device. The platform leverages these mechanics to provide features that can be used to communicate to the device, configure it, monitor its health and deploy packages to the device.
Client Module¶
- class Client(auth_token, project=None)¶
Client class provides access to device, package, volume and deployment classes.
- __init__(auth_token, project=None)¶
Get new client object
- Parameters:
auth_token (string) – Authentication token
project (string) – project_guid of the user
- apply_parameters(device_list, tree_names=None, retry_limit=0)¶
Applies configuration parameters for the given device_list. If tree_names is given, only these trees are applied.
- Parameters:
- Returns:
List of dictionaries - each with device_id, bool success status, and an error message if the success status is False for that device_id
- Return type:
Following example demonstrates how to use apply_parameters and handle errors.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project='project_guid') >>> devices = client.get_all_devices() >>> response = client.apply_parameters([device.deviceId for device in devices]) >>> for device in response: ... if not device['success']: ... print device['device_id'], device['error']
- create_device(device)¶
Create a device on rapyuta.io platform.
Following example demonstrates how to create a device.
>>> from rapyuta_io import Client, ROSDistro >>> from rapyuta_io.clients.device import Device, DeviceRuntime, DevicePythonVersion >>> client = Client(auth_token='auth_token', project='project_guid') >>> device = Device(name='test-device', runtime=DeviceRuntime.DOCKER, ros_distro=ROSDistro.MELODIC, ... python_version=DevicePythonVersion.PYTHON3) >>> device = client.create_device(device)
- delete_device(device_id)¶
Delete a device based on its device id.
- Parameters:
device_id (str) – Device Id
Following example demonstrates how to delete a device.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project='project_guid') >>> client.delete_device('device-id')
- get_all_devices(online_device=False, arch_list=None, retry_limit=0, device_name=None)¶
Get all the devices
- Parameters:
online_device (bool) – The value True returns only those devices that are online, while the value False returns all devices
arch_list (list) – If set, another call is made to filter devices by architecture. Valid architectures can be found in
DeviceArchclass. Note: Only online devices can be filtered by architecture. Therefore if arch_list is set, non-online devices are not included in the result irrespective of the value of online_device.retry_limit (int) – No of retry attempts to be carried out if any failures occurs during the API call.
device_name (str) – Optional parameter to filter the devices based on the device name.
- Returns:
List of instances of
Deviceclass- Raises:
APIError: If the API returns an error, a status code of anything other than 200/201 is returned
Following example demonstrates how to get the device list
>>> from rapyuta_io import Client >>> from rapyuta_io.clients import DeviceArch >>> client = Client(auth_token='auth_token', project='project_guid') >>> devices = client.get_all_devices() >>> filtered_by_arch_devices = client.get_all_devices(arch_list=[ >>> DeviceArch.ARM32V7, DeviceArch.ARM64V8, DeviceArch.AMD64])
- get_device(device_id, retry_limit=0)¶
Get information of a device.
- Parameters:
device_id (string) – Device Id
retry_limit (int) – No of retry attempts to be carried out if any failures occurs during the API call.
- Returns:
Instances of
Deviceclass.- Raises:
ResourceNotFoundError: If the device with given device id is not present.- Raises:
APIError: If the API returns an error, a status code of anything other than 200/201 is returned.
Following example demonstrates how to select a device information.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project='project_guid') >>> device = client.get_device(device_id="device_id")
- toggle_features(device_id, features, config=None)¶
Patch a device on rapyuta.io platform.
- Parameters:
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)], config={'vpn': {'advertise_routes': True}})
Device Module¶
- class DeploymentPhaseConstants(*values)¶
Enumeration variables for the deployment phase
Deployment phase can be any of the following types
DeploymentPhaseConstants.INPROGRESS
DeploymentPhaseConstants.PROVISIONING
DeploymentPhaseConstants.SUCCEEDED
DeploymentPhaseConstants.FAILED_TO_START
DeploymentPhaseConstants.PARTIALLY_DEPROVISIONED
DeploymentPhaseConstants.DEPLOYMENT_STOPPED
- class Device(name, runtime=None, runtime_docker=False, runtime_preinstalled=False, ros_distro=None, ros_workspace=None, description=None, python_version=DevicePythonVersion.PYTHON2, config_variables=None, labels=None)¶
Device class represents a device. Member variables of the class represent the properties of device.
Variables marked as (full-only) are only available on a full object. Use refresh() to convert a partial object into a full one.
- Variables:
uuid – Id of the device.
name – Name of the device.
status (
DeviceStatus) – Status of the device.username – (full-only) User log in to device
saltversion – (full-only) Salt version of the device.
registration_time – Device registration time.
last_online – Time when device was last online.
python_version – indicates whether device is running on python2 or python3
description – Description of the device.
labels – List of labels associated with the device.
config_variables – Configuration variables of the device.
deployments – List of deployments on device
error_code – Error code when device goes to FAILED state. Will be of the form: ‘DEV_E*’.
error_message – Error message when device goes to FAILED state.
created_by – Creator user guid.
host – (full-only) Hostname on device.
ip_interfaces – (full-only) Set of IP Interfaces on device.
lsb_distrib_description – (full-only) LSB Distribution details.
- add_config_variable(key, value)¶
Add new configuration variable to the device.
- Parameters:
key (string) – Configuration variable key
value (string) – Configuration value
- Returns:
instance of
DeviceConfigclass.- Raises:
ParameterMissingException: If any parameters are missing in the request.- Raises:
DeviceNotFoundException: If the device is not found.- Raises:
APIError: If the API returns an error, the status code is anything other than 200/201
Following example demonstrates how to add a device configuration variable.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.add_config_variable('config_key', 'config_value')
- add_label(key, value, retry_limit=0)¶
Add label to the device
- Parameters:
key (string) – label key
key – label value
retry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failures occur during the API call.
- Returns:
instances of the class
Label.- Raises:
DeviceNotFoundException: If the device is not found.- Raises:
ParameterMissingException: If any parameters are missing in the request.- Raises:
APIError: If the API call returns an error, the status code is anything other than 200/201
Following example demonstrates how to add device labels
>>> from rapyuta_io import Client >>> from rapyuta_io.clients.model import Label >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.add_label('key', 'value')
- cancel_log_file_upload(request_uuid, retry_limit=0)¶
Cancels the ongoing upload operation.
- Parameters:
- Returns:
status of the cancel operation, True indicates operation succeeded False otherwise
- Raises:
LogsUUIDNotFoundException: If the request_uuid is not found- Raises:
BadRequestError: if the upload operation is completed- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- Following example demonstrate how to cancel the ongoing upload operation
>>> from rapyuta_io import Client >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> cancel_status = device.cancel_log_file_upload('request_uuid')
Create a SharedURL that let’s you download the Log file from a Public URL.
- Parameters:
shared_url (
SharedURL) – Instance of the SharedURL Object- Returns:
Instance of
SharedURLclass
- Following example demonstrate how to get the downloadable url
>>> from datetime import timedelta, datetime >>> from rapyuta_io import Client >>> expiry_time = datetime.now() + timedelta(days=7) >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> log = [log.filename == 'file.log' for log in device.list_uploaded_files_for_device()][0] >>> shared_url = device.create_shared_url(SharedURL(log.request_uuid, expiry_time=expiry_time)) >>> print shared_url.url
- delete(retry_limit=0)¶
Delete the device
- Parameters:
retry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failures occur during the API call.
- Returns:
True if the device is deleted successfully. Otherwise returns False.
- Raises:
DeviceNotFoundException: If the device is not found.- Raises:
DeploymentRunningException: When any deployment is running on the device.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
Following example demonstrates how to delete a device
>>> from rapyuta_io import Client >>> from rapyuta_io.clients.model import Label >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.delete()
- delete_config_variable(config_id, retry_limit=0)¶
Delete configuration variable for the device.
- Parameters:
- Returns:
True if the configuration variable is deleted, otherwise returns false
- Raises:
ParameterMissingException: If any parameters are missing in the request.- Raises:
ConfigNotFoundException: If the configuration is not found.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
Following example demonstrates how to delete a device configuration variable.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.delete_config_variable(config_id='config_id')
- delete_label(label_id, retry_limit=0)¶
Delete a device label.
- Parameters:
- Returns:
Boolean value to indicate whether the label is deleted or not
- Raises:
LabelNotFoundException: If the label is not found.- Raises:
APIError: If the API call returns an error, the status code is anything other than 200/201.
Following example demonstrates how to delete a device label
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.delete_label('label_id')
- delete_uploaded_log_file(request_uuid, retry_limit=0)¶
Deletes the logs file from cloud storage
- Parameters:
- Returns:
status of the operation, True indicates operation succeeded false otherwise
- Raises:
LogsUUIDNotFoundException: If the request_uuid is not found- Raises:
BadRequestError: if the upload is in progress- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- Following example demonstrate how to delete the uploaded log file from cloud storage
>>> from rapyuta_io import Client >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> device.delete_uploaded_log_file('request_uuid')
- download_log_file(request_uuid, retry_limit=0)¶
Returns downloadable log file URL, using this URL user can download log file using Wget or curl
- Parameters:
- Returns:
url of the uploaded log file in the cloud
- Raises:
LogsUUIDNotFoundException: If the request_uuid is not found- Raises:
BadRequestError: if the upload operation is in progress- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- Following example demonstrate how to get the downloadable url
>>> from rapyuta_io import Client >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> download_url = device.download_log_file('request_uuid')
- execute_command(command, retry_limit=0)¶
Execute command on device
- Parameters:
- Returns:
Execution result
- Raises:
ParameterMissingException: If any parameters are missing in the request.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
Following example demonstrates how to execute a command.
>>> from rapyuta_io import Client >>> from rapyuta_io.clients.model import Command >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id', ) >>> command = Command(cmd='uname -a', shell='/bin/bash', bg=False) >>> device.execute_command(command)
- fetch_command_result(jid: str, deviceids: list, timeout: int, interval: int = 10)¶
Fetch the result of the command execution using the job ID (jid) and the first device ID from the list. Args:
jid (str): The job ID of the executed command. deviceids (list): A list of device IDs on which the command was executed. timeout (int): The maximum time to wait for the result (in seconds). Default is 300 seconds. interval (int): time interval for retry
- Returns:
dict: The result of the command execution.
- Raises:
TimeoutError: If the result is not available within the timeout period. APIError: If the API returns an error.
- get_config_variables()¶
Get configuration variables associated with the device
- Returns:
list of instances of
DeviceConfigclass.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- get_deployments()¶
Get partial details of deployments associated with the device. Also, update deployments field with these.
Note: Deployment details are partial. Use
refresh()as shown in the example below to refresh these to full objects.- Returns:
List of deployment details.
Following example demonstrates how to get device deployments
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> partial_deployments = device.get_deployments() >>> # to get full deployments objects: >>> for deployment in partial_deployments: >>> deployment.refresh()
- get_labels()¶
Get all labels associated with the device
- Returns:
list of instances of the class
Label.
Following example demonstrates how to get device labels
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.get_labels()
- get_log_upload_status(request_uuid, retry_limit=0)¶
Gets the current upload status
- Parameters:
- Returns:
returns instance of the class
LogUploadStatus- Raises:
LogsUUIDNotFoundException: If the request_uuid is not found- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- Following example demonstrate how to get the status of ongoing upload operation
>>> from rapyuta_io import Client >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> upload_status = device.get_log_upload_status('request_uuid')
- get_runtime()¶
Get the device runtime :return: value of device configuration variable: runtime
Following example demonstrates how to get device runtime.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.get_runtime()
- is_docker_enabled()¶
Check if docker runtime is enabled :return: boolean value depicting if docker runtime is enabled/disabled on the device
Following example demonstrates how to check if docker runtime is enabled/disabled on the device.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.is_docker_enabled()
- is_preinstalled_enabled()¶
Check if preinstalled runtime is enabled :return: boolean value depicting if preinstalled runtime is enabled/disabled on the device
Following example demonstrates how to check if preinstalled runtime is enabled/disabled on the device.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.is_preinstalled_enabled()
- is_ready()¶
Is called after the refresh() call. Implementation should return False if final state (Success/Failure) has not been achieved yet. Else, either return True to indicate Success, or raise an Exception to indicate Failure.
- list_uploaded_files_for_device(retry_limit=0, sort=None, reverse=False, paginate=False, page_size=10, page_number=1, filter_by_filename=None, filter_by_status=None)¶
Returns list of the uploaded files with status and other properties
- Parameters:
retry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failure occurs during API invocation
sort (str) – Optional parameter to sort the list of log files according to their attributes (options: [filename, status, total_size, created_at, updated_at])
reverse (bool) – Optional parameter to sort the list of log files in descending order (ascending order by default)
paginate (bool) – Optional parameter to paginate the list of log files
page_size (int) – Optional parameter to specify the number of logs to be displayed in a page. (default:10, options:[10,20,30,40])
page_number (int) – Optional parameter to specify the page number whose logs are to be displayed. (default:1)
filter_by_filename (str) – Optional parameter to filter the list of log files if the provided name is a substring of any filename.
filter_by_status (list) – Optional parameter to filter the list of log files based on their status. (options : [COMPLETED, IN PROGRESS, FAILED, CANCELLED])
- Returns:
returns the list of instance of the class
LogUploads- Raises:
BadRequestError: if the upload operation is in progress- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- Following example demonstrate how to get the downloadable url
>>> from rapyuta_io import Client >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> status_list = device.list_uploaded_files_for_device()
- metrics(retry_limit=0)¶
Deprecated since version 0.38.0: Will be removed in the future.
Gets the metric status from the device
- param retry_limit:
Optional parameter to specify the number of retry attempts to be carried out if any failure occurs during API invocation
- type retry_limit:
int
- return:
list of instances of class
Metric:- raises:
DeviceNotFoundException: If the device is not found- raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- Following example demonstrate how to get the status of metric from the device
>>> from rapyuta_io import Client >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> device.metrics()
- onboard_script()¶
Returns the OnboardScript object. This object has the information regarding api server url, auth token and command to be used to install rapyuta-agent on the device. The run method of this object is supposed to be called in order to install rapyuta-agent on the device.
- Returns:
returns the OnboardScript object
- Return type:
Following example demonstrates how to use the onboard_script method.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> onboard_script = device.onboard_script() >>> onboard_script.run()
- refresh(retry_limit=0)¶
Fetches the updated resource from the server, and adds/updates object attributes based on it.
- Parameters:
retry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failures occurs during the API call.
- Raises:
DeviceNotFountException: If the device is not found.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- save(retry_limit=0)¶
Update device details such as device name, device status and description.
- Parameters:
retry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failures occurs during the API call.
- Returns:
returns true if the device details updated successfully.
- Raises:
DeviceNotFountException: If the device is not found.- Raises:
ParameterMissingException: If any parameters are missing in the request.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
Following example demonstrates how to update a device.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.name = 'new_device_name' >>> device.save()
- subscribe_metric(metric, qos=QoS.LOW, retry_limit=0)¶
Deprecated since version 0.38.0: Will be removed in the future.
Subscribe to given metric on the device
- param metric:
metric to be subscribed
- type metric:
SystemMetric
- param qos:
QoS value of associated with metric
- type qos:
QoS
- param retry_limit:
Optional parameter to specify the number of retry attempts to be carried out if any failure occurs during API invocation
- type retry_limit:
int
- return:
returns the boolean indicating status of the operation
- raises:
DeviceNotFoundException: If the device is not found- raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- Following example demonstrate how to subscribe to a metric
>>> from rapyuta_io import Client >>> from rapyuta_io.clients.device import SystemMetric, QoS >>> client = Client(auth_token='auth_token', project='project_guid') >>> device = client.get_device('device_id') >>> device.subscribe_metric(SystemMetric.CPU, QoS.LOW)
- subscribe_topic(topic, qos=0, kind=TopicKind.METRIC, whitelist_tag=[], whitelist_field=[], fail_on_topic_inexistence=True, retry_limit=0)¶
To subscribe a topic
- Parameters:
topic (string) – topic name to subscribe
qos (integer) – QoS value for topic subscription
kind (enum
TopicKind) – subscribe the topic as a metric or logwhitelist_tag (list) – Optional parameter to specify the tags that needs to be whitelisted in metrics
whitelist_field (list) – Optional parameter to specify the fields that needs to be whitelisted in metrics
fail_on_topic_inexistence (bool) – Optional parameter to fail with error if topic doesnt exists on device
retry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failures occurs during the API call.
- Returns:
list containing subscription status.
- Raises:
DeviceNotFountException: If the device is not found.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
Following example demonstrates how to subscribe a topic
>>> from rapyuta_io import Client >>> from rapyuta_io.clients.device import QoS >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.subscribe_topic('test_topic', qos=QoS.MEDIUM.value, kind=TopicKind.METRIC)
- topic_status(retry_limit=0)¶
Get the subscribed and unsubscribed topics status
- Parameters:
retry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failures occurs during the API call.
- Returns:
Instance of class
TopicsStatus.- Raises:
DeviceNotFoundException: If the device is not found.- Raises:
UnknownTopicStatusException: If the topic status is empty.- Raises:
APIError: If the API call returns an error, the status code is anything other than 200/201.
Following example demonstrates how to get the topic status
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.topic_status()
- topics(retry_limit=0)¶
Fetching the available topics on the device
- Parameters:
retry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failures occurs during the API call.
- Returns:
List of topics in the device (list(string)
- Raises:
DeviceNotFountException: If the device is not found.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
Following example demonstrates how to get the topic list
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.topics()
- unsubscribe_metric(metric, retry_limit=0)¶
Deprecated since version 0.38.0: Will be removed in the future.
Unsubscribe to given metric
- param metric:
metric to be unsubscribed
- type metric:
SystemMetric
- param retry_limit:
Optional parameter to specify the number of retry attempts to be carried out if any failure occurs during API invocation
- type retry_limit:
int
- return:
boolean indicates the status of the operation
- raises:
DeviceNotFoundException: If the device is not found- raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- Following example demonstrate how to unsubscribe to a metric
>>> from rapyuta_io import Client >>> from rapyuta_io.clients.device import SystemMetric >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> device.unsubscribe_metric(SystemMetric.CPU)
- unsubscribe_topic(topic, kind=TopicKind.METRIC, retry_limit=0)¶
To unsubscribe a topic
- Parameters:
- Returns:
list containing unsubscription status.
- Raises:
DeviceNotFountException: If the device is not found.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
Following example demonstrates how to unsubscribe a topic
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> device.unsubscribe_topic('test_topic', TopicKind.METRIC)
- update_config_variable(config)¶
Update device configuration variable of a device.
- Parameters:
config (instance of
DeviceConfigclass) – Configuration variable- Returns:
instance of
DeviceConfigclass.- Raises:
ParameterMissingException: If any parameters are missing in the request.- Raises:
DeviceNotFoundException: If the device is not found.- Raises:
APIError: If the API call returns an error, the status code is anything other than 200/201.
Following example demonstrates how to update a device configuration variable.
>>> from rapyuta_io import Client >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> config_var = device.get_config_variables()[0] >>> config_var.value = 'new_config_value' >>> device.update_config_variable(config_var)
- update_label(label, retry_limit=0)¶
Update device label
- Parameters:
label (
Label) – instance of classLabelto updateretry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failures occurs during the API call.
- Returns:
updated instance of the class
Label.- Raises:
LabelNotFoundException: If the label is not found.- Raises:
APIError: If the API call returns an error, the status code is anything other than 200/201.
Following example demonstrates how to update a device label
>>> from rapyuta_io import Client >>> from rapyuta_io.clients.model import Label >>> client = Client(auth_token='auth_token', project="project_guid") >>> device = client.get_device('test_device_id') >>> label = device.get_labels()[0] >>> label.value = 'new label value' >>> device.update_label(label)
- upgrade()¶
Upgrade a device running with python2 to python3
- Raises:
DeviceNotFoundException: If the device is not found.- Raises:
DeploymentRunningException: When any deployment is running on the device.- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
Following example demonstrate how to upgrade a device onboarded on python2 runtime
>>> from rapyuta_io import Client >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> device.upgrade() >>> onboard_script = device.onboard_script() >>> onboard_script.run()
- upload_log_file(upload_request, retry_limit=0)¶
Uploads the specified logfile in request to the cloud storage
- Parameters:
upload_request (
LogsUploadRequest) – upload specific detailsretry_limit (int) – Optional parameter to specify the number of retry attempts to be carried out if any failure occurs during API invocation
- Returns:
UUID of the upload request using which user can query the status/download the file from cloud
- Raises:
APIError: If the api returns an error, the status code is anything other than 200/201
- Following example demonstrate how to upload the log file from device
>>> from rapyuta_io import Client >>> from rapyuta_io.clients import LogsUploadRequest >>> client = Client(auth_token='token', project='project_id') >>> device = client.get_device('device_id') >>> upload_request = LogsUploadRequest('/path/to/file.log', file_name='new-file-name.log', override=False, >>> purge_after=False, metadata={'key': 'value'}) >>> request_uuid = device.upload_log_file(upload_request)
- class DevicePythonVersion(*values)¶
Enumneration variables for the Device python version available in rapyuta.io
DevicePythonVersion.PYTHON2 (‘2’)
DevicePythonVersion.PYTHON3 (‘3’)
- class DeviceRuntime(*values)¶
Enumeration variables for the Device runtimes available in rapyuta.io.
DeviceRuntime.DOCKER (‘dockercompose’)
DeviceRuntime.PREINSTALLED (‘preinstalled’)
- class DeviceRuntimeKeys(*values)¶
The Device runtime keys to enable/disable runtimes available in rapyuta.io.
DeviceRuntimeKeys.RUNTIME_DOCKER (‘runtime_docker’)
DeviceRuntimeKeys.RUNTIME_PREINSTALLED (‘runtime_preinstalled’)
- class DeviceStatus(*values)¶
DeviceStatus enumeration represents the supported device status. Device status can be any of the below types
DeviceStatus.ONLINE
DeviceStatus.REJECTED
DeviceStatus.ACCEPTED
DeviceStatus.OFFLINE
DeviceStatus.REGISTERED
DeviceStatus.INITIALIZING
DeviceStatus.FAILED
DeviceStatus.NEW
DeviceStatus.DELETED
- class OnboardScript(token, url, command)¶
OnboardScript class can be used to download and run the device onboard script.
- Variables:
token – Authorization token needed to make api call
url – URL to download the onboard script
command – command to execute the downloaded script
- full_command()¶
Returns the full bash command that downloads and executes the onboard script.
- Returns:
returns the full bash command to onboard a device.
- Return type:
- run()¶
Downloads the onboard script and executes it in a subprocess. In case the script returns non-zero code after execution, an exception is raised.
- class QoS(*values)¶
Enumeration variables for QoS for topic/metric subscription.
QoS.LOW
QoS.MEDIUM
QoS.HIGH
- class ROSDistro(*values)¶
Enumeration variables for the Supported ROS Distros. ROS Distro may be one of:
ROSDistro.KINETIC (‘kinetic’)
ROSDistro.MELODIC (‘melodic’)
ROSDistro.NOETIC (‘noetic’)
- class SystemMetric(*values)¶
Metrics options that are currently supported by device. User can subscribe any of metrics options given below
SystemMetric.CPU
SystemMetric.MEMORY
SystemMetric.DISK
SystemMetric.DISKIO
SystemMetric.NETWORK
SystemMetric.WIRELESS
- class TopicKind(*values)¶
Enumeration variables for the Topic kind. Topic kind may be ‘Metric’ or ‘Log’
TopicKind.METRIC
TopicKind.LOG
- class TopicQOS(*values)¶
Deprecated since version 0.7.0: Use
QoSinstead.Enumeration variables for the Topic qos. Topic qos may be 0, 1 or 2
TopicQOS.ZERO
TopicQOS.ONE
TopicQOS.TWO
- class DeviceArch(*values)¶
DeviceArch enumeration represents supported device architectures. Device architecture can be any of the below types
DeviceArch.ARM32V7
DeviceArch.ARM64V8
DeviceArch.AMD64
- class Command(cmd, shell=None, env=None, bg=False, run_async=False, runas=None, pwd=None, cwd=None, timeout=300)¶
Command class represent command that is executed on a device.
- Variables:
shell – Represents the shell where it is going to execute
env – List of environment variables.
bg – Boolean value specifying whether the execution runs on the background or not
run_async – Boolean value to specify to run command in async mode i.e., to run command and return its jid (not depending on completion of the command).
runas – Run the command as a specific user
cmd – Command to execute on the device
pwd – Present working directory
cwd – Current working directory
- Note:
pwd is deprecated. Although backward compatibility is supported, it is recommended to use cwd instead.
- class DeviceConfig(*args, **kwargs)¶
DeviceConfig class represents configuration of a device. Member variables of the class represent the properties of device.
- Variables:
id – Id of the configuration.
key – Configuration key.
value – Value of the configuration key.
- class Label(*args, **kwargs)¶
Label class represents labels associated with a device.
- Variables:
id – Integer represents the id of the label
key – Key or label name
value – Value of the label
- class LogUploadStatus(*args, **kwargs)¶
This class instance represent current status of the upload request
- Variables:
status – Represents the current file upload status
error_message – Any error message during file upload
creator – User guid who initiated the upload operation
created_at – Timestamp at which logs upload initiated
request_uuid – An uniquely identifier associated with current upload
filename – Name of the file which is to be uploaded
updated_at – Timestamp at which file is updated
- class LogUploads(*args, **kwargs)¶
This class represents the status and other attributes associated with upload files.
- Variables:
status – Represents the current upload status
content_length – Length in bytes
creator – User guid who initiated the upload operation
created_at – Timestamp at which logs upload initiated
request_uuid – UUID associated with the request
creation_time – Timestamp at which file upload is completed
updated_at – Timestamp at which last file updated happened
filename – Name of the file which is to be uploaded
last_modified – represents the time at which last modification done to the file on cloud
metadata – key/value pair associated with upload request
- class LogsUploadRequest(device_path, file_name='', max_upload_rate=1048576, override=False, purge_after=False, metadata=None)¶
Request class for log upload API
- Variables:
device_path – absolute path of file on device
file_name – Name of the file in cloud storage. If not provided, file name is derived from the device_path
max_upload_rate – network bandwidth to be used for upload
override – If true overrides the destination file
purge_after – If true purges the log file after upload
metadata – Key/value to be associated with log file
- class Metric(*args, **kwargs)¶
Class represents current status of subscription of the metric
- Variables:
name – Name of the metric
kind – metric
config – Metric collection configuration
This class represents the Shared URL for Logs uploaded from the Device.
- Parameters:
request_uuid (str) – Request GUID of the Log file
expiry_time (
datetime.datetime) – Datetime object for the time at which Shared URL is supposed to expire.creator (str) – User GUID that created the Shared URL
created_at (str) – Timestamp at which Shared URL was created
The generated public URL.
- Raises:
InvalidParameterException: If the Shared URL is not created
- class TopicsStatus(*args, **kwargs)¶
Topic class represents the status - subscribed and unsubscribed - for logs and metrics
- Variables:
master_up – Boolean represents whether the master is running or not
subscribed – List of subscribed topics
unsubscribed – List of unsubscribed topics