summaryrefslogtreecommitdiffstats
path: root/meta-facebook/meta-wedge/recipes-wedge/rest-api/files
diff options
context:
space:
mode:
Diffstat (limited to 'meta-facebook/meta-wedge/recipes-wedge/rest-api/files')
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest.py88
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_bmc.py10
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_modbus.py28
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_sensors.py4
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_slotid.py33
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/setup-rest-api.sh16
6 files changed, 157 insertions, 22 deletions
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest.py
index 6d59fd6..52c98d9 100644
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest.py
+++ b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest.py
@@ -20,14 +20,24 @@
from ctypes import *
-from bottle import route, run, template, request, response
+from bottle import route, run, template, request, response, ServerAdapter
from bottle import abort
+from wsgiref.simple_server import make_server, WSGIRequestHandler, WSGIServer
import json
-from rest_fruid import *
-from rest_server import *
-from rest_sensors import *
-from rest_bmc import *
-from rest_gpios import *
+import ssl
+import socket
+import os
+import rest_fruid
+import rest_server
+import rest_sensors
+import rest_bmc
+import rest_gpios
+import rest_modbus
+import rest_slotid
+
+CONSTANTS = {
+ 'certificate': '/usr/lib/ssl/certs/rest_server.pem',
+}
# Handler for root resource endpoint
@route('/api')
@@ -50,7 +60,8 @@ def rest_sys():
"Description": "Wedge System",
},
"Actions": [],
- "Resources": [ "mb", "bmc", "server", "sensors", "gpios"],
+ "Resources": [ "mb", "bmc", "server", "sensors", "gpios",
+ "modbus_registers", "slotid"],
}
return result
@@ -70,33 +81,72 @@ def rest_sys():
# Handler for sys/mb/fruid resource endpoint
@route('/api/sys/mb/fruid')
-def rest_fruid():
- return get_fruid()
+def rest_fruid_hdl():
+ return rest_fruid.get_fruid()
# Handler for sys/bmc resource endpoint
@route('/api/sys/bmc')
-def rest_bmc():
- return get_bmc()
+def rest_bmc_hdl():
+ return rest_bmc.get_bmc()
# Handler for sys/server resource endpoint
@route('/api/sys/server')
-def rest_bmc():
- return get_server()
+def rest_server_hdl():
+ return rest_server.get_server()
# Handler for uServer resource endpoint
@route('/api/sys/server', method='POST')
-def rest_server():
+def rest_server_act_hdl():
data = json.load(request.body)
- return server_action(data)
+ return rest_server.server_action(data)
# Handler for sensors resource endpoint
@route('/api/sys/sensors')
-def rest_sensors():
- return get_sensors()
+def rest_sensors_hdl():
+ return rest_sensors.get_sensors()
# Handler for sensors resource endpoint
@route('/api/sys/gpios')
-def rest_gpios():
- return get_gpios()
+def rest_gpios_hdl():
+ return rest_gpios.get_gpios()
+
+@route('/api/sys/modbus_registers')
+def modbus_registers_hdl():
+ return rest_modbus.get_modbus_registers()
+
+# Handler for sensors resource endpoint
+@route('/api/sys/slotid')
+def rest_slotid_hdl():
+ return rest_slotid.get_slotid()
run(host = "::", port = 8080)
+
+# SSL Wrapper for Rest API
+class SSLWSGIRefServer(ServerAdapter):
+ def run(self, handler):
+ if self.quiet:
+ class QuietHandler(WSGIRequestHandler):
+ def log_request(*args, **kw): pass
+ self.options['handler_class'] = QuietHandler
+
+ # IPv6 Support
+ server_cls = self.options.get('server_class', WSGIServer)
+
+ if ':' in self.host:
+ if getattr(server_cls, 'address_family') == socket.AF_INET:
+ class server_cls(server_cls):
+ address_family = socket.AF_INET6
+
+ srv = make_server(self.host, self.port, handler,
+ server_class=server_cls, **self.options)
+ srv.socket = ssl.wrap_socket (
+ srv.socket,
+ certfile=CONSTANTS['certificate'],
+ server_side=True)
+ srv.serve_forever()
+
+# Use SSL if the certificate exists. Otherwise, run without SSL.
+if os.access(CONSTANTS['certificate'], os.R_OK):
+ run(server=SSLWSGIRefServer(host="::", port=8443))
+else:
+ run(host = "::", port = 8080)
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_bmc.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_bmc.py
index d9600ae..c4f661e 100644
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_bmc.py
+++ b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_bmc.py
@@ -20,6 +20,7 @@
from subprocess import *
+import re
# Handler for FRUID resource endpoint
def get_bmc():
@@ -51,6 +52,14 @@ def get_bmc():
mem_usage = adata[0]
cpu_usage = adata[1]
+ # Get OpenBMC version
+ version = ""
+ data = Popen('cat /etc/issue', \
+ shell=True, stdout=PIPE).stdout.read()
+ ver = re.search(r'v([\w\d._-]*)\s', data)
+ if ver:
+ version = ver.group(1)
+
result = {
"Information": {
"Description": "Wedge BMC",
@@ -58,6 +67,7 @@ def get_bmc():
"Uptime": uptime,
"Memory Usage": mem_usage,
"CPU Usage": cpu_usage,
+ "OpenBMC Version": version,
},
"Actions": [],
"Resources": [],
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_modbus.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_modbus.py
new file mode 100644
index 0000000..9d213fc
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_modbus.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+#
+# Copyright 2014-present Facebook. All Rights Reserved.
+#
+# This program file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program in a file named COPYING; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301 USA
+#
+
+import subprocess
+from subprocess import Popen
+
+# Handler for sensors resource endpoint
+def get_modbus_registers():
+ p = Popen('/usr/local/bin/rackmondata', stdout=subprocess.PIPE)
+ out, err = p.communicate()
+ return out
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_sensors.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_sensors.py
index f4f83d3..fa65372 100644
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_sensors.py
+++ b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_sensors.py
@@ -39,12 +39,10 @@ def get_sensors():
if (len(tdata) < 2):
continue
sresult[tdata[0].strip()] = tdata[1].strip()
- result.append(sresult)
-
+ result.append(sresult)
fresult = {
"Information": result,
"Actions": [],
"Resources": [],
}
-
return fresult
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_slotid.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_slotid.py
new file mode 100644
index 0000000..ee407ac
--- /dev/null
+++ b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_slotid.py
@@ -0,0 +1,33 @@
+#!/usr/bin/env python
+#
+# Copyright 2014-present Facebook. All Rights Reserved.
+#
+# This program file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program in a file named COPYING; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301 USA
+#
+
+import subprocess
+
+# Handler for sensors resource endpoint
+def get_slotid():
+ p = subprocess.Popen('source /usr/local/bin/openbmc-utils.sh;'
+ 'wedge_slot_id $(wedge_board_type)',
+ shell=True, stdout=subprocess.PIPE)
+ out, err = p.communicate()
+ try:
+ slot = int(out.strip('\n'))
+ except:
+ slot = 0
+ return { 'slotid' : slot }
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/setup-rest-api.sh b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/setup-rest-api.sh
index fe01c23..bdd79b6 100644
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/setup-rest-api.sh
+++ b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/setup-rest-api.sh
@@ -2,6 +2,22 @@
#
# Copyright 2014-present Facebook. All Rights Reserved.
#
+# This program file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program in a file named COPYING; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301 USA
+#
+
### BEGIN INIT INFO
# Provides: setup-rest-api
# Required-Start:
OpenPOWER on IntegriCloud