Is there any api to register action point similar to tailf actionpoint in confd.
Hi,
I have no idea what an actionpoint in confd is.
Regards, Michal
Hello Michal
Sorry i was not clear to you.Basically i want to implement something like this.
The following example defines an action to reset one server at a server farm:
module server-farm {
namespace "http://example.net/server-farm";;
prefix "sfarm";
list server {
key name;
leaf name {
type string;
}
action reset {
input {
leaf reset-at {
type yang:date-and-time;
mandatory true;
}
}
output {
leaf reset-finished-at {
type string;
mandatory true;
}
}
}
}
}
Hi,
to implement the action you are supposed to set a callback for the action struct lys_node using nc_set_rpc_callback(). Then it will get triggered just like any other RPC during nc_ps_poll().
Regards, Michal
Hi Michal
Thanks for the info. But when we keep this rpc (action) outside of a container, What should be the xml request be ? How to specify Namespace.
I have tried with the below xml request but it threw error message .
><error-message xml:lang="en">Missing element's "namespace".</error-message></rpc-error>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>urn:ietf:params:netconf:base:1.0</capability>
</capabilities>
</hello>
]]>]]>
<?xml version="1.0" encoding="UTF-8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
<action:reset>
<data>
<user xmlns="com:infinera:security:user">
<reset-at>Try</reset-at>
</user>
</data>
</action:reset>
</rpc>
]]>]]>
Please advise
Hi,
it seems you have taken the previous example (server-farm) from the YANG RFC action section and there is also an example invocation so I am confused as to why you have not followed it and I have no idea where you got the <action:reset> notation. Anyway, just follow the example and it will work just fine.
Regards, Michal
Hi Michal
Thanks for response, Yes it worked.Could you pls help me to parse the xml request that i pass for reset-at leaf into a string?
I tried doing below way but it prints leaf name
290 const struct lys_node *nod;
291 nod=ly_ctx_get_node(sinfo.ly_context,NULL,"/user:reset/user:reset-at",0);
292 std::cout<<"printing reset-at "<<nod->name<<"\n";
rpc reset {
input {
leaf reset-at {
type string;
description "Test Leaf2";
}
}
output {
leaf reset-finished-at {
type string;
description "Test Leaf3";
}
}
}
Hi, I am quite lost as to what is it exactly that you are asking me. Please, tell me what is your situation, are you using libnetconf2 to implement your own NETCONF server? If so, why are do you want to print the XML RPC request into string? Generally, you will not even get to the request itself using libnetconf2 API because it is completely handled internally.
Regards, Michal
Hi
I did not mean to print the xml request. I want just the leaf values into my variables.
You will get them in your action callback that will be called automatically during nc_ps_poll().
Regards, Michal
Hi Michal,
Yes i am inside my action callback , But i want to parse it . The below way ends up in a crash.
295 const struct lys_node *nod;
296
297 struct ly_set *nodeset =NULL;
298 nodeset = lyd_find_path(rpc, "/user:reset");
299 if(nodeset)
300 {
301 struct lyd_node_anydata *any = (struct lyd_node_anydata*)nodeset->set.d[0];;
302 std::cout<<" Found Filter Node : Num : "<<nodeset->number<<" Any Val type :"<< any->value_type<<" "<<any->value.str<<"\n\n";
303
304 if(any->value_type== LYD_ANYDATA_CONSTSTRING)
305 {
306
307 if( !(root = lyd_parse_mem(sinfo.ly_context, any->value.str, LYD_XML, options)))
308 std::cout<<"Not Successfull root"<<"\n";
309 std::cout<<"Printing error number"<<ly_errno<<"\n";
310 }
311 }
Yang:
rpc reset {
input {
leaf reset-at {
type string;
description "Test Leaf2";
}
}
output {
leaf reset-finished-at {
type string;
description "Test Leaf3";
}
}
}
Hi,
it crashes because you are missing a check that the returned nodeset in non-empty, NULL is returned only on a fatal error, not if no nodes are found.
Then, you are asking for /user:reset RPC node even tough you are then trying to assign it to struct lyd_node_anydata. Correctly it should be just struct lyd_node, it is not an anydata node.
Next, probably connected to the previous problem, you are trying to parse the RPC even though I said you will get the values already in your callback, you have nothing more to parse.
So, my first strong advice is that you take a good look at the whole documentation of libyang so that you understand what you are writing. Next, you may want to look at netopeer2 RPC callbacks (the standard ones, op_kill() in netopeer2/server/op_kill.c is very simple, the definition of this RPC is in ietf-netconf) and see how the values are retrieved there. After that you should know how to fix your code.
Regards, Michal