From 2f31a94c9ea8326ee4cb8d4c49617bda126d8eef Mon Sep 17 00:00:00 2001 From: Allan Vidal Date: Wed, 25 Nov 2015 17:41:50 -0200 Subject: [PATCH] Add support for TS graphical console fetching Change-Id: I89ecff86d8b6f264764128d7ec327985a76545b0 --- bin/pyghmiutil | 2 ++ pyghmi/ipmi/command.py | 5 +++ pyghmi/ipmi/oem/generic.py | 4 +++ pyghmi/ipmi/oem/lenovo/handler.py | 56 ++++++++++++++++++++++++++++++- 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/bin/pyghmiutil b/bin/pyghmiutil index 4b789d85..0a7b8211 100755 --- a/bin/pyghmiutil +++ b/bin/pyghmiutil @@ -70,6 +70,8 @@ def docommand(result, ipmisession): elif cmmand == 'leds': for led in ipmisession.get_leds(): print repr(led) + elif cmmand == 'graphical': + print ipmisession.get_graphical_console() elif cmmand == 'raw': print ipmisession.raw_command(netfn=int(args[0]), command=int(args[1]), diff --git a/pyghmi/ipmi/command.py b/pyghmi/ipmi/command.py index d1d7b058..ce4bb2cf 100644 --- a/pyghmi/ipmi/command.py +++ b/pyghmi/ipmi/command.py @@ -1702,3 +1702,8 @@ class Command(object): """ self.oem_init() self._oem.set_oem_domain_name(name) + + def get_graphical_console(self): + """Get graphical console launcher""" + self.oem_init() + return self._oem.get_graphical_console() diff --git a/pyghmi/ipmi/oem/generic.py b/pyghmi/ipmi/oem/generic.py index 85eb1042..9db559f9 100644 --- a/pyghmi/ipmi/oem/generic.py +++ b/pyghmi/ipmi/oem/generic.py @@ -208,3 +208,7 @@ class OEMHandler(object): :param name: domain name to be set """ return () + + def get_graphical_console(self): + """Get graphical console launcher""" + return () diff --git a/pyghmi/ipmi/oem/lenovo/handler.py b/pyghmi/ipmi/oem/lenovo/handler.py index beeca683..2b736fb8 100755 --- a/pyghmi/ipmi/oem/lenovo/handler.py +++ b/pyghmi/ipmi/oem/lenovo/handler.py @@ -15,6 +15,7 @@ # limitations under the License. import traceback +import urllib import pyghmi.constants as pygconst import pyghmi.exceptions as pygexc @@ -34,7 +35,7 @@ from pyghmi.ipmi.oem.lenovo import psu from pyghmi.ipmi.oem.lenovo import raid_controller from pyghmi.ipmi.oem.lenovo import raid_drive -#import pyghmi.util.webclient as wc +import pyghmi.util.webclient as wc inventory.register_inventory_category(cpu) inventory.register_inventory_category(dimm) @@ -465,3 +466,56 @@ class OEMHandler(generic.OEMHandler): self._restart_dns() return + + """ Gets a remote console launcher for a Lenovo ThinkServer. + + Returns a tuple: (content type, launcher) or None if the launcher could + not be retrieved.""" + def _get_ts_remote_console(self, bmc, username, password): + # We don't establish non-secure connections without checking + # certificates + if not self._certverify: + return + conn = wc.SecureHTTPConnection(bmc, 443, + verifycallback=self._certverify) + conn.connect() + params = urllib.urlencode({ + 'WEBVAR_USERNAME': username, + 'WEBVAR_PASSWORD': password + }) + headers = { + 'Connection': 'keep-alive' + } + conn.request('POST', '/rpc/WEBSES/create.asp', params, headers) + rsp = conn.getresponse() + if rsp.status == 200: + body = rsp.read().split('\n') + session_line = None + for line in body: + if 'SESSION_COOKIE' in line: + session_line = line + if session_line is None: + return + + session_id = session_line.split('\'')[3] + # Usually happens when maximum number of sessions is reached + if session_id == 'Failure_Session_Creation': + return + + headers = { + 'Connection': 'keep-alive', + 'Cookie': 'SessionCookie=' + session_id, + } + conn.request( + 'GET', + '/Java/jviewer.jnlp?EXTRNIP=' + bmc + '&JNLPSTR=JViewer', + None, headers) + rsp = conn.getresponse() + if rsp.status == 200: + return rsp.getheader('Content-Type'), rsp.read() + conn.close() + + def get_graphical_console(self): + return self._get_ts_remote_console(self.ipmicmd.bmc, + self.ipmicmd.ipmi_session.userid, + self.ipmicmd.ipmi_session.password)