Execute 'setsite' in TCL script

Clovertech Forums Cloverleaf Execute 'setsite' in TCL script

  • Creator
    Topic
  • #111377
    Devika Agarwal
    Participant

      Can we execute ‘setsite’ in Tcl script?

    Viewing 3 reply threads
    • Author
      Replies
      • #111378
        Keith McLeod
        Participant

          I believe this is what I last used when providing the $site value

           

          if ![catch {netcfgLoad} err] {
          NCFG:ChangeSite $site
          netcfgLoad
          }

           

        • #111406
          Jim Kosloskey
          Participant
            Here s a module I used to change dynamically to another site:
            ################################################################################
            # Name:  oth_switch_site
            # Purpose: Switch to a Cloverleaf Site
            # UPoC type: other
            # Args:  upvar 1 argument
            #                          arg4tcl         –  the additional argument block
            #                                             which the Site Name (sans pathing)
            #                                             is provided.
            #                                             A DEBUG parameter is also provided.
            # Author:       Jim Kosloskey
            # Date-written: 06/13/2013
            #
            #**************************************************************************************************************
            #*                                            C O D E   A U D I T                                                               *
            #*_____________________________________________________________________________*
            #*Date       I-Catcher  Description                                                                                          *
            #*———- ———- ———————————————–*
            #*06/13/2013            Procedure conceived.
            #*
            #*______________________________________________________________________________*
            #*
            #*______________________________________________________________________________*
            #**************************************************************************************************************
            #
            # Notes:
            #            This procedure is intended to be invoked from another Tcl procedure.
            #            The invoking procedure needs to deliver the following arguments:
            #                arg4tcl – an argument block consisting of a keyed list with the following values:
            #                           SITENM – This key has a value associated with it which is the site name
            #                                    to which we want to switch.
            #                           DEBUG    – This key has a value associated with it which tells this proc to
            #                                             produce displayed values of variables and actions within this
            #                                             proc for the purposes of debug. A value of Y or y will turn debug
            #                                             on – any other value will turn debug off.
            #            The arg4tcl block would have this look: {{SITENM “mysite”} {DEBUG “y”}}
            #
            ################################################################################
            #
            proc oth_switch_site { } {
            global HciConnName           ;#Get the connection name
            global HciSite
            global env
            #
            # Check the HCI globals to see if they exist
            # They won’t exist if we are not invoked while within Cloverleaf
            # So we need to null them so they do exist and we can have a proc
            # which works within Cloverleaf and outside Cloverleaf
            #
            if {![info exists HciConnName]} {
            variable HciConnName “not Cloverleaf”
            }
            if {![info exists HciSite]} {
            variable HciSite “not Cloverleaf”
            }
            # Upvar the variables from the invoker
            upvar arg4tcl arg4tcl
            set sitename   “”
            set mydebug_sw “N”
            set ret_cd     “”
            set err        “”
            set module     “OTH_SWITCH_SITE v1.0:”
            # Check for DEBUG  The debug_sw variable will contain the provided arg
            set ret_cd [keylget arg4tcl DEBUG mydebug_sw]
            if {$ret_cd} {                   ;# Found the argument
            } else {                       ;# Couldn’t find the argument
            echo “$HciConnName $module ERROR!!: Cannot locate DEBUG!”
            return
            }
            set mydebug_sw [string map

              $mydebug_sw]     ;#Change to logic sw

              #Get SITENM
              set ret_cd [keylget arg4tcl SITENM sitename]
              if {$ret_cd} {                   ;# Found the argument
              } else {                       ;# Couldn’t find the argument
              echo “$HciConnName $module ERROR!!: Cannot locate SITENM!”
              return
              }
              #If debug – display received arguments
              if {$mydebug_sw} {          ;#Debug on?
              echo “$HciConnName $module: argument block = >$arg4tcl<”
              echo “$HciConnName $module: SITENM = >$sitename<”
              echo “$HciConnName $module: DEBUG   = >$mydebug_sw<”
              echo “$HciConnName $module: —- Switching to Site named >$sitename<.”
              }
              #Do the switch

              set ret_cd [catch {eval [exec ${::env(HCIROOT)}/sbin/hcisetenv -site tcl $sitename]} err]
              if {$ret_cd} {
              echo “$module Switch to site >$sitename< failed…”
              echo “$module with error >$err<. Aborting!”
              return 0
              }
              return 1

              }

              email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

            1. #111486
              Devika Agarwal
              Participant

                Thanks Keith and Jim for sharing your scripts. I was finally able to setsite in Tcl. However, I am unable to stop a thread in site B from site A (script in site A) even after I changed site to site B in Tcl. Is there something I am missing?

                Devika

                • #111506
                  David Barr
                  Participant

                    Where is your TCL code executing? Is this in a TPS proc in thread in Site A?

                  • #111507
                    Devika Agarwal
                    Participant

                      It is a TPS proc and I am running it through server command-line using ‘tcl’. The proc isn’t in any threads.

                    • #111512
                      David Barr
                      Participant

                        I think you’re better off just using exec with the correct command to stop the thread.

                         

                        set res [catch { exec ksh -c "setsite site_b; hcicmd -p process_b1 -c 'thread_b1 pstop'" } output]
                        echo res = $res
                        echo output = $output

                      • #111515
                        Devika Agarwal
                        Participant

                          I am unable to execute setsite from tcl. I get ‘no such file or directory’ error. I am on Windows.

                      • #111544
                        David Barr
                        Participant

                          How about this?

                          set res [catch { exec hcicmd -s site_b -p process_b1 -c “thread_b1 pstop” } output]
                          echo res = $res
                          echo output = $output

                          • This reply was modified 5 years, 4 months ago by David Barr.
                          • #111571
                            Devika Agarwal
                            Participant

                              That worked. Thanks David. I really appreciate your help.

                        Viewing 3 reply threads
                        • You must be logged in to reply to this topic.