Skip to content

Commit

Permalink
add device discovery task
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelSuleiman committed Nov 23, 2023
1 parent 0071cb1 commit 65a385c
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions uniconfig/python/frinx_worker/uniconfig/device_discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import requests
from frinx.common.conductor_enums import TaskResultStatus
from frinx.common.frinx_rest import UNICONFIG_URL_BASE
from frinx.common.type_aliases import DictAny
from frinx.common.type_aliases import ListStr
from frinx.common.worker.service import ServiceWorkersImpl
from frinx.common.worker.service import WorkerImpl
from frinx.common.worker.task_def import TaskDefinition
from frinx.common.worker.task_def import TaskExecutionProperties
from frinx.common.worker.task_def import TaskInput
from frinx.common.worker.task_def import TaskOutput
from frinx.common.worker.task_result import TaskResult
from frinx_api.uniconfig.rest_api import Discover

from frinx_worker.uniconfig import class_to_json


class DeviceDiscoveryWorkers(ServiceWorkersImpl):
class UniconfigDeviceDiscovery(WorkerImpl):
class ExecutionProperties(TaskExecutionProperties):
exclude_empty_inputs: bool = False
transform_string_to_json_valid: bool = True

class WorkerDefinition(TaskDefinition):
name: str = 'UNICONFIG_device_discovery'
description: str = 'Verification of reachable devices in a network.'
labels: ListStr = ['BASICS', 'UNICONFIG']

class WorkerInput(TaskInput):
template: DictAny

class WorkerOutput(TaskOutput):
output: DictAny

def execute(self, worker_input: WorkerInput) -> TaskResult[WorkerOutput]:
if Discover.request is None:
raise Exception(f'Failed to create request {Discover.request}')

response = requests.request(
url=UNICONFIG_URL_BASE + Discover.uri,
method=Discover.method,

data=class_to_json(
Discover.request(
**worker_input.template
),
),
)

status = TaskResultStatus.COMPLETED
if not response.ok:
status = TaskResultStatus.FAILED

return TaskResult(
status=status,
output=self.WorkerOutput(
output=response.json()
)
)

0 comments on commit 65a385c

Please sign in to comment.