-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0071cb1
commit 65a385c
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
uniconfig/python/frinx_worker/uniconfig/device_discovery.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
) | ||
) |