Skip to content

Commit 51ca5e2

Browse files
Merge branch 'feature/ecos-alarm-and-cli' into development
1 parent fbfcccd commit 51ca5e2

3 files changed

Lines changed: 351 additions & 0 deletions

File tree

pyedgeconnect/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,14 @@ def __init__(
13281328
self.logger.addHandler(self.console_handler)
13291329

13301330
# Imported methods
1331+
from .ecos._alarm import (
1332+
acknowledge_appliance_alarms,
1333+
add_note_appliance_alarms,
1334+
clear_appliance_alarms,
1335+
delete_appliance_alarms,
1336+
get_appliance_alarm_descriptions,
1337+
get_appliance_alarms,
1338+
)
13311339
from .ecos._bonded_tunnel import (
13321340
configure_appliance_all_bonded_tunnels,
13331341
delete_appliance_multiple_bonded_tunnels,
@@ -1341,6 +1349,10 @@ def __init__(
13411349
get_appliance_multiple_bonded_tunnels_state,
13421350
get_appliance_single_bonded_tunnel_config,
13431351
)
1352+
from .ecos._cli import (
1353+
perform_appliance_cli_command,
1354+
perform_appliance_multiple_cli_command,
1355+
)
13441356
from .ecos._disk_usage import get_appliance_disk_usage
13451357
from .ecos._dns import get_appliance_dns_config, set_appliance_dns_config
13461358
from .ecos._gms import assign_orchestrator, get_orchestrator

pyedgeconnect/ecos/_alarm.py

Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
# MIT License
2+
# (C) Copyright 2022 Hewlett Packard Enterprise Development LP.
3+
#
4+
# alarm : Alarms
5+
from __future__ import annotations
6+
7+
8+
def get_appliance_alarms(
9+
self,
10+
) -> dict:
11+
"""Return active alarms
12+
13+
.. list-table::
14+
:header-rows: 1
15+
16+
* - Swagger Section
17+
- Method
18+
- Endpoint
19+
* - alarm
20+
- GET
21+
- /alarm
22+
23+
:return: Returns summary of alarms and outstanding alarm details \n
24+
* keyword **summary** (`dict`): Alarm summary object \n
25+
* keyword **num_cleared** (`int`): Number of alarms cleared
26+
* keyword **num_critical** (`int`): Number of critical
27+
alarms
28+
* keyword **num_equipment_outstanding** (`int`): Number of
29+
hardware alarms outstanding
30+
* keyword **num_major** (`int`): Number of major alarms
31+
* keyword **num_minor** (`int`): Number of minor alarms
32+
* keyword **num_outstanding** (`int`): Number of
33+
outstanding alarms
34+
* keyword **num_raise_ignore** (`int`): Number of raise
35+
ignore
36+
* keyword **num_software_outstanding** (`int`): Number of
37+
software alarms outstanding
38+
* keyword **num_tca_outstanding** (`int`): Number of TCA
39+
alarms outstanding
40+
* keyword **num_traffic_class_outstanding** (`int`): Number
41+
of traffic class alarms outstanding
42+
* keyword **num_tunnel_outstanding** (`int`): Number of
43+
tunnel alarms outstanding
44+
* keyword **num_warning** (`int`): Number of warning alarms
45+
* keyword **outstanding* (`list[dict]`): Outstanding alarms \n
46+
* [`dict`]: Outstanding Alarm detail object \n
47+
* keyword **severity** (`int`): Alarm severity,
48+
``0`` translates to ``Info``,
49+
``1`` translates to ``Warning``,
50+
``2`` translates to ``Minor``,
51+
``3`` translates to ``Major``,
52+
``4`` translates to ``Critical``,
53+
* keyword **sequenceId** (`int`): Alarm sequence ID
54+
* keyword **source** (`str`): Source IP address
55+
* keyword **acknowledged** (`bool`): ``True`` if alarm
56+
has been acknowledged
57+
* keyword **clearable** (`bool`): ``True`` if alarm
58+
can be cleared by user
59+
* keyword **time** (`int`): Time alarm occured in unix
60+
epoch ms
61+
* keyword **description** (`str`): Description of alarm
62+
detail
63+
* keyword **type** (`str`): Hardware (``HW``) or
64+
Software (``SW``)
65+
* keyword **recommendation** (`str`): Recommended action
66+
for alarm
67+
* keyword **serviceAffect** (`bool`): ``True`` if
68+
condition could be service affecting
69+
* keyword **typeId** (`int`): Alarm type ID number
70+
* keyword **name** (`str`): Alarm name
71+
* keyword **occurenceCount** (`int`): Count of
72+
occurences of alarm
73+
* keyword **active** (`bool`): ``True`` if alarm is
74+
currently active
75+
* keyword **ackedBy** (`str`): Username that
76+
acknolwedged alarm
77+
* keyword **ackedTime** (`int`): Time of acknolwedgement
78+
in Unix epoch ms
79+
* keyword **clearedBy** (`str`): Username that cleared
80+
alarm
81+
* keyword **clearedTime** (`int`): Time of clear in Unix
82+
epoch ms
83+
* keyword **note** (`str`): Additional alarm notes
84+
:rtype: dict
85+
"""
86+
return self._get("/alarm")
87+
88+
89+
def acknowledge_appliance_alarms(
90+
self,
91+
alarm_seq_ids: list[int],
92+
acknowledge: bool,
93+
ack_by: str,
94+
) -> bool:
95+
"""Acknowledge appliance alarms by sequence ids
96+
97+
.. list-table::
98+
:header-rows: 1
99+
100+
* - Swagger Section
101+
- Method
102+
- Endpoint
103+
* - alarm
104+
- POST
105+
- /alarm/acknowledgement
106+
107+
:param alarm_seq_ids: List of alarm sequence ids to acknowledge
108+
:type alarm_seq_ids: list[int]
109+
:param acknowledge: ``True`` to acknowledge alarms
110+
:type acknowledge: bool
111+
:param ack_by: User to mark alarms acknowledged by
112+
:type ack_by: str
113+
:return: Returns True/False based on successful call
114+
:rtype: bool
115+
"""
116+
data = {
117+
"sequenceIds": alarm_seq_ids,
118+
"acknowledge": acknowledge,
119+
"ackedBy": ack_by,
120+
}
121+
122+
return self._post(
123+
"/alarm/acknowledgement",
124+
data=data,
125+
return_type="bool",
126+
)
127+
128+
129+
def clear_appliance_alarms(
130+
self,
131+
alarm_seq_ids: list[int],
132+
cleared_by: str,
133+
) -> bool:
134+
"""Acknowledge appliance alarms by sequence ids
135+
136+
.. list-table::
137+
:header-rows: 1
138+
139+
* - Swagger Section
140+
- Method
141+
- Endpoint
142+
* - alarm
143+
- POST
144+
- /alarm/clearance
145+
146+
:param alarm_seq_ids: List of alarm sequence ids to clear
147+
:type alarm_seq_ids: list[int]
148+
:param cleared_by: User to mark alarms cleared by
149+
:type cleared_by: str
150+
:return: Returns True/False based on successful call
151+
:rtype: bool
152+
"""
153+
data = {
154+
"sequenceIds": alarm_seq_ids,
155+
"clearedBy": cleared_by,
156+
}
157+
158+
return self._post(
159+
"/alarm/clearance",
160+
data=data,
161+
return_type="bool",
162+
)
163+
164+
165+
def get_appliance_alarm_descriptions(
166+
self,
167+
format: str,
168+
) -> list:
169+
"""Get Orchestrator alarm descriptions
170+
171+
.. list-table::
172+
:header-rows: 1
173+
174+
* - Swagger Section
175+
- Method
176+
- Endpoint
177+
* - alarm
178+
- GET
179+
- /alarm/description2
180+
:param format: Specify to ``csv`` to download CSV format, otherwise
181+
will return information in list of dictionaries of JSON format
182+
:type format: str
183+
:return: Returns list of alarm descriptions and details \n
184+
* [`dict`]: List of alarm description dictionaries \n
185+
* keyword **typeId** (`int`): Alarm type id
186+
* keyword **severity** (`str`): Alarm severity info
187+
* keyword **description** (`str`): Alarm description
188+
* keyword **recommendedAction** (`str`): recommended action
189+
* keyword **serviceAffecting** (`bool`): Is alarm service
190+
affecting
191+
* keyword **source** (`str`): Module/system that generates
192+
alarm
193+
* keyword **systemType** (`int`): Identifies which system
194+
generated the alaram.0 = Appliance,100 = Orchestartor
195+
* keyword **sourceType** (`int`): Identifies the category of
196+
alarm. ``1`` = Tunnel, ``2`` = Traffic Class, ``3`` =
197+
Equipment, ``4`` = Software, ``5`` = Threshold
198+
* keyword **alarmType** (`int`): Uniquely identifies the
199+
type of alarm within a sourceType
200+
* keyword **clearable** (`bool`): Identifies whether an
201+
alarm is clearable
202+
:rtype: dict
203+
"""
204+
return self._get("/alarm/description2")
205+
206+
207+
def add_note_appliance_alarms(
208+
self,
209+
alarm_seq_ids: list[int],
210+
note: str,
211+
) -> bool:
212+
"""Update notes on appliance alarms
213+
214+
.. list-table::
215+
:header-rows: 1
216+
217+
* - Swagger Section
218+
- Method
219+
- Endpoint
220+
* - alarm
221+
- POST
222+
- /alarm/note
223+
224+
:param alarm_seq_ids: List of alarm sequence ids to add note to
225+
:type alarm_seq_ids: list[int]
226+
:param note: Note to add to specified alarms
227+
:type note: str
228+
:return: Returns True/False based on successful call
229+
:rtype: bool
230+
"""
231+
data = {
232+
"sequenceIds": alarm_seq_ids,
233+
"note": note,
234+
}
235+
236+
return self._post(
237+
"/alarm/note",
238+
data=data,
239+
return_type="bool",
240+
)
241+
242+
243+
def delete_appliance_alarms(
244+
self,
245+
alarm_seq_ids: list[int],
246+
) -> bool:
247+
"""Delete alarms on appliance
248+
249+
.. list-table::
250+
:header-rows: 1
251+
252+
* - Swagger Section
253+
- Method
254+
- Endpoint
255+
* - alarm
256+
- POST
257+
- /alarm/delete
258+
259+
:param alarm_seq_ids: List of alarm sequence ids to delete
260+
:type alarm_seq_ids: list[int]
261+
:return: Returns True/False based on successful call
262+
:rtype: bool
263+
"""
264+
data = {
265+
"sequenceIds": alarm_seq_ids,
266+
}
267+
268+
return self._post(
269+
"/alarm/delete",
270+
data=data,
271+
return_type="bool",
272+
)

pyedgeconnect/ecos/_cli.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# MIT License
2+
# (C) Copyright 2022 Hewlett Packard Enterprise Development LP.
3+
#
4+
# cli : API to execute commands on appliance CLI
5+
from __future__ import annotations
6+
7+
8+
def perform_appliance_cli_command(
9+
self,
10+
cli_command: str,
11+
) -> str:
12+
"""Run single cli command on appliance
13+
14+
.. list-table::
15+
:header-rows: 1
16+
17+
* - Swagger Section
18+
- Method
19+
- Endpoint
20+
* - cli
21+
- POST
22+
- /cli
23+
24+
:param cli_command: CLI command to perform on appliance, e.g.
25+
``show subnet learned``
26+
:type cli_command: str
27+
:return: Returns text response of cli command
28+
:rtype: str
29+
"""
30+
data = {"command": cli_command}
31+
return self._post(
32+
"/cli",
33+
data=data,
34+
return_type="text",
35+
)
36+
37+
38+
def perform_appliance_multiple_cli_command(
39+
self,
40+
cli_commands: list[str],
41+
) -> list:
42+
"""Run multiple cli commands on appliance
43+
44+
.. list-table::
45+
:header-rows: 1
46+
47+
* - Swagger Section
48+
- Method
49+
- Endpoint
50+
* - cli
51+
- POST
52+
- /cliMultiple
53+
54+
:param cli_commands: List of CLI command to perform on appliance,
55+
e.g. ``["show version", "show transceiver"]``
56+
:type cli_command: list[str]
57+
:return: Returns list of dictionaries of reuslts for each command \n
58+
* [`list[dict]`]: List of command results \n
59+
* keyword **command** (`str`): Cli command run
60+
* keyword **result** (`str`): Text result from cli command
61+
:rtype: list
62+
"""
63+
data = {"commands": cli_commands}
64+
return self._post(
65+
"/cliMultiple",
66+
data=data,
67+
)

0 commit comments

Comments
 (0)