示例#1
0
 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")
示例#2
0
 def _get_bootsources(self):
     """
     Internal class method to retrieve the devices available to boot from
     """
     # try:
     output = ha_library.execute_Remote_commands_iLO_and_return_output(
         self.mgt_ip, self.mgt_username, self.mgt_pw,
         "show system1/bootconfig1/bootsource1")
     bootorder = _find_value_by_keyword(output, "bootorder")
     if bootorder:
         bootsources = ha_library.execute_Remote_commands_iLO_and_return_output(
             self.mgt_ip, self.mgt_username, self.mgt_pw,
             "set system1/bootconfig1/bootsource1 bootorder=%s" % bootorder)
         bootsources_list = re.split('bootorder=[\d]', bootsources)
         # pretty_list = []
         bootsource_dict = {}
         for source in bootsources_list:
             try:
                 bootsource_dict[re.search('bootsource(.+?)=',
                                           source).group(1)] = re.search(
                                               'BootFm(.+?) ',
                                               source).group(1).lower()
                 # pretty_list.append(re.search('BootFm(.+?) ', source).group(1))
             except:
                 continue
         return bootsource_dict
         # return delete_repeats(pretty_list)
     else:
         log._debug(
             "Invalid command sent to iLO:  bootorder not found in output")
def check_wwn(wwn):
    """
    Uses regular expressions to validate WWN
    Returns True if valid WWN, False if not.
    """
    wwn_reg_expr = "^([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f])$"
    matched_val_list = re.compile(wwn_reg_expr, re.IGNORECASE).findall(wwn)
    if (len(matched_val_list) > 0):
        log._debug("Given wwn number %s is a valid WWN number" % wwn)
        return True
    else:
        log._debug("Given wwn number %s is invalid WWN number" % wwn)
        return False
示例#4
0
 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_domain(self, domain_name, domain_users):
     """
     Parameters:
             domain_name  -> Specifies the name of the domain you are creating.
                             Cannot be longer than 31 characters.  Name "all"
                             is reserved.
             domain_users -> List of users to be added to domain.
     """
     output = ha_library.run_storage_commands(
         self.mgt_ip, self.mgt_username, self.mgt_pw,
         "createdomain %s" % (domain_name))
     for user in domain_users:
         test = self.create_user(user, domain_name)
         if test is False:
             log._debug("User '%s' not added", user)
             return False
     return output
 def delete_domain(self, domain, domain_users):
     """
     Deletes domains in 3PAR system
     """
     for user in domain_users:
         test = self.delete_user(user)
         if test is False:
             log._debug("User '%s' not added", user)
             return False
     output = ha_library.run_storage_commands(self.mgt_ip,
                                              self.mgt_username,
                                              self.mgt_pw,
                                              "removedomain -f %s" % domain)
     if output:
         return output
     else:
         log._warn("Failed to execute delete_domain command")
         return False
示例#7
0
 def check_uid_light(self):
     """
     Returns either ON or OFF
     """
     output = ha_library.execute_Remote_commands_iLO_and_return_output(
         self.mgt_ip, self.self.mgt_username, self.mgt_pw,
         "show /system1/led1 enabledstate")
     result = _find_value_by_keyword(output, "enabledstate")
     if not result:
         log._warn("Failed to check UID light...")
         log._debug("output = %s" % output)
         log._debug("result = %s" % result)
         raise ValueError
     else:
         if result == "enabled":
             output = "ON"
         else:
             output = "OFF"
     return output
示例#8
0
 def create_zone(self, zone_name, members_list):
     """
     Creates a new zone
     """
     if len(members_list) == 1:
         members_string = members_list[0]
     else:
         members_string = ';'.join(members_list)
     text = run('zonecreate %s, "%s"' % (zone_name, members_string))
     if 'invalid' in text:
         log._warn('create_zone failed')
         log._debug(text)
         return False
     elif 'error' in text:
         log._warn('create_zone failed')
         log._debug(text)
         return False
     else:
         log._info('create_zone successful')
         return True
示例#9
0
 def power_on_server(self):
     """
     Returns either ON if successful or OFF if unsuccessful
     Returns -1 if command failed to send
     """
     output = ha_library.execute_Remote_commands_iLO_and_return_output(
         self.mgt_ip, self.self.mgt_username, self.mgt_pw, "start /system1")
     result = _find_value_by_keyword(output, "status_tag")
     if not result:
         output = False
         log._warn("Failed to send the command")
         log._debug("output = %s" % output)
         log._debug("result = %s" % result)
         raise ValueError
     else:
         if result == "COMMAND COMPLETED":
             output = "ON"
         else:
             output = "OFF"
     return output
示例#10
0
 def __init__(self, server_element):
     self.tag = server_element.tag  # Ex Server1
     self.ilo_ip = server_element.attrib["iLO_IPv4Address"]
     self.ilo_un = server_element.attrib["iLOAdministrator"]
     self.ilo_pw = server_element.attrib["iLOAdminPassword"]
     self.model = server_element.attrib["Model"]
     self.bios = server_element.attrib["BIOS"]
     self.factory_reset_server = server_element.attrib["FactoryResetServer"]
     self.factory_reset_ilo = server_element.attrib["FactoryResetiLO"]
     self.users = []  # users is a list of objects of type Element
     # each user Element in users List has Username and Password
     # accessible by users[user].attrib["Username"] and
     # users[user].attrib["Password"]
     for user in server_element.find("Users"):
         # adding each user Element to list, and can be
         self.users.append(user)
         # accessed externally by ServerObject.
         log._debug("Added %s to %s" % (user.tag, server_element.tag))
     self.bootorder = []
     self.bootorder = server_element.find(
         "Bootorder").attrib["Order"].split(',')
示例#11
0
 def __init__(self, san_switch_element):
     HardwareObject.__init__(self, san_switch_element.attrib)
     self.tag = san_switch_element.tag
     self.update = san_switch_element.attrib["FirmwareUpdate"]
     self.fw_loc = san_switch_element.attrib["FirmwareLoc"]
     self.fw_host = san_switch_element.attrib["FirmwareHost"]
     self.fw_un = san_switch_element.attrib["FirmwareUn"]
     self.fw_pw = san_switch_element.attrib["FirmwarePw"]
     self.fw_prot = san_switch_element.attrib["FirmwareProtocol"]
     self.zone_configs = []  # list of Element objects
     self.ports = []  # list of Element objects
     for port_zoning in san_switch_element.find("PortZoning"):
         log._debug("Port zoning not needed for now..." + port_zoning.tag)
     for zone_config in san_switch_element.find("ZoneConfigs"):
         log._debug("Currently processing %s" % zone_config.tag)
         self.zone_configs.append(zone_config)  # list of Element objects
         # view_element_and_subelements(zone_config)
     for port_attribute in san_switch_element.find("PortAttributes"):
         log._debug("Currently processing %s" % port_attribute.tag)
         self.ports.append(port_attribute)
def validate_object_attributes(object):
    """
    Checks if the passed object has certain parameters defined, else it is
    ignored and the Parser will not store it in its list

    Returns True if object attributes are valid, else False.

    """
    # first check to see if ip address is valid for listed objects using check_ipv4
    # and check_ipv6 [currently not implemented]
    if any([
            isinstance(object, hw_objects.SanSwitchObject),
            isinstance(object, hw_objects.NetworkSwitchObject),
            isinstance(object, hw_objects.StorageObject),
            isinstance(object, hw_objects.HydrogenObject),
            isinstance(object, hw_objects.AltairObject),
            isinstance(object, hw_objects.OaObject),
            isinstance(object, hw_objects.VcObject),
            isinstance(object, hw_objects.VSphereObject),
            isinstance(object, hw_objects.VSphereObject),
    ]):
        if not check_ipv4(object.ip_address):
            # POSSIBLY USE IPV6 [NOT IMPLEMENTED]
            # if any([isinstance(object, hw_objects.SanSwitchObject),
            # isinstance(object, hw_objects.NetworkSwitchObject),
            # isinstance(object, hw_objects.StorageObject)]):
            # log._debug("%s ipv4 invalid, attempting to use ipv6..."%object)
            # if not check_ipv6(object.attrib['IPv6Address']:
            # return False
            # else:
            log._warn("Invalid ipv4 address for %s: %s" %
                      (object.tag, object.ip_address))
            return False
        else:  # if IP is valid, check if pingable
            if not device_discovery.ping_ip(object.ip_address):
                log._warn("IP not reachable in %s" % object.tag)
                return False
        if isinstance(object, hw_objects.VSphereObject):
            if not all([object.password, object.username]):
                log._warn("Username or password not defined for %s" %
                          object.tag)
                return False
        if any([
                isinstance(object, hw_objects.SanSwitchObject),
                isinstance(object, hw_objects.NetworkSwitchObject),
                isinstance(object, hw_objects.StorageObject),
        ]):
            # check to see if name, username exist for storage, switch
            if not all([object.name, object.username, object.model]):
                log._warn("Name, username, or model not defined for %s" %
                          object.tag)
                return False
        # elif isinstance(object, hw_objects.HydrogenObject):
        # if not all([object.xmgr, object.hc_dict, object.h3c_switch]):
        # log._warn("Incomplete Hydrogen details, check XML")
        # elif isinstance(object, hw_objects.AltairObject):
        # if not all([object.virtualhost_dict, object.mediaserver_dict]):
        # log._warn("Incomplete Altair details, check XML")
        return True

    # ________________SPECIAL CASES_____________________
    # rack objects
    elif isinstance(object, hw_objects.RackObject):
        if not all([object.name, object.servers]):
            log._warn("Incomplete Rack definition: missing name or servers")
            return False
        else:
            return True

    # server objects
    elif isinstance(object, hw_objects.ServerObject):
        if not all([object.ilo_ip, object.ilo_un]):
            log._warn("Incomplete iLO definition: missing IP or username")
            return False
        else:
            return True

    # Firmware objects
    elif isinstance(object, hw_objects.FirmwareObject):
        if not all([
                object.oa_ip, object.oa_user, object.vc_user,
                object.vc_firmware_location
        ]):
            log._warn(
                "Incomplete Firmware definition: missing required parameters")
            return False
        if not check_ipv4(object.oa_ip):
            log._warn(
                "Invalid IP, please check XML for Firmware details for correctness"
            )
            return False
        if not device_discovery.ping_ip(object.oa_ip):
            log._warn("IP not reachable in %s" % object.tag)
            return False
        else:
            return True

    # elif isinstance(object, hw_objects.NetworkSwitchObject):
    # if not check_ipv4(object.ip_address):
    # POSSIBLY USE IPV6 [NOT IMPLEMENTED]
    # if any([isinstance(object, hw_objects.SanSwitchObject),
    # isinstance(object, hw_objects.NetworkSwitchObject),
    # isinstance(object, hw_objects.StorageObject)]):
    # log._debug("%s ipv4 invalid, attempting to use ipv6..."%object)
    # if not check_ipv6(object.attrib['IPv6Address']:
    # return False
    # else:
    # log._warn("Invalid ipv4 address for %s: %s" % (object.tag, object.ip_address))
    # return False

    # else: #if IP is valid, check if pingable
    # if not device_discovery.ping_ip(object.ip_address):
    # log._warn("IP not reachable in %s" % object.tag)
    # return False
    else:
        log._error(
            "FATAL INTERNAL ERROR: OBJECT NOT RECOGNIZED, PLEASE REPORT")
        log._debug("Unrecognized object: %s" % object)
        return False