def set_ebipa_for_interconnect(self, start_server_address, subnetmask): """ Description : This function sets an IP address for the four interconnect bays Params : start_server_address --> starting address of interconnect bays subnetmask --> subnet mask Usage : set_ebipa_interconnect() Return : return a message if there is no excpetion else return false """ try: output1 = False output2 = False output1 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "set ebipa interconnect %s %s 1-4" % (start_server_address, subnetmask), "Successfully set interconnect bay # 1 to IP address") output2 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "SAVE EBIPA", "EBIPA configuration was saved.") if output1 and output2: log._info( "EBIPA Interconnect Address set for all the interconnects") else: log._error( "EBIPA Interconnect Address not set for all the interconnects" ) except: raise Exception("Failed to set EBIPA Interconnect Address")
def configure_users(self, user_name, password): obj = telnetlib.Telnet(self.switch_ip) obj.read_until("login: "******"\n") obj.read_until("Password: "******"\n") obj.write("sys \n") obj.write("local-user %s" % user_name) time.sleep(5) obj.write("authorization-attribute user-role network-admin") obj.write("password simple %s" % password) obj.write("service-type telnet") ''' obj.write("save \n") obj.read_until("Are you sure? [Y/N]:") obj.write("Y \n") obj.read_until("press the enter key):") obj.write("\n") obj.read_until("overwrite? [Y/N]:") obj.write("Y \n") ''' obj.write("quit \n") obj.write("quit \n") obj.write("quit \n") ret = obj.read_all() log._info(ret)
def set_boot_order(self, bootorder_list): """ order: list which contains the following possibilities in a given order: cd, floppy, usb, disk, network """ boot_dict = self._get_bootsources() available_sources_list = delete_repeats( [boot_dict[key] for key in boot_dict]) for source in bootorder_list: source = source.strip().lower() if source == 'usb': source = 'usbkey' if source not in available_sources_list: log._warn( "Option '%s' in Bootorder list does not exist within iLO! Bootorder not set" % (source)) return False source_num = 1 for source in bootorder_list: source = source.lower() if source == 'usb': source = 'usbkey' for key, value in boot_dict.iteritems(): if source == value: temp_key = key output = ha_library.execute_Remote_commands_iLO_and_return_output( self.mgt_ip, self.mgt_username, self.mgt_pw, "set system1/bootconfig1/bootsource%s bootorder=%s" % (temp_key, source_num)) log._info("Set Bootsource%s ('%s') to priority %d" % (temp_key, source, source_num)) source_num += 1 log._info("Successfully set boot order to %s" % (''.join(bootorder_list))) return self._get_bootsources()
def create_vlun(self, hostname, lun, vv_name): """ Exports a virtual volume as a SCSI LUN Parameters: lun -> LUN number as string from 0 to 16383 or 'auto' hostname -> Specifies the host where the LUN is exported, up to 31 characters vv_name -> Specifies virtual volume name (virtual disk name) """ if is_int(lun): log._info("Creating Vlun : %s" % (hostname + "\\" + lun)) output = execute_local_command( SELECT_MANAGER % (self.mgt_ip, self.mgt_username, self.mgt_pw) + SELECT_SYSTEM % (self.system) + "add lun %s host=\"%s\" storage=\"%s\" " % (lun, hostname, vv_name) + EXIT) if output: log._info("Vlun : %s got created successfully" % (hostname + "\\" + lun)) return output else: log._warn("Failed to execute createvlun command") return False else: return False
def reset_ilo(self, ilo_bay_number, force="false"): """ Description : This function will reset ilo present in a bay. It will reset based on the force parameter Params : ilo_bay_number--> Bay number of server which should be resetted force --> a boolean parameter based on which ilo will be reset. By default this parameter will be false. Return : Returns a message if command is executed else returns false """ try: output1 = False output2 = False if force == "false": output1 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "reset iLO %s" % (ilo_bay_number), "Successfully reset iLO through IPMI") else: output2 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "reset iLO %s force" % (ilo_bay_number), "Successfully reset iLO through IPMI") log._debug(output2) if output1 or output2: log._info("ILO is successfully reset") else: log._error("ILO is not successfully reset") except: raise Exception("Failed to reset iLO")
def create_virtual_volume(self, name, size, user_cpg, thin=False): """ Parameters: name -> Name of virtual volume, up to 31 characters size -> Size of the volume in GB, must be integer. user_cpg -> Name of common provisioning group (CPG) thin -> Optional boolean flag for thin provisoned volume Default is thick provision """ if is_int(size): log._info("Creating Virtual Volume: %s" % name) if thin: output = execute_local_command( SELECT_MANAGER % (self.mgt_ip, self.mgt_username, self.mgt_pw) + SELECT_SYSTEM % (self.system) + '"add storage ""%s"" GROUP=""\Disk Groups\%s"" SIZE=\"%s\" thin_provision=TRUE"' % (name, user_cpg, size) + EXIT) else: output = execute_local_command( SELECT_MANAGER % (self.mgt_ip, self.mgt_username, self.mgt_pw) + SELECT_SYSTEM % (self.system) + '"add storage ""%s"" GROUP=""\Disk Groups\%s"" SIZE=\"%s\""' % (name, user_cpg, size) + EXIT) if 'error' not in output: log._info("Virtual volume %s got created successfully" % name) return output else: log._warn( "Error in creating virtual volume. Make sure parameters are listed correctly in ConfigMgr.xml. Output:%s" % (output)) return False else: raise ValueError("size not of type 'int'")
def set_ebipa_server_and_inter_gateway(self, gateway): """ Description : This function sets EBIPA server and interconnect gateway ip address Params : gateway --> gateway for OA Usage : set_ebipa_ser_inter_gateway("172.24.110.2", "Admin", "Insight7", "172.24.110.1") Return : return output if there is no exception else return false """ try: output1 = False output2 = False output3 = False output4 = False output1 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "set ebipa server gateway %s 1-16" % (gateway), "Successfully set the gateway") output2 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "SAVE EBIPA", "EBIPA configuration was saved.") output3 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "set ebipa interconnect gateway %s 1-4" % (gateway), "Successfully set the gateway") output4 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "SAVE EBIPA", "EBIPA configuration was saved.") if output1 and output2 and output3 and output4: log._info("EBIPA interconnect and server gateway is set") else: log._error("EBIPA interconnect and server gateway is not set") except: raise Exception("Failed to set EBIPA Server Gateway")
def set_ebipa_servers(self, start_server_address, subnetmask): """ Description : This function sets the IP address for all 16 bays Params : start_server_address --> starting Address of Bays subnetmask --> The subnet mask Usage : set_ebipa_address("172.24.110.45", "255.255.255.0") Return : return message if there is no exception else return false """ try: output1 = False output2 = False output1 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "set ebipa server %s %s 1-16" % (start_server_address, subnetmask), "Successfully set device (iLO) bay # 1 to IP address") output2 = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "SAVE EBIPA", "EBIPA configuration was saved.") if output1 and output2: log._info("EBIPA Address set for all the bays") else: log._error("EBIPA Address not set for all the bays") except: raise Exception("Failed to set EBIPA Address")
def _get_command_status(output): """ Input output string, parses until 'status' keyword is found. Returns value of status. """ index = output.index("status=") status = output[index + 7] log._info("status = %s" % status) return status
def delete_zone(self, zone_name): """ Deletes a zone. """ output = run('zonedelete %s' % (zone_name)) if 'not found' or 'error' in output: log._warn('delete_zone failed') return False else: log._info('delete_zone successful') return True
def __init__(self, vsphere_element): self.tag = vsphere_element.tag self.ip_address = vsphere_element.attrib["IPv4Address"] self.username = vsphere_element.attrib["Username"] self.password = vsphere_element.attrib["Password"] self.vms = [] for vm in vsphere_element.find("VMs"): # adding to list of vms, each vm is ElementObject self.vms.append(vm) log._info("Added VM '%s' to vSphere object '%s'" % (vm.tag, vsphere_element.tag))
def __init__(self, vsphere_server, vsphere_username, vsphere_password): self.server = vsphere_server self.username = vsphere_username self.password = vsphere_password try: log._info("Attempting to connect to vCenter server: %s" % (self.server)) self.client = Client(self.server, self.username, self.password) log._info("CONNECTED to vCenter server: %s" % (self.server)) except VimFault as e: log._warn("Failed to connect to vCenter: %s" % (e.fault_name)) return False
def reset_vm(self, vm): """ Resets the virtual machine Params: - vm: (str) The name of the virtual machine. (Ex. 'cosmos-jvm') """ try: log._info("Restarting %s" % vm.name) task = vm.RestartVM_Task() except VimFault as e: log._warn("ERROR: Failed to restart %s %s" % (vm.name, e))
def __init__(self, rack_element): self.tag = rack_element.tag # Ex Rack1 self.name = rack_element.attrib["Name"] self.servers = [] for server in rack_element.find("Servers"): # sending the server Element to ServerObject constructor # list of ServerObjects that represent each server self.servers.append(ServerObject(server)) log._info("Added server %s to rack %s, Model: %s" % (server.tag, rack_element.tag, server.attrib["Model"])) # self.ipdu is a dict with keys of 'IPAddress', 'Username' and # Password' self.ipdu = copy.deepcopy(rack_element.find("iPDU").attrib)
def configure_port_speed(self, port_no, speed): obj = telnetlib.Telnet(self.switch_ip) obj.read_until("login: "******"\n") obj.read_until("Password: "******"\n") obj.write("sys \n") obj.write("interface Ten-GigabitEthernet 1/0/%s \n" % port_no) obj.write("speed %s \n" % speed) obj.write("quit \n") obj.write("quit \n") obj.write("quit \n") ret = obj.read_all() log._info(ret)
def store_san_switch_data(self): # Switches switches = self.root.find("Switches") san_switches = switches.find("SAN_Switches") for san_switch in san_switches: log._info("Reading SAN switch %s" % (san_switch.attrib['Name'])) try: obj = hw_objects.SanSwitchObject(san_switch) except: raise err.ObjectError(san_switch.tag) if validate_object_attributes(obj): self.san_switches_list.append(obj) log._info("SUCCESS: SAN switch object stored") else: log._warn(err.INVALID_OBJECT_WARNING % san_switch.tag)
def delete_host(self, hostname): """ Deletes a host from the storage system """ log._info("Deleting host %s" % hostname) output = execute_local_command( SELECT_MANAGER % (self.mgt_ip, self.mgt_username, self.mgt_pw) + SELECT_SYSTEM % (self.system) + '\"delete host \"\"%s\"\"\" ' % (hostname) + EXIT) if output: log._info("Host %s got deleted successfully" % hostname) return output else: log._warn("Failed to execute delete_host command") return False
def destroy_vm(self, vm_name): """ Destroys VM*, deleting its contents and removing it from parent folder Params: - vm: (str) The name of the virtual machine to be deleted. *Assumes proper permissions (VirtualMachine.Inventory.Delete) """ vm = VirtualMachine.get(self.client, name=vm_name) try: log._info("Destroying %s" % vm.name) task = vm.Destroy_Task() except VimFault as e: log._warn("ERROR: Failed to destroy %s %s" % (vm.name, e))
def power_off_vm(self, vm_name): """ Powers off a VM defined in the Client Params: - vm: (str) The name of the virtual machine. (Ex. 'cosmos-jvm') """ vm = self.get_vm(vm_name) if vm.runtime.powerState == "poweredOff": log._warn("ERROR: %s is already powered off." % vm.name) else: try: log._info("Powering off %s" % vm.name) task = vm.PowerOffVM_Task() except VimFault as e: log._warn("ERROR: Failed to power off %s %s" % (vm.name, e))
def create_alias(self, alias_name, wwn_list): """ Creates a new alias, in this case creates a host with members from wwn_list """ if len(wwn_list) == 1: wwn_string = wwn_list[0] else: wwn_string = ';'.join(wwn_list) text = run('alicreate %s, "%s"' % (alias_name, wwn_string)) if 'invalid' in text: log._warn('create_alias failed') return False else: log._info('create_alias successful') return True
def delete_config(self, config_name): """ """ text = run('cfgdelete %s' % (config_name)) if 'not found' in text: log._warn('delete_config failed: config name "%s" not found' % (config_name)) log._debug(text) return False elif 'error' in text: log._warn('delete_config failed') log._debug(text) return False else: log._info('delete_config successful') return True
def restart_interconnect(self): """ Description : This function restarts interconnects e.i., VC module Params : none Usage : restart_interconnect() Return : return output if there is no exception else return false """ try: output = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "restart interconnect 1", "Resetting Interconnect tray in bay") if output: log._info("VC module has been restarted successfully") else: log._error("Failed to restart VC module") except: raise Exception("Failed to clear VC mode")
def suspend_vm(self, vm): """ Powers off a VM defined in the Client Params: - vm: (str) The name of the virtual machine. (Ex. 'cosmos-jvm') """ if vm.runtime.powerState in ["poweredOff", "suspended"]: log._warn( "ERROR: %s is powered off or suspended. Cannot suspend." % vm.name) else: try: log._info("Suspending %s" % vm.name) task = vm.SuspendVM_Task() except VimFault as e: log._warn("ERROR: Failed to suspend %s %s" % (vm.name, e))
def enable_force_downgrade(self): """ Description : This function is to enable force downgrade the firmware to lower versions on devices within the enclosure Usage : enable_force_downgrade() Return : output message from console interaction """ try: output = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "set firmware management force downgrade enable", "Operation was successful.") if output: log._info("Force downgrade is enabled") else: log._warn("Failed to enable force downgrade") except: log._error("Unable to enable force downgrade")
def select_bays_for_firmware_deployment(self): """ Description : This function is to select the device for firmware upgrade Usage : select_bays_for_firmware_deployment() Return : output message from console interaction """ try: output = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "set firmware management BAYS_TO_INCLUDE Server 1-16", "Enclosure Firmware Management settings applied successfully.") if output: log._info("Server bay selection done") else: log._warn("server bay not selected") except: log._error("Unable to select Server Bay")
def set_power_policy(self): """ Description : This function is to set power policy while firmware update initiated Usage : set_power_policy() Return : output message from console interaction """ try: output = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "SET FIRMWARE MANAGEMENT POWER force", "Power policy successfully changed to FORCE.") if output: log._info("Server power policy applied successfully") else: log._warn("Server power policy not applied") except: log._error("Unable to apply Server power policy")
def set_spp_url_for_firmware_management(self, url): """ Description : This function sets SPP url to OA Params : url --> http url where SPP iso is been served Usage : set_spp_url_for_firmware_management("http://172.24.36.85/SPP2013020.2013_0204.107.iso") Return : output message from console interaction """ try: output = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "set firmware management url " + url, "Enclosure Firmware Management URL set to") if output: log._info("Successfully set the SPP ISO URL") else: log._warn("Error setting SPP ISO URL") except: log._error("Unable to set Firmware management URL")
def set_firmware_management_policy(self): """ Description : This function is to set firmware update policy when a blade is insrted into enclosure Usage : set_firmware_management_policy() Return : output message from console interaction """ try: output = ha_library.runOAcommands( self.oa_ip, self.oa_username, self.oa_password, "set firmware management policy manual", "Enclosure Firmware Management policy set to manual update and discovery." ) if output: log._info("Firmware management policy set to manual") else: log._warn("Firmware management policy falied") except: log._error("Unable to set firmware deployment policy")
def upload_switch_config_file_to_tftp_server(self): """ Description : This function Uploads the switch configuration file to a TFTP server Usage : upload_switch_config_file_to_tftp_server("172.24.111.2", "switch user name", "switch user password") Return : output message from console interaction """ log._info("Executing switch configuration on %s " % self.switch_ip) put_config_file = telnetlib.Telnet(self.switch_ip) put_config_file.read_until("login: "******"\n") put_config_file.read_until("Password: "******"\n") put_config_file.write("tftp %s put %s \n" % (self.tftp_server_ip, self.switch_conf_file)) put_config_file.write("quit \n") put_config_file.write("quit \n") ret = put_config_file.read_all() log._info(ret)
def download_firmware_image_to_switch(self, command): download_firmware_on_switch = telnetlib.Telnet(self.switch_ip) download_firmware_on_switch.read_until("login: "******"\n") download_firmware_on_switch.read_until("Password: "******"\n") # download_firmware_on_switch.write("sys \n") log._info( "Initializing switch firmware download on switch, it takes about 8-10 minutes..." ) log._info("Please wait") download_firmware_on_switch.write(command + " \n") download_firmware_on_switch.read_until("Overwrite it? [Y/N]:") download_firmware_on_switch.write("Y \n") download_firmware_on_switch.write("quit \n") download_firmware_on_switch.write("quit \n") # put_config_file.write("quit \n") ret = download_firmware_on_switch.read_all() print ret