cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
643
Views
5
Helpful
1
Replies

How to use Python SDK / API to acknowledge and reboot service profile

cshao
Level 1
Level 1

I have reviewed UCS programmability guide from DEVNET but no luck. Can you please help on the exact Python SDK / API to ' acknowledge & reboot a service profile ' after SP configuration change? ( for both UCS Central and Manager )

Regards,

Charles

1 Reply 1

delgadm
Cisco Employee
Cisco Employee

Hi Charles! Thanks for submitting your question. UCSM has a feature that generates code in Python that is equivalent to actions taken in the UCSM user interface. This comes in handy when you would like to programmatically accomplish what you know how to do in the user interface. Here's what you can do to generate code to start a service profile in UCSM:

  1. Log into UCSM (you can also use the UCSM Platform Emulator if want to try it with an endpoint that is not in production).
  2. Simultaneously press the keys <cntrl><alt><q> (substitute the <alt> key with <option> on a mac)
  3. You'll see Record XML appear at the top of the UCSM UI. Click Record XML.
  4. Perform the action in the UCSM UI you wish to convert to generate code for.
  5. Click Stop XML Recording when you complete your tasks in the UCSM UI
  6. Save the newly generated XML log file.
  7. Execute the code below to convert the XML log file to Python code.

Covert the capture XML log file to Python:

from ucsmsdk.utils.converttopython import convert_to_ucs_python

convert_to_ucs_python(xml=True, literal_path="path_to_the_log_file_from_step_6_above")

convert_to_ucs_python returns the python code needed to perform the action recorded in the UI. The example below shows the outcome of the steps above and how code was generated to set a service profile's desired power state to on:

### Please review the generated cmdlets before deployment.

##### Start-Of-PythonScript #####

from ucsmsdk.mometa.ls.LsPower import LsPower

mo = LsPower(parent_mo_or_dn="org-root/org-da-compute/ls-HCI-1", state="admin-up")
handle.add_mo(mo, True)

handle.commit()
##### End-Of-PythonScript #####
### End of Convert-To-Python ###

Additional Resources: