6 Replies Latest reply on Dec 4, 2014 3:03 AM by John Landells

    JYthon scripting in Bladelogic

    Siddu angadi

      Hi,

       

      Can someone please help me on following query?

       

      I have created one sample Run.py to create folder under SERVER structure. When I run it directly, it is working fine.

       

      I want to run it from Bladelogic Console through NSH, it is giving error. The code is as below:

       

      jli.setServiceProfileName and jli.setRoleName are not be same, which depends on console login. So I am commenting these and executing through NSH job and however I am end up with error. How to achieve this?

       

       

       

       

       

      import sys
      import re
      import bladelogic.cli.CLI as blcli
      jli = blcli.CLI()
      jli.setServiceProfileName('defaultProfile')
      jli.setRoleName('BLAdmins')
      jli.connect()

         cmdServer = ["StaticServerGroup","createGroupWithParentName",newGroup,parentGroup]
         serverGroup = jli.run(cmdServer)

        • 1. JYthon scripting in Bladelogic

          What is the error you are getting ?

          What type of NSh script have you configured this to be ?

          • 2. JYthon scripting in Bladelogic
            Siddu angadi

            It is straight fwd NSH script with run time arguments.  Is there any specific stpes to I need to take on NSH scripting?

             

            When I uncomment jli.setServiceProfileName and jli.setRoleName, and run with defaultProfile and BLAdmin role, it will get successfull.

             

            Thanks

            Siddu

            • 3. JYthon scripting in Bladelogic

              When you run from the appserver, you dont need to provide the profile detail and role as it is taken from the credentials of the user who is executing the job,

              So, just connect and execute the jli/

              • 4. Re: JYthon scripting in Bladelogic
                Siddu angadi

                Below is my error screenshot:

                 

                Untitled.png

                 

                My code file as below:

                 

                "

                 

                 

                import sys
                import re
                import string as s
                import bladelogic.cli.CLI as blcli
                jli = blcli.CLI()
                jli.connect()

                JOB_GROUP = sys.argv[1]
                JOB_NAME = sys.argv[2]
                cmd =["DeployJob","getDBKeyByGroupAndName",JOB_GROUP,JOB_NAME]
                JOB_KEY1 = jli.run(cmd)
                JOB_KEY = JOB_KEY1.returnValue
                cmd2 =["Job","setPropertyValue",JOB_KEY,"QUALITY_APPROVAL","true"]
                changeProp=jli.run(cmd2)
                print changeProp.returnValue

                 

                 

                "

                • 5. JYthon scripting in Bladelogic
                  Siddu angadi

                  Screenshot is proper and am copying the error file below:

                   

                  -----------------------------------------------------------

                   

                  Error          Apr 3, 2012 10:13:12 AM          com.bladelogic.om.infra.session.client.SessionLoginException: com.bladelogic.om.infra.session.client.SessionLoginException: No authentication profile name specified.

                  Error          Apr 3, 2012 10:13:12 AM          at java.lang.reflect.Method.invoke(Unknown Source)

                  Error          Apr 3, 2012 10:13:12 AM          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

                  Error          Apr 3, 2012 10:13:12 AM          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

                  Error          Apr 3, 2012 10:13:12 AM          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                  Error          Apr 3, 2012 10:13:12 AM          at com.bladelogic.om.infra.cli.CLIMain.loginToAppServer(CLIMain.java:815)

                  Error          Apr 3, 2012 10:13:12 AM          at com.bladelogic.om.infra.session.client.SessionLoginManager.login(SessionLoginManager.java:93)

                  Error          Apr 3, 2012 10:13:12 AM          at com.bladelogic.om.infra.session.client.SessionLoginManager.connect(SessionLoginManager.java:164)

                  Error          Apr 3, 2012 10:13:12 AM          at com.bladelogic.om.infra.cli.CliLoginOperations.obtainSessionCredential(CliLoginOperations.java:96)

                  Error          Apr 3, 2012 10:13:12 AM          at com.bladelogic.om.infra.cli.CliLoginOperations.getSessionCredentialFromCache(CliLoginOperations.java:154)

                  Error          Apr 3, 2012 10:13:12 AM          cli.loginToAppServer();

                  Error          Apr 3, 2012 10:13:12 AM          File "C:\Program Files\BMC Software\BladeLogic\NSH\br\jython\bladelogic\cli\CLI.py", line 84, in connect

                  Error          Apr 3, 2012 10:13:12 AM          jli.connect()

                  Error          Apr 3, 2012 10:13:12 AM          File "Program Files\BMC Software\BladeLogic\NSH\share\sensors\changeProp.jli", line 13, in <module>

                  Error          Apr 3, 2012 10:13:12 AM          Traceback (most recent call last):

                  Error          Apr 3, 2012 10:13:07 AM          *sys-package-mgr*: can't write cache file for 'C:\Program Files\BMC Software\BladeLogic\NSH\br\stdlib\vim25-1.0.jar'

                  Error          Apr 3, 2012 10:13:06 AM          *sys-package-mgr*: processing modified jar, 'C:\Program Files\BMC Software\BladeLogic\NSH\br\stdlib\vim25-1.0.jar'

                   

                  ----------------------------------------------------------

                  • 6. Re: JYthon scripting in Bladelogic

                    I know this is an old post, but since it never seemed to get answered, I though it might still help someone if I add a reply...

                     

                    In order to run a Jython script from within BladeLogic, we need it to either be called by an NSH script, or better still, to actually BE an NSH script.  The easiest way to achieve this is to wrap your Jython in NSH:

                    #!/bin/nsh
                    exec bljython - "$@"  <<__EndOfJython__
                    #========================================================================================
                    # Jython code goes here
                    #
                          .
                          .
                          .
                      <more Jython code>
                          .
                          .
                          .
                    __EndOfJython__
                    

                     

                    This snippet executes everything between the 2 __EndOfJython__ tags using BLJython, but is actually a valid NSH script.  There can sometimes be a few "gotchas" when passing parameters, but most of the time it works perfectly!

                     

                    Hope this helps someone!

                     

                    God bless,

                    -John.