def test_005_add_hierarchy_hw(): from ucscsdk.mometa.org.OrgOrg import OrgOrg from ucscsdk.mometa.ls.LsServer import LsServer org = OrgOrg(parent_mo_or_dn="org-root", name="test_org") handle.remove_mo(org) handle.commit() handle.add_mo(org) handle.commit() sp = LsServer(parent_mo_or_dn=org, name="test_sp") handle.add_mo(sp) handle.commit() test_sp = handle.query_dn("org-root/org-test_org/ls-test_sp") test_sp.descr = "update_description" handle.set_mo(test_sp) handle.commit() test_sp = handle.query_dn("org-root/org-test_org/ls-test_sp") handle.remove_mo(sp) handle.commit() handle.remove_mo(org) handle.commit() expected = "update_description" assert_equal(test_sp.descr, expected)
def test_002_create_specific_obj(): # Create an object of type LsServer with parent dn specified # check if the object has the right values populated from ucscsdk.mometa.ls.LsServer import LsServer obj = LsServer("org-root", "temp_sp") assert_equal(obj.name, "temp_sp") assert_equal(obj.rn, "ls-temp_sp") assert_equal(obj.dn, "org-root/ls-temp_sp")
def setup(): global sp_test global handle handle = custom_setup() org = handle.query_dn("org-root") sp_test = LsServer(org, name="test", usr_lbl="TEST") handle.add_mo(sp_test, True) handle.commit()
def setup_module(): from ucscsdk.ucsceventhandler import UcscEventHandle from ucscsdk.mometa.ls.LsServer import LsServer global handle, sp, ueh, vlan_mo, vlan_name handle = custom_setup() ueh = UcscEventHandle(handle) org = handle.query_dn("org-root") sp = LsServer(org, name="eventhandle-test", descr="") handle.add_mo(sp, True)
def test_001_add_sp(): from ucscsdk.mometa.ls.LsServer import LsServer sp = LsServer(parent_mo_or_dn="org-root", name="test_sp") add_mo(mo=sp) xml_str = commit() print(xml_str) expected = ( b'''<configConfMos cookie="cookie" inHierarchical="false"><inConfigs><pair key="org-root/ls-test_sp">''' + b'''<lsServer dn="org-root/ls-test_sp" name="test_sp" status="created" /></pair></inConfigs></configConfMos>''' ) assert_equal(xml_str, expected)
def setup_module(): from ucscsdk.mometa.ls.LsServer import LsServer global handle handle = custom_setup() org = handle.query_dn("org-root") sp_TEST = LsServer(org, name="TEST", usr_lbl="TEST") handle.add_mo(sp_TEST, True) sp_list.append(sp_TEST) sp_test = LsServer(org, name="test", usr_lbl="test", descr="test") handle.add_mo(sp_test, True) sp_list.append(sp_test) sp_test11 = LsServer(org, name="test11", usr_lbl="test11") handle.add_mo(sp_test11, True) sp_list.append(sp_test11) sp_test12 = LsServer(org, name="test12", usr_lbl="test12") handle.add_mo(sp_test12, True) sp_list.append(sp_test12) handle.commit()
def test_001_sp_minimal(): from ucscsdk.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="", sol_policy_name="", uuid="0", descr="", stats_policy_name="default", 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") handle.add_mo(mo) handle.commit() ########################################################## # Modify a single property in the Sp created above # and genertate XML with DIRTY option set ########################################################## import ucscsdk.ucscxmlcodec as xc from ucscsdk.ucsccoremeta 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 test_004_get_org_and_add_sp_set_mo_org(): from ucscsdk.mometa.ls.LsServer import LsServer org = handle.query_dn("org-root") sp = LsServer(parent_mo_or_dn=org, name="test_sp") set_mo(org) xml_str = commit() print(xml_str) expected = ( b'''<configConfMos cookie="cookie" inHierarchical="false"><inConfigs><pair key="org-root">''' + b'''<orgOrg dn="org-root" status="modified"><lsServer dn="org-root/ls-test_sp" name="test_sp" />''' + b'''</orgOrg></pair></inConfigs></configConfMos>''') assert_equal(xml_str, expected)
def test_002_add_hierarchy(): from ucscsdk.mometa.org.OrgOrg import OrgOrg from ucscsdk.mometa.ls.LsServer import LsServer org = OrgOrg(parent_mo_or_dn="org-root", name="test_org") sp = LsServer(parent_mo_or_dn=org, name="test_sp") add_mo(mo=org) xml_str = commit() print(xml_str) expected = ( b'''<configConfMos cookie="cookie" inHierarchical="false"><inConfigs>''' + b'''<pair key="org-root/org-test_org"><orgOrg dn="org-root/org-test_org" name="test_org" status="created">''' + b'''<lsServer dn="org-root/org-test_org/ls-test_sp" name="test_sp" /></orgOrg></pair></inConfigs></configConfMos>''' ) assert_equal(xml_str, expected)
def test_005_add_sp_hw(): from ucscsdk.mometa.ls.LsServer import LsServer sp = LsServer(parent_mo_or_dn="org-root", name="test_sp") handle.remove_mo(sp) handle.commit() handle.add_mo(sp) handle.commit() test_sp = handle.query_dn("org-root/ls-test_sp") test_sp.descr = "update_description" handle.set_mo(test_sp) handle.commit() test_sp = handle.query_dn("org-root/ls-test_sp") handle.remove_mo(sp) handle.commit() expected = '''update_description''' assert_equal(test_sp.descr, expected)
def setup_func(): global obj obj = LsServer("org-root", "test")
from ucscsdk.mometa.ls.LsServer import LsServer from ucscsdk.mometa.ls.LsVConAssign import LsVConAssign from ucscsdk.mometa.lstorage.LstorageProfileBinding import LstorageProfileBinding from ucscsdk.mometa.vnic.VnicEther import VnicEther from ucscsdk.mometa.vnic.VnicEtherIf import VnicEtherIf from ucscsdk.mometa.ls.LsPower import LsPower from ucscsdk.mometa.ls.LsRequirement import LsRequirement obj = handle.query_dn(org) mo = LsServer(parent_mo_or_dn=obj, name=template, type="initial-template", ext_ip_state="none", ext_ip_pool_name=row['Mgmt_IP_Pool'], ident_pool_name=row['UUID'], bios_profile_name="S3260", boot_policy_name=row['Boot_Policy'], maint_policy_name=row['Maint_Policy'], power_policy_name="Ceph-Power", uuid="derived") mo_1 = VnicEther(parent_mo_or_dn=mo, name="Default", switch_id="A-B", mtu="1500", cdn_source="vnic-name", ident_pool_name="mac-pool", qos_policy_name="Ceph_Qos_Policy", admin_host_port="ANY", admin_vcon="1",
if row['org']: org = row['org'] else: org = 'org-root' if not row['Template']: print "Error on row %d: no template name found" % row_num continue template = row['Template'] print "Deleting global service profile template: %s" % (template) from ucscsdk.mometa.ls.LsServer import LsServer obj = handle.query_dn(org) mo = LsServer(parent_mo_or_dn=obj, name=template) handle.remove_mo(mo) handle.commit() handle.logout() except Exception, err: print "Exception:", str(err) import traceback, sys print '-'*60 traceback.print_exc(file=sys.stdout) print '-'*60
profile_name = row['SP_Name'] if not profile_name: profile_name = "%s-instance-" % template num_instances = int(row['instances']) if not num_instances: num_instances = 1 print "Creating %s service profiles with name prefix %s" % (num_instances, profile_name) from ucscsdk.mometa.ls.LsServer import LsServer obj = handle.query_dn(org) for instance in range(1, num_instances + 1): sp_name = "%s-%s" % (profile_name, instance) mo = LsServer(parent_mo_or_dn=obj, src_templ_name=template, name=sp_name, type="instance", uuid="derived") handle.add_mo(mo, True) handle.commit() handle.logout() except Exception, err: print "Exception:", str(err) import traceback, sys print '-'*60 traceback.print_exc(file=sys.stdout) print '-'*60
def main(): argument_spec = ucs_argument_spec argument_spec.update( org_dn=dict(type='str', default='org-root'), name=dict(type='str', required=True), source_template=dict(type='str', required=True), user_label=dict(type='str', default=''), power_state=dict(type='str', choices=['up', 'down']), state=dict(type='str', default='present', choices=['present', 'absent']), ) module = AnsibleModule( argument_spec, supports_check_mode=True, ) ucs = UCSModule(module) err = False # UCSModule creation above verifies ucsmsdk is present and exits on failure. Additional imports are done below. from ucscsdk.mometa.ls.LsServer import LsServer from ucscsdk.mometa.ls.LsPower import LsPower changed = False try: mo_exists = False props_match = False dn = module.params['org_dn'] + '/ls-' + module.params['name'] mo = ucs.login_handle.query_dn(dn) if mo: mo_exists = True if module.params['state'] == 'absent': # mo must exist but all properties do not have to match if mo_exists: if not module.check_mode: ucs.login_handle.remove_mo(mo) ucs.login_handle.commit() changed = True else: if mo_exists: # check top-level mo props kwargs = dict(src_templ_name=module.params['source_template']) kwargs['usr_lbl'] = module.params['user_label'] # service profiles are of type 'instance' kwargs['type'] = 'instance' if mo.check_prop_match(**kwargs): # top-level props match if module.params.get('power_state'): child_dn = dn + '/power' mo_1 = ucs.login_handle.query_dn(child_dn) if mo_1: kwargs = dict(state=module.params['power_state']) if mo_1.check_prop_match(**kwargs): props_match = True else: # no power state provided, use existing state as match props_match = True if not props_match: if not module.check_mode: # create if mo does not already exist mo = LsServer( parent_mo_or_dn=module.params['org_dn'], name=module.params['name'], src_templ_name=module.params['source_template'], type='instance', usr_lbl=module.params['user_label'], ) if module.params.get('power_state'): admin_state = 'admin-' + module.params['power_state'] mo_1 = LsPower( parent_mo_or_dn=mo, state=admin_state, ) ucs.login_handle.add_mo(mo, True) ucs.login_handle.commit() changed = True except Exception as e: err = True ucs.result['msg'] = "setup error: %s " % str(e) ucs.result['changed'] = changed if err: module.fail_json(**ucs.result) module.exit_json(**ucs.result)
def configure_service_profile_template(ucs, module): from ucscsdk.mometa.ls.LsServer import LsServer from ucscsdk.mometa.vnic.VnicConnDef import VnicConnDef from ucscsdk.mometa.vnic.VnicIScsiNode import VnicIScsiNode from ucscsdk.mometa.ls.LsRequirement import LsRequirement from ucscsdk.mometa.ls.LsPower import LsPower from ucscsdk.mometa.lstorage.LstorageProfileBinding import LstorageProfileBinding from ucscsdk.mometa.mgmt.MgmtInterface import MgmtInterface from ucscsdk.mometa.mgmt.MgmtVnet import MgmtVnet from ucscsdk.mometa.vnic.VnicIpV4MgmtPooledAddr import VnicIpV4MgmtPooledAddr if not module.check_mode: try: # create if mo does not already exist mo = LsServer( parent_mo_or_dn=module.params['org_dn'], bios_profile_name=module.params['bios_policy'], boot_policy_name=module.params['boot_policy'], descr=module.params['description'], ext_ip_state=module.params['mgmt_ip_state'], ext_ip_pool_name=module.params['mgmt_ip_pool'], # graphics_card_policy_name=module.params['graphics_card_policy'], host_fw_policy_name=module.params['host_firmware_package'], ident_pool_name=module.params['uuid_pool'], # kvm_mgmt_policy_name=module.params['kvm_mgmt_policy'], local_disk_policy_name=module.params['local_disk_policy'], maint_policy_name=module.params['maintenance_policy'], mgmt_access_policy_name=module.params['ipmi_access_profile'], name=module.params['name'], power_policy_name=module.params['power_control_policy'], power_sync_policy_name=module.params['power_sync_policy'], scrub_policy_name=module.params['scrub_policy'], sol_policy_name=module.params['sol_policy'], stats_policy_name=module.params['threshold_policy'], type=module.params['template_type'], usr_lbl=module.params['user_label'], vmedia_policy_name=module.params['vmedia_policy'], ) if module.params['storage_profile']: # Storage profile mo_1 = LstorageProfileBinding( parent_mo_or_dn=mo, storage_profile_name=module.params['storage_profile'], ) if module.params['mgmt_interface_mode']: # Management Interface mo_1 = MgmtInterface( parent_mo_or_dn=mo, mode=module.params['mgmt_interface_mode'], ip_v4_state='pooled', ) mo_2 = MgmtVnet( parent_mo_or_dn=mo_1, id='1', name=module.params['mgmt_vnet_name'], ) VnicIpV4MgmtPooledAddr( parent_mo_or_dn=mo_2, name=module.params['mgmt_inband_pool_name'], ) # LAN/SAN connectivity policy mo_1 = VnicConnDef( parent_mo_or_dn=mo, lan_conn_policy_name=module.params['lan_connectivity_policy'], san_conn_policy_name=module.params['san_connectivity_policy'], ) if module.params['iqn_pool']: # IQN pool mo_1 = VnicIScsiNode( parent_mo_or_dn=mo, iqn_ident_pool_name=module.params['iqn_pool']) # power state admin_state = 'admin-' + module.params['power_state'] mo_1 = LsPower( parent_mo_or_dn=mo, state=admin_state, ) if module.params['server_pool']: # server pool mo_1 = LsRequirement( parent_mo_or_dn=mo, name=module.params['server_pool'], qualifier=module.params['server_pool_qualification'], ) ucs.login_handle.add_mo(mo, True) ucs.login_handle.commit() except Exception as e: # generic Exception handling because SDK can throw a variety of exceptions ucs.result['msg'] = "setup error: %s " % str(e) module.fail_json(**ucs.result) ucs.result['changed'] = True
def test_002_sp_expert(): from ucscsdk.mometa.ls.LsServer import LsServer from ucscsdk.mometa.ls.LsVConAssign import LsVConAssign from ucscsdk.mometa.vnic.VnicEther import VnicEther from ucscsdk.mometa.vnic.VnicEtherIf import VnicEtherIf from ucscsdk.mometa.vnic.VnicFc import VnicFc from ucscsdk.mometa.vnic.VnicFcIf import VnicFcIf from ucscsdk.mometa.vnic.VnicFcNode import VnicFcNode from ucscsdk.mometa.storage.StorageIniGroup import StorageIniGroup from ucscsdk.mometa.vnic.VnicFcGroupDef import VnicFcGroupDef from ucscsdk.mometa.storage.StorageInitiator import StorageInitiator from ucscsdk.mometa.ls.LsPower import LsPower from ucscsdk.mometa.fabric.FabricVCon import FabricVCon mo = LsServer(parent_mo_or_dn="org-root", vmedia_policy_name="", ext_ip_state="none", bios_profile_name="SRIOV", mgmt_fw_policy_name="", agent_policy_name="", mgmt_access_policy_name="", dynamic_con_policy_name="", sol_policy_name="", uuid="00000000-0000-0000-0000-0000000000bb", descr="", stats_policy_name="default", ext_ip_pool_name="ext-mgmt", boot_policy_name="default", usr_lbl="", host_fw_policy_name="", vcon_profile_name="", ident_pool_name="", src_templ_name="", local_disk_policy_name="default", scrub_policy_name="", power_policy_name="default", maint_policy_name="", name="test_sp") mo_1 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="1", transport="ethernet", vnic_name="eth0") mo_2 = LsVConAssign(parent_mo_or_dn=mo, admin_vcon="any", order="2", transport="fc", vnic_name="fc0") mo_3 = VnicEther(parent_mo_or_dn=mo, nw_ctrl_policy_name="", name="eth0", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="A", pin_to_group_name="", mtu="1500", qos_policy_name="", adaptor_profile_name="", ident_pool_name="default", order="1", nw_templ_name="", addr="derived") mo_3_1 = VnicEtherIf(parent_mo_or_dn=mo_3, default_net="yes", name="default") mo_4 = VnicFc(parent_mo_or_dn=mo, addr="derived", name="fc0", admin_host_port="ANY", admin_vcon="any", stats_policy_name="default", admin_cdn_name="", switch_id="A", pin_to_group_name="", pers_bind="disabled", pers_bind_clear="no", qos_policy_name="", adaptor_profile_name="", ident_pool_name="", order="2", nw_templ_name="", max_data_field_size="2048") mo_4_1 = VnicFcIf(parent_mo_or_dn=mo_4, name="default") mo_5 = VnicFcNode(parent_mo_or_dn=mo, ident_pool_name="", addr="20:00:00:25:B5:00:00:00") mo_6 = StorageIniGroup(parent_mo_or_dn=mo, name="test", descr="", group_policy_name="", policy_name="", rmt_disk_cfg_name="") mo_6_1 = VnicFcGroupDef(parent_mo_or_dn=mo_6, storage_conn_policy_name="", name="", descr="", stats_policy_name="default") mo_6_2 = StorageInitiator(parent_mo_or_dn=mo_6, name="fc0", descr="") mo_7 = LsPower(parent_mo_or_dn=mo, state="admin-up") mo_8 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="1", inst_type="auto") mo_9 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="2", inst_type="auto") mo_10 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="3", inst_type="auto") mo_11 = FabricVCon(parent_mo_or_dn=mo, placement="physical", fabric="NONE", share="shared", select="all", transport="ethernet,fc", id="4", inst_type="auto") handle.add_mo(mo) handle.commit() obj = handle.query_dn("org-root/ls-test_sp") handle.remove_mo(obj) handle.commit()
if not profile_name: profile_name = "%s-instance-" % template num_instances = int(row['instances']) if not num_instances: num_instances = 1 print "Disassociating %s service profiles with name prefix %s" % (num_instances, profile_name) from ucscsdk.mometa.ls.LsServer import LsServer obj = handle.query_dn(org) for instance in range(1, num_instances + 1): sp_name = "%s-%s" % (profile_name, instance) dn = "%s/ls-%s/pn-req" % (org, sp_name) mo_1 = handle.query_dn(dn) if mo_1 == None: mo = LsServer(parent_mo_or_dn=obj, name=sp_name) handle.remove_mo(mo) else: handle.remove_mo(mo_1) handle.commit() handle.logout() except Exception, err: print "Exception:", str(err) import traceback, sys print '-'*60 traceback.print_exc(file=sys.stdout) print '-'*60