November 8, 2016 · ucsmsdk ucspython

Ucs config backup to Python script - ucsmsdk

ucmsdk in version 0.9.2.0 will add the ability of being able to generate a python script for configuring Ucs server based on a config state backup XML.

convert_from_backup(backup_file, output_file=None)

backup_file - needs to a config backup XML downloaded from a UCS server.

output_file - file where the equivalent python script is desired.

Example usage:

from ucsmsdk.utils.convertfrombackup import convert_from_backup  
convert_from_backup(backup_file="/Users/vvb/configbackup.xml", output_file="/Users/vvb/ucs_config.py")  

Without the output_file argument, the output is redirected to stdout.

Usage:

Below is a very small part of the config backup xml,

<?xml version="1.0" ?>  
<topRoot>  
  <topMetaInf ecode="E001" name="meta-sec"/>
    <orgOrg descr="" name="root">
      <lsbootPolicy bootMode="legacy" descr="" enforceVnicName="yes" name="new_boot_pol" policyOwner="local" purpose="operational" rebootOnUpdate="no">
        <lsbootVirtualMedia access="read-only-remote-cimc" lunId="0" mappingName="" order="1"/>
    <lsbootVirtualMedia access="read-only-local" lunId="0" mappingName="" order="2"/>
    <lsbootStorage order="3">
      <lsbootLocalStorage>
        <lsbootUsbFlashStorageImage order="3"/>
      </lsbootLocalStorage>
    </lsbootStorage>
      </lsbootPolicy>
    </orgOrg>
</topRoot>  

will be converted into

#!/usr/bin/env python

from ucsmsdk.ucshandle import UcsHandle

handle = UcsHandle(ip="", username="", password="")  
handle.login()

from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy  
from ucsmsdk.mometa.lsboot.LsbootVirtualMedia import LsbootVirtualMedia  
from ucsmsdk.mometa.lsboot.LsbootStorage import LsbootStorage  
from ucsmsdk.mometa.lsboot.LsbootLocalStorage import LsbootLocalStorage  
from ucsmsdk.mometa.lsboot.LsbootUsbFlashStorageImage import LsbootUsbFlashStorageImage



mo = LsbootPolicy(parent_mo_or_dn=obj, name="new_boot_pol", reboot_on_update="no", policy_owner="local", purpose="operational", enforce_vnic_name="yes", boot_mode="legacy")  
mo_1 = LsbootVirtualMedia(parent_mo_or_dn=mo, access="read-only-remote-cimc", lun_id="0", order="1")  
mo_2 = LsbootVirtualMedia(parent_mo_or_dn=mo, access="read-only-local", lun_id="0", order="2")  
mo_3 = LsbootStorage(parent_mo_or_dn=mo, order="3")  
mo_4 = LsbootLocalStorage(parent_mo_or_dn=mo_3, )  
mo_5 = LsbootUsbFlashStorageImage(parent_mo_or_dn=mo_4, order="3")  
handle.add_mo(mo, True)  
handle.commit()

handle.logout() 
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket