From b9b780fe1764cc45a95918dd3285fb931afa43ae Mon Sep 17 00:00:00 2001 From: Yuriy Zveryanskyy Date: Thu, 21 Apr 2016 13:53:23 +0300 Subject: [PATCH] Change global names in Intel NM driver Remove unneeded "INTEL_NM" prefix. There is comment on review of I9becb7e4f62c773d2a21fd53255acad3098b47a3 Change-Id: Icb83201d3d4efbada96c250a52a2bf4eef31b81d --- .../intel_nm/nm_commands.py | 141 +++++++++--------- ironic_staging_drivers/intel_nm/nm_vendor.py | 2 +- 2 files changed, 71 insertions(+), 72 deletions(-) diff --git a/ironic_staging_drivers/intel_nm/nm_commands.py b/ironic_staging_drivers/intel_nm/nm_commands.py index a1e4bd9..ad8514a 100644 --- a/ironic_staging_drivers/intel_nm/nm_commands.py +++ b/ironic_staging_drivers/intel_nm/nm_commands.py @@ -26,7 +26,7 @@ from ironic_staging_drivers.common.i18n import _LW LOG = log.getLogger(__name__) -INTEL_NM_DOMAINS = { +DOMAINS = { 'platform': 0x00, 'cpu': 0x01, 'memory': 0x02, @@ -34,7 +34,7 @@ INTEL_NM_DOMAINS = { 'io': 0x04 } -INTEL_NM_TRIGGERS = { +TRIGGERS = { 'none': 0x00, 'temperature': 0x01, 'power': 0x02, @@ -42,39 +42,39 @@ INTEL_NM_TRIGGERS = { 'boot': 0x04 } -INTEL_NM_CPU_CORRECTION = { +CPU_CORRECTION = { 'auto': 0x00, 'unagressive': 0x20, 'aggressive': 0x40, } -INTEL_NM_STORAGE = { +STORAGE = { 'persistent': 0x00, 'volatile': 0x80, } -INTEL_NM_ACTIONS = { +ACTIONS = { 'alert': 0x00, 'shutdown': 0x01, } -INTEL_NM_POWER_DOMAIN = { +POWER_DOMAIN = { 'primary': 0x00, 'secondary': 0x80, } -INTEL_NM_BOOT_MODE = { +BOOT_MODE = { 'power': 0x00, 'performance': 0x01, } -INTEL_NM_DAYS = collections.OrderedDict([('monday', 0x01), - ('tuesday', 0x02), - ('wednesday', 0x04), - ('thursday', 0x08), - ('friday', 0x10), - ('saturday', 0x20), - ('sunday', 0x40)]) +DAYS = collections.OrderedDict([('monday', 0x01), + ('tuesday', 0x02), + ('wednesday', 0x04), + ('thursday', 0x08), + ('friday', 0x10), + ('saturday', 0x20), + ('sunday', 0x40)]) VERSIONS = { 0x01: '1.0', @@ -90,7 +90,7 @@ IPMI_VERSIONS = { 0x03: '3.0' } -INTEL_NM_STATISTICS = { +STATISTICS = { 'global': { 'power': 0x01, 'temperature': 0x02, @@ -116,29 +116,29 @@ def _reverse_dict(d): return {v: k for k, v in d.items()} -INTEL_NM_DOMAINS_REV = _reverse_dict(INTEL_NM_DOMAINS) -INTEL_NM_TRIGGERS_REV = _reverse_dict(INTEL_NM_TRIGGERS) -INTEL_NM_CPU_CORRECTION_REV = _reverse_dict(INTEL_NM_CPU_CORRECTION) -INTEL_NM_STORAGE_REV = _reverse_dict(INTEL_NM_STORAGE) -INTEL_NM_ACTIONS_REV = _reverse_dict(INTEL_NM_ACTIONS) -INTEL_NM_POWER_DOMAIN_REV = _reverse_dict(INTEL_NM_POWER_DOMAIN) +DOMAINS_REV = _reverse_dict(DOMAINS) +TRIGGERS_REV = _reverse_dict(TRIGGERS) +CPU_CORRECTION_REV = _reverse_dict(CPU_CORRECTION) +STORAGE_REV = _reverse_dict(STORAGE) +ACTIONS_REV = _reverse_dict(ACTIONS) +POWER_DOMAIN_REV = _reverse_dict(POWER_DOMAIN) # OEM group extension code defined in IPMI spec -INTEL_NM_NETFN = '0x2E' +NETFN = '0x2E' # Intel manufacturer ID for OEM extension, LS byte first -INTEL_NM_ID = ('0x57', '0x01', '0x00') +INTEL_ID = ('0x57', '0x01', '0x00') # Intel NM commands -INTEL_NM_POLICY_CONTROL = '0xC0' -INTEL_NM_POLICY_SET = '0xC1' -INTEL_NM_POLICY_GET = '0xC2' -INTEL_NM_SUSPEND_SET = '0xC5' -INTEL_NM_SUSPEND_GET = '0xC6' -INTEL_NM_CAPABILITIES_GET = '0xC9' -INTEL_NM_VERSION_GET = '0xCA' -INTEL_NM_STATISTICS_RESET = '0xC7' -INTEL_NM_STATISTICS_GET = '0xC8' +POLICY_CONTROL = '0xC0' +POLICY_SET = '0xC1' +POLICY_GET = '0xC2' +SUSPEND_SET = '0xC5' +SUSPEND_GET = '0xC6' +CAPABILITIES_GET = '0xC9' +VERSION_GET = '0xCA' +STATISTICS_RESET = '0xC7' +STATISTICS_GET = '0xC8' _INVALID_TIME = datetime.datetime.utcfromtimestamp(0).isoformat() _UNSPECIFIED_TIMESTAMP = 0xFFFFFFFF @@ -198,14 +198,14 @@ def _add_to_dict(data_dict, values, names): def _create_command_head(command): """Create first part of Intel NM command.""" - cmd = [INTEL_NM_NETFN, command] - _append_to_command(cmd, INTEL_NM_ID) + cmd = [NETFN, command] + _append_to_command(cmd, INTEL_ID) return cmd def _add_domain_policy_id(cmd, data): """Add domain id and policy id to command.""" - _append_to_command(cmd, _hex(INTEL_NM_DOMAINS[data['domain_id']])) + _append_to_command(cmd, _hex(DOMAINS[data['domain_id']])) _append_to_command(cmd, _hex(data['policy_id'])) @@ -213,13 +213,13 @@ def _days_compose(days): """Converting list of days to binary representation.""" pattern = 0 for day in days: - pattern |= INTEL_NM_DAYS[day] + pattern |= DAYS[day] return pattern def _days_parse(pattern): """Parse binary data with days of week.""" - return [day for day in INTEL_NM_DAYS if pattern & INTEL_NM_DAYS[day]] + return [day for day in DAYS if pattern & DAYS[day]] def _ipmi_timestamp_to_isotime(timestamp): @@ -245,16 +245,16 @@ def set_policy(policy): if policy['policy_trigger'] in ('none', 'boot'): policy['trigger_limit'] = 0 - cmd = _create_command_head(INTEL_NM_POLICY_SET) - _append_to_command(cmd, _hex(INTEL_NM_DOMAINS[policy['domain_id']] | + cmd = _create_command_head(POLICY_SET) + _append_to_command(cmd, _hex(DOMAINS[policy['domain_id']] | 0x10 if policy['enable'] else 0x00)) _append_to_command(cmd, _hex(policy['policy_id'])) # 0x10 is policy add flag - _append_to_command(cmd, _hex(INTEL_NM_TRIGGERS[policy['policy_trigger']] | - INTEL_NM_CPU_CORRECTION[policy['cpu_power_correction']] - | INTEL_NM_STORAGE[policy['storage']] | 0x10)) - _append_to_command(cmd, _hex(INTEL_NM_ACTIONS[policy['action']] | - INTEL_NM_POWER_DOMAIN[policy['power_domain']])) + _append_to_command(cmd, _hex(TRIGGERS[policy['policy_trigger']] | + CPU_CORRECTION[policy['cpu_power_correction']] + | STORAGE[policy['storage']] | 0x10)) + _append_to_command(cmd, _hex(ACTIONS[policy['action']] | + POWER_DOMAIN[policy['power_domain']])) if isinstance(policy['target_limit'], int): limit = policy['target_limit'] @@ -277,18 +277,18 @@ def parse_policy(raw_data): policy = {} raw_int = _raw_to_int(raw_data) - policy['domain_id'] = INTEL_NM_DOMAINS_REV[raw_int[3] & 0x0F] + policy['domain_id'] = DOMAINS_REV[raw_int[3] & 0x0F] policy['enabled'] = bool(raw_int[3] & 0x10) policy['per_domain_enabled'] = bool(raw_int[3] & 0x20) policy['global_enabled'] = bool(raw_int[3] & 0x40) policy['created_by_nm'] = not bool(raw_int[3] & 0x80) - policy['policy_trigger'] = INTEL_NM_TRIGGERS_REV[raw_int[4] & 0x0F] + policy['policy_trigger'] = TRIGGERS_REV[raw_int[4] & 0x0F] policy['power_policy'] = bool(raw_int[4] & 0x10) - power_correction = INTEL_NM_CPU_CORRECTION_REV[raw_int[4] & 0x60] + power_correction = CPU_CORRECTION_REV[raw_int[4] & 0x60] policy['cpu_power_correction'] = power_correction - policy['storage'] = INTEL_NM_STORAGE_REV[raw_int[4] & 0x80] - policy['action'] = INTEL_NM_ACTIONS_REV[raw_int[5] & 0x01] - policy['power_domain'] = INTEL_NM_POWER_DOMAIN_REV[raw_int[5] & 0x80] + policy['storage'] = STORAGE_REV[raw_int[4] & 0x80] + policy['action'] = ACTIONS_REV[raw_int[5] & 0x01] + policy['power_domain'] = POWER_DOMAIN_REV[raw_int[5] & 0x80] policy_values = struct.unpack('