Merge "Change global names in Intel NM driver"

This commit is contained in:
Jenkins 2016-04-22 11:32:17 +00:00 committed by Gerrit Code Review
commit 38281db50f
2 changed files with 71 additions and 72 deletions

View File

@ -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']
@ -279,18 +279,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('<HIHH', bytearray(raw_int[6:]))
policy_names = ('target_limit', 'correction_time', 'trigger_limit',
'reporting_period')
@ -301,7 +301,7 @@ def parse_policy(raw_data):
def set_policy_suspend(suspend):
"""Return hex data for policy suspend set command."""
cmd = _create_command_head(INTEL_NM_SUSPEND_SET)
cmd = _create_command_head(SUSPEND_SET)
_add_domain_policy_id(cmd, suspend)
periods = suspend['periods']
_append_to_command(cmd, _hex(len(periods)))
@ -335,12 +335,12 @@ def parse_policy_suspend(raw_data):
def get_capabilities(data):
"""Return hex data for capabilities get command."""
cmd = _create_command_head(INTEL_NM_CAPABILITIES_GET)
_append_to_command(cmd, _hex(INTEL_NM_DOMAINS[data['domain_id']]))
cmd = _create_command_head(CAPABILITIES_GET)
_append_to_command(cmd, _hex(DOMAINS[data['domain_id']]))
power_policy = 0x10
_append_to_command(cmd, _hex(INTEL_NM_TRIGGERS[data['policy_trigger']] |
_append_to_command(cmd, _hex(TRIGGERS[data['policy_trigger']] |
power_policy |
INTEL_NM_POWER_DOMAIN[data['power_domain']]))
POWER_DOMAIN[data['power_domain']]))
return cmd
@ -358,8 +358,8 @@ def parse_capabilities(raw_data):
'min_correction_time', 'max_correction_time',
'min_reporting_period', 'max_reporting_period')
_add_to_dict(capabilities, capabilities_values, capabilities_names)
capabilities['domain_id'] = INTEL_NM_DOMAINS_REV[raw_int[20] & 0x0F]
power_domain = INTEL_NM_POWER_DOMAIN_REV[raw_int[20] & 0x80]
capabilities['domain_id'] = DOMAINS_REV[raw_int[20] & 0x0F]
power_domain = POWER_DOMAIN_REV[raw_int[20] & 0x80]
capabilities['power_domain'] = power_domain
return capabilities
@ -367,7 +367,7 @@ def parse_capabilities(raw_data):
def control_policies(control_data):
"""Return hex data for enable or disable policy command."""
cmd = _create_command_head(INTEL_NM_POLICY_CONTROL)
cmd = _create_command_head(POLICY_CONTROL)
enable = control_data['enable']
scope = control_data['scope']
@ -378,11 +378,11 @@ def control_policies(control_data):
policy_id = 0
elif scope == 'domain':
flags = '0x03' if enable else '0x02'
domain_id = INTEL_NM_DOMAINS[control_data['domain_id']]
domain_id = DOMAINS[control_data['domain_id']]
policy_id = 0
elif scope == 'policy':
flags = '0x05' if enable else '0x04'
domain_id = INTEL_NM_DOMAINS[control_data['domain_id']]
domain_id = DOMAINS[control_data['domain_id']]
policy_id = control_data['policy_id']
_append_to_command(cmd, flags)
@ -394,7 +394,7 @@ def control_policies(control_data):
def get_policy(data):
"""Return hex data for policy get command."""
cmd = _create_command_head(INTEL_NM_POLICY_GET)
cmd = _create_command_head(POLICY_GET)
_add_domain_policy_id(cmd, data)
return cmd
@ -402,7 +402,7 @@ def get_policy(data):
def remove_policy(data):
"""Return hex data for policy remove command."""
cmd = _create_command_head(INTEL_NM_POLICY_SET)
cmd = _create_command_head(POLICY_SET)
_add_domain_policy_id(cmd, data)
# first 0 is remove policy, extra will be ignored
_append_to_command(cmd, ('0x00',) * 12)
@ -412,7 +412,7 @@ def remove_policy(data):
def get_policy_suspend(data):
"""Return hex data for policy get suspend command."""
cmd = _create_command_head(INTEL_NM_SUSPEND_GET)
cmd = _create_command_head(SUSPEND_GET)
_add_domain_policy_id(cmd, data)
return cmd
@ -420,7 +420,7 @@ def get_policy_suspend(data):
def remove_policy_suspend(data):
"""Return hex data for policy remove suspend command."""
cmd = _create_command_head(INTEL_NM_SUSPEND_SET)
cmd = _create_command_head(SUSPEND_SET)
_add_domain_policy_id(cmd, data)
# remove suspend
_append_to_command(cmd, '0x00')
@ -430,7 +430,7 @@ def remove_policy_suspend(data):
def get_version(data):
"""Return hex data for version get command."""
cmd = _create_command_head(INTEL_NM_VERSION_GET)
cmd = _create_command_head(VERSION_GET)
return cmd
@ -451,11 +451,11 @@ def parse_version(raw_data):
def reset_statistics(data):
"""Return hex data for reset statistics command."""
cmd = _create_command_head(INTEL_NM_STATISTICS_RESET)
cmd = _create_command_head(STATISTICS_RESET)
global_scope = data['scope'] == 'global'
if 'parameter_name' in data:
# statistics parameter is set, get corresponding value
mode = INTEL_NM_STATISTICS['global'][data['parameter_name']]
mode = STATISTICS['global'][data['parameter_name']]
# domain id should be always 0x00 for global reset by parameter name
data['domain_id'] = 'platform'
else:
@ -470,10 +470,9 @@ def reset_statistics(data):
def get_statistics(data):
"""Return hex data for get statistics command."""
cmd = _create_command_head(INTEL_NM_STATISTICS_GET)
cmd = _create_command_head(STATISTICS_GET)
scope = data['scope']
_append_to_command(cmd, _hex(
INTEL_NM_STATISTICS[scope][data['parameter_name']]))
_append_to_command(cmd, _hex(STATISTICS[scope][data['parameter_name']]))
if scope == 'global':
data['policy_id'] = 0x00 # will be ignored
# case for "special" Node Manager global parameters (Mode 0x1B - 0x1F)
@ -506,7 +505,7 @@ def parse_statistics(raw_data):
else:
statistics['timestamp'] = isotime
statistics['domain_id'] = INTEL_NM_DOMAINS_REV[raw_int[19] & 0x0F]
statistics['domain_id'] = DOMAINS_REV[raw_int[19] & 0x0F]
statistics['administrative_enabled'] = bool(raw_int[19] & 0x10)
statistics['operational_state'] = bool(raw_int[19] & 0x20)
statistics['measurement_state'] = bool(raw_int[19] & 0x40)

View File

@ -200,7 +200,7 @@ class IntelNMVendorPassthru(base.VendorInterface):
_('Parameter name is mandatory for getting statistics'))
# valid parameters depend on scope
if (kwargs['parameter_name'] not in
nm_commands.INTEL_NM_STATISTICS[kwargs['scope']]):
nm_commands.STATISTICS[kwargs['scope']]):
raise exception.InvalidParameterValue(
_('Invalid parameter name %(param)% for scope '
'%(scope)s') % {'param': kwargs['parameter_name'],