NEO Tasks
File Name |
neo_tasks.py |
|
Description |
This SDK manipulates NEO tasks data using NEO's REST API. The script includes the following main operations:
|
|
Usage |
neo_tasks.py [-h] -s SERVER -u USERNAME -p PASSWORD [-r {http,https}] --port {80,443,3080,3443} -o {delete,add,getall,run,get} [-t PARAMETERS] [-f FILE] [-b] |
|
Arguments |
-h |
Displays the help menu |
-s SERVER |
NEO server IP |
|
-u USERNAME |
NEO username |
|
-p PASSWORD |
NEO password |
|
--port |
The port used to communicate with NEO. If NEO is run on a physical machine:
If NEO run on a docker container:
|
|
-r {http,https} |
Connection protocol to NEO |
|
-o {add,get,getall,delete,run} |
Script operations |
|
-t PARAMETERS |
URL parameters. Valid formats:
|
|
-b |
Blocks any action while running a provisioning task. Can only be used for the 'execute' operation. |
|
-f FILE |
A file in json format containing the payload of the request. |
'add'
Required Arguments |
|
File Name |
|
For example:
{
"action": "run_cli",
"description": "Adding VLAN to switch",
"object_type": "System",
"object_ids": ["10.209.24.39"],
"params": {
"commandline": ["#!desc: Adding VLAN to switch",
"#!system_profile: Ethernet",
"#!system_type: mlnxos_switch",
"#!update_conf: true",
"#!owner: *system*",
"#<VLAN_ID>|desc:Number of VLAN to create",
"#<VLAN_ID>|type:str",
"#<VLAN_ID>|restriction:regex ^\\d{1,5}$|^\\d{1,5}-\\d{1,5}$",
"#<VLAN_ID>|error:vlan_id can be a single number between 1-4094 or a range
of numbers(example: 4-17)",
"#<VLAN_name>|desc:Textual name for the VLAN",
"#<VLAN_name>|type:str",
"#<VLAN_name>|restriction:regex ^.{1,40}$",
"#<VLAN_name>|error:vlan_name maximum size is 40 characters",
"vlan <VLAN_ID>",
"exit",
"vlan <VLAN_ID> name \"<VLAN_name>\""],
"arguments": {
"globals": {
"VLAN_ID": "836",
"VLAN_name": "example"
}
}
}
}
Output example:
[root@ufm_sdk]# /opt/neo/venv/bin/python neo_tasks.py -s 10.209.37.77 -u admin -r https --port 443 -p 123456 -o add -f tasks_add_example
======================================================================
<<< NEO - Adding a new task SDK >>>
----------------------------------------------------------------------
[*] Running Settings:
-> NEO server IP address: 10.209.37.77
-> NEO user name: admin
======================================================================
[*] Adding a new task stages:
-1- Setting Up data...
-2- Sending Adding a new task request...
======================================================================
[*] Adding a new task results:
>> Adding a new task request HTTP response status code: 201
>> Adding a new task request HTTP response text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/neo/app/tasks/ cde6fc47-309c-4aa4-ae58-adb026a85067">/neo/app/tasks/cde6fc47-309c-4aa4-ae58- adb026a85067</a>. If not click the link.
======================================================================
'get'
Required Arguments |
|
Parameters |
'task_id' – the task ID of an existing task |
Output example:
[root@ufm_sdk]# /opt/neo/venv/bin/python neo_tasks.py -s 10.209.37.77 -u admin -r https --port 443 -p 123456 -o get -t "task_id=register-snmp-v2-traps-task"
======================================================================
<<< NEO - Getting task data SDK >>>
----------------------------------------------------------------------
[*] Running Settings:
-> NEO server IP address: 10.209.37.77
-> NEO user name: admin
======================================================================
[*] Getting task data stages:
-1- Setting Up data...
-2- Sending Getting task data request...
======================================================================
[*] Getting task data results:
>> Getting task data request HTTP response status code: 200
>> Getting task data request HTTP response text:
{
"lastJobId": "",
"description": "Register for SNMP v2 traps for switches",
"schedule": {},
"instanceID": "register-snmp-v2-traps-task",
"createdOn": null,
"object_type": null,
"object_ids": [],
"parent_task_id": null,
"action": "Provisioning",
"readOnly": true,
"task_type": "",
"params": {
"commandline": [
"snmp-server host <ip_address> traps version 2c <community_name>"
],
"arguments": {
"globals": {
"community_name": "public",
"ip_address": "10.209.37.77"
}
}
},
"lastRunTime": null,
"owner": "admin",
"hidden": false
}
======================================================================
'getall'
Output example:
[root@ufm_sdk]# /opt/neo/venv/bin/python neo_tasks.py -s 10.209.37.77 -u admin -r https --port 443 -p 123456 -o getall
======================================================================
<<< NEO - Getting all tasks data SDK >>>
----------------------------------------------------------------------
[*] Running Settings:
-> NEO server IP address: 10.209.37.77
-> NEO user name: admin
======================================================================
[*] Getting all tasks data stages:
-1- Setting Up data...
-2- Sending Getting all tasks data request...
======================================================================
[*] Getting all tasks data results:
>> Getting all tasks data request HTTP response status code: 200
>> Getting all tasks data request HTTP response text:
[
{
"lastJobId": "",
"description": "Enable Link Layer Discovery",
"schedule": {},
"instanceID": "enable-lldp-snmp-task",
"createdOn": null,
"object_type": null,
"object_ids": [],
"parent_task_id": null,
"action": "Provisioning",
"readOnly": true,
"task_type": "",
"params": {
"commandline": [
"snmp-server enable",
"snmp-server community <community_name>",
"lldp"
],
"arguments": {
"globals": {
"community_name": "public"
}
}
},
"lastRunTime": null,
"owner": "admin",
"hidden": false
},
.
.
.
]
======================================================================
'delete'
Required Arguments |
|
Parameters |
'task_id' – the task ID of an existing task |
Output example:
[root@ufm_sdk]# /opt/neo/venv/bin/python neo_tasks.py -s 10.209.37.77 -u admin -r https --port 443 -p 123456 -o delete -t "task_id=cde6fc47-309c-4aa4-ae58-adb026a85067"
======================================================================
<<< NEO - Removing a task SDK >>>
----------------------------------------------------------------------
[*] Running Settings:
-> NEO server IP address: 10.209.37.77
-> NEO user name: admin
======================================================================
[*] Removing a task stages:
-1- Setting Up data...
-2- Sending Removing a task request...
======================================================================
[*] Removing a task results:
>> Removing a task request HTTP response status code: 204
======================================================================
'run'
Required Arguments |
|
Parameters |
'task_id' – the task ID of an existing task |
Output example:
[root@ufm_sdk]# /opt/neo/venv/bin/python neo_tasks.py -s 10.209.37.77 -u admin -r https --port 443 -p 123456 -o run -t "task_id=cde6fc47-309c-4aa4-ae58-adb026a85067"
======================================================================
<<< NEO - Running a task SDK >>>
----------------------------------------------------------------------
[*] Running Settings:
-> NEO server IP address: 10.209.37.77
-> NEO user name: admin
======================================================================
[*] Running a task stages:
-1- Setting Up data...
-2- Sending Running a task request...
======================================================================
[*] Running a task results:
>> Running a task request HTTP response status code: 202
>> Running a task request HTTP response text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/neo/app/jobs/11">/ neo/app/jobs/11</a>. If not click the link.
======================================================================
For executing the task and waiting until it's done, use the -b argument.