mirror of
https://opendev.org/x/pyghmi
synced 2025-01-27 19:37:44 +00:00
Prepare to switch to flake8 - 05
Final wave of changes to prepare to migrate to flake8 tests. Change-Id: I75c3acfc8b0ab34b82faf7b500ec9c27aa3efa91
This commit is contained in:
parent
e665ced5b4
commit
4f9103d5a7
@ -1,4 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -12,24 +11,26 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
# __author__ = 'jjohnson2@lenovo.com'
|
||||
|
||||
# this is a quick sample of how to write something that acts like a bmc
|
||||
# to play:
|
||||
# run fakebmc
|
||||
# # ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power status
|
||||
# Chassis Power is off
|
||||
# # ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power on
|
||||
# Chassis Power Control: Up/On
|
||||
# # ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power status
|
||||
# Chassis Power is on
|
||||
# # ipmitool -I lanplus -U admin -P password -H 127.0.0.1 mc reset cold
|
||||
# Sent cold reset command to MC
|
||||
# (fakebmc exits)
|
||||
"""this is a quick sample of how to write something that acts like a bmc
|
||||
to play:
|
||||
run fakebmc
|
||||
# ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power status
|
||||
Chassis Power is off
|
||||
# ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power on
|
||||
Chassis Power Control: Up/On
|
||||
# ipmitool -I lanplus -U admin -P password -H 127.0.0.1 power status
|
||||
Chassis Power is on
|
||||
# ipmitool -I lanplus -U admin -P password -H 127.0.0.1 mc reset cold
|
||||
Sent cold reset command to MC
|
||||
(fakebmc exits)
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import pyghmi.ipmi.bmc as bmc
|
||||
import sys
|
||||
|
||||
import pyghmi.ipmi.bmc as bmc
|
||||
|
||||
|
||||
class FakeBmc(bmc.Bmc):
|
||||
def __init__(self, authdata, port):
|
||||
|
@ -22,9 +22,8 @@ import termios
|
||||
import threading
|
||||
import tty
|
||||
|
||||
from six import string_types
|
||||
|
||||
from pyghmi.ipmi import console
|
||||
import six
|
||||
|
||||
|
||||
def _doinput(sol):
|
||||
@ -42,7 +41,7 @@ def _doinput(sol):
|
||||
|
||||
def _print(data):
|
||||
bailout = False
|
||||
if not isinstance(data, string_types):
|
||||
if not isinstance(data, six.string_types):
|
||||
bailout = True
|
||||
data = repr(data)
|
||||
sys.stdout.write(data)
|
||||
|
@ -1,4 +1,3 @@
|
||||
#!/usr/bin/env python
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@ -11,18 +10,17 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# Written by pmartini2, but mostly a clone of fakebmc, written by jjohnson2
|
||||
# __author__ = 'pmartini2@bloomberg.net'
|
||||
|
||||
# This is a simple, but working proof of concept of using pyghmi.ipmi.bmc to
|
||||
# control a VM
|
||||
"""This is a simple, but working proof of concept of using pyghmi.ipmi.bmc to
|
||||
control a VM
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import libvirt
|
||||
import pyghmi.ipmi.bmc as bmc
|
||||
import sys
|
||||
import threading
|
||||
|
||||
import libvirt
|
||||
import pyghmi.ipmi.bmc as bmc
|
||||
|
||||
|
||||
def lifecycle_callback(connection, domain, event, detail, console):
|
||||
console.state = console.domain.state(0)
|
||||
|
@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -55,16 +53,15 @@ class EntryField(object):
|
||||
|
||||
# General parameter parsing functions
|
||||
def parse_inventory_category(name, info, countable=True):
|
||||
"""Parses every entry in an inventory category (CPU, memory, PCI, drives,
|
||||
etc).
|
||||
"""Parses every entry in an inventory category
|
||||
|
||||
For example: CPU, memory, PCI, drives
|
||||
Expects the first byte to be a count of the number of entries, followed
|
||||
by a list of elements to be parsed by a dedicated parser (below).
|
||||
|
||||
:param name: the name of the parameter (e.g.: "cpu")
|
||||
:param info: a list of integers with raw data read from an IPMI requests
|
||||
:param countable: whether the data have an entries count field
|
||||
|
||||
:returns: dict -- a list of entries in the category.
|
||||
"""
|
||||
raw = info["data"][1:]
|
||||
|
@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2016-2017 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,19 +12,22 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import struct
|
||||
import weakref
|
||||
from xml.etree.ElementTree import fromstring
|
||||
import zipfile
|
||||
|
||||
import pyghmi.constants as pygconst
|
||||
import pyghmi.exceptions as pygexc
|
||||
import pyghmi.ipmi.private.session as ipmisession
|
||||
from pyghmi.ipmi import sdr
|
||||
import pyghmi.util.webclient as webclient
|
||||
import struct
|
||||
import six
|
||||
|
||||
try:
|
||||
from urllib import urlencode
|
||||
except ImportError:
|
||||
from urllib.parse import urlencode
|
||||
import weakref
|
||||
from xml.etree.ElementTree import fromstring
|
||||
import zipfile
|
||||
|
||||
try:
|
||||
range = xrange
|
||||
@ -280,8 +281,9 @@ class SMMClient(object):
|
||||
self.wc.request(
|
||||
'POST', '/data',
|
||||
('get=passwordMinLength,passwordForceChange,passwordDurationDays,'
|
||||
'passwordExpireWarningDays,passwordChangeInterval,'
|
||||
'passwordReuseCheckNum,passwordFailAllowdNum,passwordLockoutTimePeriod'))
|
||||
'passwordExpireWarningDays,passwordChangeInterval,'
|
||||
'passwordReuseCheckNum,passwordFailAllowdNum,'
|
||||
'passwordLockoutTimePeriod'))
|
||||
rsp = self.wc.getresponse()
|
||||
rspbody = rsp.read()
|
||||
accountinfo = fromstring(rspbody)
|
||||
@ -301,12 +303,10 @@ class SMMClient(object):
|
||||
'possible': [self.fanmodes[x] for x in self.fanmodes]}
|
||||
return settings
|
||||
|
||||
|
||||
def set_bmc_configuration(self, changeset):
|
||||
rules = []
|
||||
for key in changeset:
|
||||
if (isinstance(changeset[key], str) or
|
||||
isinstance(changeset[key], unicode)):
|
||||
if isinstance(changeset[key], six.string_types):
|
||||
changeset[key] = {'value': changeset[key]}
|
||||
if key.lower() in self.rulemap:
|
||||
rules.append('{0}:{1}'.format(
|
||||
@ -321,8 +321,8 @@ class SMMClient(object):
|
||||
break
|
||||
else:
|
||||
raise pygexc.InvalidParameterValue(
|
||||
'{0} not a valid mode for fanspeed'.format(
|
||||
changeset[key]['value']))
|
||||
'{0} not a valid mode for fanspeed'.format(
|
||||
changeset[key]['value']))
|
||||
if rules:
|
||||
rules = 'set={0}'.format(','.join(rules))
|
||||
self.wc.request('POST', '/data', rules)
|
||||
@ -352,7 +352,7 @@ class SMMClient(object):
|
||||
rsp['data'] = b'\x01'
|
||||
initpct = 1.0
|
||||
if progress:
|
||||
progress({'phase': 'initializing', 'progress': initpct})
|
||||
progress({'phase': 'initializing', 'progress': initpct})
|
||||
while bytearray(rsp['data'])[0] != 0:
|
||||
ipmisession.Session.pause(3)
|
||||
initpct += 3.0
|
||||
@ -389,8 +389,12 @@ class SMMClient(object):
|
||||
cv = self.ipmicmd.certverify
|
||||
wc = webclient.SecureHTTPConnection(self.smm, 443, verifycallback=cv)
|
||||
wc.connect()
|
||||
loginform = urlencode({'user': self.username,
|
||||
'password': self.password})
|
||||
loginform = urlencode(
|
||||
{
|
||||
'user': self.username,
|
||||
'password': self.password
|
||||
}
|
||||
)
|
||||
wc.request('POST', '/data/login', loginform)
|
||||
rsp = wc.getresponse()
|
||||
if rsp.status != 200:
|
||||
|
@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,12 +12,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from pyghmi.ipmi.oem.lenovo.inventory import EntryField, \
|
||||
parse_inventory_category_entry
|
||||
from pyghmi.ipmi.oem.lenovo import inventory
|
||||
|
||||
pci_fields = (
|
||||
EntryField("index", "B"),
|
||||
EntryField("PCIType", "B", mapper={
|
||||
inventory.EntryField("index", "B"),
|
||||
inventory.EntryField("PCIType", "B", mapper={
|
||||
0x0: "On board slot",
|
||||
0x1: "Riser Type 1",
|
||||
0x2: "Riser Type 2",
|
||||
@ -31,23 +28,23 @@ pci_fields = (
|
||||
0x8: "ROC",
|
||||
0x9: "Mezz"
|
||||
}),
|
||||
EntryField("BusNumber", "B"),
|
||||
EntryField("DeviceFunction", "B"),
|
||||
EntryField("VendorID", "<H"),
|
||||
EntryField("DeviceID", "<H"),
|
||||
EntryField("SubSystemVendorID", "<H"),
|
||||
EntryField("SubSystemID", "<H"),
|
||||
EntryField("InterfaceType", "B"),
|
||||
EntryField("SubClassCode", "B"),
|
||||
EntryField("BaseClassCode", "B"),
|
||||
EntryField("LinkSpeed", "B"),
|
||||
EntryField("LinkWidth", "B"),
|
||||
EntryField("Reserved", "h")
|
||||
inventory.EntryField("BusNumber", "B"),
|
||||
inventory.EntryField("DeviceFunction", "B"),
|
||||
inventory.EntryField("VendorID", "<H"),
|
||||
inventory.EntryField("DeviceID", "<H"),
|
||||
inventory.EntryField("SubSystemVendorID", "<H"),
|
||||
inventory.EntryField("SubSystemID", "<H"),
|
||||
inventory.EntryField("InterfaceType", "B"),
|
||||
inventory.EntryField("SubClassCode", "B"),
|
||||
inventory.EntryField("BaseClassCode", "B"),
|
||||
inventory.EntryField("LinkSpeed", "B"),
|
||||
inventory.EntryField("LinkWidth", "B"),
|
||||
inventory.EntryField("Reserved", "h")
|
||||
)
|
||||
|
||||
|
||||
def parse_pci_info(raw):
|
||||
return parse_inventory_category_entry(raw, pci_fields)
|
||||
return inventory.parse_inventory_category_entry(raw, pci_fields)
|
||||
|
||||
|
||||
def get_categories():
|
||||
|
@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,8 +12,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from pyghmi.ipmi.oem.lenovo.inventory import EntryField, \
|
||||
parse_inventory_category_entry
|
||||
from pyghmi.ipmi.oem.lenovo import inventory
|
||||
|
||||
|
||||
psu_type = {
|
||||
0b0001: "Other",
|
||||
@ -45,59 +43,49 @@ psu_voltage_range_switch = {
|
||||
|
||||
|
||||
def psu_status_word_slice(w, s, e):
|
||||
return int(w[-e-1:-s], 2)
|
||||
return int(w[-e - 1:-s], 2)
|
||||
|
||||
|
||||
def psu_status_word_bit(w, b):
|
||||
return int(w[-b-1])
|
||||
return int(w[-b - 1])
|
||||
|
||||
|
||||
def psu_status_word_parser(word):
|
||||
fields = {}
|
||||
word = "{0:016b}".format(word)
|
||||
|
||||
fields["DMTF Power Supply Type"] = \
|
||||
psu_type.get(psu_status_word_slice(word, 10, 13), "Invalid")
|
||||
fields["DMTF Power Supply Type"] = psu_type.get(psu_status_word_slice(
|
||||
word, 10, 13), "Invalid")
|
||||
|
||||
# fields["Status"] = \
|
||||
# psu_status.get(psu_status_word_slice(word, 7, 9), "Invalid")
|
||||
|
||||
fields["DMTF Input Voltage Range"] = \
|
||||
psu_voltage_range_switch.get(
|
||||
psu_status_word_slice(word, 3, 6),
|
||||
"Invalid"
|
||||
)
|
||||
fields["DMTF Input Voltage Range"] = psu_voltage_range_switch.get(
|
||||
psu_status_word_slice(word, 3, 6), "Invalid")
|
||||
|
||||
# Power supply is unplugged from the wall
|
||||
fields["Unplugged"] = \
|
||||
bool(psu_status_word_bit(word, 2))
|
||||
|
||||
# fields["Power supply is present"] = \
|
||||
# bool(psu_status_word_bit(word, 1))
|
||||
fields["Unplugged"] = bool(psu_status_word_bit(word, 2))
|
||||
|
||||
# Power supply is hot-replaceable
|
||||
fields["Hot Replaceable"] = \
|
||||
bool(psu_status_word_bit(word, 0))
|
||||
fields["Hot Replaceable"] = bool(psu_status_word_bit(word, 0))
|
||||
|
||||
return fields
|
||||
|
||||
|
||||
psu_fields = (
|
||||
EntryField("index", "B"),
|
||||
EntryField("Presence State", "B", presence=True),
|
||||
EntryField("Capacity W", "<H"),
|
||||
EntryField("Board manufacturer", "18s"),
|
||||
EntryField("Board model", "18s"),
|
||||
EntryField("Board manufacture date", "10s"),
|
||||
EntryField("Board serial number", "34s"),
|
||||
EntryField("Board manufacturer revision", "5s"),
|
||||
EntryField("Board product name", "10s"),
|
||||
EntryField("PSU Asset Tag", "10s"),
|
||||
EntryField(
|
||||
inventory.EntryField("index", "B"),
|
||||
inventory.EntryField("Presence State", "B", presence=True),
|
||||
inventory.EntryField("Capacity W", "<H"),
|
||||
inventory.EntryField("Board manufacturer", "18s"),
|
||||
inventory.EntryField("Board model", "18s"),
|
||||
inventory.EntryField("Board manufacture date", "10s"),
|
||||
inventory.EntryField("Board serial number", "34s"),
|
||||
inventory.EntryField("Board manufacturer revision", "5s"),
|
||||
inventory.EntryField("Board product name", "10s"),
|
||||
inventory.EntryField("PSU Asset Tag", "10s"),
|
||||
inventory.EntryField(
|
||||
"PSU Redundancy Status",
|
||||
"B",
|
||||
valuefunc=lambda v: "Not redundant" if v == 0x00 else "Redundant"
|
||||
),
|
||||
EntryField(
|
||||
inventory.EntryField(
|
||||
"PSU Status Word",
|
||||
"<H",
|
||||
valuefunc=psu_status_word_parser, multivaluefunc=True
|
||||
@ -106,7 +94,7 @@ psu_fields = (
|
||||
|
||||
|
||||
def parse_psu_info(raw):
|
||||
return parse_inventory_category_entry(raw, psu_fields)
|
||||
return inventory.parse_inventory_category_entry(raw, psu_fields)
|
||||
|
||||
|
||||
def get_categories():
|
||||
|
@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,40 +12,41 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from pyghmi.ipmi.oem.lenovo.inventory import EntryField, \
|
||||
parse_inventory_category_entry
|
||||
from pyghmi.ipmi.oem.lenovo import inventory
|
||||
|
||||
|
||||
raid_controller_fields = (
|
||||
EntryField("ControllerID", "I"),
|
||||
EntryField("AdapterType", "B", mapper={
|
||||
inventory.EntryField("ControllerID", "I"),
|
||||
inventory.EntryField("AdapterType", "B", mapper={
|
||||
0x00: "Unknown",
|
||||
0x01: "RAIDController"
|
||||
}),
|
||||
EntryField("SupercapPresence", "B", mapper={
|
||||
inventory.EntryField("SupercapPresence", "B", mapper={
|
||||
0x00: "Absent",
|
||||
0x01: "Present"
|
||||
}),
|
||||
EntryField("FlashComponent1Name", "16s"),
|
||||
EntryField("FlashComponent1Version", "64s"),
|
||||
EntryField("FlashComponent2Name", "16s"),
|
||||
EntryField("FlashComponent2Version", "64s"),
|
||||
EntryField("FlashComponent3Name", "16s"),
|
||||
EntryField("FlashComponent3Version", "64s"),
|
||||
EntryField("FlashComponent4Name", "16s"),
|
||||
EntryField("FlashComponent4Version", "64s"),
|
||||
EntryField("FlashComponent5Name", "16s"),
|
||||
EntryField("FlashComponent5Version", "64s"),
|
||||
EntryField("FlashComponent6Name", "16s"),
|
||||
EntryField("FlashComponent6Version", "64s"),
|
||||
EntryField("FlashComponent7Name", "16s"),
|
||||
EntryField("FlashComponent7Version", "64s"),
|
||||
EntryField("FlashComponent8Name", "16s"),
|
||||
EntryField("FlashComponent8Version", "64s")
|
||||
inventory.EntryField("FlashComponent1Name", "16s"),
|
||||
inventory.EntryField("FlashComponent1Version", "64s"),
|
||||
inventory.EntryField("FlashComponent2Name", "16s"),
|
||||
inventory.EntryField("FlashComponent2Version", "64s"),
|
||||
inventory.EntryField("FlashComponent3Name", "16s"),
|
||||
inventory.EntryField("FlashComponent3Version", "64s"),
|
||||
inventory.EntryField("FlashComponent4Name", "16s"),
|
||||
inventory.EntryField("FlashComponent4Version", "64s"),
|
||||
inventory.EntryField("FlashComponent5Name", "16s"),
|
||||
inventory.EntryField("FlashComponent5Version", "64s"),
|
||||
inventory.EntryField("FlashComponent6Name", "16s"),
|
||||
inventory.EntryField("FlashComponent6Version", "64s"),
|
||||
inventory.EntryField("FlashComponent7Name", "16s"),
|
||||
inventory.EntryField("FlashComponent7Version", "64s"),
|
||||
inventory.EntryField("FlashComponent8Name", "16s"),
|
||||
inventory.EntryField("FlashComponent8Version", "64s")
|
||||
)
|
||||
|
||||
|
||||
def parse_raid_controller_info(raw):
|
||||
return parse_inventory_category_entry(raw, raid_controller_fields)
|
||||
return inventory.parse_inventory_category_entry(
|
||||
raw, raid_controller_fields)
|
||||
|
||||
|
||||
def get_categories():
|
||||
|
@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,41 +12,41 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from pyghmi.ipmi.oem.lenovo.inventory import EntryField, \
|
||||
parse_inventory_category_entry
|
||||
from pyghmi.ipmi.oem.lenovo import inventory
|
||||
|
||||
|
||||
raid_drive_fields = (
|
||||
EntryField("index", "B"),
|
||||
EntryField("VendorID", "64s"),
|
||||
EntryField("Size", "I",
|
||||
valuefunc=lambda v: str(v) + " MB"),
|
||||
EntryField("MediaType", "B", mapper={
|
||||
inventory.EntryField("index", "B"),
|
||||
inventory.EntryField("VendorID", "64s"),
|
||||
inventory.EntryField("Size", "I",
|
||||
valuefunc=lambda v: str(v) + " MB"),
|
||||
inventory.EntryField("MediaType", "B", mapper={
|
||||
0x00: "HDD",
|
||||
0x01: "SSD",
|
||||
0x02: "SSM_FLASH"
|
||||
}),
|
||||
EntryField("InterfaceType", "B", mapper={
|
||||
inventory.EntryField("InterfaceType", "B", mapper={
|
||||
0x00: "Unknown",
|
||||
0x01: "ParallelSCSI",
|
||||
0x02: "SAS",
|
||||
0x03: "SATA",
|
||||
0x04: "FC"
|
||||
}),
|
||||
EntryField("FormFactor", "B", mapper={
|
||||
inventory.EntryField("FormFactor", "B", mapper={
|
||||
0x00: "Unknown",
|
||||
0x01: "2.5in",
|
||||
0x02: "3.5in"
|
||||
}),
|
||||
EntryField("LinkSpeed", "B", mapper={
|
||||
inventory.EntryField("LinkSpeed", "B", mapper={
|
||||
0x00: "Unknown",
|
||||
0x01: "1.5 Gb/s",
|
||||
0x02: "3.0 Gb/s",
|
||||
0x03: "6.0 Gb/s",
|
||||
0x04: "12.0 Gb/s"
|
||||
}),
|
||||
EntryField("SlotNumber", "B"),
|
||||
EntryField("ControllerIndex", "B"),
|
||||
EntryField("DeviceState", "B", mapper={
|
||||
inventory.EntryField("SlotNumber", "B"),
|
||||
inventory.EntryField("ControllerIndex", "B"),
|
||||
inventory.EntryField("DeviceState", "B", mapper={
|
||||
0x00: "active",
|
||||
0x01: "stopped",
|
||||
0xff: "transitioning"
|
||||
@ -56,7 +54,7 @@ raid_drive_fields = (
|
||||
|
||||
|
||||
def parse_raid_drive_info(raw):
|
||||
return parse_inventory_category_entry(raw, raid_drive_fields)
|
||||
return inventory.parse_inventory_category_entry(raw, raid_drive_fields)
|
||||
|
||||
|
||||
def get_categories():
|
||||
|
@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2013 IBM Corporation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -1879,9 +1877,9 @@ ipmi_completion_codes = {
|
||||
}
|
||||
|
||||
priv_levels = {
|
||||
'callback': 1,
|
||||
'user': 2,
|
||||
'operator': 3,
|
||||
'admin': 4,
|
||||
'oem': 5,
|
||||
}
|
||||
'callback': 1,
|
||||
'user': 2,
|
||||
'operator': 3,
|
||||
'admin': 4,
|
||||
'oem': 5,
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2017 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,53 +12,55 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from ctypes import addressof, c_int, c_long, c_short, c_ubyte, c_uint
|
||||
from ctypes import cast, create_string_buffer, POINTER, pointer, sizeof
|
||||
from ctypes import Structure
|
||||
import ctypes
|
||||
import fcntl
|
||||
import pyghmi.ipmi.private.util as iutil
|
||||
from select import select
|
||||
|
||||
|
||||
class IpmiMsg(Structure):
|
||||
_fields_ = [('netfn', c_ubyte),
|
||||
('cmd', c_ubyte),
|
||||
('data_len', c_short),
|
||||
('data', POINTER(c_ubyte))]
|
||||
import pyghmi.ipmi.private.util as iutil
|
||||
|
||||
|
||||
class IpmiSystemInterfaceAddr(Structure):
|
||||
_fields_ = [('addr_type', c_int),
|
||||
('channel', c_short),
|
||||
('lun', c_ubyte)]
|
||||
class IpmiMsg(ctypes.Structure):
|
||||
_fields_ = [('netfn', ctypes.c_ubyte),
|
||||
('cmd', ctypes.c_ubyte),
|
||||
('data_len', ctypes.c_short),
|
||||
('data', ctypes.POINTER(ctypes.c_ubyte))]
|
||||
|
||||
|
||||
class IpmiRecv(Structure):
|
||||
_fields_ = [('recv_type', c_int),
|
||||
('addr', POINTER(IpmiSystemInterfaceAddr)),
|
||||
('addr_len', c_uint),
|
||||
('msgid', c_long),
|
||||
class IpmiSystemInterfaceAddr(ctypes.Structure):
|
||||
_fields_ = [('addr_type', ctypes.c_int),
|
||||
('channel', ctypes.c_short),
|
||||
('lun', ctypes.c_ubyte)]
|
||||
|
||||
|
||||
class IpmiRecv(ctypes.Structure):
|
||||
_fields_ = [('recv_type', ctypes.c_int),
|
||||
('addr', ctypes.POINTER(IpmiSystemInterfaceAddr)),
|
||||
('addr_len', ctypes.c_uint),
|
||||
('msgid', ctypes.c_long),
|
||||
('msg', IpmiMsg)]
|
||||
|
||||
|
||||
class IpmiReq(Structure):
|
||||
_fields_ = [('addr', POINTER(IpmiSystemInterfaceAddr)),
|
||||
('addr_len', c_uint),
|
||||
('msgid', c_long),
|
||||
class IpmiReq(ctypes.Structure):
|
||||
_fields_ = [('addr', ctypes.POINTER(IpmiSystemInterfaceAddr)),
|
||||
('addr_len', ctypes.c_uint),
|
||||
('msgid', ctypes.c_long),
|
||||
('msg', IpmiMsg)]
|
||||
|
||||
|
||||
_IONONE = 0
|
||||
_IOWRITE = 1
|
||||
_IOREAD = 2
|
||||
IPMICTL_SET_MY_ADDRESS_CMD = _IOREAD << 30 | sizeof(c_uint) << 16 | \
|
||||
ord('i') << 8 | 17 # from ipmi.h
|
||||
IPMICTL_SEND_COMMAND = _IOREAD << 30 | sizeof(IpmiReq) << 16 | \
|
||||
ord('i') << 8 | 13 # from ipmi.h
|
||||
IPMICTL_SET_MY_ADDRESS_CMD = (_IOREAD << 30 |
|
||||
ctypes.sizeof(ctypes.c_uint) << 16 |
|
||||
ord('i') << 8 | 17) # from ipmi.h
|
||||
IPMICTL_SEND_COMMAND = (_IOREAD << 30 |
|
||||
ctypes.sizeof(IpmiReq) << 16 |
|
||||
ord('i') << 8 | 13) # from ipmi.h
|
||||
# next is really IPMICTL_RECEIVE_MSG_TRUNC, but will only use that
|
||||
IPMICTL_RECV = (_IOWRITE | _IOREAD) << 30 | sizeof(IpmiRecv) << 16 | \
|
||||
ord('i') << 8 | 11 # from ipmi.h
|
||||
BMC_SLAVE_ADDR = c_uint(0x20)
|
||||
IPMICTL_RECV = ((_IOWRITE | _IOREAD) << 30 |
|
||||
ctypes.sizeof(IpmiRecv) << 16 |
|
||||
ord('i') << 8 | 11) # from ipmi.h
|
||||
BMC_SLAVE_ADDR = ctypes.c_uint(0x20)
|
||||
CURRCHAN = 0xf
|
||||
ADDRTYPE = 0xc
|
||||
|
||||
@ -74,11 +74,13 @@ class Session(object):
|
||||
self.ipmidev = open(devnode, 'rw')
|
||||
fcntl.ioctl(self.ipmidev, IPMICTL_SET_MY_ADDRESS_CMD, BMC_SLAVE_ADDR)
|
||||
# the interface is initted, create some reusable memory for our session
|
||||
self.databuffer = create_string_buffer(4096)
|
||||
self.datactypes.buffer = ctypes.create_string_ctypes.buffer(4096)
|
||||
self.req = IpmiReq()
|
||||
self.rsp = IpmiRecv()
|
||||
self.addr = IpmiSystemInterfaceAddr()
|
||||
self.req.msg.data = cast(addressof(self.databuffer), POINTER(c_ubyte))
|
||||
self.req.msg.data = ctypes.cast(
|
||||
ctypes.addressof(self.datactypes.buffer),
|
||||
ctypes.POINTER(ctypes.c_ubyte))
|
||||
self.rsp.msg.data = self.req.msg.data
|
||||
self.userid = None
|
||||
self.password = None
|
||||
@ -91,9 +93,9 @@ class Session(object):
|
||||
@property
|
||||
def parsed_rsp(self):
|
||||
response = {'netfn': self.rsp.msg.netfn, 'command': self.rsp.msg.cmd,
|
||||
'code': ord(self.databuffer.raw[0]),
|
||||
'code': ord(self.datactypes.buffer.raw[0]),
|
||||
'data': list(bytearray(
|
||||
self.databuffer.raw[1:self.rsp.msg.data_len]))}
|
||||
self.datactypes.buffer.raw[1:self.rsp.msg.data_len]))}
|
||||
errorstr = iutil.get_ipmi_error(response)
|
||||
if errorstr:
|
||||
response['error'] = errorstr
|
||||
@ -110,18 +112,18 @@ class Session(object):
|
||||
waitall=False):
|
||||
self.addr.channel = CURRCHAN
|
||||
self.addr.addr_type = ADDRTYPE
|
||||
self.req.addr_len = sizeof(IpmiSystemInterfaceAddr)
|
||||
self.req.addr = pointer(self.addr)
|
||||
self.req.addr_len = ctypes.sizeof(IpmiSystemInterfaceAddr)
|
||||
self.req.addr = ctypes.pointer(self.addr)
|
||||
self.req.msg.netfn = netfn
|
||||
self.req.msg.cmd = command
|
||||
data = buffer(bytearray(data))
|
||||
self.databuffer[:len(data)] = data[:len(data)]
|
||||
data = ctypes.buffer(bytearray(data))
|
||||
self.datactypes.buffer[:len(data)] = data[:len(data)]
|
||||
self.req.msg.data_len = len(data)
|
||||
fcntl.ioctl(self.ipmidev, IPMICTL_SEND_COMMAND, self.req)
|
||||
self.await_reply()
|
||||
self.rsp.msg.data_len = 4096
|
||||
self.rsp.addr = pointer(self.addr)
|
||||
self.rsp.addr_len = sizeof(IpmiSystemInterfaceAddr)
|
||||
self.rsp.addr = ctypes.pointer(self.addr)
|
||||
self.rsp.addr_len = ctypes.sizeof(IpmiSystemInterfaceAddr)
|
||||
fcntl.ioctl(self.ipmidev, IPMICTL_RECV, self.rsp)
|
||||
return self.parsed_rsp
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2015 Lenovo
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,19 +12,22 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# This represents the server side of a session object
|
||||
# Split into a separate file to avoid overly manipulating the as-yet
|
||||
# client-centered session object
|
||||
"""This represents the server side of a session object
|
||||
Split into a separate file to avoid overly manipulating the as-yet
|
||||
client-centered session object
|
||||
"""
|
||||
|
||||
import collections
|
||||
import hashlib
|
||||
import hmac
|
||||
import os
|
||||
import pyghmi.ipmi.private.constants as constants
|
||||
import pyghmi.ipmi.private.session as ipmisession
|
||||
import socket
|
||||
import struct
|
||||
import uuid
|
||||
|
||||
import pyghmi.ipmi.private.constants as constants
|
||||
import pyghmi.ipmi.private.session as ipmisession
|
||||
|
||||
|
||||
class ServerSession(ipmisession.Session):
|
||||
def __new__(cls, authdata, kg, clientaddr, netsocket, request, uuid,
|
||||
|
@ -26,12 +26,10 @@ import socket
|
||||
import struct
|
||||
import threading
|
||||
|
||||
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
from cryptography.hazmat.primitives.ciphers import algorithms
|
||||
from cryptography.hazmat.primitives.ciphers import Cipher
|
||||
from cryptography.hazmat.primitives.ciphers import modes
|
||||
|
||||
import pyghmi.exceptions as exc
|
||||
from pyghmi.ipmi.private import constants
|
||||
from pyghmi.ipmi.private import util
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from dateutil import tz
|
||||
|
||||
|
||||
|
@ -19,22 +19,21 @@
|
||||
import base64
|
||||
import copy
|
||||
import gzip
|
||||
import io
|
||||
import json
|
||||
import pyghmi.exceptions as pygexc
|
||||
import socket
|
||||
import ssl
|
||||
import threading
|
||||
|
||||
import pyghmi.exceptions as pygexc
|
||||
import six
|
||||
|
||||
try:
|
||||
import Cookie
|
||||
import httplib
|
||||
except ImportError:
|
||||
import http.client as httplib
|
||||
import http.cookies as Cookie
|
||||
import io
|
||||
import six
|
||||
|
||||
__author__ = 'jjohnson2'
|
||||
|
||||
|
||||
# Used as the separator for form data
|
||||
|
Loading…
x
Reference in New Issue
Block a user