November 8, 2016 · ucsmsdk ucspython

Auto-generate python script for tasks done on UI

Welcome the convert_to_ucs_python API.

Assumption:

User knows to do an operation via the JAVA based UCSM GUI
UCSM UI and convert_to_ucs_python should be launched on the same client machine.

Basic Idea:

How it works:

UCSM GUI logs all the activities that are performed via it, and the python shell monitors that log to generate the equivalent python script. Since the logging is local to the machine where the UI is running, convert_to_ucs_python also must run on the same machine.
Sample Usage:

Step 1 - Launch the UCSM GUI.

from ucsmsdk.utils.ucsguilaunch import ucs_gui_launch  
from ucsmsdk.ucshandle import UcsHandle

# Login to the server
handle = UcsHandle(<ip>, <username>, <password>)  
handle.login()

# launch the UCSM GUI
ucs_gui_launch(handle)  

Step 2 - Run convert_to_ucs_python

The CLI will go into a listen mode until Ctrl+C is pressed again. Until then it prints equivalent script for operations done on the UI.

Print the equivalent script to console

from ucsmsdk.utils.converttopython import convert_to_ucs_python

convert_to_ucs_python()

Print the equivalent script to console, also print the XMLs that the UI sends out

from ucsmsdk.utils.converttopython import convert_to_ucs_python

convert_to_ucs_python(dump_xml=True)  

Output the script to a file

from ucsmsdk.utils.converttopython import convert_to_ucs_python

file_path = r”/home/user/pythoncode.py”

convert_to_ucs_python(dump_to_file=True, dump_file_path=file_path)  

XML to python

xml_str=’‘’<configConfRename  
                dn=”org-root/ls-ra1” 
                inNewName=”ra2” 
                inHierarchical=”false”> 
                </configConfRename>’‘’

convert_to_ucs_python(xml=True, request=xml_str)  

note:

The path of UCSM UI logs is differs based on the OS and so sometimes the convert_to_ucs_python API may not be able to autodetect the logfiles that it needs to function. The following workaround can be applied in those cases,

Manually find the path to which UCSM UI logs

$ sudo find / -name '.ucsm' 
./Library/Application Support/Oracle/Java/Deployment/log/.ucsm 
$

Run convert_to_ucs_python by specifying the log_path

from ucsmsdk.utils.converttopython import convert_to_ucs_python

convert_to_ucs_python(gui_log=True, path=<path that was found above>)  
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket