6 Replies Latest reply on Mar 26, 2014 9:47 AM by Jorge Lavín

    Remote nexec via BLJython

      Hi all


      A little context: I'm trying to implement Jython scripting for automatism in Bladelogic BSA. For now, I want the remote funcionality that NSH gives but in a Jython script. I thought that it could be done via calls with Popen (check the end of this message):

       

      in the testing machine we have a bljython setup:

       

      Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
      [Java HotSpot(TM) 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_37
      Type "help", "copyright", "credits" or "license" for more information.
      
      
      

       

      In the Bladelogic GUI I try to launch, as a type 3 NSH Script

       

      #!/usr/bin/env bljython
      
      
                              ####################
                              ######IMPORTS#######
                              ####################
                            
      import sys
      sys.path.append('/tmp/JLG/lib')
      import os
      import time
      print ('Importing Jython Scripting Modules...')
      try:
          from logger import Logger
          from server import BSAServer, JLI
      except ImportError, e:
          print ('[ERROR] Failed import: ' + e.message)
          sys.exit(0)
      
      
                              #############################
                              ######GLOBAL VARIABLES#######
                              #############################
                           
      LOG = Logger(0)
      TARGET = BSAServer(sys.argv[1])
      TARGET.runNexec()
      
      
      

       

      where BSAServer is defined as (Entity is not relevant here, it only defines a name and JLI is the class for BLCLI)

       

      class BSAServer(Entity):
          """Base class for Server entity """
               
          def __init__(self, serverName):
              ''' As a first approach, we let BSAServers be identified by their hostname '''
            
              self.name = serverName
      
      
      

       

      and the method we are interested in is

       

      def runNexec(self, command='pwd'):
              ''' Runs a nexec '''
            
              p = Popen('nexec '+hostname+' command', stdout=PIPE, stderr=PIPE)
            
              (out, err) = (p.communicate())
            
              status = p.poll()
         
              if status != 0:
                  return (1,log.log_error(err))
             
              else:
                  print (0,out.splitlines())
      
      
      

       

       

      but the NSH Script Job doesn't implement this. In the Job log I get (The [ERROR] is part of the Logger custom class we have)

       

      [ERROR] nexec: symbol lookup error: /usr/local/bl_agent/NSH/lib/libnc.so: undefined symbol: XML_ParserCreate
      
      

       

      when TARGET.runNexec() is executed.

       

      I'm mentioning John Landells because he could be helpful

       

      Thanks all for your time and efforts

        • 1. Re: Remote nexec via BLJython

          Not sure how helpful I can *REALLY* be, but I'll try....

           

          My suspicion is that because you're calling out of Jython (which is simply a Java process) that you're not in NSH when you call the Popen(), so nexec is simply not available.  Can you extend the Popen() call to run the nexec inside an nsh shell?  You may have to handle authentication though, so this might not be the neatest method.

           

          We should maybe have Carl Burger look at this too, as he's a but of a Jython ninja!

           

          -John.

          1 of 1 people found this helpful
          • 2. Re: Re: Remote nexec via BLJython

            Hi John

             

            Thanks for a very fast reply


            A litle more info,


            First I tried to call the nexec as:

             

            nsh -c 'nexec hostname command'
            

             

            which works perfectly in the command line of the test machine, Now, if I move it inside a Popen, it no longer works. In fact, I get the very same error. I also tried to just open a nsh console (which will cause the job to stand still, but at least it executes)  but i get the same error.

             

            At this particular moment there are credentials cached in the test machine

            • 3. Re: Re: Remote nexec via BLJython
              Bill Robinson

              what version of bladelogic is this ?

              1 of 1 people found this helpful
              • 4. Re: Re: Remote nexec via BLJython

                Now I'm upgrading to 8.3, AppServer version is 8.3 and agent of that machine was 8.2

                • 5. Re: Re: Remote nexec via BLJython
                  Bill Robinson

                  you are getting this error in 8.3 ? or some other version ?

                   

                  there was an issue in 8.1 (and possibly later) where the libnc.so: undefined symbol: XML_ParserCreate   message was thrown when a nsh script that uses the nsh perl module is called and nsh is configured to use the nsh proxy.

                   

                  what are you nexec'ing here ?

                  • 6. Re: Re: Re: Remote nexec via BLJython

                    There was some kind of version conflict in the machine. There was a 8.2 installation of the agent and a 8.3 installation of the console. It seems to me that libnc.so that was being used was the 8.2 one. Now I get the expected output for the nexec

                     

                    [ERROR] nexec: Error accessing host xxx: No authorization to access host
                    
                    

                     

                    the same with the NSH console, whose configuration seems to be wrong. I'm executing a 'hostname'

                     

                    Thanks again, this community is really a life-saver