6 Replies Latest reply on Jul 23, 2014 10:13 AM by John Landells

    Using Jython Against 2 BL Environments

      Hi All,

       

      IHAC that has 2 completely separate BladeLogic environments - one for developing new content, and their production system.  They want me to look at writing a script which can move content from one environment to the other and for various reasons, Jython seems the most appropriate method in this instance.

       

      However.....

       

      Can anyone tell me *HOW* I can access 2 separate BladeLogic environments from within a single Jython script, please?  I've tried creating 2 separate instances of the CLI class, but this doesn't seem to work - all my BLCLI calls are going to whichever instance was create first.

       

      Many thanks,

      -John.

        • 1. Re: Using Jython Against 2 BL Environments
          Bill Robinson

          in the br/jython/bladelogic/cli/CLI.py add:

           

            def disconnect(self):

                          from com.bladelogic.client import *

                          i = net.ClientConnectionPool.getInstance();

                          ii = net.ClientConnectionPool.getInstance().closeAllConnections();

                          BRProfile.setSessionCredential(None);

                          return net.ClientConnectionPool.getInstance().getConnectionCount();

           

          you should be able to call that to destroy the connection, then create a new on to the other env.

          • 2. Re: Using Jython Against 2 BL Environments

            Hi Bill,

             

            This method works, but means continually closing and opening connections as we need to iterate across items in the individual environments.  On the other hand, we can create multiple instances of the CLI class, both pointing to different app servers with the relevant SSO files etc, but these instances both seem to ignore their associated parameters and only operate on the first connection that we create.

             

            Am I doing something stupid here, or is the Jython CLI really so badly designed that unique instances are actually not unique???

             

            Cheers,

            -John.

            • 3. Re: Using Jython Against 2 BL Environments
              Bill Robinson

              how are you creating the separate instances ?  can you paste in the code ?

              • 4. Re: Using Jython Against 2 BL Environments

                import bladelogic.cli.CLI as blcli

                 

                blcliProfileDev = "BLDev"

                blcliProfileProd = "BLProd"

                blcliRole = "BLAdmins"

                jli_prod = ""

                jli_dev = ""

                 

                blDev = {"AppServerHost": "bldev.***.***.***********.com", "AppServerPort": "9840", "SSOFile": "/C/BMC/BladeLogic/cache/bl_sesscc.dev", "ServiceProfile": "BLDev"}

                blProd = {"AppServerHost": "blprod.***.***.***********.com", "AppServerPort": "9840", "SSOFile": "/C/BMC/BladeLogic/cache/bl_sesscc.prod", "ServiceProfile": "BLProd"}

                 

                def blcliConnect(jli, blEnv):

                    jlang.System.setProperty("com.bladelogic.cli.debug.release-only","false")

                    jli.setServiceProfileName(blEnv["ServiceProfile"])

                    jli.setRoleName(blcliRole)

                    jli.setAppServerHost(blEnv["AppServerHost"])

                    jli.setAppServerPort(blEnv["AppServerPort"])

                    jli.setSsoCredentialCache(blEnv["SSOFile"])

                    jli.connect()

                 

                 

                jli_dev = blcli.CLI()

                jli_prod = blcli.CLI()

                • 5. Re: Using Jython Against 2 BL Environments

                  Just a thought....

                   

                  Wold the Web Services be powerful enough to handle this or would I maybe be better off building some kind of socket communication between my 2 systems?  The socket approach feels a little OTT in my book, but would at least allow me to have Jython processes running against their own, individual app servers.  My alternative is dumping everything out to a helper server, but I'm reluctant to use the export functionality from BladeLogic due to the number of issues we've faced here with it.

                   

                  Thoughts?

                   

                  -John.

                  • 6. Re: Re: Using Jython Against 2 BL Environments

                    I've just been revisiting this thread, as we never got to the bottom of the issue....


                    Here's my sample code so far:

                     

                    import bladelogic.cli.CLI as blcli
                    import java.lang as jlang
                     
                    blcliProfileDev = "BLDev"
                    blcliProfileProd = "BLProd"
                    blcliRole = "BLAdmins"
                    jli_prod = ""
                    jli_dev = ""
                    
                    blDev = {"AppServerHost": "bldev.***.***.**********.com", "AppServerPort": "9840", "SSOFile": "/C/BMC/BladeLogic/cache/bl_sesscc.dev", "ServiceProfile": "BLDev"}
                    blProd = {"AppServerHost": "blprod.***.***.**********.com", "AppServerPort": "9840", "SSOFile": "/C/BMC/BladeLogic/cache/bl_sesscc.prod", "ServiceProfile": "BLProd"}
                    
                    def blcliConnect(jli, blEnv):
                        jlang.System.setProperty("com.bladelogic.cli.debug.release-only","false")
                        jli.setServiceProfileName(blEnv["ServiceProfile"])
                        jli.setRoleName(blcliRole)
                        jli.setAppServerHost(blEnv["AppServerHost"])
                        jli.setAppServerPort(blEnv["AppServerPort"])
                        jli.setSsoCredentialCache(blEnv["SSOFile"])
                        jli.connect()
                    
                    def blcliCall(jli, *blcliArgs):
                        blcliCmd = list(blcliArgs)
                        blcliResult = jli.run(blcliCmd)
                        return (blcliResult.success(), blcliResult.returnValue)
                    
                    jli_dev = blcli.CLI()
                    jli_prod = blcli.CLI()
                    
                    blcliConnect(jli_dev, blDev)
                    blcliConnect(jli_prod, blProd)
                    
                    (ok, allDevServers) = blcliCall(jli_dev, "Server", "listAllServers")
                    (ok, allProdServers) = blcliCall(jli_prod, "Server", "listAllServers")
                    
                    exit(0)
                    

                     

                     

                    What I don't understand is that even though I receive 2 separate JLI instances, both supposedly connected to a different BladeLogic system, why does the second call to Server.listAllServers return the same results as the first one???

                     

                    It would be awesome if we could get to the bottom of this, as I now know that I'm not the only person trying to get this working!

                     

                    -John.