cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2569
Views
0
Helpful
5
Replies

http::geturl VRF?

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!

5 Replies 5

Joe Clarke
Cisco Employee
Cisco Employee

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/"

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 

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
}

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

Yeah.  Seems many platforms didn't actually get VRF support.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: