Exemplo n.º 1
0
    def _rflash_activate(self, activate_arg):
        """ACTIVATE firmware
        called by rflash activate
        :param activate_arg: firmware tar ball or firmware id
        :return: ok if success
        :raise: error message if failed
        """
        activate_id = activate_version = ''
        if 'activate_id' in activate_arg:
            activate_id = activate_arg['activate_id']
        if 'update_file' in activate_arg:
            result = self._rflash_upload(activate_arg['update_file'])
            if result != RESULT_OK:
                self._msg_process_rflash(result, all_nodes_result, False)
                return

            activate_version = activate_arg['activate_version']
            (result, info) = self._get_firm_id([activate_version])
            if result == RESULT_OK:
                activate_id = info.pop(0)
            else:
                return

        result = self._rflash_activate_id(activate_id)
        if result != RESULT_OK:
            self._msg_process_rflash(result, all_nodes_result, False)
            return
        else:
            flash_started_msg = 'rflash %s started, please wait...' % activate_version
            self._msg_process_rflash(flash_started_msg, {}, False)

        firm_id_list = [activate_id]
        (result, priority_ids) = self._check_id_status(firm_id_list)
        if result == RESULT_OK:
            utils.update2Ddict(all_nodes_result, self.node, 'result', 'OK')
            if priority_ids:
                self._set_priority(priority_ids)
Exemplo n.º 2
0
    def get_nic_netinfo(self, nic):

        path = RSPCONFIG_NETINFO_URL['get_nic_netinfo'].replace('#NIC#', nic)
        data = self.request('GET', path, cmd='get_nic_netinfo')

        try:
            netinfo = {}
            for k, v in data.items():
                dev,match,netid = k.partition("/ipv4/")
                if 'LinkLocal' in v["Origin"] or v["Address"].startswith("169.254"):
                    msg = "Found LinkLocal address %s for interface %s, Ignoring..." % (v["Address"], dev)
                    self._print_record_log(msg, 'get_netinfo')
                    continue
                utils.update2Ddict(netinfo, netid, 'ip', v['Address'])
                utils.update2Ddict(netinfo, netid, 'ipsrc', v['Origin'].split('.')[-1])
                utils.update2Ddict(netinfo, netid, 'netmask', v['PrefixLength'])
                utils.update2Ddict(netinfo, netid, 'gateway', v['Gateway'])
            return netinfo
        except KeyError:
            error = 'Received wrong format response: %s' % data
            raise SelfServerException(error)
Exemplo n.º 3
0
 def get_netinfo(self):
     data = self.request('GET',
                         RSPCONFIG_NETINFO_URL['get_netinfo'],
                         cmd="get_netinfo")
     try:
         netinfo = {}
         for k, v in data.items():
             if 'network/config' in k:
                 if 'HostName' in v:
                     netinfo["hostname"] = v["HostName"]
                 if 'DefaultGateway' in v:
                     netinfo["defaultgateway"] = v["DefaultGateway"]
                 continue
             dev, match, netid = k.partition("/ipv4/")
             if netid:
                 nicid = dev.split('/')[-1]
                 if nicid not in netinfo:
                     netinfo[nicid] = {}
                 if 'LinkLocal' in v["Origin"] or v["Address"].startswith(
                         "169.254"):
                     msg = "Found LinkLocal address %s for interface %s, Ignoring..." % (
                         v["Address"], dev)
                     self._print_record_log(msg, 'get_netinfo')
                     # Save Zero Conf information
                     netinfo[nicid]["zeroconf"] = v["Address"]
                     continue
                 if 'ip' in netinfo[nicid]:
                     msg = "Another valid ip %s found." % (v["Address"])
                     self._print_record_log(msg, 'get_netinfo')
                     del netinfo[nicid]
                     netinfo[
                         'error'] = 'Interfaces with multiple IP addresses are not supported'
                     break
                 utils.update2Ddict(netinfo, nicid, "ipsrc",
                                    v["Origin"].split('.')[-1])
                 utils.update2Ddict(netinfo, nicid, "netmask",
                                    v["PrefixLength"])
                 utils.update2Ddict(netinfo, nicid, "gateway", v["Gateway"])
                 utils.update2Ddict(netinfo, nicid, "ip", v["Address"])
                 utils.update2Ddict(netinfo, nicid, "ipobj", netid)
                 if dev in data:
                     info = data[dev]
                     utils.update2Ddict(netinfo, nicid, "vlanid",
                                        info.get("Id", "Disable"))
                     utils.update2Ddict(netinfo, nicid, "mac",
                                        info["MACAddress"])
                     ntpservers = None
                     tmp_ntpservers = ','.join(info["NTPServers"])
                     if tmp_ntpservers:
                         ntpservers = tmp_ntpservers
                     utils.update2Ddict(netinfo, nicid, "ntpservers",
                                        ntpservers)
         return netinfo
     except KeyError:
         error = 'Received wrong format response: %s' % data
         raise SelfServerException(error)
Exemplo n.º 4
0
    def rflash(self, args):
        """handle rflash command
        :param args: subcommands and parameters for rflash
        """
        subcommand = args[0]
        if subcommand == 'activate' or subcommand == 'upload':
            self.rflash_log_file = XCAT_LOG_RFLASH_DIR + '/' + self.node + '.log'
            self.rflash_log_handle = open(self.rflash_log_file, 'a')

        try:
            result = self._login()
        except (xcat_exception.SelfServerException,
                xcat_exception.SelfClientException) as e:
            result = e.message

        if result != RESULT_OK:
            self.messager.info('%s: %s' % (self.node, result))
            if subcommand == 'activate' or subcommand == 'upload':
                self.rflash_log_handle.writelines(result + '\n')
                self.rflash_log_handle.flush()
                if subcommand == 'activate':
                    utils.update2Ddict(all_nodes_result, self.node, 'result',
                                       [result])
            return

        if subcommand == 'activate':
            activate_arg = args[1]
            self._rflash_activate(activate_arg)

        if subcommand == 'check':
            firm_info = self._firm_info('rflash_check')
            for i in firm_info:
                result = '%s: %s' % (self.node, i)
                self.messager.info(result)

        if subcommand == 'delete':
            firmware_id = args[1]
            result = self._rflash_delete(firmware_id)
            if result == RESULT_OK:
                result = '%s: [%s] Firmware removed' % (self.node, firmware_id)
                self.messager.info(result)
            else:
                result = '%s: %s' % (self.node, result)
                self.messager.info(result)

        if subcommand == 'list':
            firm_info = self._rflash_list()
            for i in firm_info:
                result = '%s: %s' % (self.node, i)
                self.messager.info(result)

        if subcommand == 'upload':
            upload_file = args[1]
            result = self._rflash_upload(upload_file)
            if result == RESULT_OK:
                result = 'Firmware upload successful. Use -l option to list.'
                self._msg_process_rflash(result, {}, False)
            else:
                self._msg_process_rflash(result, {}, False)

        if subcommand == 'activate' or subcommand == 'upload':
            self.rflash_log_handle.close()
Exemplo n.º 5
0
    def _check_id_status(self, firm_id_list):
        """check firm id status
        :param firm_id_list: list of firm ids want to check
        :return: result
        """
        result = RESULT_OK
        set_priority_ids = []
        process_status = {}
        failed_msg = []
        for i in range(80):
            try:
                (has_functional,
                 firm_info) = self._get_firm_info('rflash_check_status')
            except (xcat_exception.SelfServerException,
                    xcat_exception.SelfClientException) as e:
                self._msg_process_rflash(e.message, all_nodes_result, False)
                return (RESULT_FAIL, set_priority_ids)

            activation_num = 0
            for key in firm_info:
                firm_id = key.split('-')[-1]
                if firm_id in firm_id_list:
                    activation_state = firm_info[key]['Activation']
                    firm_version = firm_info[key]['Version']
                    if activation_state == 'Failed':
                        activation_msg = 'Firmware %s activation failed.' % (
                            firm_version)
                        self._msg_process_rflash(activation_msg, {}, False)
                        failed_msg.append(activation_msg)
                        result = RESULT_FAIL
                        firm_id_list.rempove(firm_id)
                    if activation_state == 'Active':
                        activation_msg = 'Firmware %s activation successful.' % (
                            firm_version)
                        self._msg_process_rflash(activation_msg, {}, False)
                        firm_id_list.remove(firm_id)
                        priority = firm_info[key]['Priority']
                        if priority != '0':
                            set_priority_ids.append(firm_id)
                    if activation_state == 'Activating':
                        activating_progress_msg = 'Activating %s ... %s%%' \
                                % (firm_version, firm_info[key]['Progress'])
                        self._msg_process_rflash(activating_progress_msg, {},
                                                 True)
                        process_status[firm_id] = activating_progress_msg

            if not firm_id_list:
                break
            gevent.sleep(15)

        if firm_id_list:
            result = RESULT_FAIL
            for firm_id in firm_id_list:
                if firm_id in process_status:
                    failed_msg.append('After %d seconds check the current status is %s' \
                                    % (80*15, process_status[firm_id]))

        if failed_msg:
            utils.update2Ddict(all_nodes_result, self.node, 'result',
                               [failed_msg])

        return (result, set_priority_ids)
Exemplo n.º 6
0
    def _get_firm_info(self, status):
        """get firmware information
        :param status: current status
        :returns: firmware version information
        """
        firm_info = {}
        has_functional = False
        url = HTTP_PROTOCOL + self.bmcip + FIRM_URL
        response = self.client.request('GET', url, OpenBMC.headers, '', status)
        functional_url = PROJECT_URL + '/software/functional'

        for key in response['data']:
            key_id = key.split('/')[-1]
            if key_id == 'functional':
                for endpoint in response['data'][key]['endpoints']:
                    purpose = response['data'][endpoint]['Purpose'].split(
                        '.')[-1]
                    key_sort = purpose + '-' + endpoint.split('/')[-1]

                    utils.update2Ddict(firm_info, key_sort, 'is_functional',
                                       True)
                    has_functional = True

            if 'Version' in response['data'][key]:
                purpose = response['data'][key]['Purpose'].split('.')[-1]
                key_sort = purpose + '-' + key_id
                if (functional_url in response['data'] and key
                        in response['data'][functional_url]['endpoints']):
                    utils.update2Ddict(firm_info, key_sort, 'is_functional',
                                       True)
                utils.update2Ddict(firm_info, key_sort, 'Version',
                                   response['data'][key]['Version'])
                utils.update2Ddict(firm_info, key_sort, 'Purpose', purpose)
                utils.update2Ddict(
                    firm_info, key_sort, 'Activation',
                    response['data'][key]['Activation'].split('.')[-1])
                if 'Priority' in response['data'][key]:
                    utils.update2Ddict(firm_info, key_sort, 'Priority',
                                       str(response['data'][key]['Priority']))
                if 'ExtendedVersion' in response['data'][key]:
                    utils.update2Ddict(
                        firm_info, key_sort, 'ExtendedVersion',
                        response['data'][key]['ExtendedVersion'])
                if 'Progress' in response['data'][key]:
                    utils.update2Ddict(firm_info, key_sort, 'Progress',
                                       response['data'][key]['Progress'])

        return (has_functional, firm_info)