link information anymore.
+ Add "configure system hostname ." option to not use a FQDN
for system name.
+ + Add "-f json0" to provide a more regular/machine-parsable output
+ to JSON output, even when not compiled with --enable-json0.
* Fixes:
+ Handle team interfaces like a bond. Real MAC address cannot be
retrieved yet.
struct json_writer_private {
FILE *fh;
+ int variant;
struct element *root;
struct element *current; /* should always be an object */
};
static void
json_cleanup(struct json_writer_private *p)
{
- json_element_cleanup(p->root);
+ if (p->variant != 0)
+ json_element_cleanup(p->root);
}
static void
}
struct writer*
-json_init(FILE *fh)
+json_init(FILE *fh, int variant)
{
struct writer *result;
struct json_writer_private *priv;
priv->fh = fh;
priv->root = priv->current = json_element_new(NULL, NULL, OBJECT);
+ priv->variant = variant;
result = malloc(sizeof(*result));
if (result == NULL) fatal(NULL, NULL);
Choose the output format. Currently
.Em plain ,
.Em xml ,
-.Em json
+.Em json ,
+.Em json0
and
.Em keyvalue
formats are available. The default is
.Em plain .
+.Em json0
+is more verbose than
+.Em json
+but the structure of the JSON object is not affected by the number of
+interfaces or the number of neighbors. It is therefore easier to
+parse.
.It Fl c Ar file
Read the given configuration file. This option may be repeated several
times. If a directory is provided, each file contained in it will be
if (strcmp(fmt, "plain") == 0) w = txt_init(stdout);
else if (strcmp(fmt, "keyvalue") == 0) w = kv_init(stdout);
- else if (strcmp(fmt, "json") == 0) w = json_init(stdout);
+ else if (strcmp(fmt, "json") == 0) w = json_init(stdout, 1);
+ else if (strcmp(fmt, "json0") == 0) w = json_init(stdout, 0);
#ifdef USE_XML
else if (strcmp(fmt, "xml") == 0) w = xml_init(stdout);
#endif
extern struct writer *txt_init(FILE *);
extern struct writer *kv_init(FILE *);
-extern struct writer *json_init(FILE *);
+extern struct writer *json_init(FILE *, int);
#ifdef USE_XML
extern struct writer *xml_init(FILE *);
assert j == expected
+@pytest.mark.skipif('JSON' not in pytest.config.lldpcli.outputs,
+ reason="JSON not supported")
+def test_json0_output(lldpd1, lldpd, lldpcli, namespaces, uname):
+ with namespaces(2):
+ lldpd()
+ with namespaces(1):
+ result = lldpcli("-f", "json0", "show", "neighbors", "details")
+ assert result.returncode == 0
+ out = result.stdout.decode('ascii')
+ j = json.loads(out)
+
+ eth0 = j['lldp'][0]['interface'][0]
+ del eth0['age']
+ del eth0['chassis'][0]['capability'][3]
+ del eth0['chassis'][0]['capability'][1]
+ expected = {"lldp": [{
+ "interface": [{
+ "name": "eth0",
+ "via": "LLDP",
+ "rid": "1",
+ "chassis": [{
+ "id": [{
+ "type": "mac",
+ "value": "00:00:00:00:00:02"
+ }],
+ "name": [{"value": "ns-2.example.com"}],
+ "descr": [{"value": "Spectacular GNU/Linux 2016 {}".format(uname)}],
+ "mgmt-ip": [{"value": "fe80::200:ff:fe00:2"}],
+ "capability": [
+ {"type": "Bridge", "enabled": False},
+ {"type": "Wlan", "enabled": False},
+ ]}
+ ],
+ "port": [{
+ "id": [{
+ "type": "mac",
+ "value": "00:00:00:00:00:02"
+ }],
+ "descr": [{"value": "eth1"}],
+ "ttl": [{"value": "120"}]
+ }]
+ }]}
+ ]}
+
+ if 'Dot3' in pytest.config.lldpd.features:
+ expected['lldp'][0]['interface'][0]['port'][0]['auto-negotiation'] = [{
+ "enabled": False,
+ "supported": False,
+ "current": [{"value":
+ "10GigBaseCX4 - X copper over 8 pair 100-Ohm balanced cable"}]
+ }]
+ assert j == expected
+
+
@pytest.mark.skipif('XML' not in pytest.config.lldpcli.outputs,
reason="XML not supported")
def test_xml_output(lldpd1, lldpd, lldpcli, namespaces, uname):