def query_instance(input): ip = input['ip'] username = input['username'] password = input['password'] exists = '' temp_dict_obj = {} ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_classid("fabricVlan") except: print("Could not query children of org-root") if mo: count = 0 for obj in mo: count = count + 1 temp_dict_obj['name'] = obj.name temp_dict_obj['sharing'] = obj.sharing temp_dict_obj['id'] = obj.id temp_dict_obj['mcast_policy_name'] = obj.mcast_policy_name temp_dict_obj['policy_owner'] = obj.policy_owner temp_dict_obj['default_net'] = obj.default_net temp_dict_obj['pub_nw_name'] = obj.pub_nw_name temp_dict_obj['compression_type'] = obj.compression_type try_list[count] = temp_dict_obj temp_dict_obj = {} else: exists = "" ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return try_list
def query_disk_group_mo(input): name = input['name'] ip = input['ip'] username = input['username'] password = input['password'] slot_numbers = input['slot_numbers'] raid_level = input['raid_level'] exists = '' ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: slot_numbers_exist = False current_slot_numbers = [] mo = ucs_handle.query_dn("org-root/disk-group-config-" + name) mo_block = ucs_handle.query_children( in_dn="org-root/disk-group-config-" + name, class_id="lstorageLocalDiskConfigRef") for obj in mo_block: current_slot_numbers.append(obj.slot_num) if (collections.Counter(slot_numbers) == collections.Counter( current_slot_numbers)): slot_numbers_exist = True if (raid_level == mo.raid_level and slot_numbers_exist): exists = True else: exists = False except: print("Could not query children of org-root") ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return exists
def query_diskgrouppolicyInstances(input): ip=input['ip'] username=input['username'] password=input['password'] exists='' temp_dict_obj={} temp_list=[] ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) try: mo = ucs_handle.query_classid("lstorageDiskGroupConfigPolicy") except: print("Could not query children of org-root") if mo: count=0 for obj in mo: mo_children=ucs_handle.query_children(in_dn="org-root/disk-group-config-"+obj.name,class_id="lstorageLocalDiskConfigRef") if(mo_children): for object in mo_children: temp_list.append(object.slot_num) count=count+1 temp_dict_obj['name']=obj.name temp_dict_obj['raid_level']=obj.raid_level temp_dict_obj['slot_numbers']=temp_list try_list[count]=temp_dict_obj temp_list=[] temp_dict_obj={} ucs_handle=pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return try_list
def query_mo(input): name=input['name'] type=input['type'] device_name=input['device_name'] ip=input['ip'] username=input['username'] password=input['password'] exists='' mo_children_exists=False ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) try: mo = ucs_handle.query_dn("org-root/boot-policy-"+name) if(type == "LAN"): mo_children =ucs_handle.query_children(in_dn="org-root/boot-policy-"+name+"/lan",hierarchy=True) for obj in mo_children: if(obj.vnic_name==device_name): mo_children_exists=True elif(type == "LocalLun"): mo_children = ucs_handle.query_children(in_dn="org-root/boot-policy-"+name+"/storage/local-storage/local-hdd",hierarchy=True) for obj in mo_children: if(obj.lun_name == device_name): mo_children_exists=True except Exception,e: print(Exception) print(e) print("Could not query children of org-root")
def query_uuid_poolInstances(input): ip=input['ip'] username=input['username'] password=input['password'] exists='' temp_dict_obj={} ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) try: mo = ucs_handle.query_classid("uuidpoolPool") except: print("Could not query children of org-root") if mo: count=0 for obj in mo: mo_children=ucs_handle.query_children(in_dn="org-root/uuid-pool-"+obj.name,class_id="uuidpoolBlock") if(mo_children): temp_dict_obj['to']=mo_children[0].to temp_dict_obj['r_from']=mo_children[0].r_from else: temp_dict_obj['to']="" temp_dict_obj['r_from']="" count=count+1 temp_dict_obj['name']=obj.name temp_dict_obj['descr']=obj.descr try_list[count]=temp_dict_obj temp_dict_obj={} else: exists="" ucs_handle=pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return try_list
def query_biospolicyInstances(input): ip = input['ip'] username = input['username'] password = input['password'] exists = '' temp_dict_obj = {} ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_classid("biosVProfile") except: results['error'] = "Could not query children of org-root" return results if mo: count = 0 for obj in mo: mo_children = ucs_handle.query_children( in_dn="org-root/bios-prof-" + obj.name, class_id="biosVfConsistentDeviceNameControl") count = count + 1 temp_dict_obj['consistent_device_naming'] = mo_children[ 0].vp_cdn_control temp_dict_obj['name'] = obj.name temp_dict_obj['descr'] = obj.descr try_list[count] = temp_dict_obj temp_dict_obj = {} else: exists = "" ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return try_list
def main(): json_input = json.loads(sys.argv[1]) ucs_handle = pickle.loads(str(ucs_login.main(json_input['ip'],json_input['username'],json_input['password']))) json_input['ucs_handle'] = ucs_handle resultsjson = sp_template_exists(json_input) resultsjson=json.dumps(resultsjson) ucs_handle=pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) print(resultsjson) return resultsjson
def ucs_logout(self): handle = pickle.loads(str(ucs_login.main())) results = {} try: handle.logout() #results['logged_out'] = True print("Logged out successfully") except: print("logout failed")
def query_storageprofileInstances(input): ip = input['ip'] username = input['username'] password = input['password'] exists = '' temp_dict_obj = {} ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_classid("lstorageProfile") except: print("Could not query children of org-root") if mo: count = 0 for obj in mo: count = count + 1 try_list['name'] = obj.name mo_children = ucs_handle.query_children( in_dn="org-root/profile-" + obj.name, class_id="lstorageDasScsiLun") if (mo_children): temp_list = [] local_lun_dict = {} for mo_children_object in mo_children: local_lun_dict['name'] = mo_children_object.name local_lun_dict['size'] = mo_children_object.size temp1 = str(mo_children_object.oper_local_disk_policy_name) if (temp1 != ""): mo_disk_group_policy = ucs_handle.query_dn(temp1) if (mo_disk_group_policy): local_lun_dict[ 'disk_group_configuration_name'] = mo_disk_group_policy.name else: local_lun_dict[ 'disk_group_configuration_name'] = "" else: local_lun_dict['disk_group_configuration_name'] = "" temp_list.append(local_lun_dict) local_lun_dict = {} try_list['local_lun_list'] = temp_list #print(try_list) else: try_list['local_lun_list'] = [] final_dict[count] = try_list ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return final_dict
def query_service_profile(input): name = input['name'] ip = input['ip'] username = input['username'] password = input['password'] exists = '' ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_dn("org-root/ls-" + name) except: print("Could not query children of org-root") if (mo): exists = "true" else: exists = "false" ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return exists
def query_hostfirmwarepackage(input): name = input['name'] ip = input['ip'] username = input['username'] password = input['password'] exists = '' ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_dn("org-root/fw-host-pack-" + name) except: print("Could not query children of org-root") if mo: exists = "true" else: exists = "false" ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return exists
def query_storage_profile_mo(input): name=input['name'] local_lun_list = input['local_lun_list'] ip=input['ip'] username=input['username'] password=input['password'] exists='' ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) try: mo_children_exists = False mo = ucs_handle.query_dn("org-root/profile-"+name) if(mo): if(local_lun_list <> None): temp_exists = True for object in local_lun_list: if(temp_exists == False): mo_children_exists = False break mo_children = ucs_handle.query_dn("org-root/profile-"+name+"/das-scsi-lun-"+object['name']) if(mo_children and object['size'] == mo_children.size): if(object['disk_group_configuration_name'] <> ""): mo_disk_group = ucs_handle.query_dn("org-root/disk-group-config-"+object['disk_group_configuration_name']) if(mo_disk_group): mo_children_exists = True else: temp_exists = False else: mo_children_exists = True else: temp_exists = False else: mo_children_exists = True else: exists = False except: print("Could not query children of org-root") if (mo and mo_children_exists): exists="true" else: exists="false" ucs_handle=pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return exists
def query_vnictemplateInstances(input): ip = input['ip'] username = input['username'] password = input['password'] exists = '' temp_dict_obj = {} ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_classid("vnicLanConnTempl") except: print("Could not query children of org-root") if mo: count = 0 for obj in mo: mo_children = ucs_handle.query_children( in_dn="org-root/lan-conn-templ-" + obj.name, class_id="vnicEtherIf") if (mo_children): temp_dict_obj['vlan_name'] = mo_children[0].name temp_dict_obj['default_net'] = mo_children[0].default_net else: temp_dict_obj['vlan_name'] = "" temp_dict_obj['default_net'] = "" count = count + 1 temp_dict_obj['name'] = obj.name temp_dict_obj['descr'] = obj.descr temp_dict_obj['switch_id'] = obj.switch_id temp_dict_obj['redundancy_pair_type'] = obj.redundancy_pair_type temp_dict_obj['templ_type'] = obj.templ_type temp_dict_obj['cdn_source'] = obj.cdn_source temp_dict_obj['admin_cdn_name'] = obj.admin_cdn_name temp_dict_obj['mtu'] = obj.mtu temp_dict_obj['ident_pool_name'] = obj.ident_pool_name try_list[count] = temp_dict_obj temp_dict_obj = {} else: exists = "" ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return try_list
def query_serverpoolInstances(input): ip = input['ip'] username = input['username'] password = input['password'] exists = '' temp_dict_obj = {} ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_classid("computePool") except: print("Could not query children of org-root") if mo: count = 0 for obj in mo: mo_children = ucs_handle.query_children( in_dn="org-root/compute-pool-" + obj.name, class_id="computePooledSlot") temp_list = [] temp_dict = {} if (mo_children): for object in mo_children: temp_dict['slot_id'] = object.slot_id temp_dict['chassis_id'] = object.chassis_id temp_list.append(temp_dict) temp_dict = {} else: temp_dict['slot_id'] = "" temp_dict['chassis_id'] = "" temp_list.append(temp_dict) temp_dict = {} count = count + 1 temp_dict_obj['name'] = obj.name temp_dict_obj['descr'] = obj.descr temp_dict_obj['pooled_servers'] = temp_list try_list[count] = temp_dict_obj temp_dict_obj = {} else: exists = "" ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return try_list
def query_serviceprofileInstances(input): ip=input['ip'] username=input['username'] password=input['password'] exists='' temp_dict_obj={} ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) try: mo = ucs_handle.query_classid("lsServer") except: print("Could not query children of org-root") if mo: count=0 for obj in mo: count = count+1 if (obj.type == 'instance'): try_list['instance'] = obj.name final_dict[count] = try_list ucs_handle=pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return final_dict
def query_instance(input): ip=input['ip'] username=input['username'] password=input['password'] exists='' temp_dict_obj={} ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) try: mo = ucs_handle.query_classid("firmwareComputeHostPack") except: print("Could not query children of org-root") if mo: count=0 for obj in mo: count=count+1 temp_dict_obj['name']=obj.name temp_dict_obj['descr']=obj.descr try_list[count]=temp_dict_obj temp_dict_obj={} else: exists="" ucs_handle=pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return try_list
def query_server_pool_mo(input): name=input['name'] ip=input['ip'] username=input['username'] password=input['password'] pooled_servers=input['pooled_servers'] exists='' ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) try: mo = ucs_handle.query_dn("org-root/compute-pool-"+name) if(mo and len(pooled_servers) <> 0): pooled_server_exists = True for obj in pooled_servers: mo_block=ucs_handle.query_dn("org-root/compute-pool-"+name+"/blade-"+obj['chassis_id']+"-"+obj['slot_id']) pooled_server_exists = (pooled_server_exists and mo_block) except Exception as e : print("Could not query children of org-root" + str (e)) if (mo and pooled_server_exists): exists="true" else: exists="false" ucs_handle=pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return exists
def query_macmo(input): name=input['name'] ip=input['ip'] username=input['username'] password=input['password'] r_from=input['r_from'] to=input['to'] exists='' ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) try: mo = ucs_handle.query_dn("org-root/mac-pool-"+name) if(to <> "" or r_from <> ""): mo_block=ucs_handle.query_dn("org-root/mac-pool-"+name+"/block-"+r_from+"-"+to) else: mo_block=True except: print("Could not query children of org-root") if (mo and mo_block): exists="true" else: exists="false" ucs_handle=pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return exists
def query_vnictemplate(input): name = input['name'] ip = input['ip'] username = input['username'] password = input['password'] vlan_name = input['vlan_name'] exists = '' ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_dn("org-root/lan-conn-templ-" + name) if (vlan_name <> ""): mo_block = ucs_handle.query_dn("org-root/lan-conn-templ-" + name + "/if-" + vlan_name) else: mo_block = True except: print("Could not query children of org-root") if (mo and mo_block): exists = "true" else: exists = "false" ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return exists
def query_mo(input): name = input['name'] ip = input['ip'] username = input['username'] password = input['password'] temp_dict_obj = {} ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_dn("org-root/boot-policy-" + name) except: print("Could not query children of org-root") if mo: temp_dict_obj['name'] = mo.name temp_dict_obj['descr'] = mo.descr temp_dict_obj['reboot_on_update'] = mo.reboot_on_update temp_dict_obj['policy_owner'] = mo.policy_owner temp_dict_obj['enforce_vnic_name'] = mo.enforce_vnic_name temp_dict_obj['boot_mode'] = mo.boot_mode return temp_dict_obj else: print("No boot policy object with the name " + name) ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return temp_dict_obj
def query_instance(input): ip = input['ip'] username = input['username'] password = input['password'] type = input['type'] exists = '' temp_dict_obj = {} ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_classid("lsbootPolicy") except: print("Could not query children of org-root") if mo: count = 0 for obj in mo: te = "org-root/boot-policy-" + obj.name if (type == "LocalLun"): te = '"' + te + '"' filter_string = str('(dn,' + te + ')') filter_string = str(filter_string) my = ucs_handle.query_classid( filter_str=filter_string, hierarchy=True, class_id="lsbootLocalLunImagePath") if (len(my) > 0): temp_mo_obj = ucs_handle.query_classid( filter_str=filter_string, class_id="lsbootLocalHddImage") order = temp_mo_obj[0].order for obj1 in my: temp_dict_obj['name'] = obj.name temp_dict_obj['order'] = order temp_dict_obj['device_name'] = obj1.lun_name temp_dict_obj['type'] = type try_list[count] = temp_dict_obj temp_dict_obj = {} count = count + 1 else: temp_dict_obj['name'] = obj.name temp_dict_obj['order'] = "" temp_dict_obj['device_name'] = "" temp_dict_obj['type'] = type try_list[count] = temp_dict_obj temp_dict_obj = {} count = count + 1 elif (type == "LAN"): te = '"' + te + '"' filter_string = str('(dn,' + te + ')') filter_string = str(filter_string) my = ucs_handle.query_classid(filter_str=filter_string, hierarchy=True, class_id="lsbootLanImagePath") if (len(my) > 0): temp_mo_obj = ucs_handle.query_classid( filter_str=filter_string, class_id="lsbootLan") order = temp_mo_obj[0].order for obj1 in my: temp_dict_obj['name'] = obj.name temp_dict_obj['order'] = order temp_dict_obj['device_name'] = obj1.vnic_name temp_dict_obj['type'] = type try_list[count] = temp_dict_obj temp_dict_obj = {} count = count + 1 else: temp_dict_obj['name'] = obj.name temp_dict_obj['order'] = "" temp_dict_obj['device_name'] = "" temp_dict_obj['type'] = type try_list[count] = temp_dict_obj temp_dict_obj = {} count = count + 1 else: temp_dict_obj['name'] = obj.name temp_dict_obj['order'] = "" temp_dict_obj['device_name'] = "" temp_dict_obj['type'] = "" try_list[count] = temp_dict_obj temp_dict_obj = {} count = count + 1 else: exists = "" ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return try_list
def query_service_profile_template(input): name = input['name'] ip = input['ip'] username = input['username'] password = input['password'] exists = '' ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) try: mo = ucs_handle.query_dn("org-root/ls-" + name) except: print("Could not query children of org-root") if (mo): if (input['storage_profile_name'] <> ""): mo_storage_profile = ucs_handle.query_children( in_dn="org-root/ls-" + input['name'], class_id="lstorageProfileBinding") if (len(mo_storage_profile) <> 0): mo_storage_prof_name_preset = mo_storage_profile[ 0].storage_profile_name else: mo_storage_prof_name_preset = None else: mo_storage_prof_name_preset = None if (input['maint_policy_name'] <> ""): mo_maint_policy_name = "org-root/maint-" + input[ 'maint_policy_name'] else: mo_boot_policy = None if (input['server_pool_name'] <> ""): mo_server_pool_name = ucs_handle.query_children( in_dn="org-root/ls-" + input['name'], class_id="lsRequirement") if (len(mo_server_pool_name) <> 0): mo_server_pool_name_preset = mo_server_pool_name[0].name else: mo_server_pool_name_preset = None else: mo_server_pool_name_preset = None mo_vnic_ether = ucs_handle.query_children(in_dn="org-root/ls-" + input['name'], class_id="vnicEther") vnic_profile_exists = '' if (input['vnic_name'] <> "" and input['vnic_template_name'] <> "" and input['vnic_order'] <> ""): for obj in mo_vnic_ether: if (obj.name == input['vnic_name'] and obj.adaptor_profile_name == input['adapter_profile_name'] and obj.nw_templ_name == input['vnic_template_name'] and obj.order == input['vnic_order']): vnic_profile_exists = True else: vnic_profile_exists = False else: vnic_profile_exists = True if (mo.ident_pool_name == input['ident_pool_name'] and mo.local_disk_policy_name == input['local_disk_policy_name'] and mo.boot_policy_name == input['boot_policy_name'] and mo.bios_profile_name == input['bios_profile_name'] and mo.oper_maint_policy_name == mo_maint_policy_name and mo.host_fw_policy_name == input['host_fw_policy_name'] and mo_storage_prof_name_preset == input['storage_profile_name'] and mo_server_pool_name_preset == input['server_pool_name'] and mo.ext_ip_pool_name == input['mgmt_ip_address'] and vnic_profile_exists): exists = "true" else: exists = "false" else: exists = "false" ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return exists
def boot_lan_vnic(input): ip=input['ip'] username=input['username'] password=input['password'] vnic_name = input['vnic_name'] name = input['name'] #mo_bootlan = module.params.get('mo_bootlan') state = input['state'] type_string = "type" results = {} ucs_handle = pickle.loads(str(ucs_login.main(ip,username,password))) #mo_bootlan_parsed = jsonpickle.decode(mo_bootlan) ###-------CHECK IF MO EXISTS------------------------------------------------ try: mo = ucs_handle.query_children(in_dn="org-root/boot-policy-"+name+"/lan", class_id="LsbootLanImagePath") except: print "Could not query children of org-root" ###-------------check if obj is empty or non-empty ------------------------ obj_exists = lambda obj: True if obj != [] else False ###-------if expected state is "present"---------------------------------- if state == "present": if mo: if (len(mo) == 1): if (mo[0].vnic_name == vnic_name): results['expected'] = True; results['present'] = True; results['changed'] = False; else: try: mo_lan = LsbootLanImagePath(parent_mo_or_dn="org-root/boot-policy-"+name+"/lan", prov_srv_policy_name="", img_sec_policy_name="", vnic_name=vnic_name, i_scsi_vnic_name="", boot_ip_policy_name="", img_policy_name="", type="secondary") ucs_handle.add_mo(mo_lan) ucs_handle.commit() results['expected'] = True; results['present'] = True; results['changed'] = False; except: print "Modify boot policy mo 1 failed" if (len(mo) == 2): if (mo[0].vnic_name == vnic_name or mo[1].vnic_name == vnic_name): results['expected'] = True; results['present'] = True; results['changed'] = False; else: results['expected'] = False; results['present'] = False; results['changed'] = False; ###----------------else create boot policy with desired config ---------------- else: try: obj = ucs_handle.query_dn("org-root/boot-policy-"+name) if (obj): mo = LsbootLanImagePath(parent_mo_or_dn="org-root/boot-policy-"+name+"/lan", prov_srv_policy_name="", img_sec_policy_name="", vnic_name=vnic_name, i_scsi_vnic_name="", boot_ip_policy_name="", img_policy_name="", type="primary") ucs_handle.add_mo(mo) ucs_handle.commit() results['present'] = True; results['changed'] = True; else: results['present'] = False; results['changed'] = False; except: print "Modify boot lan image mo failed" ###-------if expected state is "absent"--------------------------------------- if state == "absent": if mo: if (len(mo) == 1): if (mo[0].vnic_name == vnic_name): try: mo_primary = ucs_handle.query_dn("org-root/boot-policy-"+name+"/lan/path-primary") ucs_handle.remove_mo(mo_primary) results['present'] = False; results['removed'] = True; ucs_handle.commit() except: print "Remove boot lan image mo failed" if (len(mo) == 2): if (mo[0].vnic_name == vnic_name and mo[0].type == "secondary"): try: mo_2 = ucs_handle.query_dn("org-root/boot-policy-"+name+"/lan/path-secondary") ucs_handle.remove_mo(mo_2) ucs_handle.commit() except: print "Remove boot lan image secondary failed" if (mo[0].vnic_name == vnic_name and mo[0].type == "primary"): try: mo_parent = ucs_handle.query_dn("org-root/boot-policy-"+name+"/lan") mo_modify = LsbootLanImagePath(parent_mo_or_dn=mo_parent, prov_srv_policy_name="", img_sec_policy_name="", vnic_name=mo[1].vnic_name, i_scsi_vnic_name="", boot_ip_policy_name="", img_policy_name="", type="primary") mo_parent = ucs_handle.query_dn("org-root/boot-policy-"+name+"/lan") mo_2 = ucs_handle.query_dn("org-root/boot-policy-"+name+"/lan/path-secondary") ucs_handle.remove_mo(mo_2) ucs_handle.add_mo(mo_parent, True) ucs_handle.commit() results['present'] = False; results['removed'] = True; except: print "Remove boot lan mo for primary failed" if (mo[1].vnic_name == vnic_name and mo[1].type == "secondary"): try: mo_secondary = ucs_handle.query_dn("org-root/boot-policy-"+name+"/lan/path-secondary") ucs_handle.remove_mo(mo_secondary) ucs_handle.commit() results['present'] = False; results['removed'] = True; except: print "Remove boot lan image mo for secondary failed" if (mo[1].vnic_name == vnic_name and mo[1].type == "primary"): try: mo_1 = ucs_handle.query_dn("org-root/boot-policy-"+name+"/lan/path-secondary") mo_parent = ucs_handle.query_dn("org-root/boot-policy-"+name+"/lan") mo_modify = LsbootLanImagePath(parent_mo_or_dn=mo_parent, prov_srv_policy_name="", img_sec_policy_name="", vnic_name=mo[0].vnic_name, i_scsi_vnic_name="", boot_ip_policy_name="", img_policy_name="", type="primary") ucs_handle.remove_mo(mo_1) ucs_handle.add_mo(mo_modify,True) results['present'] = False; results['removed'] = True; ucs_handle.commit() except: print "Remove boot lan image mo for primary failed" else: results['removed'] = False; results['present'] = False; return results
def disk_group_policy(input): name = input['name'] raid_level = input['raid_level'] slot_numbers = input['slot_numbers'] 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/disk-group-config-" + name) mo_block = ucs_handle.query_children( in_dn="org-root/disk-group-config-" + name, class_id="lstorageLocalDiskConfigRef") except: print("Could not query children of disk group policy") ###----if expected state is "present"------------------------ if state == "present": if mo: slot_numbers_exist = False current_slot_numbers = [] for obj in mo_block: current_slot_numbers.append(obj.slot_num) if (collections.Counter(slot_numbers) == collections.Counter( current_slot_numbers)): slot_numbers_exist = True if (mo.raid_level == raid_level and slot_numbers_exist): results['name'] = name results['expected'] = True results['changed'] = False results['present'] = True else: for slot_num in slot_numbers: query_slot = ucs_handle.query_dn( "org-root/disk-group-config-" + name + "/slot-" + slot_num) if (query_slot == None): mo_2 = LstorageLocalDiskConfigRef(parent_mo_or_dn=mo, slot_num=slot_num) ucs_handle.add_mo(mo, True) ucs_handle.commit() mo = LstorageDiskGroupConfigPolicy(parent_mo_or_dn="org-root", raid_level=raid_level, name=name) ucs_handle.add_mo(mo, True) ucs_handle.commit() results['name'] = name results['expected'] = True results['changed'] = True results['present'] = True ###----------if not, create boot policy with desired config ---------------- else: try: mo = LstorageDiskGroupConfigPolicy(parent_mo_or_dn="org-root", raid_level=raid_level, name=name) mo_1 = LstorageVirtualDriveDef( parent_mo_or_dn=mo, read_policy="platform-default", drive_cache="platform-default", strip_size="platform-default", io_policy="platform-default", write_cache_policy="platform-default", access_policy="platform-default") if (len(slot_numbers) > 0): for slot_num in slot_numbers: mo_2 = LstorageLocalDiskConfigRef(parent_mo_or_dn=mo, slot_num=slot_num) ucs_handle.add_mo(mo) ucs_handle.commit() results['name'] = name results['present'] = False results['created'] = True results['changed'] = True except Exception as e: print("disk group configuration policy creation failed " + str(e)) ###------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("Removal Mac-pool 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
def bios_policy(input): name = input['name'] descr = input['descr'] consistent_device_naming = input['consistent_device_naming'] 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/bios-prof-" + name) mo_block = ucs_handle.query_dn("org-root/bios-prof-" + name + "/Consistent-Device-Name-Control") except: results['error'] = "Could not query children of bios_policy" return results ###----if expected state is "present"------------------------ if state == "present": if mo: if (mo.name == name and mo.descr == descr and mo_block.vp_cdn_control == consistent_device_naming): results['name'] = name results['expected'] = True results['changed'] = False results['present'] = True else: try: mo = BiosVProfile(parent_mo_or_dn="org-root", name=name, descr=descr) modified_mo = BiosVfConsistentDeviceNameControl( parent_mo_or_dn=mo, vp_cdn_control=consistent_device_naming) results['name'] = name results['expected'] = False results['changed'] = True results['present'] = True ucs_handle.add_mo(mo, True) ucs_handle.commit() #results['mo_bootpolicy'] = json.dumps(json.loads(jsonpickle.encode(mo))); except Exception as e: results[ 'error'] = "Modification of bios policy mo failed" + str( e) return results ###----------if not, create boot policy with desired config ---------------- else: try: mo = BiosVProfile(parent_mo_or_dn="org-root", name=name, descr=descr) mo_1 = BiosVfQuietBoot(parent_mo_or_dn=mo, vp_quiet_boot="platform-default") mo_2 = BiosVfPOSTErrorPause( parent_mo_or_dn=mo, vp_post_error_pause="platform-default") mo_3 = BiosVfResumeOnACPowerLoss( parent_mo_or_dn=mo, vp_resume_on_ac_power_loss="platform-default") mo_4 = BiosVfFrontPanelLockout( parent_mo_or_dn=mo, vp_front_panel_lockout="platform-default") mo_5 = BiosVfConsistentDeviceNameControl( parent_mo_or_dn=mo, vp_cdn_control=consistent_device_naming) mo_6 = BiosVfIntelTurboBoostTech( parent_mo_or_dn=mo, vp_intel_turbo_boost_tech="platform-default") mo_7 = BiosVfEnhancedIntelSpeedStepTech( parent_mo_or_dn=mo, vp_enhanced_intel_speed_step_tech="platform-default") mo_8 = BiosVfIntelHyperThreadingTech( parent_mo_or_dn=mo, vp_intel_hyper_threading_tech="platform-default") mo_9 = BiosVfCoreMultiProcessing( parent_mo_or_dn=mo, vp_core_multi_processing="platform-default") mo_10 = BiosVfExecuteDisableBit( parent_mo_or_dn=mo, vp_execute_disable_bit="platform-default") mo_11 = BiosVfIntelVirtualizationTechnology( parent_mo_or_dn=mo, vp_intel_virtualization_technology="platform-default") mo_12 = BiosVfProcessorPrefetchConfig( parent_mo_or_dn=mo, vp_dcuip_prefetcher="platform-default", vp_adjacent_cache_line_prefetcher="platform-default", vp_hardware_prefetcher="platform-default", vp_dcu_streamer_prefetch="platform-default") mo_13 = BiosVfDirectCacheAccess( parent_mo_or_dn=mo, vp_direct_cache_access="platform-default") mo_14 = BiosVfProcessorCState( parent_mo_or_dn=mo, vp_processor_c_state="platform-default") mo_15 = BiosVfProcessorC1E( parent_mo_or_dn=mo, vp_processor_c1_e="platform-default") mo_16 = BiosVfProcessorC3Report( parent_mo_or_dn=mo, vp_processor_c3_report="platform-default") mo_17 = BiosVfProcessorC6Report( parent_mo_or_dn=mo, vp_processor_c6_report="platform-default") mo_18 = BiosVfProcessorC7Report( parent_mo_or_dn=mo, vp_processor_c7_report="platform-default") mo_19 = BiosVfProcessorCMCI( parent_mo_or_dn=mo, vp_processor_cmci="platform-default") mo_20 = BiosVfCPUPerformance( parent_mo_or_dn=mo, vp_cpu_performance="platform-default") mo_21 = BiosVfMaxVariableMTRRSetting( parent_mo_or_dn=mo, vp_processor_mtrr="platform-default") mo_22 = BiosVfLocalX2Apic(parent_mo_or_dn=mo, vp_local_x2_apic="platform-default") mo_23 = BiosVfProcessorEnergyConfiguration( parent_mo_or_dn=mo, vp_power_technology="platform-default", vp_energy_performance="platform-default") mo_24 = BiosVfFrequencyFloorOverride( parent_mo_or_dn=mo, vp_frequency_floor_override="platform-default") mo_25 = BiosVfPSTATECoordination( parent_mo_or_dn=mo, vp_pstate_coordination="platform-default") mo_26 = BiosVfDRAMClockThrottling( parent_mo_or_dn=mo, vp_dram_clock_throttling="platform-default") mo_27 = BiosVfInterleaveConfiguration( parent_mo_or_dn=mo, vp_channel_interleaving="platform-default", vp_rank_interleaving="platform-default", vp_memory_interleaving="platform-default") mo_28 = BiosVfScrubPolicies(parent_mo_or_dn=mo, vp_patrol_scrub="platform-default", vp_demand_scrub="platform-default") mo_29 = BiosVfAltitude(parent_mo_or_dn=mo, vp_altitude="platform-default") mo_30 = BiosVfPackageCStateLimit( parent_mo_or_dn=mo, vp_package_c_state_limit="platform-default") mo_31 = BiosVfCPUHardwarePowerManagement( parent_mo_or_dn=mo, vp_cpu_hardware_power_management="platform-default") mo_32 = BiosVfEnergyPerformanceTuning( parent_mo_or_dn=mo, vp_pwr_perf_tuning="platform-default") mo_33 = BiosVfWorkloadConfiguration( parent_mo_or_dn=mo, vp_workload_configuration="platform-default") ucs_handle.add_mo(mo) ucs_handle.commit() results['name'] = name results['present'] = False results['created'] = True results['changed'] = True #results['mo_bootpolicy'] = json.dumps(json.loads(jsonpickle.encode(mo))); except Exception as e: results['error'] = "Bios Policy 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 Exception as e: results['error'] = "Remove of bios policy 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
def vnic_template(input): name = input['name'] descr=input['descr'] switch_id=input['switch_id'] redundancy_pair_type="none" templ_type= input['templ_type'] vlan_name=input['vlan_name'] default_net=input['default_net'] cdn_source=input['cdn_source'] admin_cdn_name=input['admin_cdn_name'] mtu=input['mtu'] ident_pool_name= input['ident_pool_name'] 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/lan-conn-templ-"+name) mo_block=ucs_handle.query_dn("org-root/lan-conn-templ-"+name+"/if-"+vlan_name) mo_children=ucs_handle.query_children(in_dn="org-root/lan-conn-templ-"+name,class_id="vnicEtherIf") except: print("Could not query children of macpool") ###----if expected state is "present"------------------------ if state == "present": block_temp=False if(mo_block and mo_block.name ==vlan_name and mo_block.default_net ==default_net): block_temp=True elif (vlan_name == "" and not(mo_children)): block_temp=True elif (mo_children): block_temp=False else: block_temp=False if (mo): if ( mo.name == name and mo.descr == descr and mo.switch_id ==switch_id and mo.redundancy_pair_type == redundancy_pair_type and mo.templ_type ==templ_type and mo.cdn_source == cdn_source and mo.admin_cdn_name == admin_cdn_name and mo.mtu ==mtu and mo.ident_pool_name == ident_pool_name and block_temp): results['name']=name; results['expected'] = True; results['changed'] = False; results['present'] = True; else: try: modified_mo = VnicLanConnTempl(parent_mo_or_dn="org-root", name=name, descr=descr ,switch_id =switch_id , redundancy_pair_type = redundancy_pair_type ,templ_type = templ_type , cdn_source = cdn_source , admin_cdn_name = admin_cdn_name , mtu =mtu ,ident_pool_name = ident_pool_name ) if(vlan_name): mo_1= VnicEtherIf(parent_mo_or_dn=modified_mo,default_net=default_net, name=vlan_name) ucs_handle.add_mo(modified_mo,True) ucs_handle.commit() results['name']=name; results['present'] = True; results['removed'] = False; results['changed'] = True except Exception,e: print(e) ###----------if not, create boot policy with desired config ---------------- else: try: mo = VnicLanConnTempl(parent_mo_or_dn="org-root", name=name, descr=descr ,switch_id =switch_id , redundancy_pair_type = redundancy_pair_type ,templ_type = templ_type , cdn_source = cdn_source , admin_cdn_name = admin_cdn_name , mtu=mtu ,ident_pool_name = ident_pool_name ) if(vlan_name): mo_1= VnicEtherIf(parent_mo_or_dn=mo,default_net=default_net, name=vlan_name) ucs_handle.add_mo(mo) ucs_handle.commit() results['name']=name; results['present'] = False; results['created'] = True; results['changed'] = True; except: results['error'] = "Vnic template creation failed" return results
def storage_profile(input): name = input['name'] local_lun_list = input['local_lun_list'] state = input['state'] ip = input['ip'] username = input['username'] password = input['password'] mo = "" mo_block = "" ucs_handle = pickle.loads(str(ucs_login.main(ip, username, password))) ###-------CHECK IF MO EXISTS--------------------------------- try: mo = ucs_handle.query_dn("org-root/profile-" + name) except Exception as e: results['error'] = "Could not query storage profile mo " + str(e) ###----if expected state is "present"------------------------ if state == "present": if (mo): current_conf_dict = {} current_conf_dict['name'] = mo.name try: mo_children = ucs_handle.query_children( in_dn="org-root/profile-" + mo.name, class_id="lstorageDasScsiLun") except: results[ 'error'] = "Could not query children of storage profile mo " + str( e) if (mo_children): temp_list = [] for object in mo_children: temp_dict = {} temp_dict['name'] = object.name temp_dict['size'] = object.size if (object.oper_local_disk_policy_name <> ""): local_disk_policy_name = object.oper_local_disk_policy_name.replace( 'org-root/disk-group-config-', '') else: local_disk_policy_name = "" temp_dict[ 'disk_group_configuration_name'] = local_disk_policy_name temp_list.append(temp_dict) current_conf_dict['local_lun_list'] = temp_list else: current_conf_dict['local_lun_list'] = "" if (len(local_lun_list) <> 0): current_local_lun_config_list = current_conf_dict[ 'local_lun_list'] local_lun_exists = True for object in local_lun_list: if (contains(current_local_lun_config_list, object['name'], object['disk_group_configuration_name'], object['size'])): temp_exists = True local_lun_exists = (local_lun_exists and temp_exists) else: local_lun_exists = False local_lun_modify(ucs_handle, mo, object) if (local_lun_exists): results['name'] = name results['present'] = True results['removed'] = False results['changed'] = False else: results['name'] = name results['present'] = True results['removed'] = False results['changed'] = True else: results['name'] = name results['present'] = True results['removed'] = False results['changed'] = False ###----------if not, create boot policy with desired config ---------------- else: try: parent_mo = LstorageProfile(parent_mo_or_dn="org-root", name=name) if (len(local_lun_list) <> 0): for object in local_lun_list: mo_1 = LstorageDasScsiLun( parent_mo_or_dn=parent_mo, local_disk_policy_name=object[ 'disk_group_configuration_name'], name=object['name'], size=object['size']) ucs_handle.add_mo(parent_mo) ucs_handle.commit() results['name'] = name results['present'] = False results['created'] = True results['changed'] = True except Exception as e: results['error'] = "storage profile creation failed " + str(e) return results ###------if expected state is "absent"---------------------------- if state == "absent": if mo: try: ucs_handle.remove_mo(mo) ucs_handle.commit() results['name'] = name results['present'] = False results['removed'] = True except Exception as e: results[ 'error'] = "Removal of storage profile mo failed " + str(e) else: results['name'] = name results['removed'] = False results['present'] = False ucs_handle = pickle.dumps(ucs_handle) ucs_logout.main(ucs_handle) return results
def vlan(input): name = input['name'] sharing = "none" id = input['id'] mcast_policy_name = "" policy_owner = "local" default_net = input['default_net'] pub_nw_name = "" compression_type = "included" 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("fabric/lan/net-" + name) except: print("Could not query children of vlan") ###----if expected state is "present"------------------------ if state == "present": if mo: if (mo.name == name and mo.sharing == sharing and mo.id == id and mo.mcast_policy_name == mcast_policy_name and mo.policy_owner == policy_owner and mo.default_net == default_net and mo.pub_nw_name == pub_nw_name and mo.compression_type == compression_type): 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.sharing = sharing mo.id = id mo.mcast_policy_name = mcast_policy_name mo.policy_owner = policy_owner mo.default_net = default_net mo.pub_nw_name = pub_nw_name mo.compression_type = compression_type 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="Modification of vlan mo failed") ###----------if not, create boot policy with desired config ---------------- else: try: mo = FabricVlan(parent_mo_or_dn="fabric/lan", name=name, sharing=sharing, id=id, mcast_policy_name=mcast_policy_name, policy_owner=policy_owner, default_net=default_net, pub_nw_name=pub_nw_name, compression_type=compression_type) 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("Vlan 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 Vlan 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
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
def uuid_pool(input): name = input['name'] descr=input['descr'] to=input['to'] r_from=input['r_from'] 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/uuid-pool-"+name) mo_block=ucs_handle.query_dn("org-root/uuid-pool-"+name+"/block-from-"+r_from+"-to-"+to) except: print("Could not query children of uuid suffix pool") ###----if expected state is "present"------------------------ if state == "present": if mo: if ( mo.descr == descr ): if(to <> "" and r_from <> ""): if(mo_block): results['name']=name; results['expected'] = True; results['changed'] = False; results['present'] = True; else: mo_1= UuidpoolBlock(parent_mo_or_dn=mo, to=to, r_from=r_from) ucs_handle.add_mo(mo,True) ucs_handle.commit() results['name']=name; results['present'] = True; results['removed'] = False; results['changed'] = True else: results['name']=name; results['expected'] = True; results['changed'] = False; results['present'] = True; else: try: modified_mo = UuidpoolPool(parent_mo_or_dn="org-root", name=name, descr=descr) if(to <> "" and r_from <> ""): mo_1= UuidpoolBlock(parent_mo_or_dn=modified_mo, to=to, r_from=r_from) ucs_handle.add_mo(modified_mo,True) ucs_handle.commit() results['name']=name; results['present'] = True; results['removed'] = False; results['changed'] = True except Exception,e: print(e) ###----------if not, create boot policy with desired config ---------------- else: try: mo = UuidpoolPool(parent_mo_or_dn="org-root", name=name, descr=descr) if(to <> "" and r_from <> ""): mo_1= UuidpoolBlock(parent_mo_or_dn=mo, to=to, r_from=r_from) ucs_handle.add_mo(mo) ucs_handle.commit() results['name']=name; results['present'] = False; results['created'] = True; results['changed'] = True; except: print("uuid suffix pool creation failed")