lf_json_autogen.py: now has /probe url functionality

Signed-off-by: Jed Reynolds <jed@candelatech.com>
This commit is contained in:
Jed Reynolds
2021-09-10 14:33:56 -07:00
parent ab7f0ccf6b
commit 9f74fec635

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
Generated by LANforge JsonApiPythonGenerator, Tue Sep 07 15:54:21 PDT 2021
Generated by LANforge JsonApiPythonGenerator, Fri Sep 10 14:30:41 PDT 2021
- - WORK IN PROGRESS - -
The API this library provides is actively being changed.
This file expects to live in py-json/LANforge directory.
@@ -1075,6 +1075,8 @@ class LFJsonGet(LFCliBase):
/port/$shelf_id
/port/$shelf_id/$resource_id
/port/$shelf_id/$resource_id/$port_id
/portprobe/
/portprobe/$shelf_id/$resource_id/$port_id
/ports/
/ports/$shelf_id
/ports/$shelf_id/$resource_id
@@ -1212,6 +1214,63 @@ class LFJsonGet(LFCliBase):
singular_key="interface",
plural_key="interfaces")
#
"""----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
Notes for <PROBE> type requests
If you need to call the URL directly,
request one of these URLs:
/probe/
/probe/$shelf_id/$resource_id/$port_id
When requesting specific column names, they need to be URL encoded:
entity+id, probe+results
Example URL: /probe?fields=entity+id,probe+results
Example py-json call (it knows the URL):
record = LFJsonGet.get_probe(eid_list=['1.234', '1.344'],
requested_col_names=['probe results'],
debug_=True)
The record returned will have these members:
{
'entity id': # Entity ID
'probe results': # Probe the low level information about the port.
}
----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----"""
def get_probe(self,
eid_list=None,
requested_col_names=(),
debug_=False):
debug_ |= self.debug
url = "/probe"
if (eid_list is None) or (len(eid_list) < 1):
raise ValueError("no entity id in request")
trimmed_fields = []
if isinstance(requested_col_names, str):
if not requested_col_names.strip():
raise ValueError("column name cannot be blank")
trimmed_fields.append(requested_col_names.strip())
if isinstance(requested_col_names, list):
for field in requested_col_names:
if not field.strip():
raise ValueError("column names cannot be blank")
field = field.strip()
if field.find(" ") > -1:
raise ValueError("field should be URL encoded: [%s]" % field)
trimmed_fields.append(field)
url += self.make_eid_url(eid_list=eid_list)
if len(trimmed_fields) > 0:
url += "?fields=%s" % (",".join(trimmed_fields))
response = self.json_get(url, debug_=debug_)
if response is None:
return None
return self.extract_values(response=response,
singular_key="probe-results",
plural_key="probe-results")
#
"""----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
Notes for <QUIT> type requests