def boot_policy_create(handle, name, org_dn="org-root", reboot_on_update="no", enforce_vnic_name="yes", boot_mode="legacy", policy_owner="local", descr=None, **kwargs): """ creates boot policy Args: handle (UcsHandle) name (string): boot policy name org_dn (string): org dn reboot_on_update (string): valid values are "yes", "no" enforce_vnic_name (string): valid values are "yes", "no" boot_mode (string): "legacy" or "uefi" policy_owner (string): "local" or "pending-policy" or "policy" descr (string): Basic description. **kwargs: Any additional key-value pair of managed object(MO)'s property and value, which are not part of regular args. This should be used for future version compatibility. Returns: LsbootPolicy: managed object Raises: UcsOperationError: if OrgOrg is not present Example: boot_policy_create(handle, name="sample_boot", org_dn="org-root/org-finance", reboot_on_update="yes", enforce_vnic_name="yes", boot_mode="legacy", descr="sample description") """ from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy obj = handle.query_dn(org_dn) if not obj: raise UcsOperationError( "boot_policy_create", "Org '%s' does not \ exist" % org_dn) mo = LsbootPolicy(parent_mo_or_dn=obj, name=name, reboot_on_update=reboot_on_update, enforce_vnic_name=enforce_vnic_name, boot_mode=boot_mode, policy_owner=policy_owner, descr=descr) mo.set_prop_multiple(**kwargs) handle.add_mo(mo, modify_present=True) handle.commit() return mo
def boot_policy_create(handle, name, org_dn="org-root", reboot_on_update=False, enforce_vnic_name=True, boot_mode="legacy", policy_owner="local", descr=None, **kwargs): """ This method creates boot policy. Args: handle (UcsHandle) name (string): Name of the boot policy. org_dn (string): Org DN. reboot_on_update (bool): True/False. Default False. enforce_vnic_name (bool): True/False. Default True. boot_mode (string): "legacy" or "uefi" policy_owner (string): "local" or "pending-policy" or "policy" descr (string): Basic description. Returns: LsbootPolicy: Managed Object Raises: UcsOperationError Example: boot_policy_create(handle, name="sample_boot", org_dn="org-root/org-finance", reboot_on_update=True, enforce_vnic_name=True, boot_mode="legacy", descr="sample description") """ from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy obj = handle.query_dn(org_dn) if not obj: raise UcscOperationError("boot_policy_create", "Org '%s' does not \ exist" % org_dn) reboot_on_update = ("no", "yes")[reboot_on_update] enforce_vnic_name = ("no", "yes")[enforce_vnic_name] mo = LsbootPolicy(parent_mo_or_dn=obj, name=name, reboot_on_update=reboot_on_update, enforce_vnic_name=enforce_vnic_name, boot_mode=boot_mode, policy_owner=policy_owner, descr=descr) mo.set_prop_multiple(**kwargs) handle.add_mo(mo, modify_present=True) handle.commit() return mo
def set_vmedia_boot_policy(ucs_handle, sp_template_boot_policy_object, org_name): sp_template_boot_policy_name = sp_template_boot_policy_object.name mo = LsbootPolicy(parent_mo_or_dn="org-root/org-" + org_name, name=sp_template_boot_policy_name) LsbootVirtualMedia(parent_mo_or_dn=mo, access="read-only-remote-cimc", lun_id="0", order="3") ucs_handle.add_mo(mo, True) ucs_handle.commit() if sp_template_boot_policy_name == "HyperFlex": mo = LsbootUsbFlashStorageImage( parent_mo_or_dn= "org-root/org-hxcluster/boot-policy-HyperFlex/storage/local-storage", order="3") elif sp_template_boot_policy_name == "HyperFlex-m5": mo = LsbootEmbeddedLocalDiskImage( parent_mo_or_dn="org-root/org-" + org_name + "/boot-policy-" + sp_template_boot_policy_name + "/storage/local-storage", order="3") ucs_handle.add_mo(mo, True) mo = LsbootVirtualMedia(parent_mo_or_dn="org-root/org-" + org_name + "/boot-policy-" + sp_template_boot_policy_name, access="read-only-remote-cimc", order="1") ucs_handle.add_mo(mo, True) mo = LsbootVirtualMedia(parent_mo_or_dn="org-root/org-" + org_name + "/boot-policy-" + sp_template_boot_policy_name, access="read-only", order="2") ucs_handle.add_mo(mo, True) ucs_handle.commit()
def createKubeBootPolicy(handle, org): print "Creating Kube Boot Policy" 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.LsbootDefaultLocalImage import LsbootDefaultLocalImage mo = LsbootPolicy(parent_mo_or_dn=org, name="kube", descr="Kuberenetes", reboot_on_update="yes", policy_owner="local", enforce_vnic_name="yes", boot_mode="legacy") mo_1 = LsbootVirtualMedia(parent_mo_or_dn=mo, access="read-only-remote-cimc", lun_id="0", order="2") mo_2 = LsbootStorage(parent_mo_or_dn=mo, order="1") mo_2_1 = LsbootLocalStorage(parent_mo_or_dn=mo_2, ) mo_2_1_1 = LsbootDefaultLocalImage(parent_mo_or_dn=mo_2_1, order="1") handle.add_mo(mo, modify_present=True) try: handle.commit() except UcsException as err: if err.error_code == "103": print "\talready exists"
def create_boot_policy(handle, org): 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.LsbootDefaultLocalImage import LsbootDefaultLocalImage print "Creating KUBAM Boot Policy" mo_bp = LsbootPolicy( parent_mo_or_dn=org, name="kubam", descr="kubam", reboot_on_update="yes", policy_owner="local", enforce_vnic_name="yes", boot_mode="legacy" ) LsbootVirtualMedia(parent_mo_or_dn=mo_bp, access="read-only-remote-cimc", lun_id="0", order="2") mo_bs = LsbootStorage(parent_mo_or_dn=mo_bp, order="1") mo_bls = LsbootLocalStorage(parent_mo_or_dn=mo_bs, ) LsbootDefaultLocalImage(parent_mo_or_dn=mo_bls, order="1") handle.add_mo(mo_bp, modify_present=True) try: handle.commit() except UcsException as err: if err.error_code == "103": print "\talready exists" else: return 1, err.error_descr return 0, None
def boot_policy_create(handle, name, descr="", reboot_on_update="yes", enforce_vnic_name="yes", boot_mode="legacy", parent_dn="org-root", boot_device={}): """ This method creates boot policy. Args: handle (UcsHandle) name (string): Name of the boot policy. reboot_on_update (string): "yes" or "no" enforce_vnic_name (string): "yes" or "no" boot_mode (string): "legacy" or "uefi" parent_dn (string): Org DN. descr (string): Basic description. boot_device (dict): Dictionary of boot devices. {"1":"cdrom-local"} Returns: LsbootPolicy: Managed Object Example: boot_policy_create(handle, name="sample_boot", reboot_on_update="yes", boot_mode="legacy", parent_dn="org-root/org-finance", boot_device={"2":"cdrom-local","1":"usb-external", "3":"usb-internal"}) """ from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy mo = handle.query_dn(parent_dn) if mo is None: raise ValueError("org '%s' does not exist" % parent_dn) mo = LsbootPolicy(parent_mo_or_dn=mo, name=name, descr=descr, reboot_on_update=reboot_on_update, enforce_vnic_name=enforce_vnic_name, boot_mode=boot_mode) if boot_device is not None: _add_device(handle, mo, boot_device) handle.add_mo(mo, modify_present=True) handle.commit() return mo
def boot_policy_create(handle, name, descr="", reboot_on_update="yes", enforce_vnic_name="yes", boot_mode="legacy", parent_dn="org-root"): """ This method creates boot policy. Args: handle (UcsHandle) name (string): Name of the boot policy. reboot_on_update (string): "yes" or "no" enforce_vnic_name (string): "yes" or "no" boot_mode (string): "legacy" or "uefi" parent_dn (string): Org DN. descr (string): Basic description. Returns: None Example: boot_policy_create(handle, name="sample_boot", reboot_on_update="yes", boot_mode="legacy", parent_dn="org-root/org-finance") """ from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy obj = handle.query_dn(parent_dn) if obj: mo = LsbootPolicy(parent_mo_or_dn=parent_dn, name=name, descr=descr, reboot_on_update=reboot_on_update, enforce_vnic_name=enforce_vnic_name, boot_mode=boot_mode) handle.add_mo(mo, modify_present=True) handle.commit() else: log.info("Sub-Org <%s> not found!" % org_name)
mo_1 = VnicEtherIf(parent_mo_or_dn=mo, default_net="yes", name="iSCSI-A") handle.add_mo(mo) handle.commit() mo = VnicLanConnTempl(parent_mo_or_dn=my_Full_Path_Org, templ_type="updating-template", name="iSCSI-B", descr="iSCSI FI-B", stats_policy_name="default", admin_cdn_name="", switch_id="B", pin_to_group_name="", mtu="9000", policy_owner="local", qos_policy_name="Nimble-QoS", ident_pool_name="iSCSI-B", cdn_source="vnic-name", nw_ctrl_policy_name="Nimble-iSCSI") mo_1 = VnicEtherIf(parent_mo_or_dn=mo, default_net="yes", name="iSCSI-B") handle.add_mo(mo) handle.commit() #Create Local Disk Conf Policy (any-configuration) mo = StorageLocalDiskConfigPolicy(parent_mo_or_dn=my_Full_Path_Org, protect_config="yes", name="Local_Disk_CP", descr="Local Disk Configuration Policy Desc", flex_flash_raid_reporting_state="enable", flex_flash_state="enable", policy_owner="local", mode="any-configuration") handle.add_mo(mo) handle.commit() #Create Boot Policy (boot from SD) mo = LsbootPolicy(parent_mo_or_dn=my_Full_Path_Org, name="Boot_Policy", descr="Boot Policy Desc", reboot_on_update="no", policy_owner="local", enforce_vnic_name="yes", boot_mode="legacy") mo_1 = LsbootVirtualMedia(parent_mo_or_dn=mo, access="read-write-drive", lun_id="0", mapping_name="", order="2") mo_2 = LsbootStorage(parent_mo_or_dn=mo, order="1") mo_2_1 = LsbootLocalStorage(parent_mo_or_dn=mo_2, ) mo_2_1_1 = LsbootUsbFlashStorageImage(parent_mo_or_dn=mo_2_1, order="1") handle.add_mo(mo) handle.commit() #Create HBA Template if(FC): mo = VnicSanConnTempl(parent_mo_or_dn=my_Full_Path_Org, templ_type="updating-template", name="fc-a", descr="", stats_policy_name="default", switch_id="A", pin_to_group_name="", policy_owner="local", qos_policy_name="", ident_pool_name="WWPN_Pool-A", max_data_field_size="2048") mo_1 = VnicFcIf(parent_mo_or_dn=mo, name="default") handle.add_mo(mo) handle.commit() mo = VnicSanConnTempl(parent_mo_or_dn=my_Full_Path_Org, templ_type="updating-template", name="fc-b", descr="", stats_policy_name="default", switch_id="B", pin_to_group_name="", policy_owner="local", qos_policy_name="", ident_pool_name="WWPN_Pool-B", max_data_field_size="2048")
##### End-Of-PythonScript ##### #Create Boot Policy ##### Start-Of-PythonScript ##### 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="org-root/org-Sub_Org_Test", name="Boot_Policy", descr="Boot Policy Desc", reboot_on_update="no", policy_owner="local", enforce_vnic_name="yes", boot_mode="legacy") mo_1 = LsbootVirtualMedia(parent_mo_or_dn=mo, access="read-write-drive", lun_id="0", mapping_name="", order="2") mo_2 = LsbootStorage(parent_mo_or_dn=mo, order="1") mo_2_1 = LsbootLocalStorage(parent_mo_or_dn=mo_2, ) mo_2_1_1 = LsbootUsbFlashStorageImage(parent_mo_or_dn=mo_2_1, order="1") handle.add_mo(mo) handle.commit() ##### End-Of-PythonScript #####
def boot_policy(input): name = input['name'] type = input['type'] device_name = input['device_name'] order = input['order'] state = input['state'] ip = input['ip'] username = input['username'] password = input['password'] mo = "" mo_block = "" results = {} ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) ###-------CHECK IF MO EXISTS--------------------------------- try: mo = ucs_handle.query_dn("org-root/boot-policy-" + name) except: return '{"error":"Could not query children of boot policy"}' ###----if expected state is "present"------------------------ if state == "present": if (mo and (type == "LAN" or type == "LocalLun")): if (type == "LAN"): lan_query = query_lanmo(ucs_handle, mo, device_name, order) local_lun_query = True elif (type == "LocalLun"): local_lun_query = query_locallunmo(ucs_handle, mo, device_name, order) lan_query = True else: print("The type mentioned is not supported by this module.") if (mo.name == name and lan_query and local_lun_query): results['name'] = name results['expected'] = True results['changed'] = False results['present'] = True else: try: if (lan_query and ~(local_lun_query)): modified_mo = LsbootStorage(parent_mo_or_dn=mo, ) mo_1 = LsbootLocalStorage( parent_mo_or_dn=modified_mo, ) mo_1_1 = LsbootLocalHddImage(parent_mo_or_dn=mo_1, order=order) mo_1_1_1 = LsbootLocalLunImagePath( parent_mo_or_dn=mo_1_1, lun_name=device_name, type="primary") ucs_handle.add_mo(modified_mo, True) ucs_handle.commit() elif (local_lun_query and ~(lan_query)): modified_mo = LsbootLan(parent_mo_or_dn=mo, order=order) mo_1_1 = LsbootLanImagePath( parent_mo_or_dn=modified_mo, type="primary", vnic_name=device_name) ucs_handle.add_mo(mo, True) ucs_handle.commit() else: modified_mo = LsbootStorage(parent_mo_or_dn=mo, ) mo_1 = LsbootLocalStorage( parent_mo_or_dn=modified_mo, ) mo_1_1 = LsbootLocalHddImage(parent_mo_or_dn=mo_1, order=order) mo_1_1_1 = LsbootLocalLunImagePath( parent_mo_or_dn=mo_1_1, lun_name=device_name, type="primary") ucs_handle.add_mo(mo, True) ucs_handle.commit() modified_mo = LsbootLan(parent_mo_or_dn=mo, order=order) mo_1_1 = LsbootLanImagePath(parent_mo_or_dn=mo_1, type="primary", vnic_name=device_name) ucs_handle.add_mo(mo, True) ucs_handle.commit() results['name'] = name results['present'] = True results['removed'] = False results['changed'] = True except Exception, e: return '{"error":"%s" %e}' elif (mo and type == ""): results['name'] = name results['present'] = True results['removed'] = False results['changed'] = False ###----------if not, create boot policy with desired config ---------------- else: try: mo = LsbootPolicy(parent_mo_or_dn="org-root", name=name, descr="") if (type != ""): if (type == "LAN"): mo_1 = LsbootLan(parent_mo_or_dn=mo, order=order) mo_1_1 = LsbootLanImagePath(parent_mo_or_dn=mo_1, type="primary", vnic_name=device_name) else: mo_2 = LsbootStorage(parent_mo_or_dn=mo, order=order) mo_2_1 = LsbootLocalStorage(parent_mo_or_dn=mo_2, ) mo_2_1_1 = LsbootLocalHddImage(parent_mo_or_dn=mo_2_1, order=order) mo_2_1_1_1 = LsbootLocalLunImagePath( parent_mo_or_dn=mo_2_1_1, lun_name=device_name, type="primary") ucs_handle.add_mo(mo) ucs_handle.commit() results['name'] = name results['present'] = False results['created'] = True results['changed'] = True except: return '{"error":"boot policy creation failed"}'
def main(): logging.basicConfig(level=logging.INFO) argument_spec = ucs_argument_spec argument_spec.update( name=dict(type='str', required=True), description=dict(type='str', default=''), state=dict(type='str', default='present', choices=['present', 'absent']), boot_mode=dict(type='str', default='legacy', choices=['legacy', 'uefi']), enforce_vnic_name=dict(type='str', default='yes', choices=['yes', 'no']), reboot_on_update=dict(type='str', default='no', choices=['yes', 'no']), boot_security=dict(type='str', default='no', choices=['yes', 'no']), boot_order=dict(type='list'), ) module = AnsibleModule( argument_spec, supports_check_mode=True, ) ucs = UCSModule(module) err = False # UCSModule creation above verifies ucsmsdk is present and exits on failure, so additional imports are done below. from ucsmsdk.mometa.lsboot.LsbootBootSecurity import LsbootBootSecurity from ucsmsdk.mometa.lsboot.LsbootDefaultLocalImage import LsbootDefaultLocalImage # from ucsmsdk.mometa.lsboot.LsbootDef import LsbootDef # from ucsmsdk.mometa.lsboot.LsbootEFIShell import LsbootEFIShell # from ucsmsdk.mometa.lsboot.LsbootEmbeddedLocalDiskImagePath import LsbootEmbeddedLocalDiskImagePath # from ucsmsdk.mometa.lsboot.LsbootEmbeddedLocalDiskImage import LsbootEmbeddedLocalDiskImage # from ucsmsdk.mometa.lsboot.LsbootEmbeddedLocalLunImage import LsbootEmbeddedLocalLunImage # from ucsmsdk.mometa.lsboot.LsbootIScsiImagePath import LsbootIScsiImagePath # from ucsmsdk.mometa.lsboot.LsbootIScsi import LsbootIScsi # from ucsmsdk.mometa.lsboot.LsbootLanImagePath import LsbootLanImagePath # from ucsmsdk.mometa.lsboot.LsbootLan import LsbootLan # from ucsmsdk.mometa.lsboot.LsbootLocalDiskImagePath import LsbootLocalDiskImagePath # from ucsmsdk.mometa.lsboot.LsbootLocalDiskImage import LsbootLocalDiskImage from ucsmsdk.mometa.lsboot.LsbootLocalHddImage import LsbootLocalHddImage # from ucsmsdk.mometa.lsboot.LsbootNvmeDiskSsd import LsbootNvmeDiskSsd # from ucsmsdk.mometa.lsboot.LsbootNvmePciSsd import LsbootNvmePciSsd # from ucsmsdk.mometa.lsboot.LsbootNvme import LsbootNvme from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy # from ucsmsdk.mometa.lsboot.LsbootSanCatSanImagePath import LsbootSanCatSanImagePath # from ucsmsdk.mometa.lsboot.LsbootSanCatSanImage import LsbootSanCatSanImage # from ucsmsdk.mometa.lsboot.LsbootSanImagePath import LsbootSanImagePath # from ucsmsdk.mometa.lsboot.LsbootSanImage import LsbootSanImage # from ucsmsdk.mometa.lsboot.LsbootSan import LsbootSan # from ucsmsdk.mometa.lsboot.LsbootUEFIBootParam import LsbootUEFIBootParam # from ucsmsdk.mometa.lsboot.LsbootUsbExternalImage import LsbootUsbExternalImage # from ucsmsdk.mometa.lsboot.LsbootUsbFlashStorageImage import LsbootUsbFlashStorageImage # from ucsmsdk.mometa.lsboot.LsbootUsbInternalImage import LsbootUsbInternalImage from ucsmsdk.mometa.lsboot.LsbootVirtualMedia import LsbootVirtualMedia changed = False try: mo_exists = False parent_props_match = False child_props_match = True dn_base = 'org-root' dn = dn_base + '/boot-policy-' + 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: boot_security_policy_enabled = False if module.params[PARAM_BOOT_SECURITY] == 'yes' and module.params[ PARAM_BOOT_MODE] == BOOT_MODE_UEFI: boot_security_policy_enabled = True boot_order_tree = build_boot_order_tree( dn, module.params[BOOT_ORDER], boot_security_policy_enabled) boot_order_matches = dict() if mo_exists: # check top-level mo props kwargs = dict(name=module.params['name']) kwargs['descr'] = module.params['description'] kwargs[PARAM_BOOT_MODE] = module.params[PARAM_BOOT_MODE] kwargs['enforce_vnic_name'] = module.params[ 'enforce_vnic_name'] kwargs['reboot_on_update'] = module.params['reboot_on_update'] if (mo.check_prop_match(**kwargs)): parent_props_match = True logging.info("parent props match: %s", parent_props_match) # verify boot order settings if module.params.get('boot_order'): child_props_match = verify_boot_order_settings( mo, dn, boot_security_policy_enabled, boot_order_matches, boot_order_tree, ucs) if not (parent_props_match and child_props_match): if not module.check_mode: # if some boot order entries need to be removed remove them first check_and_remove_boot_order_entries( mo_exists, child_props_match, boot_order_matches, boot_order_tree, ucs) if not parent_props_match: mo = LsbootPolicy( parent_mo_or_dn=dn_base, name=module.params['name'], descr=module.params['description'], boot_mode=module.params['boot_mode'], enforce_vnic_name=module. params['enforce_vnic_name'], reboot_on_update=module.params['reboot_on_update']) ucs.login_handle.add_mo(mo, True) for boot_order_dn in boot_order_tree.keys(): if not (boot_order_matches.get(boot_order_dn) and boot_order_matches[boot_order_dn]): new_order = boot_order_tree.get(boot_order_dn) # boot security if boot_order_dn == get_dn_path( dn, BOOT_SECURITY_DN): # secure_boot='yes' if boot_security_policy_enabled == BOOT_SECURITY_YES else 'no' # print("secure_boot", secure_boot) mo_bsec = LsbootBootSecurity( parent_mo_or_dn=dn, secure_boot='yes' if boot_security_policy_enabled else 'no') ucs.login_handle.add_mo(mo_bsec, True) # local disk elif boot_order_dn == get_dn_path( dn, LOCAL_DISK_DN): logging.info("dn: %s order: %s", boot_order_dn, new_order) mo_blocal_storage = create_local_storage( dn, new_order, ucs) mo_blocal_image = LsbootDefaultLocalImage( parent_mo_or_dn=mo_blocal_storage, order=new_order) ucs.login_handle.add_mo(mo_blocal_image, True) # local lun elif boot_order_dn == get_dn_path( dn, LOCAL_LUN_DN): logging.info("dn: %s order: %s", boot_order_dn, new_order) mo_blocal_storage = create_local_storage( dn, new_order, ucs) mo_blocal_lun = LsbootLocalHddImage( parent_mo_or_dn=mo_blocal_storage, order=new_order) ucs.login_handle.add_mo(mo_blocal_lun, True) lun_images = get_params( module.params[BOOT_ORDER], LOCAL_LUN) logging.info("dn: %s lun_image: %s", boot_order_dn, lun_images) add_lun_local_image_path( mo_blocal_lun, lun_images, ucs) # local CD/DVD elif boot_order_dn == get_dn_path( dn, VIRTUAL_MEDIA_DN): logging.info("dn: %s order: %s", boot_order_dn, new_order) mo_bvmedia = LsbootVirtualMedia( parent_mo_or_dn=dn, order=new_order, access=ACCESS_READ_ONLY) ucs.login_handle.add_mo(mo_bvmedia, True) # cimc CD/DVD elif boot_order_dn == get_dn_path( dn, CIMC_MEDIA_DVD_DN): logging.info("dn: %s order: %s", boot_order_dn, new_order) mo_boot_cimc_vmedia_dvd = LsbootVirtualMedia( parent_mo_or_dn=dn, order=new_order, access=ACCESS_READ_ONLY_REMOTE_CIMC) ucs.login_handle.add_mo( mo_boot_cimc_vmedia_dvd, True) # cimc HDD elif boot_order_dn == get_dn_path( dn, CIMC_MEDIA_HDD_DN): logging.info("dn: %s order: %s", boot_order_dn, new_order) mo_boot_cimc_vmedia_hdd = LsbootVirtualMedia( parent_mo_or_dn=dn, order=new_order, access=ACCESS_READ_WRITE_REMOTE_CIMC) ucs.login_handle.add_mo( mo_boot_cimc_vmedia_hdd, True) ucs.login_handle.commit() changed = True except Exception as e: err = True ucs.result['msg'] = "setup error: %s " % str(e) traceback.print_exc() ucs.result['changed'] = changed if err: module.fail_json(**ucs.result) module.exit_json(**ucs.result)
def boot_policy(input): name = input['name'] descr = input['descr'] reboot_on_update = input['reboot_on_update'] policy_owner = input['policy_owner'] enforce_vnic_name = input['enforce_vnic_name'] boot_mode = input['boot_mode'] state = input['state'] ip=input['ip'] username=input['username'] password=input['password'] results = {} ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) ###-------CHECK IF MO EXISTS--------------------------------- try: mo = ucs_handle.query_dn("org-root/boot-policy-"+name) except: print("Could not query children of org-root") ###----if expected state is "present"------------------------ if state == "present": if mo: if (mo.name == name and mo.descr == descr and mo.boot_mode == boot_mode and mo.reboot_on_update == reboot_on_update and mo.policy_owner == policy_owner and mo.enforce_vnic_name == enforce_vnic_name): results['name']=name; results['expected'] = True; results['changed'] = False; results['present'] = True; #results['mo_bootpolicy'] = json.dumps(json.loads(jsonpickle.encode(mo))); else: try: mo.descr = descr mo.boot_mode = boot_mode mo.reboot_on_update = reboot_on_update mo.policy_owner = policy_owner mo.enforce_vnic_name = enforce_vnic_name results['name']=name; results['expected'] = False; results['changed'] = True; results['present'] = True; ucs_handle.set_mo(mo) ucs_handle.commit() #results['mo_bootpolicy'] = json.dumps(json.loads(jsonpickle.encode(mo))); except: module.fail_json(msg="Modify boot policy mo failed") ###----------if not, create boot policy with desired config ---------------- else: try: #print("inside creator block") mo = LsbootPolicy(parent_mo_or_dn="org-root", name=name, descr=descr, reboot_on_update=reboot_on_update, policy_owner=policy_owner, enforce_vnic_name=enforce_vnic_name, boot_mode=boot_mode) results['name']=name; results['present'] = False; results['created'] = True; results['changed'] = True; #results['mo_bootpolicy'] = json.dumps(json.loads(jsonpickle.encode(mo))); ucs_handle.add_mo(mo) ucs_handle.commit() except: print("Boot Policy creation failed") ###------if expected state is "absent"---------------------------- if state == "absent": if mo: try: ucs_handle.remove_mo(mo) results['name']=name; results['present'] = False; results['removed'] = True; ucs_handle.commit() except: print("Remove boot policy mo failed") else: results['name']=name; results['removed'] = False; results['present'] = False; ucs_handle=pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return results
handle.commit() ##### End-Of-PythonScript ##### ##### Start-Of-PythonScript ##### from ucsmsdk.mometa.lsboot.LsbootPolicy import LsbootPolicy from ucsmsdk.mometa.lsboot.LsbootLan import LsbootLan from ucsmsdk.mometa.lsboot.LsbootLanImagePath import LsbootLanImagePath 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.LsbootDefaultLocalImage import LsbootDefaultLocalImage mo = LsbootPolicy(parent_mo_or_dn="org-root", name="PXE_Boot", descr="", reboot_on_update="no", policy_owner="local", enforce_vnic_name="yes", boot_mode="legacy") mo_1 = LsbootVirtualMedia(parent_mo_or_dn=mo, access="read-only", lun_id="0", mapping_name="", order="1") mo_2 = LsbootLan(parent_mo_or_dn=mo, prot="pxe", order="2") mo_2_1 = LsbootLanImagePath(parent_mo_or_dn=mo_2, prov_srv_policy_name="", img_sec_policy_name="", vnic_name="PXE", i_scsi_vnic_name="", boot_ip_policy_name="",