Intermediate UCS Python SDK Part I Cisco DevNet Learning Labs


UCS Python SDK is a set of Python modules, each containing one or more classes, developed specifically to automate UCS Manager. UCS Python SDK is developed with PEP8 compliance and supports every Managed Object exposed by the UCS XML Object Model . A special function convert_to_ucs_python() enables automatic Python script generation from operations performed in the UCS Manager GUI. Use convert_to_ucs_python() to quickly script UCS tasks.

Cisco UCS is an Integrated Compute Infrastructure that has supported an XML API since its introduction. UCS Manager is the service that provides the XML API endpoint along with a graphical interface and a command line. The UCS components both physical and logical are represented as XML objects in a hierarchical Object Model format and can be manipulated via the XML API.

All UCS objects are described in an XML schema, this schema defines the objects their attributes and associated values. The schema is also used to generate a significant amount of the UCS Manager Python SDK. Because a UCS component must be part of the Object Model to be part of the UCS system all components of UCS are always available via the XML API.


This Intermediate UCS Python Learning Lab will guide you through the use of UCS Python SDK to connect to a UCS Manager, add/set several UCS Manager settings, export UCS Manager configurations (backup), create one-time backup jobs and import a backup export.

Completion time: 30 minutes


Prior to starting this learning lab it would be helpful to understand UCS Manager and the functionality that it provides to manage UCS compute environments.

An understanding of Python would also be helpful.

UCS Python SDK

UCS Python SDK is a library of python code that enables the retrieval and manipulation of UCS Manager managed objects. UCS Manager API interaction can be categorized into several distinct sections.

  • Sessions
  • Methods
  • Queries and Filters
  • Configurations and Transactions
  • Event Subscription

UCS Python SDK provides modules, classes and functions for all the categorizations of UCS Manager API interactions, along with functions that allow for the inspection of object metadata and object hierarchical containment.

UCS Python SDK Download and Documentation

UCS Python SDK is a community supported project, the code, documentation and samples repositories are on

Event Infrastructure Utilization

If you are utilizing event provided infrastructure a script has been provided to reset the environment to pre-lab settings.

On the desktop Double-click the Reset-Ucs-LL shortcut, provide the UCS Manager IP address that was assigned to you for the Learning Lab and hit Enter

Repeat this process for each assigned IP address, if you were assigned more than one.

Reset-Ucs-LL Icon:

Reset-Ucs-LL Console:

Exercise 1

Use the UCS Python SDK to view the UCS Manager Timezone and NTP servers.

  1. Enter the following python code to login to UCS Manager

    from ucsmsdk.ucshandle import UcsHandle
    handle = UcsHandle("<ucsm-ip>", "<ucsm-user>","<ucsm-password>")

    The response True means that the login was successful

  2. To retrieve the Timezone import the CommDateTime class

    from ucsmsdk.mometa.comm.CommDateTime import CommDateTime
  3. Query the CommDateTime Dn that is a reference to the Timezone managed object and save it to a variable

    timezone_mo = handle.query_dn("sys/svc-ext/datetime-svc")
  4. Print the Timezone object and view the output, it should be very similar to the image below

    print timezone_mo

    The Timezone object has multiple attributes, the timezone attribute, if one is set, will be a string in tzdata form.

  5. Retrieve the NTP Servers, import the class for NTP Servers and use the query_classid method of the UcsHandle class

    from ucsmsdk.mometa.comm.CommNtpProvider import CommNtpProvider
    ntp_mos = handle.query_classid("CommNtpProvider")
  6. Print the retrieved NTP Server managed objects

    print ntp_mos

    The image shows that no objects were retrieved, this is because there are no NTP servers defined. If some NTP servers are defined then those object references will be returned.

    This is the end of Exercise 1

Exercise 2

Use the UCS Python SDK to view the UCS Manager DNS Servers.

  1. Retrieve the DNS object and DNS Servers, import the class for DNS and the class for DNS Servers and use the query_dn and query_classid methods of the UcsHandle class

    from ucsmsdk.mometa.comm.CommDns import CommDns
    dns_mo = handle.query_dn("sys/svc-ext/dns-svc")
    from ucsmsdk.mometa.comm.CommDnsProvider import CommDnsProvider
    dns_mos = handle.query_classid("CommDnsProvider")
  2. Print the retrieved DNS Server managed objects

    print dns_mos

    The image shows that no objects were retrieved, this is because there are no DNS servers defined. If some DNS servers are defined then those object references will be returned.

    This is the end of Exercise 2

Exercise 3

Use the UCS Python SDK to set the UCS Timezone

  1. Set the UCS Timezone to America/Lima

    from ucsmsdk.mometa.comm.CommDateTime import CommDateTime
    timezone_mo = handle.query_dn("sys/svc-ext/datetime-svc")
    timezone_mo.timezone = 'America/Lima'
    timezone_mo = handle.query_dn("sys/svc-ext/datetime-svc")
    print timezone_mo

    The image shows that the timezone attribute has been set.

    This is the end of Exercise 3