mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-01 13:23:01 +02:00
yanger: use argparse in yanger
This should be a non-functional change in preparation for upcoming patches. Signed-off-by: Richard Alpe <richard@bit42.se>
This commit is contained in:
committed by
Mattias Walström
parent
415632f3b7
commit
ce37b33390
@@ -3,6 +3,7 @@
|
||||
import subprocess
|
||||
import json
|
||||
import sys # (built-in module)
|
||||
import argparse
|
||||
|
||||
def json_get_yang_type(iface_in):
|
||||
if iface_in['link_type'] == "loopback":
|
||||
@@ -358,18 +359,19 @@ def add_ethtool_std(ifname, iface_out):
|
||||
insert(iface_out, "ieee802-ethernet-interface:ethernet", "speed", str(num))
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 2:
|
||||
print(f"usage: yanger <model> [params]", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
model = sys.argv[1]
|
||||
if(model == 'ietf-interfaces'):
|
||||
parser = argparse.ArgumentParser(description="YANG data creator")
|
||||
parser.add_argument("model", help="IETF Model")
|
||||
parser.add_argument("-p", "--param", default=None, help="Model dependant parameter")
|
||||
args = parser.parse_args()
|
||||
|
||||
if (args.model == 'ietf-interfaces'):
|
||||
# For now, we handle each interface separately, as this is how it's
|
||||
# currently implemented in sysrepo. I.e sysrepo will subscribe to
|
||||
# each individual interface and query it for YANG data.
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print(f"usage: yanger ietf-interfaces IFNAME", file=sys.stderr)
|
||||
if not args.param:
|
||||
print(f"usage: yanger ietf-interfaces -p INTERFACE", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
yang_data = {
|
||||
@@ -378,14 +380,14 @@ if __name__ == "__main__":
|
||||
}
|
||||
}
|
||||
|
||||
ifname = sys.argv[2]
|
||||
ifname = args.param
|
||||
iface_out = yang_data['ietf-interfaces:interfaces']['interface'][0]
|
||||
|
||||
add_ip_link(ifname, iface_out)
|
||||
add_ip_addr(ifname, iface_out)
|
||||
add_ethtool_groups(ifname, iface_out)
|
||||
add_ethtool_std(ifname, iface_out)
|
||||
elif(model == 'ietf-routing'):
|
||||
elif (args.model == 'ietf-routing'):
|
||||
yang_data = {
|
||||
"ietf-routing:routing": {
|
||||
"ribs": {
|
||||
@@ -400,6 +402,6 @@ if __name__ == "__main__":
|
||||
ipv4routes = yang_data['ietf-routing:routing']['ribs']['rib'][0]
|
||||
add_ipv4_route(ipv4routes);
|
||||
else:
|
||||
print(f"Unsupported model {model}", file=sys.stderr)
|
||||
print(f"Unsupported model {args.model}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
print(json.dumps(yang_data, indent=2))
|
||||
|
||||
+6
-3
@@ -129,10 +129,11 @@ static json_t *json_get_ip_link(void)
|
||||
static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent,
|
||||
char *model, const char *arg)
|
||||
{
|
||||
char *yanger_args[4] = {
|
||||
char *yanger_args[5] = {
|
||||
"/libexec/infix/yanger",
|
||||
model,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
FILE *stream;
|
||||
@@ -144,8 +145,10 @@ static int ly_add_yanger_data(const struct ly_ctx *ctx, struct lyd_node **parent
|
||||
return SR_ERR_SYS;
|
||||
}
|
||||
|
||||
if (!strcmp(model, "ietf-interfaces"))
|
||||
yanger_args[2] = (char *)arg;
|
||||
if (!strcmp(model, "ietf-interfaces")) {
|
||||
yanger_args[2] = "-p";
|
||||
yanger_args[3] = (char *)arg;
|
||||
}
|
||||
|
||||
fd = memfd_create("my_temp_file", MFD_CLOEXEC | MFD_NOEXEC_SEAL);
|
||||
if (fd == -1) {
|
||||
|
||||
Reference in New Issue
Block a user