cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
18562
Views
4
Helpful
17
Comments
ericwill
Cisco Employee
Cisco Employee

This version of the UCS Manager Python SDK is **Deprecated**


Please use this version - Cisco UCS Python SDK - ucsmsdk

Cisco UCS Manager Python SDK (BETA version 0.8.3) is available for download.

Cisco UCS Manager Python SDK is a python module which helps automate all aspects of Cisco UCS management including server, network, storage and hypervisor management. The bulk of the Cisco UCS Python SDK work on the UCS Manager’s Management Information Tree (MIT), performing create, modify or delete actions on the Managed Objects (MO) in the tree. The next chapter provides an overview of the Cisco UCS Management Information Model (MIM).  One of the easiest ways to learn UCS configuration through UCS Python SDK is to automatically generate python script, for configuration actions performed with the UCSM GUI, using ConvertToPython API.

Cisco UCS Manager Python SDK release 0.8.3 is licensed under Apache License, Version 2.0

What's new in version 0.8.3?

  • Embedded dynamic import support to enhance memory utilization.
  • XmlParser changed to cElementTree to improve performance.
  • Modified URI method to verify correct port.
  • Modified Login API to decide connection protocol (via http or https) based on both port and noSsl flag
  • Fixed StartGuiSession for jnlpfile variable error and added support to launch GUI in debug mode for java version > 1.7.45
  • Fixed GetJavaInstallation method to display JAVA_HOME path in case of an exception.
  • Modified WatchUcsGui in order to support multiline query via ConvertToPython API

**Note for users who has scripts developed using SDK 0.8.2 or earlier release**

Due to dynamic import support in release 0.8.3, scripts written using earlier versions of SDK need to be modified to make it work with this latest release 0.8.3. Please refer to section 3.6.1 in Cisco UCS SDK release 0.8.3 user guide (cisco_ucs_python_sdk_rel_0.8.3.pdf) for details.

What's new in version 0.8.2?

  • Refreshed with UCSM Schema 2.2(2c)
  • Removed keys() function while iterating dictionary to improve execution speed.
  • Fixed "AttributeError", which happens when configuring an unknown MO.

For any queries/feedback on the Python SDK, please add a discussion to the Cisco Developed Integrations sub-space on Cisco UCS Communities.

Comments
ctorlins
Level 1
Level 1

Hi Erik, would you be able to update the API document to also version 0.8, it still lists the 0.6 version , looking

for any documentation enhancements to match 0.8

thanks

c

reswaran
Cisco Employee
Cisco Employee

It will be updated in a day or two.

ctorlins
Level 1
Level 1

Great, thanks! Looking really forward to good documentation and new API calls in the 2.2 release, in particular around Firmware managed and Fabric Interconnect control! Thanks!!!

ctorlins
Level 1
Level 1

can we add this to github to monitor changes better? github/datacenter is by Cisco. Thanks!

c

reswaran
Cisco Employee
Cisco Employee

I have uploaded the latest user guide. But not sure if it has the information that you are looking for. We have provided inline documentation for each API. You can use pydoc to refer to this inline help.

jmunk
Level 4
Level 4

Eric

The "nested" import of Python classes does not seem to work on Windows for the 8.0.3 version of the UCSM Python SDK. I did not have similar problems with the 8.0.2 version.

I am running Windows 7 and use the following procedure for installing Python 2.7.8 and the UCSM Python SDK:

1. Install Python 2.7.8 on Windows "by the book"

2. Copy the UcsSDK directory to my Python program files folder C:\Python27\UcsSdk and run "python setup.py build" and then "python setup.py install" from here (for the 8.0.3 version I only ran "python setup.py install" according to the PKG-INFO file)(.

This works fine for SDK version 8.0.2. However for SDK version 8.0.3, my Python program can no longer recognize the object class Ids (in casu the first classid it adresseses is "MacpoolPool.ClassId()", and that fails with "NameError: name 'MacpoolPool' is not defined").

The difference between the SDK versions 8.0.2 and 8.0.3 Python "packages" is, that in 8.0.2 You have directly in the C:\Python27\Lib\site-packages\UcsSdk one single file, Mos.py, which has all the class defitions (e.g. class MacpoolPool(ManagedObject)). In contrast in version 8.0.3 You use "nested" import of Python classes etc. through C:\Python27\Lib\site-packages\UcsSdk -> C:\Python27\Lib\site-packages\UcsSdk\MoMeta, where there is one separate file per Class (e.g. MacpoolPool.py).

And for some reason this does not seem to work in Windows 7, even though the __init__.py files appear to be correct.

BR

Jesper

ragupta4
Cisco Employee
Cisco Employee

Jesper

In Version 0.8.3, if you want to use the MO as "MacpoolPool.ClassId()" then you need to import the respective module as below, then you can use this classid referencing utility similar to what you used to do in version 0.8.2.

from UcsSdk.MoMeta.MacpoolPool import MacpoolPool

Earlier all the Mo class definitions were in single file, now we have individual file for each mo class definition. So now you have to individually import the definition of respective Mo.

Thanks

Rahul

jmunk
Level 4
Level 4

Rahul

- Great with such quick response!

- That works!

- I use a lot of classes. Is there any way, possibly another “way” of importing, such that I can import all classes together. Otherwise it will be quite cumbersome to import all relevant classes.

BR

Jesper

Fra: Rahul Gupta

Sendt: 27. oktober 2014 10:51

Til: Jesper Munk

Emne: Re: - Cisco UCS Manager Python SDK (BETA version 0.8.3)

Cisco Communities <https://communities.cisco.com/>

Cisco UCS Manager Python SDK (BETA version 0.8.3)

new comment by Rahul Gupta<https://communities.cisco.com/people/ragupta4>

View all comments on this document<https://communities.cisco.com/docs/DOC-36899#comment-16958>

ragupta4
Cisco Employee
Cisco Employee

Currently there is no straight forward way to import all the MO definition at once.

And by default UcsSdk packages doesn't import any MoMeta modules statically i.e. on the import of the package.

However if you don't want to write individual Mo definition you can write below method in your script and call it in the begining itself. Hope this helps.

def loadAllMo():

    import os

    import UcsSdk

    exports = []

    globals_, locals_ = globals(), locals()

    package_path = os.path.dirname(UcsSdk.__file__)

    package_name = os.path.basename(package_path)

    mometa_path = os.path.join(package_path,'MoMeta')

    for filename in os.listdir(mometa_path):

        modulename, ext = os.path.splitext(filename)

        if not modulename.endswith('Meta') and ext in ('.py') and modulename != '__init__':

            subpackage = '{}.{}'.format(package_name+".MoMeta", modulename)

            module = __import__(subpackage, globals_, locals_, [modulename])

            modict = module.__dict__

            names = [name for name in modict if name[0] != '_']

            exports.extend(names)

            globals_.update((name, modict[name]) for name in names)

           

if __name__ == "__main__":

    loadAllMo()

    print LsServer.ClassId()

Thanks

jmunk
Level 4
Level 4

Rahul

- Looks really great, I will test and give You feedback (probably tomorrow)

- Actually I just did the same “outside” Python with copying all MoMeta and MethodMeta files into two large files, and importing them, but Your method “inside” Python is definitely the best

- Look forward to test it!

BR

Jesper

Fra: Rahul Gupta

Sendt: 28. oktober 2014 08:30

Til: Jesper Munk

Emne: Re: - Cisco UCS Manager Python SDK (BETA version 0.8.3)

Cisco Communities <https://communities.cisco.com/>

Cisco UCS Manager Python SDK (BETA version 0.8.3)

new comment by Rahul Gupta<https://communities.cisco.com/people/ragupta4>

View all comments on this document<https://communities.cisco.com/docs/DOC-36899#comment-16977>

mariorui
Cisco Employee
Cisco Employee

Eager Newb here, so please forward me to another forum if this is not appropriate.

When using the "ConverToPython" I am given a "NameError":

MARIO:Desktop mario$ python convert.py

Exception: name 'ConvertToPython' is not defined

------------------------------------------------------------

Traceback (most recent call last):

  File "convert.py", line 11, in <module>

    ConvertToPython(dumpToFile=True, dumpFilePath=outfilepath)

NameError: name 'ConvertToPython' is not defined

------------------------------------------------------------

MY CODE:

from UcsSdk import *

ucsm_ip = 'x.x.x.x'

user = 'admin'

password = 'Cisco123'

if __name__ == "__main__":

        try:

                handle = UcsHandle()

                handle.Login(ucsm_ip, user, password)

                outfilepath = r"/Users/mario/Desktop/ucs.out"

                ConvertToPython(dumpToFile=True, dumpFilePath=outfilepath)

        except Exception, err:

                print "Exception:",str(err)

                import traceback,sys

                print '-'*60

                traceback.print_exc(file=sys.stdout)

                print '-'*60

ragupta4
Cisco Employee
Cisco Employee

Please use below import:

from WatchUcsGui import ConvertToPython

- Rahul

ben.crook
Level 1
Level 1

i am new to python and the ucs sdk for python. i was able to use this to load all mo , but how am i supposed to know which mo files to import based on whatever objects i am calling in my code? there are SO many of them. i understand it is better to load only what you need and i would prefer that but is there some online referencing of say objects or dns from the visore.html view that cross reference which .py files from the mo's you need to import based on what objects or dns you are calling or using?

UPDATE:

nm, i figured it out , all the filenames match the objects from visore

ragupta4
Cisco Employee
Cisco Employee

Yes Ben you cracked it. File names are same as the object name returned by visore.

-Rahul

akalambu@cisco.com
Cisco Employee
Cisco Employee

Does anyone have any sample code to reacknowledge blade and rack servers

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Quick Links

Review Cisco Networking for a $25 gift card