11-30-2016 08:40 PM
Hi,
Im trying to POST some data from Cisco IOS using TCL HTTP lib. Do anyone knows how to set VRF which should be used for HTTP connection from TCL script?
HTTP lib:
tmpsys:/lib/tcl/http.tcl
TCL script example
::cisco::eem::event_register_none maxrun 60 namespace import ::cisco::eem::* namespace import ::cisco::lib::* namespace import http::* if [catch {cli_open} result] { puts stderr $result exit 1 } else { array set cli1 $result } if [catch {cli_exec $cli1(fd) "enable"} result] { puts stderr $result exit 1 } set http_check_url "http://1.1.1.1/" if [catch {http::geturl $http_check_url} result] { puts stderr $result exit 1 } set output [http::data $result] action_syslog msg "RESULT: $result" http::Finish $result http::cleanup $result
Thanks!
12-01-2016 08:00 AM
I think you'll need to create a new URL type for this. Define a function called vrf_sock:
proc vrf_sock { {options {}} host port } {
set fd [socket $options $host $port]
fconfigure $fd -vrf MYVRF
return $fd
}
Then register a handler for this function with the http library:
http::register "http+vrf" 80 "::vrf_sock"
Then call geturl with this new URL scheme:
set http_check_url "http+vrf://1.1.1.1/"
12-21-2017 02:28 PM
Hi Joe,
I'm looking at http gets from the management vrf on C4500-X platform, used in a similar manner to your auto install post to send switch info to an external API.
A present I seem to be unable to get your "vrf_sock" solution to work on IOS-XE and i do not seem to be able to find any additional info for tcl fconfigure or socket functions.
using your example i end up with no value given for parameter "port" to "::vrf_sock"
when removing the port param from vrf_sock I end up with couldn't open socket: host is unreachable
any help you can offer would be greatly appreciated
Cheers
Olaf
12-23-2017 05:46 AM
Try this function instead:
proc vrf_sock { args } { set options [list] while { [llength $args] } { switch -glob -- [lindex $args 0] { -my* {lappend options [lindex $args 0] ; lappend options [lindex $args 1] ; set args [lrange $args 2 end] ; break} -async {lappend options [lindex $args 0] ; set args [lrange $args 1 end] ; break} -* {error "unknown option [lindex $args 0]"} default break } } if { [llength $args] != 2 } { error "usage: vrf_sock ?options? host port" } set host [lindex $args 0] set port [lindex $args 1] set fd [socket $options $host $port] fconfigure $fd -vrf MYVRF return $fd }
03-29-2019 12:25 AM
Hi Joe,
I hope you are well.
I never actually solved this in the end and had to park this part of the project at the time.
I have been looking at it again recently and came across https://bst.cloudapps.cisco.com/bugsearch/bug/CSCvn44930
Would you think this this is root cause?
Cheers
04-02-2019 02:25 AM
Yeah. Seems many platforms didn't actually get VRF support.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide