ucsmsdk.utils package

Submodules

This module has helper methods to facilitate image download from CCO

class ucsmsdk.utils.ccoimage.UcsCcoImage[source]

Bases: object

Describes the cco image object

ucsmsdk.utils.ccoimage.get_ucs_cco_image(image, file_dir, proxy=None)[source]

Downloads image from CCO

Parameters:
  • image (UcsCcoImage) – object of type UcsCcoImage
  • file_dir (str) – directory to download image to
  • proxy (str) – proxy (if any)
Returns:

None

Example

image_list = get_ucs_cco_image_list(“username”, “password”)

get_ucs_cco_image(image=image_list[0], file_dir=”/home/user/images”)

ucsmsdk.utils.ccoimage.get_ucs_cco_image_list(username=None, password=None, mdf_id_list=None, proxy=None)[source]

Gets the list of images available on CCO

Parameters:
  • username (str) – username to connect to image server
  • password (str) – password to connect to image server
  • mdf_id_list (list) – list of mdf id
  • proxy (str) – proxy used for connection
Returns:

List of UcsCcoImage objects

Example

image_list = get_ucs_cco_image_list(“username”, “password”)

This module contains the api used to provide compare and sync functionality within ucsm or across ucsm.

ucsmsdk.utils.comparesyncmo.compare_ucs_mo(ref_obj, diff_obj, exclude_different=False, include_equal=False, version_filter=True, include_operational=False, xlate_org=None, xlate_map=None)[source]

Compares the state of two managed objects with same dn.

Parameters:
  • ref_obj (list) – list of Managed Objects of reference UCSM
  • diff_obj (list) – list of Managed Objects of difference UCSM
  • exclude_different (bool) – default:False. When True, compares MOs that exist on both reference and difference UCSM
  • include_equal (bool) – default:False. When True, also displays MOs which are equal.
  • version_filter (bool) – default:True. When False, ignores properties which is introduced in later UCSM version than reference UCSM version.
  • include_operational (bool) – default:False. When True, compares all the properties of mo.
  • xlate_org (str) – org-dn of reference mo, compares objects of same type and same rn under different org.
  • xlate_map (dict) – {“difference_dn”: “reference_dn”}, compares objects of same type with different dn.
Returns:

MoDiff Object
: dn - dn of Managed Object

input_object - Managed Object side_indicator -

“=>” Add the diff obj to ref ucsm

or Modify the ref object by diff object on ref ucsm

“<=” Removes the ref obj from ref ucsm

“==” object is equal on both ref and diff ucsm

diff_property - property list with different value

Return type:

List of MoDiff objects

Example

#1 ref_mos = [ref_handle.query_dn(dn=”org-root/ls-sp”)] diff_mos = [diff_handle.query_dn(dn=”org-root/ls-sp”)] compare_ucs_mo(ref_mos, diff_mos)

#2 ref_mos = [ref_handle.query_dn(dn=”org-root/org-ref/ls-sp”)] diff_mos = [diff_handle.query_dn(dn=”org-root/org-diff/ls-sp”)] compare_ucs_mo(ref_mos, diff_mos, xlate_org = “org-root/org-ref”)

#3 ref_mos = [ref_handle.query_dn(dn=”org-root/ls-ref”)] diff_mos = [diff_handle.query_dn(dn=”org-root/ls-diff”)] compare_ucs_mo(ref_mos, diff_mos,

xlate_map = {“org-root/ls-diff”: “org-root/ls-ref”})
ucsmsdk.utils.comparesyncmo.sync_ucs_mo(ref_handle, difference, delete_not_present=False, version_filter=True)[source]

syncs the difference object on reference ucsm. In other words, make the state of reference ucsm for the respective ref object same as difference object on reference ucsm.

Parameters:
  • ref_handle (UcsHandle) – connect handle of reference ucsm
  • difference (list of MoDiff objects) – output of compare-ucs-mo api
  • delete_not_present (bool) – by dafault False. If set to true, will delete ref mo which does not exist on difference ucsm
  • version_filter (bool) – by default True: If set to False, ignore properties which is introduced in later ucsm version than reference ucsm
Returns:

None

Example

#1 ref_mos = [ref_handle.query_dn(dn=”org-root/ls-sp”)] diff_mos = [diff_handle.query_dn(dn=”org-root/ls-sp”)] difference = compare_ucs_mo(ref_handle, ref_mos,diff_handle, diff_mos) sync_ucs_mo(ref_handle, difference=difference, delete_not_present=True)

ucsmsdk.utils.comparesyncmo.write_mo_diff(diff_obj)[source]

Writes the difference managedObject(output of CompareManagedObject) on the terminal.

This module generated the python script using UCS GUI, GUI logs and xml request.

ucsmsdk.utils.converttopython.convert_to_ucs_python(log_path=None, xml=False, request=None, gui_log=False, path=None, literal_path=None, dump_to_file=False, dump_file_path=None, dump_xml=False)[source]

This operation generates python script from ucsm gui using ucsm logs or directly from ucs logfile or xml request.

Parameters:
  • log_path (str) – ucsm guilog path, if code unable to find the ucsm guilog path you can specify the path using this parameter.
  • xml (bool) – if True, generates python script using xml request.
  • request (str) – xml request
  • gui_log (bool) – if True, generates python script using ucsm logfile
  • path (str) – path of the file containing xml request or ucsm logfile
  • literal_path (str) – path of the file containing xml request or ucsm logfile
  • dump_to_file (bool) – if True, dump the code to file
  • dump_file_path (str) – path of file where to dump generated code.
  • dump_xml (bool) – if True, display the xml extracted for generating code

Examples

  • Optional in all param set - dump_to_file, dump_file_path, dump_xml

  • param set 1:

    convert_to_ucs_python()

    convert_to_ucs_python(dump_xml=True)

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

    convert_to_ucs_python(dump_to_file=True,

    dump_file_path=file_path, dump_xml=True)

  • param set 2:
    xml_str=’‘’

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

    convert_to_ucs_python(xml=True, request=xml_str)

    file_path = ‘/home/user/ucsmxml/configrequest.xml’

    convert_to_ucs_python(xml=True, path=file_path)

  • param set 3:

    file_path = ‘/home/user/ucsmlog/centrale_14804.log’

    convert_to_ucs_python(gui_log=True, path=file_path)

This module contains APIs to facilitate Ucs backup and import

ucsmsdk.utils.ucsbackup.backup_ucs(handle, backup_type, file_dir, file_name, timeout_in_sec=600, preserve_pooled_values=False)[source]

backup_ucs helps create and download Ucs backups.

Parameters:
  • handle (UcsHandle) – Ucs Connection handle
  • backup_type (str) – type of backup i.e. fullstate/config-logical/config-system/config-all
  • file_dir (str) – directory to download ucs backup file to
  • file_name (str) – name for the backup file (supported file extension are ‘.tar.gz’ and ‘.xml’)
  • timeout_in_sec (number) – time in seconds for which method waits for the backUp file to generate before it exits.
  • preserve_pooled_values (boolean) – True/False, False - by default

Example

file_dir = “/home/user/backup”

file_name = “config_backup.xml”

backup_ucs(handle, backup_type=”config-logical”,
file_dir=test_support, file_name=file_name)
ucsmsdk.utils.ucsbackup.import_ucs_backup(handle, file_dir, file_name, merge=False)[source]

This operation uploads a Ucs backup taken earlier via GUI or backup_ucs operation for all configuration, system configuration, and logical configuration files. User can perform an import while the system is up and running.

Parameters:
  • handle (UcsHandle) – connection handle
  • file_dir (str) – directory containing ucs backup file
  • file_name (str) – backup file name to be imported
  • merge (boolean) – True/False, specifies whether to merge the backup configuration with the existing UCSM configuration

Example

file_dir = “/home/user/backup”

file_name = “config_backup.xml”

import_ucs_backup(handle, file_dir=file_dir, file_name=file_name)

import_ucs_backup(handle, file_dir=file_dir, file_name=file_name,
merge=True)

This module contains APIs used to launch the Java based UCSM GUI.

ucsmsdk.utils.ucsguilaunch.ucs_gui_launch(handle, need_url=False)[source]

ucs_gui_launch launches the Java based UCSM GUI. This method requires the necessary Jdk to be in place, for it to be successful.

Parameters:
  • handle (UcsHandle) – Ucs connection handle
  • need_url (bool) – True/False, returns the URL to launch GUI, if True

Example

ucs_gui_launch(handle)

ucs_gui_launch(handle, need_url=True)

This module contains the APIs used to launch ucs kvm.

ucsmsdk.utils.ucskvmlaunch.ucs_kvm_launch(handle, service_profile=None, blade=None, rack_unit=None, frame_title=None, need_url=False)[source]

ucs_kvm_launch launches the kvm session for a specified server.

Parameters:
  • handle (UcsHandle) –
  • service_profile (LsServer) –
  • blade (ComputeBlade) –
  • rack_unit (ComputeRackUnit) –
  • frame_title (str) – title of launched frame
  • need_url (bool) – True/False, Returns URL to launch kvm, if True

Example

# sp is service profile object

ucs_kvm_launch(handle, service_profile=sp)

ucs_kvm_launch(handle, service_profile=sp, frame_title=”using sp”)

ucs_kvm_launch(handle, service_profile=sp, need_url=True)

# blade1 is ComputeBlade object

ucs_kvm_launch(handle, blade=blade1)

# rack1 is ComputeRackUnit object

ucs_kvm_launch(handle, rack_unit=rack1)

This module contains the APIs used to create and download tech_support file.

ucsmsdk.utils.ucstechsupport.get_ucs_tech_support(handle, ucs_manager=False, ucs_mgmt=False, chassis_id=None, cimc_id=None, adapter_id=None, iom_id=None, fex_id=None, rack_server_id=None, rack_adapter_id=None, remove_from_ucs=False, download_techsupp=True, file_dir=None, file_name=None, timeout_in_sec=600)[source]

This operation creates and downloads the technical support file for the specified Ucs server.

Parameters:
  • handle (UcsHandle) – Ucs connection handle
  • ucs_manager (bool) – True/False, False - by default Create and download TechSupport for UCSM, if true
  • ucs_mgmt (bool) – True/False, False - by default Create and download TechSupport for UCSM Management services(excluding Fabric interconnects), if true
  • chassis_id (int) – chassis id
  • cimc_id (int/string) – for a specific chassis. Can be ‘all’.
  • adapter_id (int/string) – for a specific chassis. Can be ‘all’.
  • iom_id (int/string) – for a specific chassis. Can be ‘all’.
  • fex_id (int) – id of a fabric extender.
  • rack_server_id (int) – id of a rack server.
  • rack_adapter_id (int/string) – adaptor_id for a specific rack server. Can be ‘all’.
  • remove_from_ucs (bool) – True/False, False - by default TechSupport will be removed from server, if True
  • download_techsupp (bool) – True/False, True - by default Download the TechSupport file, if True
  • file_dir (str) – directory to download tech support file to
  • file_name (str) – name of the download tech support file
  • timeout_in_sec (int) – specifies the time in seconds after which the operation times-out.

Example

  • M - Manadatory, O - Optional

  • Note: Mandatory in ALL param sets: file_dir, file_name Optional in ALL param sets: timeout_in_sec, remove_from_ucs,

    download_techsupp

  • param set 1:

  • M - ucs_manager

file_dir = “/home/user/techsupp” file_name = “techsupp_ucs_manager.tar” get_ucs_tech_support(handle,

file_dir=file_dir, file_name=file_name, ucs_manager=True)
get_ucs_tech_support(handle,
file_dir=file_dir, file_name=file_name, ucs_manager=True, timeout_in_sec=300, remove_from_ucs=True)
  • param set 2:
  • M - ucs_manager

file_dir = “/home/user/techsupp” file_name = “techsupp_ucs_mgmt.tar” get_ucs_tech_support(handle,

file_dir=file_dir, file_name=file_name, ucs_mgmt=True)
  • param set 3:
  • M - chassis_id, cimc_id
  • O - adapter_id

file_dir = “/home/user/techsupp” file_name = “techsupp_ucs_mgmt.tar” get_ucs_tech_support(handle,

file_dir=file_dir, file_name=file_name, chassis_id=1, cimc_id=1, adapter_id=1)
  • param set 4:
  • M - chassis_id, iom_id

file_dir = “/home/user/techsupp” file_name = “techsupp_ucs_mgmt.tar” get_ucs_tech_support(handle,

file_dir=file_dir, file_name=file_name, chassis_id=1, iom_id=1)
  • param set 5:
  • M - fex_id

file_dir = “/home/user/techsupp” file_name = “techsupp_ucs_mgmt.tar” get_ucs_tech_support(handle,

file_dir=file_dir, file_name=file_name, fex_id=1)
  • param set 6:
  • M - rack_server_id
  • O - rack_adapter_id

file_dir = “/home/user/techsupp” file_name = “techsupp_ucs_mgmt.tar” get_ucs_tech_support(handle,

file_dir=file_dir, file_name=file_name, rack_server_id=1, rack_adapter_id=1)

Module contents