2
0
mirror of https://opendev.org/x/pyghmi synced 2025-01-27 19:37:44 +00:00

Manage NTP configuration of ThinkSystem D2 SMM

This provides access to the NTP configuration of SMMs so that
API and CLI can manipulate it.

Change-Id: I896df6b254b2838d8ec89c56d07245ae4dd03bff
This commit is contained in:
Jarrod Johnson 2017-08-17 11:04:11 -04:00
parent 9f8984d254
commit cbc1445d7c
2 changed files with 56 additions and 1 deletions

View File

@ -251,6 +251,8 @@ class OEMHandler(generic.OEMHandler):
if self.has_tsm:
ntpres = self.ipmicmd.xraw_command(netfn=0x32, command=0xa7)
return ntpres['data'][0] == '\x01'
elif self.is_fpc:
return self.smmhandler.get_ntp_enabled(self._fpc_variant)
return None
def get_ntp_servers(self):
@ -260,6 +262,8 @@ class OEMHandler(generic.OEMHandler):
srvs.append(ntpres['data'][1:129].rstrip('\x00'))
srvs.append(ntpres['data'][129:257].rstrip('\x00'))
return srvs
if self.is_fpc:
return self.smmhandler.get_ntp_servers()
return None
def set_ntp_enabled(self, enabled):
@ -271,6 +275,9 @@ class OEMHandler(generic.OEMHandler):
self.ipmicmd.xraw_command(
netfn=0x32, command=0xa8, data=(3, 0), timeout=15)
return True
if self.is_fpc:
self.smmhandler.set_ntp_enabled(enabled)
return True
return None
def set_ntp_server(self, server, index=0):
@ -281,6 +288,12 @@ class OEMHandler(generic.OEMHandler):
cmddata += server.ljust(128, '\x00')
self.ipmicmd.xraw_command(netfn=0x32, command=0xa8, data=cmddata)
return True
elif self.is_fpc:
if not 0 <= index <= 2:
raise pygexc.InvalidParameterValue(
'SMM supports indexes 0 through 2')
self.smmhandler.set_ntp_server(server, index)
return True
return None
@property

View File

@ -274,6 +274,48 @@ class SMMClient(object):
wc.set_header('ST2', self.st2)
return wc
def get_ntp_enabled(self, variant):
self.wc.request('POST', '/data', 'get=ntpOpMode')
rsp = self.wc.getresponse()
info = fromstring(rsp.read())
self.logout()
for data in info.findall('ntpOpMode'):
return data.text == '1'
def set_ntp_enabled(self, enabled):
self.wc.request('POST', '/data', 'set=ntpOpMode:{0}'.format(
1 if enabled else 0))
rsp = self.wc.getresponse()
result = rsp.read()
self.logout()
if '<status>ok</status>' not in result:
raise Exception("Unrecognized result: " + result)
def set_ntp_server(self, server, index):
self.wc.request('POST', '/data', 'set=ntpServer{0}:{1}'.format(
index + 1, server))
rsp = self.wc.getresponse()
result = rsp.read()
if '<status>ok</status>' not in result:
raise Exception("Unrecognized result: " + result)
self.logout()
return True
def get_ntp_servers(self):
self.wc.request(
'POST', '/data', 'get=ntpServer1,ntpServer2,ntpServer3')
rsp = self.wc.getresponse()
result = fromstring(rsp.read())
srvs = []
for data in result.findall('ntpServer1'):
srvs.append(data.text)
for data in result.findall('ntpServer2'):
srvs.append(data.text)
for data in result.findall('ntpServer3'):
srvs.append(data.text)
self.logout()
return srvs
def update_firmware(self, filename, data=None, progress=None, bank=None):
if progress is None:
progress = lambda x: True
@ -285,7 +327,7 @@ class SMMClient(object):
data = z.open(filename)
break
progress({'phase': 'upload', 'progress': 0.0})
url = self.wc
url = self.wc # this is just to get self.st1 initted
url = '/fwupload/fwupload.esp?ST1={0}'.format(self.st1)
self.wc.upload(url, filename, data, formname='fileUpload',
otherfields={'preConfig': 'on'})