JLI script with one argument in the input


In the following example, the JLI command requires one input argument. This example JLI script executes BLCLI commands to obtain the permissions on a server (which you specify in the input). It returns a string that combines two outputs — ACL and server type — separated by a tab character.

BLCLI command

blcli -v <profile> Server showPermissions <machine name or ip address>

Input

Server name

Output

ACL and server type, separated by a tab character.

For example:
BLAdmins        Server.*

JLI command

./bljythonexe “<location of jli script file>” “<Server Name>”

Warning

Note

The exact JLI command depends on your operating system:

  • On Windows, use the bljythonexe command.
  • On UNIX, use the bljython command.

Sample script

import re
import sys
import string as s
import bladelogic.cli.CLI as blcli
#Server Name
serverName=sys.argv[1]
jli = blcli.CLI()
jli.setServiceProfileName("<profile>")
jli.setRoleName("<Role>")
jli.connect()
def execute(command):
    print command
    #main CLI command execution.
     propertyObject = jli.run(cmd)
                 
    #If command executed successfully, return the result received after command execution.
    if(propertyObject.success()):
          propertyKey = propertyObject.returnValue
    return str(propertyKey)
                     
def split(result):
    #Using regular expression to split the result with a tab
     arr = re.split('\t',result)
     i = 0
                  
    #looping the array elements to remove newline.      
    for element in arr:
         #Strips newlines from right end of the string.
          arr[i]=s.rstrip(element)
          i+=1
    return arr
#declaring the command array to hold commands to be executed
cmd =[]       
#Appending namespace
cmd.append('Server')
#Appending command
cmd.append('showPermissions')
#Appending other parameters
cmd.append(serverName)
#Result is returned as an array.
result = split(execute(cmd))  
print result
acl=result[0]
type=result[1]
print acl
print type
sys.exit(0)


 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*

TrueSight Server Automation 23.2