def set_host(self, hostname, wwn=None): """ Changes the specified host properties, specifically wwn More options can be easily added later as needed.. Parameters: hostname -> hostname to be modified system -> system where the host exists wwn -> World wide name of the fibre channel adapter """ if wwn is not None: output = execute_local_command( SELECT_MANAGER % (self.mgt_ip, self.mgt_username, self.mgt_pw) + SELECT_SYSTEM % (self.system) + 'set host "\Hosts\%s add_world_wide_name=%s' % (hostname, wwn) + EXIT) if output: return output else: log._warn("Failed to execute createvlun command") return False else: log._warn("set_host: no wwn passed to function") return False
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 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_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 create_host(self, hostname, host_os, domain, wwn_or_iscsi=None): """ Defines a new system host. Either Fibre Channel or iSCSI specified by 'conn_type' parameter. Parameters: hostname -> Name of host, up to 31 characters wwn_or_iscsi -> Specifies a WWN or iSCSI name to be assigned host_os -> Specifies OS running on host conn_type -> valid values are 'wwn' or 'iscsi' """ try: if wwn_or_iscsi is not None: if check_wwn(wwn_or_iscsi): output = ha_library.run_storage_commands( self.mgt_ip, self.mgt_username, self.mgt_pw, "createhost -os %s -domain %a %s %s" % (host_os, domain, hostname, wwn_or_iscsi)) else: output = ha_library.run_storage_commands( self.mgt_ip, self.mgt_username, self.mgt_pw, "createhost -iscsi -os %s -domain %s %s %s" % (host_os, domain, hostname, wwn_or_iscsi)) # else: # raise ValueError("invalid conn_type: only accepts either 'wwn' or 'iscsi'") else: output = ha_library.run_storage_commands( self.mgt_ip, self.mgt_username, self.mgt_pw, "createhost -os %s -domain %s %s" % (host_os, domain, hostname)) time.sleep(5) return output except: log._warn("storage_3par: failed to execute create_host command..") return False
def ping_list_of_ips(self): """ Description : This funtion checks if the given IP address is i=online or not by using PING utility Usage : change_oa_ip(List of ip address) Return : output message from console interaction """ reachableIP = [] notReachableIP = [] with open(os.devnull, "wb") as limbo: for ip in self.ip_address_list: result = subprocess.Popen(["ping", "-n", "1", ip], stdout=limbo, stderr=limbo).wait() if result == 1: notReachableIP.append(ip) else: reachableIP.append(ip) log._info("") log._info('-----------------') log._info('Reachable IPs are') log._info('-----------------') for i in reachableIP: log._info(i) log._info("") log._info('-------------------') log._warn('Unreachable IPs are') log._info('-------------------') for j in notReachableIP: log._info(j)
def get_vm(self, vm_name): try: vm = VirtualMachine.get(self.client, name=vm_name) except ObjectNotFoundError: log._warn("Error finding VM '%s', does not exist within client" % (vm_name)) return False return vm
def _verify_command_completed(string): """ Checks string to see if 'COMMAND COMPLETED' occurs """ if 'COMMAND COMPLETED' in string: return True else: log._warn("Error verifying command completed") return False
def get_vluns(self): output = execute_local_command( SELECT_MANAGER % (self.mgt_ip, self.mgt_username, self.mgt_pw) + SELECT_SYSTEM % (self.system) + '"ls lun full" ' + EXIT) if output: return output else: log._warn("Failed to execute get_vluns command") return False
def get_domains2(self): """ Returns domains in 3PAR system """ output = ha_library.run_storage_commands_and_return_output( self.mgt_ip, self.mgt_username, self.mgt_pw, "showdomain") if output: return output else: log._warn("Failed to execute get_domains command") return False
def get_hosts2(self): """ Returns host information from 3par system """ output = ha_library.run_storage_commands_and_return_output( self.mgt_ip, self.mgt_username, self.mgt_pw, "showhost") if output[0]: return output else: log._warn("Failed to execute get_hosts command") return output
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 get_cpgs2(self): """ Returns common provisioning group information """ output = ha_library.run_storage_commands_and_return_output( self.mgt_ip, self.mgt_username, self.mgt_pw, "showcpg") if output: return output else: log._warn("Failed to execute get_cpg command") return False
def get_vluns2(self): """ Returns VLUN information from the system """ output = ha_library.run_storage_commands_and_return_output( self.mgt_ip, self.mgt_username, self.mgt_pw, "showvlun") if output: return output else: log._warn("Failed to execute get_vlun command") 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, 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 parse_xml(self): """ Parses XML. Returns: - True if successful - False if XML is malformed. """ try: self.tree = ET.parse(self.fullpath) self.root = self.tree.getroot() return True except: log._warn("Failed to parse XML, check XML Schema for errors") return False
def list_all_users(self): """ Uses mpconfig.jar iLO open source package. """ # output = ha_library.execute_Remote_commands_iLO_and_return_output(self.mgt_ip, self.mgt_username, self.mgt_pw, "show") # errorCode = processOutput(output) return_code = subprocess.call([ 'java', '-classpath', MPCONFIG, 'mpconfig', '--host', self.mgt_ip, '--username', self.mgt_username, '--password', self.mgt_pw, '--cmd', 'list-user-accounts' ]) if return_code: log._warn("Failed to list users, check input XML file...")
def delete_cpg(self, cpg_name): """ Deletes disk group, see add_disk_group """ output = execute_local_command( SELECT_MANAGER % (self.mgt_ip, self.mgt_username, self.mgt_pw) + SELECT_SYSTEM % (self.system) + 'delete disk_group %s' % (cpg_name) + EXIT) if output: return output else: log._warn("Failed to execute delete disk_group command") return False
def delete_vlun(self, lun, virt_vol, host): """ Deletes VLUN from the system """ output = ha_library.run_storage_commands( self.mgt_ip, self.mgt_username, self.mgt_pw, "removevlun -f %s %s %s" % (virt_vol, lun, host)) if output: return output else: log._warn("Failed to execute delete_vlun command for %s" % virt_vol) return False
def modify_user(self, username, password): """ Same as add_user but used to edit an existing user. Uses mpconfig.jar iLO open source package. Does not take nickname or group argument. """ return_code = subprocess.call([ 'java', '-classpath', MPCONFIG, 'mpconfig', '--host', self.mgt_ip, '--username', self.mgt_username, '--password', self.mgt_pw, '--cmd', 'modify-user-account', username, password ]) if return_code: log._warn("Failed to modify user, user may not exist...")
def delete_cpg(self, cpg_name): """ Deletes common provisioning group information """ output = ha_library.run_storage_commands(self.mgt_ip, self.mgt_username, self.mgt_pw, "removecpg -f %s" % cpg_name) if output: return output else: log._warn("Failed to execute delete_cpg command on %s" % cpg_name) return False
def get_raw_xml_host_data(self): """ Gets raw XML of host data. Inputs: None Uses mpconfig.jar iLO open source package. """ return_code = subprocess.call([ 'java', '-classpath', MPCONFIG, 'mpconfig', '--host', self.mgt_ip, '--username', self.self.mgt_username, '--password', self.mgt_pw, '--cmd', 'get-host-data' ]) if return_code: log._warn("Failed to get Raw XML of host data...")
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 delete_host(self, host): """ Deletes host from 3par system """ output = ha_library.run_storage_commands(self.mgt_ip, self.mgt_username, self.mgt_pw, "removehost %s" % host) # can add check by issuing get_host and seeing if host in output of # get_host... if output: return output else: log._warn("Failed to execute delete_host command on %s" % host) return False
def delete_virtualvolume(self, virt_vol): """ Deletes virtual volumes on the 3par system. """ output = ha_library.run_storage_commands(self.mgt_ip, self.mgt_username, self.mgt_pw, "removevv -f %s" % virt_vol) if output: return output else: log._warn("Failed to execute delete_virtualvolume command on %s" % virt_vol) return False
def delete_user(self, username): """ Parameters: username -> Name of the user, up to 31 characters long. First character must be alphanumeric, and can contain period ('.'), dash ('-') and underscore ('_'). domain_name -> List of users to be added to domain. Optional Parameters: role -> browse, edit, service, super [default is super] """ output = ha_library.run_storage_commands( self.mgt_ip, self.mgt_username, self.mgt_pw, "removeuser -f %s" % (username)) if output: return output else: log._warn("Failed to execute createuser command") return False
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 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