def hfp_create(handle, org_dn, name, blade_bundle_version="", rack_bundle_version="", ignore_comp_check="yes", update_trigger="immediate", mode="staged", stage_size="0", policy_owner="local", descr="testdescr"): """ Creates a HostFirmwarePack Policy Args: handle (UcsHandle) org_dn (string): the dn of the org in which policy is required name (string) : name of the policy blade_bundle_version (string): blade version rack_bundle_version (string): rack version ignore_comp_check (string): "yes", "no" update_trigger (string): "immediate" mode (string): "one-shot", "staged" stage_size (number): stage_size policy_owner (string): "local", "global". Default is local descr (string): description of the policy Returns: FirmwareComputeHostPack: Managed object Raises: ValueError: If OrgOrg does not exist Example: hfp_create(handle, name="sample_fp", rack_bundle_version="", blade_bundle_version="", org_dn="org-root") """ from ucsmsdk.mometa.firmware.FirmwareComputeHostPack import \ FirmwareComputeHostPack org = handle.query_dn(org_dn) if org is None: raise ValueError("Org '%s' does not exist" % org_dn) mo = FirmwareComputeHostPack(parent_mo_or_dn=org, name=name, blade_bundle_version=blade_bundle_version, rack_bundle_version=rack_bundle_version, ignore_comp_check=ignore_comp_check, update_trigger=update_trigger, mode=mode, stage_size=stage_size, policy_owner=policy_owner, descr=descr) handle.add_mo(mo, modify_present=True) handle.commit() return mo
def hfp_create(handle, name, blade_bundle_version, rack_bundle_version, mode="staged", descr="", parent_dn="org-root"): """ This method creates Host Firmware pack. Args: handle (UcsHandle) name (string): Name of the firmware pack. rack_bundle_version (string): Rack bundle version blade_bundle_version (string): Blade bundle version mode (string): "one-shot" or "staged" descr (string): Basic description. parent_dn (string): Parent of Org Returns: FirmwareComputeHostPack: Managed Object Raises: ValueError: If OrgOrg is not present Example: hfp_create(handle, name="sample_fp", rack_bundle_version="", blade_bundle_version="") """ from ucsmsdk.mometa.firmware.FirmwareComputeHostPack import\ FirmwareComputeHostPack org = handle.query_dn(parent_dn) if not org: raise ValueError("org '%s' does not exist" % parent_dn) mo = FirmwareComputeHostPack(parent_mo_or_dn=org.dn, name=name, blade_bundle_version=blade_bundle_version, rack_bundle_version=rack_bundle_version, mode=mode, descr=descr) handle.add_mo(mo, modify_present=True) handle.commit() return mo
def firmware_pack_create(handle, org_name, name, rack_bundle_version, blade_bundle_version, descr="", mode="staged", org_parent="org-root"): """ This method creates Host Firmware pack. Args: handle (UcsHandle) org_name (string): Name of the organization name (string): Name of the firmware pack. rack_bundle_version (string): Rack bundle version blade_bundle_version (string): Blade bundle version mode (string): "one-sot" or "staged" descr (string): Basic description. org_parent (string): Parent of Org Returns: None Example: firmware_pack_create(handle, org_name="sample_org", name="sample_fp", rack_bundle_version="", blade_bundle_version="") """ org_dn = org_parent + "/org-" + org_name p_mo = handle.query_dn(org_dn) if not p_mo: log.info("Sub-Org <%s> not found!" % org_name) else: from ucsmsdk.mometa.firmware.FirmwareComputeHostPack import\ FirmwareComputeHostPack mo = FirmwareComputeHostPack(parent_mo_or_dn=org_dn, name=name, descr=descr, rack_bundle_version=rack_bundle_version, mode=mode, blade_bundle_version=blade_bundle_version) handle.add_mo(mo) handle.commit()
def hfp_create(handle, name, blade_bundle_version, rack_bundle_version, mode="staged", descr="", parent_dn="org-root"): from ucsmsdk.mometa.firmware.FirmwareComputeHostPack import\ FirmwareComputeHostPack org = handle.query_dn(parent_dn) if not org: raise ValueError("org '%s' does not exist" % parent_dn) mo = FirmwareComputeHostPack(parent_mo_or_dn=org.dn, name=name, blade_bundle_version=blade_bundle_version, rack_bundle_version=rack_bundle_version, mode=mode, descr=descr) handle.add_mo(mo, modify_present=True) handle.commit() return mo
def main(): argument_spec = ucs_argument_spec argument_spec.update( name=dict(type='str', required=True), state=dict(type='str', default='present', choices=['present', 'absent']), descr=dict(type='str', required=False), blade_bundle_version=dict(type='str', required=False), rack_bundle_version=dict(type='str', required=False), exclude_server_components=dict(type='list', required=False), ) module = AnsibleModule(argument_spec, ) ucs = UCSModule(module) err = False print("********Inputs start********") print("name=", module.params['name']) print("state=", module.params['state']) print("descr=", module.params['descr']) print("blade_bundle_version=", module.params['blade_bundle_version']) print("rack_bundle_version=", module.params['rack_bundle_version']) print("exclude_server_components=", module.params['exclude_server_components']) print("********Inputs end********") # UCSModule creation above verifies ucsmsdk is present and exits on failure, so additional imports are done below. from ucsmsdk.mometa.firmware.FirmwareComputeHostPack import FirmwareComputeHostPack from ucsmsdk.mometa.firmware.FirmwareExcludeServerComponent import FirmwareExcludeServerComponent changed = False try: mo_exists = False props_match = False # dn is org-root/fw-host-pack-<name> #dn_base = 'org-root/fw-host-pack-' dn_base = 'org-root' dn = dn_base + '/fw-host-pack-' + 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: print("mo exists") # check top-level mo props kwargs = dict(name=module.params['name']) kwargs['descr'] = module.params['descr'] kwargs['blade_bundle_version'] = module.params[ 'blade_bundle_version'] kwargs['rack_bundle_version'] = module.params[ 'rack_bundle_version'] if (mo.check_prop_match(**kwargs)): props_match = True if not props_match: print("mo do not exists or props do not match") mo = FirmwareComputeHostPack( parent_mo_or_dn=dn_base, name=module.params['name'], descr=module.params['descr'], blade_bundle_version=module.params['blade_bundle_version'], rack_bundle_version=module.params['rack_bundle_version'], ) ucs.login_handle.add_mo(mo, True) ucs.login_handle.commit() changed = True if module.params['exclude_server_components'] is None: module.params['exclude_server_components'] = [] for server_comp in module.params['exclude_server_components']: print("server_comp=", server_comp) mo_exclude_component_exists = False print(dn + '/exclude-server-component-' + server_comp) mo_exclude_component = ucs.login_handle.query_dn( dn + '/exclude-server-component-' + server_comp) if mo_exclude_component: mo_exclude_component_exists = True print("mo_exclude_component_exists=", mo_exclude_component_exists) if not mo_exclude_component_exists: mo_exclude_component = FirmwareExcludeServerComponent( parent_mo_or_dn=dn, server_component=server_comp, ) ucs.login_handle.add_mo(mo_exclude_component, True) ucs.login_handle.commit() changed = True mo_list = ucs.login_handle.query_children( in_mo=mo, class_id="FirmwareExcludeServerComponent") for child in mo_list: #print(str(child)) #print(child.server_component) if child.server_component not in module.params[ 'exclude_server_components']: print(child.server_component, "to be removed") ucs.login_handle.remove_mo(child) ucs.login_handle.commit() print("props_match=", props_match) #print(str(mo)); 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 host_firmware_package(input): name = input['name'] descr = input['descr'] 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/fw-host-pack-" + name) except Exception as e: results[ 'error'] = "Could not query children of host firware package " + str( e) return results ###----if expected state is "present"------------------------ if state == "present": if mo: if (mo.name == name and mo.descr == descr): 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 = FirmwareComputeHostPack(parent_mo_or_dn="org-root", name=name, descr=descr) ucs_handle.add_mo(mo, True) ucs_handle.commit() results['name'] = name results['expected'] = False results['changed'] = True results['present'] = True #results['mo_bootpolicy'] = json.dumps(json.loads(jsonpickle.encode(mo))); except Exception as e: results[ 'error'] = "Modification of host firmware package mo failed " + str( e) return results ###----------if not, create boot policy with desired config ---------------- else: try: mo = FirmwareComputeHostPack(parent_mo_or_dn="org-root", name=name, descr=descr, override_default_exclusion="yes") mo_1 = FirmwareExcludeServerComponent( parent_mo_or_dn=mo, server_component="local-disk") ucs_handle.add_mo(mo) ucs_handle.commit() results['name'] = name results['present'] = False results['created'] = True results['changed'] = True except Exception as e: results[ 'error'] = "host firmware package creation failed " + str( e) return results ###------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: results[ 'error'] = "Removal of host firmware package mo failed" + str( e) return results else: results['name'] = name results['removed'] = False results['present'] = False ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return results