cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
43280
Views
20
Helpful
46
Comments
Jeffrey Foster
Cisco Employee
Cisco Employee

This version of the UCS Manager Python SDK has been deprecated please use the UCS Manager Python SDK  located here, Cisco UCS Python SDK - ucsmsdk


The following Python SDKs are available for download from Cisco:

Cisco UCS Manager Python SDK v0.8.3:

Downloads:

Documentation Links:

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

Cisco IMC Python SDK v0.7.2:

Downloads:



Cisco IMC Python SDK v0.7.1:

Downloads:

Documentation Links:

Note: Due to the changes in the naming convention of the APIs in the SDK release 0.7.1, scripts written using SDK release 0.6.x need to be modified to make it work with SDK release 0.7.1. Also this version is not compatible with IMC Plugin 0.9.1 for Nagios.



Cisco IMC Python SDK v0.6.2:

Downloads:

Documentation Links:

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


Internal (Cisco) developers/users can contact the team at ucs-python@cisco.com

Comments
ragupta4
Cisco Employee
Cisco Employee

With Python version 2.7.9 and above, python embedded the certificate validation.

In case of any issues with ssl protocol or certificate validation issue, you can run the below method before importing UcsSdk as a workaround.

def sslWorkaround():

isVerifyCertificate = False

if not sys.version_info < (2, 6):

  from functools import partial

  import ssl

  ssl.wrap_socket = partial(ssl.wrap_socket, ssl_version=ssl.PROTOCOL_TLSv1)

  if not sys.version_info < (2, 7, 9) and not isVerifyCertificate:

  ssl._create_default_https_context = ssl._create_unverified_context

- Rahul

Sakatiamy
Community Member

The workaround is working !

Thanks a lot Rahul,

Kind regards

zmeng
Cisco Employee
Cisco Employee

I have below code:

from UcsSdk import *

from UcsSdk.WatchUcsGui import ConvertToPython

ucsm_ip = 'x.x.x.x'

user = 'admin'

password = 'xxxxxx'

if __name__ == "__main__":

        try:

                handle = UcsHandle()

                handle.Login(ucsm_ip, user, password)

                ConvertToPython()

                handle.Logout()

        except Exception, err:

                print "Exception:",str(err)

                import traceback,sys

                print '-'*60

                traceback.print_exc(file=sys.stdout)

                print '-'*60

it return error :

Traceback (most recent call last):

  File "test.py", line 10, in <module>

    ConvertToPython()

  File "/usr/lib/python2.6/site-packages/UcsSdk/WatchUcsGui.py", line 1223, in ConvertToPython

    lastUpdatedFile = files[0]

IndexError: list index out of range

what's wrong here??

akalambu@cisco.com
Cisco Employee
Cisco Employee

am able to use the ConvertToPython for most APIs

But when i create a service profile template that results in List Index out of range and the below exception.

Traceback (most recent call last):

  File "ucs_main.py", line 8, in <module>

    ConvertToPython(dumpToFile=True, dumpFilePath=outputfilepath)

  File "/usr/local/lib/python2.7/dist-packages/UcsSdk/WatchUcsGui.py", line 1234, in ConvertToPython

    FindXmlRequestsInFile_test(fileStream, True)

  File "/usr/local/lib/python2.7/dist-packages/UcsSdk/WatchUcsGui.py", line 1133, in FindXmlRequestsInFile_test

    ExtractXML(fileStream, line)

  File "/usr/local/lib/python2.7/dist-packages/UcsSdk/WatchUcsGui.py", line 1116, in ExtractXML

    GenerateCmdlets(requestString)

  File "/usr/local/lib/python2.7/dist-packages/UcsSdk/WatchUcsGui.py", line 1064, in GenerateCmdlets

    cmdlet = GenerateConfigConfCmdlets(xmlString)

  File "/usr/local/lib/python2.7/dist-packages/UcsSdk/WatchUcsGui.py", line 524, in GenerateConfigConfCmdlets

    node = topNode.getElementsByTagName("inConfig")[0]

IndexError: list index out of range


Any thoughts?

robimath
Cisco Employee
Cisco Employee

IS there a git location from which i can download the existing scripts using the SDK  ?

tocao
Cisco Employee
Cisco Employee

If you can give us some simple examples,that would be great.

like how to list all the severs, all the hbas, etc.

Can you tell me how to do that? Thanks.

robimath
Cisco Employee
Cisco Employee

Is there any  plans to add os login handles  to SDK  ?

jmunk
Level 4
Level 4

How do I save the value of a given attribute of an object?

I have read a ComputeBlade object with

uBlade = u.GetManagedObject(None, ComputeBlade.ClassId(), {ComputeBlade.SERIAL:thisSerial})

I can print the contents of my uBlade Object with WriteObject(uBlade), and can see, that its attribute "AssignedToDn" has value "org-root/org-VmWare/ls-VmWareSP01".

I want to save the value of this attribute to use it to get the Service Profile with this Dn.

Normally in Python, this should be done with

myAssignedToDn = uBlade.AssignedToDn or

myAssignedToDn = getattr(uBlade, 'AssignedToDn')

However this yields the error "AttributeError: 'list' object has no attribute 'AssignedToDn'"

(I tried all combinations of Upper and Lower Case for attribute "Ucs" with same result)

So how do I get the value of attribute "AssignedToDn" for my uBlade Object?

BR

Jesper

jmunk
Level 4
Level 4

Let me add, that I have imported everything from UCS SDK, and "assigned" type Compute Blade to the variable I use to store the UCS Blade MO:

from UcsSdk import *

uBlade = ComputeBlade()

I have been looking around in the User Guide for UCS Python code, where You extract an attribute from a MO Object, and cannot find any.

ragupta4
Cisco Employee
Cisco Employee

Hi Jesper,

Which version of python sdk are you using?

Thanks

Rahul

jmunk
Level 4
Level 4

Got this answer from the Cisco BU through Cisco DK, which works!

> GetManagedObject() always returns a list of elements of the class listed in the request, even if there is only one element.

> This guarantees consistency in the return type, whether your request returns one or multiple elements.

>

> In your case, uBlade is thus a list of ComputeBlade, probably containing a single element, given that you seem to be filtering using a serial number.

>

> Try changing this line:

> uBlade = u.GetManagedObject(None, ComputeBlade.ClassId(),

> {ComputeBlade.SERIAL:thisSerial})

> To this :

> uBlade = u.GetManagedObject(None, ComputeBlade.ClassId(),

> {ComputeBlade.SERIAL:thisSerial})[0]

>

===============

Rahul (CC’ing Lars Granberg at Cisco DK, whom I have also asked this question)!

I am using 0.8.3 which is the newest on UCS communities (https://communities.cisco.com/docs/DOC-37174)

To my error description I will add, that when I do a “print uBlade” (where uBlade is my Class ComputeBlade Instance), I get “[<UcsSdk.UcsBase.ManagedObject instance at 0x0000000008A23848>]”, so my variable has class “ManagedObject”, but possibly not Class “ComputeBlade”

Below is my complete script for Your information

BR

Jesper

Complete Script:

===========

import sys, os

from UcsSdk import *

import re

import time

import datetime

from io import TextIOWrapper, BytesIO

from xmo import *

u = UcsHandle()

uip = "192.168.158.88"

uuser = "a"

upassw = "a"

u.Login(uip,uuser,upassw)

if u:

    result = (u, 0)

    print "uLogin SUCCES"

else:

    print "uLogin ERROR: login failed"

uBlade = ComputeBlade()

print "Type of uBlade is "+str(type(uBlade))

thisSerial = "3384"

thisBladeUserLabel = "RhelServer06"

uBlade = u.GetManagedObject(None, ComputeBlade.ClassId(), {ComputeBlade.SERIAL:thisSerial})

if uBlade:

    print "Blade before Update:"

    WriteObject(uBlade)

    print "Print 'uBlade': "

    print uBlade

    getattr(uBlade,'ComputeBlade.UCS')

    #assocSpDn = uBlade.assignedToDn # <= This is where it fails. I show a number of commands here, which all fails

    #assocSpDn = uBlade.ASSIGNED_TO_DN

    assocSpDn = uBlade.Ucs

    #assocSpDn = uBlade.UCS

    #assocSpDn = uBlade.ucs

    print "assocSpDn "+assocSpDn

    updatedUBlade = u.SetManagedObject(uBlade, ComputeBlade.ClassId(), {ComputeBlade.USR_LBL:thisBladeUserLabel})

    if updatedUBlade:

        print "Blade after Update:"

        WriteObject(updatedUBlade)

    assocSp = ""

    if assocSpDn:

        uSp = u.GetManagedObject(None, LsServer.ClassId(), {LsServer.DN:assocSpDn})

        if uSp:

            WriteObject(uSp)

        else:

            print "assocSp with Dn "assocSpDn" not found"

seifallahbenamara
Community Member

you can skip the Python certification validation :

        handle.Login("x.x.x.x", username="xxxx", password="xxxx",noSsl=True, port=80, dumpXml=YesOrNo.TRUE)

-baseif

robimath
Cisco Employee
Cisco Employee

Hi SDK Dev ,

When I try to get the MO’s using the OutCOnfigs.GetChild() attribute on the ConfigResolveDn instance it gives attribute error .

AttributeError: ExternalMethod instance has no attribute 'OutConfigs'

The same works for ConfigResolveChildren or ConfigResolveClass . Can you help ?

Thanks

Robin

My code:

        crc = handle.ConfigResolveDn(parentDn, YesOrNo.TRUE,True)

        if (crc.errorCode == 0):

            for child in crc.OutConfigs.GetChild():

                bootorder = child.Order

                boottype  = child.Type

Output  :

handle is: <UcsSdk.UcsHandle.UcsHandle instance at 0x7f256f62e710>

UCS-11 ====> <configResolveDn cookie="1457640957/f81d4eb7-6af0-4490-a526-689eb43d23f2" dn="sys/chassis-4/blade-8/boot-policy" inHierarchical="true" />

UCS-11 <====  <configResolveDn dn="sys/chassis-4/blade-8/boot-policy" cookie="1457640957/f81d4eb7-6af0-4490-a526-689eb43d23f2" response="yes"> <outConfig> <lsbootDef advBootOrderApplicable="yes" bootMode="legacy" childAction="deleteNonPresent" descr="" dn="sys/chassis-4/blade-8/boot-policy" enforceVnicName="no" intId="73694698" name="boot-policy" policyLevel="0" policyOwner="local" purpose="operational" rebootOnUpdate="yes"> <lsbootVirtualMedia access="read-only" childAction="deleteNonPresent" lunId="0" mappingName="" order="1" rn="read-only-vm" type="virtual-media"/> <lsbootLan access="read-only" childAction="deleteNonPresent" order="2" prot="pxe" rn="lan" type="lan"> <lsbootLanImagePath bootIpPolicyName="" childAction="deleteNonPresent" iSCSIVnicName="" imgPolicyName="" imgSecPolicyName="" provSrvPolicyName="" rn="path-secondary" type="secondary" vnicName="eth1"/> <lsbootLanImagePath bootIpPolicyName="" childAction="deleteNonPresent" iSCSIVnicName="" imgPolicyName="" imgSecPolicyName="" provSrvPolicyName="" rn="path-primary" type="primary" vnicName="eth0"/> </lsbootLan> <lsbootSan access="read-write" childAction="deleteNonPresent" order="3" rn="san" type="san"> <lsbootSanCatSanImage childAction="deleteNonPresent" rn="sanimg-secondary" type="secondary" vnicName="fc1"> <lsbootSanCatSanImagePath childAction="deleteNonPresent" lun="0" rn="sanimgpath-primary" type="primary" vnicName="fc1" wwn="50:06:01:6A:47:20:4B:AF"/> </lsbootSanCatSanImage> <lsbootSanCatSanImage childAction="deleteNonPresent" rn="sanimg-primary" type="primary" vnicName="fc0"> <lsbootSanCatSanImagePath childAction="deleteNonPresent" lun="0" rn="sanimgpath-primary" type="primary" vnicName="fc0" wwn="50:06:01:62:47:20:4B:AF"/> </lsbootSanCatSanImage> </lsbootSan> </lsbootDef> </outConfig> </configResolveDn>

Exception: ExternalMethod instance has no attribute 'OutConfigs'

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

Traceback (most recent call last):

  File "/home/robimath/repox/Interop-Automation-System/test.py", line 44, in check_boot_order

    for child in crc.OutConfigs.GetChild():

AttributeError: ExternalMethod instance has no attribute 'OutConfigs'

Amir Safayan
Level 1
Level 1

Any ideas on when the next version of the Python SDK will be released?

arusrini
Cisco Employee
Cisco Employee

Amir,

The next version of theUCSM SDK is already out and is here: Cisco Ucs Python SDK - ucsmsdk (0.9.0.0)

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