def test_003_StorageLocalDiskPartition(): xml_str = '''<storageController childAction="deleteNonPresent" controllerStatus="unknown" deviceRaidSupport="yes" faultMonitoring="supported" hwRevision="1064E(B3)" id="1" lc="allocated" locationDn="" model="SAS1064E PCI-Express Fusion-MPT SAS" oobControllerId="not-applicable" oobInterfaceSupported="no" operQualifierReason="N/A" operState="unknown" operability="unknown" pciAddr="01:00.0" pciSlot="" perf="unknown" power="unknown" presence="equipped" raidSupport="RAID0, RAID1" rebuildRate="unknown" revision="0" rn="storage-SAS-1" serial="" thermal="unknown" type="SAS" vendor="LSI Logic Symbios Logic" voltage="unknown"> <storageLocalDiskConfigDef childAction="deleteNonPresent" descr="" flexFlashRAIDReportingState="disable" flexFlashState="disable" intId="none" mode="any-configuration" name="" policyLevel="0" policyOwner="local" protectConfig="no" rn="local-disk-config"> <storageLocalDiskPartition childAction="deleteNonPresent" descr="" intId="none" name="" order="1" policyLevel="0" policyOwner="local" rn="partition" size="unknown" type="none"/></storageLocalDiskConfigDef></storageController> ''' obj = xc.from_xml_str(xml_str) xml_element = obj.to_xml() xc.to_xml_str(xml_element)
def test_002_StorageLocalDiskPartition(): xml_str = '''<configResolveClass cookie="1447403324/24f7c591-2b3e-4bf4-8cee-716d3b4297b1" response="yes" classId="storageLocalDiskPartition"> <outConfigs> <storageLocalDiskPartition childAction="deleteNonPresent" descr="" dn="org-root/local-disk-config-default/partition" intId="29002" name="" order="1" policyLevel="0" policyOwner="local" size="unknown" type="none"/> <storageLocalDiskPartition childAction="deleteNonPresent" descr="" dn="sys/chassis-1/blade-2/board/storage-SAS-1/local-disk-config/partition" intId="none" name="" order="1" policyLevel="0" policyOwner="local" size="unknown" type="none"/> </outConfigs> </configResolveClass> ''' obj = xc.from_xml_str(xml_str) xml_element = obj.to_xml() xc.to_xml_str(xml_element)
def test_001_StorageLocalDiskPartition(): xml_str = ''' <storageLocalDiskPartition childAction="deleteNonPresent" descr="" dn="org-root/local-disk-config-default/partition" intId="29002" name="" order="1" policyLevel="0" policyOwner="local" size="unknown" type="none"/> ''' obj = xc.from_xml_str(xml_str) xml_element = obj.to_xml() xc.to_xml_str(xml_element)
def test_002_knownmo_unknownprop(): xml_str = ''' <lsServer agentPolicyName="" name="ra11" type="instance" usrLbl="b" unknownProps="unknown"/>''' obj = xc.from_xml_str(xml_str) obj.unknownProps = "known" xml_element = obj.to_xml(option=WriteXmlOption.DIRTY) print xc.to_xml_str(xml_element)
def test_001_sp_minimal(): from ucsmsdk.mometa.ls.LsServer import LsServer mo = LsServer(parent_mo_or_dn="org-root", vmedia_policy_name="", ext_ip_state="none", bios_profile_name="", mgmt_fw_policy_name="", agent_policy_name="", mgmt_access_policy_name="", dynamic_con_policy_name="", kvm_mgmt_policy_name="", sol_policy_name="", uuid="0", descr="", stats_policy_name="default", policy_owner="local", ext_ip_pool_name="ext-mgmt", boot_policy_name="", usr_lbl="", host_fw_policy_name="", vcon_profile_name="", ident_pool_name="default", src_templ_name="", local_disk_policy_name="", scrub_policy_name="", power_policy_name="default", maint_policy_name="", name="test_sp", resolve_remote="yes") handle.add_mo(mo) handle.commit() ########################################################## # Modify a single property in the Sp created above # and genertate XML with DIRTY option set ########################################################## import ucsmsdk.ucsxmlcodec as xc from ucsmsdk.ucscoremeta import WriteXmlOption obj = handle.query_dn("org-root/ls-test_sp") obj.usr_lbl = "new_label" print(xc.to_xml_str(obj.to_xml(option=WriteXmlOption.DIRTY))) print(xc.to_xml_str(obj.to_xml(option=WriteXmlOption.ALL_CONFIG))) print(xc.to_xml_str(obj.to_xml())) ########################################################## # Delete the SP ########################################################## obj = handle.query_dn("org-root/ls-test_sp") handle.remove_mo(obj) handle.commit()
def commit(): from ucsmsdk.ucsbasetype import ConfigMap, Dn, DnSet, Pair import ucsmsdk.ucsmethodfactory as mf import ucsmsdk.ucsxmlcodec as xc global to_commit refresh_dict = {} mo_dict = to_commit if not mo_dict: print "No Mo to be Committed" return None config_map = ConfigMap() for mo_dn in mo_dict: mo = mo_dict[mo_dn] child_list = mo.child while len(child_list) > 0: current_child_list = child_list child_list = [] for child_mo in current_child_list: if child_mo.is_dirty(): refresh_dict[child_mo.dn] = child_mo child_list.extend(child_mo.child) pair = Pair() pair.key = mo_dn pair.child_add(mo_dict[mo_dn]) config_map.child_add(pair) xml_element = mf.config_conf_mos("cookie", config_map, False) xml_str = xc.to_xml_str(xml_element) to_commit = {} return xml_str
def test_003_mixed_filter(): expected = b'<filter>' \ b'<not>' \ b'<or>' \ b'<eq class="lsServer" property="type" value="instance" />' \ b'<and><eq class="lsServer" property="usrLbl" ' \ b'value="lsserver" />' \ b'<not><wcard class="lsServer" property="descr" ' \ b'value="description" />' \ b'</not>' \ b'</and>' \ b'</or>' \ b'</not>' \ b'</filter>' filter_str = 'not(' \ '(type, "instance", type="eq") or ' \ '(usr_lbl, "lsserver", type="eq") and ' \ 'not(descr, "description", type="re"))' filter_xml = generate_infilter(class_id="LsServer", filter_str=filter_str, is_meta_class_id=True) xml_str = to_xml_str(filter_xml.to_xml()) assert_equal(xml_str, expected)
def commit(): from ucsmsdk.ucsbasetype import ConfigMap, Dn, DnSet, Pair import ucsmsdk.ucsmethodfactory as mf import ucsmsdk.ucsxmlcodec as xc global to_commit refresh_dict = {} mo_dict = to_commit if not mo_dict: print("No Mo to be Committed") return None config_map = ConfigMap() for mo_dn in mo_dict: mo = mo_dict[mo_dn] child_list = mo.child while len(child_list) > 0: current_child_list = child_list child_list = [] for child_mo in current_child_list: if child_mo.is_dirty(): refresh_dict[child_mo.dn] = child_mo child_list.extend(child_mo.child) pair = Pair() pair.key = mo_dn pair.child_add(mo_dict[mo_dn]) config_map.child_add(pair) xml_element = mf.config_conf_mos("cookie", config_map, False) xml_str = xc.to_xml_str(xml_element) to_commit = {} return xml_str
def ls_filter(): global success filter_ = generate_infilter(class_id="lsServer", filter_str='(type, "instance", type="eq")', is_meta_class_id=True) expected = b'<filter><eq class="lsServer" property="type" ' \ b'value="instance" /></filter>' if to_xml_str(filter_.to_xml()) != expected: success = False
def test_005_create_gmo_from_xml(): xml_str = ''' <faultInst descr="TCA: etherTxStats totalBytesDelta = 1005, raised above 0" dn="sys/chassis-1/slot-1/host/port-2/fault-F35275" status="modified"/> ''' gmo = ucsmo.generic_mo_from_xml(xml_str) xml_element = gmo.to_xml() to_xml_str = xc.to_xml_str(xml_element)
def org_filter(): global success filter_ = generate_infilter(class_id="orgOrg", filter_str='(descr, "oroorg", type="eq")', is_meta_class_id=True) expected = b'<filter><eq class="orgOrg" property="descr" ' \ b'value="oroorg" /></filter>' if to_xml_str(filter_.to_xml()) != expected: success = False
def test_004_create_gmo_using_parent_mo(): args = {"a": 1, "b": 2, "c": 3, "rn": "parent"} obj = ucsmo.GenericMo("testLsA", "org-root", **args) obj1 = ucsmo.GenericMo("testLsB", obj, rn="child") elem = obj.to_xml() xml_str = xc.to_xml_str(elem) expected = b'<testLsA a="1" b="2" c="3" dn="org-root/parent" rn="parent"><testLsB dn="org-root/parent/child" rn="child" /></testLsA>' assert_equal(xml_str, expected)
def test_004_create_gmo_using_parent_mo(): args = {"a": 1, "b": 2, "c":3, "rn": "parent"} obj = ucsmo.GenericMo("testLsA", "org-root", **args) obj1 = ucsmo.GenericMo("testLsB", obj, rn="child") elem = obj.to_xml() xml_str = xc.to_xml_str(elem) expected = b'<testLsA a="1" b="2" c="3" dn="org-root/parent" rn="parent"><testLsB dn="org-root/parent/child" rn="child" /></testLsA>' assert_equal(xml_str, expected)
def test_002_create_gmo_using_param_dict(): args = {"a": 1, "b": 2, "c":3} obj = ucsmo.GenericMo("testLsA", "org-root", **args) obj1 = ucsmo.GenericMo("testLsB", "org-root", **args) obj.child_add(obj1) elem = obj.to_xml() xml_str = xc.to_xml_str(elem) expected = b'<testLsA a="1" b="2" c="3" dn="" rn=""><testLsB a="1" b="2" c="3" dn="" rn="" /></testLsA>' assert_equal(xml_str, expected)
def test_001_mo_to_xml(): from ucsmsdk.mometa.fabric.FabricVsan import FabricVsan expected = '<fabricVsan dn="org-root/net-test" name="test" status="modified" />' mo = FabricVsan("org-root", "test") mo.status = "modified" elem = mo.to_xml() xml_str = xc.to_xml_str(elem) assert_equal(xml_str, expected)
def test_001_mo_to_xml(): from ucsmsdk.mometa.fabric.FabricVsan import FabricVsan expected = b'<fabricVsan dn="org-root/net-test" name="test" status="modified" />' mo = FabricVsan("org-root", "test") mo.status = "modified" elem = mo.to_xml() xml_str = xc.to_xml_str(elem) assert_equal(xml_str, expected)
def test_002_create_gmo_using_param_dict(): args = {"a": 1, "b": 2, "c": 3} obj = ucsmo.GenericMo("testLsA", "org-root", **args) obj1 = ucsmo.GenericMo("testLsB", "org-root", **args) obj.child_add(obj1) elem = obj.to_xml() xml_str = xc.to_xml_str(elem) expected = b'<testLsA a="1" b="2" c="3" dn="" rn=""><testLsB a="1" b="2" c="3" dn="" rn="" /></testLsA>' assert_equal(xml_str, expected)
def test_001_not_filter(): expected = b'<filter><not><eq class="lsServer" property="dn" value="org-root/ls-C1_B1" /></not></filter>' filter_str = 'not (dn,"org-root/ls-C1_B1", type="eq")' filter_xml = generate_infilter(class_id="LsServer", filter_str=filter_str, is_meta_class_id=True) xml_str = to_xml_str(filter_xml.to_xml()) assert_equal(xml_str, expected)
def test_002_knownmo_unknownprop(): xml_str = ''' <lsServer agentPolicyName="" name="ra11" type="instance" usrLbl="b" rn = "ls-ra11" unknownProps="unknown"/>''' obj = xc.from_xml_str(xml_str) obj.unknownProps = "known" xml_element = obj.to_xml(option=WriteXmlOption.DIRTY) print(xc.to_xml_str(xml_element))
def test_001_knownmo_unknownprop(): xml_str = ''' <lsServer agentPolicyName="" name="ra11" type="instance" usrLbl="b" unknownProps="unknown"/>''' obj = xc.from_xml_str(xml_str) obj.unknownProps = "known" xml_element = obj.to_xml() expected = '<lsServer agentPolicyName="" dn="ls-ra11" name="ra11" type="instance" unknownProps="known" usrLbl="b" />' result_str = xc.to_xml_str(xml_element) assert_equal(result_str, expected)
def test_001_knownmo_unknownprop(): xml_str = ''' <lsServer agentPolicyName="" name="ra11" type="instance" usrLbl="b" rn = "ls-ra11" unknownProps="unknown"/>''' obj = xc.from_xml_str(xml_str) obj.unknownProps = "known" xml_element = obj.to_xml() expected = b'<lsServer agentPolicyName="" dn="ls-ra11" name="ra11" type="instance" unknownProps="known" usrLbl="b" />' result_str = xc.to_xml_str(xml_element) assert_equal(result_str, expected)
def test_001_mo_heirarchy_to_xml(): # first form the object from xml # and then convert it back to xml response_str = ''' <configResolveClasses cookie="1441601790/263349a7-1897-4df0-aff3-bc27c7316862" response="yes" classId="memoryUnit"> <outConfigs> <memoryUnit adminState="policy" array="1" bank="1" capacity="4096" childAction="deleteNonPresent" clock="1333" dn="sys/chassis-1/blade-2/board/memarray-1/mem-9" formFactor="DIMM" id="9" latency="0.800000" location="DIMM_E1" locationDn="" model="M393B5170FH0-YH9" operQualifier="" operQualifierReason="N/A" operState="operable" operability="operable" perf="unknown" power="not-supported" presence="equipped" revision="0" serial="0x835CE6DB" set="0" speed="unspecified" thermal="ok" type="Other" vendor="0x80CE" visibility="yes" voltage="not-supported" width="64"> <memoryUnitEnvStats childAction="deleteNonPresent" intervals="58982460" rn="dimm-env-stats" suspect="no" temperature="20.000000" temperatureAvg="20.000000" temperatureMax="20.000000" temperatureMin="20.000000" thresholded="" timeCollected="2015-09-07T10:31:06.608" update="262146"> <memoryUnitEnvStatsHist1 childAction="deleteNonPresent" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262"> <memoryUnitEnvStatsHist2 childAction="deleteNonPresent" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262"> </memoryUnitEnvStatsHist2> </memoryUnitEnvStatsHist1> </memoryUnitEnvStats> </memoryUnit> </outConfigs> </configResolveClasses> ''' response = xc.from_xml_str(response_str) expected = '<memoryUnitEnvStatsHist1 childAction="deleteNonPresent" dn="sys/chassis-1/blade-2/board/memarray-1/mem-9/dimm-env-stats/1" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262"><memoryUnitEnvStatsHist2 childAction="deleteNonPresent" dn="sys/chassis-1/blade-2/board/memarray-1/mem-9/dimm-env-stats/1/1" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262" /></memoryUnitEnvStatsHist1>' obj = response.out_configs.child[0].child[0].child[0] assert_equal(xc.to_xml_str(obj.to_xml()), expected)
def test_001_mo_heirarchy_to_xml(): # first form the object from xml # and then convert it back to xml response_str = ''' <configResolveClasses cookie="1441601790/263349a7-1897-4df0-aff3-bc27c7316862" response="yes" classId="memoryUnit"> <outConfigs> <memoryUnit adminState="policy" array="1" bank="1" capacity="4096" childAction="deleteNonPresent" clock="1333" dn="sys/chassis-1/blade-2/board/memarray-1/mem-9" formFactor="DIMM" id="9" latency="0.800000" location="DIMM_E1" locationDn="" model="M393B5170FH0-YH9" operQualifier="" operQualifierReason="N/A" operState="operable" operability="operable" perf="unknown" power="not-supported" presence="equipped" revision="0" serial="0x835CE6DB" set="0" speed="unspecified" thermal="ok" type="Other" vendor="0x80CE" visibility="yes" voltage="not-supported" width="64"> <memoryUnitEnvStats childAction="deleteNonPresent" intervals="58982460" rn="dimm-env-stats" suspect="no" temperature="20.000000" temperatureAvg="20.000000" temperatureMax="20.000000" temperatureMin="20.000000" thresholded="" timeCollected="2015-09-07T10:31:06.608" update="262146"> <memoryUnitEnvStatsHist1 childAction="deleteNonPresent" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262"> <memoryUnitEnvStatsHist2 childAction="deleteNonPresent" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262"> </memoryUnitEnvStatsHist2> </memoryUnitEnvStatsHist1> </memoryUnitEnvStats> </memoryUnit> </outConfigs> </configResolveClasses> ''' response = xc.from_xml_str(response_str) expected = b'<memoryUnitEnvStatsHist1 childAction="deleteNonPresent" dn="sys/chassis-1/blade-2/board/memarray-1/mem-9/dimm-env-stats/1" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262"><memoryUnitEnvStatsHist2 childAction="deleteNonPresent" dn="sys/chassis-1/blade-2/board/memarray-1/mem-9/dimm-env-stats/1/1" id="1" mostRecent="no" rn="1" suspect="no" temperature="28.000000" temperatureAvg="25.599997" temperatureMax="28.000000" temperatureMin="24.000000" thresholded="" timeCollected="2015-09-07T09:43:53.262" /></memoryUnitEnvStatsHist1>' obj = response.out_configs.child[0].child[0].child[0] assert_equal(xc.to_xml_str(obj.to_xml()), expected)