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/bmc_command.py112
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest.py221
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_bmc.py77
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_fruid.py89
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_gpios.py56
-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_psu_update.py81
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_sensors.py57
-rw-r--r--meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_server.py68
-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.sh79
11 files changed, 0 insertions, 901 deletions
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/bmc_command.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/bmc_command.py
deleted file mode 100644
index d4dc877..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/bmc_command.py
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/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
-#
-
-from __future__ import absolute_import
-from __future__ import division
-from __future__ import print_function
-from __future__ import unicode_literals
-
-import os
-import subprocess
-import select
-import sys
-import time
-
-DEFAULT_TIMEOUT = 10 #sec
-
-# Note: Python 3.0 supports communicate() with a timeout option.
-# If we upgrade to this version we will no longer need timed_communicate
-
-class TimeoutError(Exception):
- def __init__(self, output, error):
- super(TimeoutError, self).__init__('process timed out')
- self.output = output
- self.error = error
-
-class WaitTimeoutError(Exception):
- pass
-
-def kill_process(proc):
- proc.terminate()
- try:
- timed_wait(proc, 0.1)
- except WaitTimeoutError:
- proc.kill()
- try:
- timed_wait(proc, 0.1)
- except WaitTimeoutError:
- # This can happen if the process is stuck waiting inside a system
- # call for a long time. There isn't much we can do unless we want
- # to keep waiting forever. Just give up. The child process will
- # remain around as a zombie until we exit.
- pass
-
-def timed_wait(proc, timeout):
- # There unfortunately isn't a great way to wait for a process with a
- # timeout, other than polling. (Registering for SIGCHLD and sleeping might
- # be one option, but that's fragile and not thread-safe.)
- poll_interval = 0.1
- end_time = time.time() + timeout
- while True:
- if proc.poll() is not None:
- return
- time_left = max(end_time - time.time(), 0)
- if time_left <= 0:
- raise WaitTimeoutError()
- time.sleep(min(time_left, poll_interval))
-
-def timed_communicate(proc, timeout=DEFAULT_TIMEOUT):
- end_time = time.time() + timeout
-
- p = select.poll()
- outfd = proc.stdout.fileno()
- errfd = proc.stderr.fileno()
- p.register(outfd, select.POLLIN)
- p.register(errfd, select.POLLIN)
- results = {outfd: [], errfd: []}
- remaining_fds = set([outfd, errfd])
-
- bufsize = 4096
- while remaining_fds:
- time_left = max(end_time - time.time(), 0)
- r = p.poll(time_left * 1000) # poll() takes timeout in milliseconds
- if not r:
- kill_process(proc)
- raise TimeoutError(b''.join(results[outfd]),
- b''.join(results[errfd]))
- for fd, flags in r:
- # We didn't put the fds in non-blocking mode, but we know the fd
- # has data to read, so os.read() will return immediately.
- d = os.read(fd, bufsize)
- if d:
- results[fd].append(d)
- else:
- # EOF on this fd, stop listening on it
- p.unregister(fd)
- remaining_fds.remove(fd)
-
- try:
- timed_wait(proc, max(end_time - time.time(), 0))
- except WaitTimeoutError:
- kill_process(proc)
- raise TimeoutError(b''.join(results[outfd]),
- b''.join(results[errfd]))
-
- return b''.join(results[outfd]), b''.join(results[errfd])
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
deleted file mode 100644
index af3e75d..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest.py
+++ /dev/null
@@ -1,221 +0,0 @@
-#!/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
-#
-
-from ctypes import *
-import bottle
-from cherrypy.wsgiserver import CherryPyWSGIServer
-from cherrypy.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter
-import datetime
-import logging
-import logging.config
-import json
-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
-import rest_psu_update
-
-CONSTANTS = {
- 'certificate': '/usr/lib/ssl/certs/rest_server.pem',
- 'key': '/usr/lib/ssl/private/rest_server_key.pem',
-}
-
-LOGGER_CONF = {
- 'version': 1,
- 'disable_existing_loggers': False,
- 'formatters': {
- 'default': {
- 'format': '%(message)s'
- },
- },
- 'handlers': {
- 'file_handler': {
- 'level': 'INFO',
- 'formatter':'default',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename':'/tmp/rest.log',
- 'maxBytes': 1048576,
- 'backupCount': 3,
- 'encoding': 'utf8'
- },
- },
- 'loggers': {
- '': {
- 'handlers': ['file_handler'],
- 'level': 'DEBUG',
- 'propagate': True,
- },
- }
-}
-
-# Handler for root resource endpoint
-@bottle.route('/api')
-def rest_api():
- result = {
- "Information": {
- "Description": "Wedge RESTful API Entry",
- },
- "Actions": [],
- "Resources": [ "sys"],
- }
-
- return result
-
-# Handler for sys resource endpoint
-@bottle.route('/api/sys')
-def rest_sys():
- result = {
- "Information": {
- "Description": "Wedge System",
- },
- "Actions": [],
- "Resources": [ "mb", "bmc", "server", "sensors", "gpios",
- "modbus_registers", "slotid"],
- }
-
- return result
-
-# Handler for sys/mb resource endpoint
-@bottle.route('/api/sys/mb')
-def rest_sys():
- result = {
- "Information": {
- "Description": "System Motherboard",
- },
- "Actions": [],
- "Resources": [ "fruid"],
- }
-
- return result
-
-# Handler for sys/mb/fruid resource endpoint
-@bottle.route('/api/sys/mb/fruid')
-def rest_fruid_hdl():
- return rest_fruid.get_fruid()
-
-# Handler for sys/bmc resource endpoint
-@bottle.route('/api/sys/bmc')
-def rest_bmc_hdl():
- return rest_bmc.get_bmc()
-
-# Handler for sys/server resource endpoint
-@bottle.route('/api/sys/server')
-def rest_server_hdl():
- return rest_server.get_server()
-
-# Handler for uServer resource endpoint
-@bottle.route('/api/sys/server', method='POST')
-def rest_server_act_hdl():
- data = json.load(request.body)
- return rest_server.server_action(data)
-
-# Handler for sensors resource endpoint
-@bottle.route('/api/sys/sensors')
-def rest_sensors_hdl():
- return rest_sensors.get_sensors()
-
-# Handler for sensors resource endpoint
-@bottle.route('/api/sys/gpios')
-def rest_gpios_hdl():
- return rest_gpios.get_gpios()
-
-@bottle.route('/api/sys/modbus_registers')
-def modbus_registers_hdl():
- return rest_modbus.get_modbus_registers()
-
-@bottle.route('/api/sys/psu_update')
-def psu_update_hdl():
- return rest_psu_update.get_jobs()
-
-@bottle.route('/api/sys/psu_update', method='POST')
-def psu_update_hdl():
- data = json.load(request.body)
- return rest_psu_update.begin_job(data)
-
-# Handler for sensors resource endpoint
-@bottle.route('/api/sys/slotid')
-def rest_slotid_hdl():
- return rest_slotid.get_slotid()
-
-# SSL Wrapper for Rest API
-class SSLCherryPyServer(bottle.ServerAdapter):
- def run(self, handler):
- server = CherryPyWSGIServer((self.host, self.port), handler)
- server.ssl_adapter = pyOpenSSLAdapter(CONSTANTS['certificate'], CONSTANTS['key'])
- try:
- server.start()
- finally:
- server.stop()
-
-
-def log_after_request():
- try:
- length = bottle.response.content_length
- except:
- try:
- length = len(bottle.response.body)
- except:
- length = 0
-
- logging.info('{} - - [{}] "{} {} {}" {} {}'.format(
- bottle.request.environ.get('REMOTE_ADDR'),
- datetime.datetime.now().strftime('%d/%b/%Y %H:%M:%S'),
- bottle.request.environ.get('REQUEST_METHOD'),
- bottle.request.environ.get('REQUEST_URI'),
- bottle.request.environ.get('SERVER_PROTOCOL'),
- bottle.response.status_code,
- length))
-
-
-# Error logging to log file
-class ErrorLogging(object):
- def write(self, err):
- logging.error(err)
-
-
-# Middleware to log the requests
-class LogMiddleware(object):
- def __init__(self, app):
- self.app = app
-
- def __call__(self, e, h):
- e['wsgi.errors'] = ErrorLogging()
- ret_val = self.app(e, h)
- log_after_request()
- return ret_val
-
-# overwrite the stderr and stdout to log to the file
-bottle._stderr = logging.error
-bottle._stdout = logging.info
-logging.config.dictConfig(LOGGER_CONF)
-
-bottle_app = LogMiddleware(bottle.app())
-# Use SSL if the certificate and key exists. Otherwise, run without SSL.
-if (os.access(CONSTANTS['key'], os.R_OK) and
- os.access(CONSTANTS['certificate'], os.R_OK)):
- bottle.run(host = "::", port= 8443, server=SSLCherryPyServer, app=bottle_app)
-else:
- bottle.run(host = "::", port = 8080, server='cherrypy', app=bottle_app)
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
deleted file mode 100644
index c4f661e..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_bmc.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/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
-#
-
-
-from subprocess import *
-import re
-
-# Handler for FRUID resource endpoint
-def get_bmc():
- # Get BMC Reset Reason
- wdt_counter = Popen('devmem 0x1e785010', \
- shell=True, stdout=PIPE).stdout.read()
- wdt_counter = int(wdt_counter, 0)
-
- wdt_counter &= 0xff00
-
- if wdt_counter:
- por_flag = 0
- else:
- por_flag = 1
-
- if por_flag:
- reset_reason = "Power ON Reset"
- else:
- reset_reason = "User Initiated Reset or WDT Reset"
-
- # Get BMC's Up Time
- uptime = Popen('uptime', \
- shell=True, stdout=PIPE).stdout.read()
-
- # Get Usage information
- data = Popen('top -b n1', \
- shell=True, stdout=PIPE).stdout.read()
- adata = data.split('\n')
- 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",
- "Reset Reason": reset_reason,
- "Uptime": uptime,
- "Memory Usage": mem_usage,
- "CPU Usage": cpu_usage,
- "OpenBMC Version": version,
- },
- "Actions": [],
- "Resources": [],
- }
-
- return result;
-
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_fruid.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_fruid.py
deleted file mode 100644
index 3248e92..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_fruid.py
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/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
-#
-
-
-from ctypes import *
-
-# Handler for FRUID resource endpoint
-fru = CDLL("libwedge_eeprom.so")
-
-class FRU(Structure):
- _fields_ = [ ("fbw_version", c_ubyte),
- ("fbw_product_name", c_char * 13),
- ("fbw_product_number", c_char * 10),
- ("fbw_assembly_number", c_char * 15),
- ("fbw_facebook_pcba_number", c_char * 15),
- ("fbw_facebook_pcb_number", c_char * 15),
- ("fbw_odm_pcba_number", c_char * 14),
- ("fbw_odm_pcba_serial", c_char * 13),
- ("fbw_production_state", c_ubyte),
- ("fbw_product_version", c_ubyte),
- ("fbw_product_subversion", c_ubyte),
- ("fbw_product_serial", c_char * 13),
- ("fbw_product_asset", c_char * 13),
- ("fbw_system_manufacturer", c_char * 9),
- ("fbw_system_manufacturing_date", c_char * 10),
- ("fbw_pcb_manufacturer", c_char * 9),
- ("fbw_assembled", c_char * 9),
- ("fbw_local_mac", c_ubyte * 6),
- ("fbw_mac_base", c_ubyte * 6),
- ("fbw_dummy", c_char),
- ("fbw_mac_size", c_ushort),
- ("fbw_location", c_char * 9),
- ("fbw_crc8", c_ubyte) ]
-
-def get_fruid():
- myfru = FRU()
- p_myfru = pointer(myfru)
- fru.wedge_eeprom_parse(None, p_myfru)
-
- mac2str = lambda mac: ':'.join(['{:02X}'.format(b) for b in mac])
-
- fruinfo = { "Version": myfru.fbw_version,
- "Product Name": myfru.fbw_product_name,
- "Product Part Number": myfru.fbw_product_number,
- "System Assembly Part Number": myfru.fbw_assembly_number,
- "Facebook PCBA Part Number": myfru.fbw_facebook_pcba_number,
- "Facebook PCB Part Number": myfru.fbw_facebook_pcb_number,
- "ODM PCBA Part Number": myfru.fbw_odm_pcba_number,
- "ODM PCBA Serial Number": myfru.fbw_odm_pcba_serial,
- "Product Production State": myfru.fbw_production_state,
- "Product Version": myfru.fbw_product_version,
- "Product Sub-Version": myfru.fbw_product_subversion,
- "Product Serial Number": myfru.fbw_product_serial,
- "Product Asset Tag": myfru.fbw_product_asset,
- "System Manufacturer": myfru.fbw_system_manufacturer,
- "System Manufacturing Date": myfru.fbw_system_manufacturing_date,
- "PCB Manufacturer": myfru.fbw_pcb_manufacturer,
- "Assembled At": myfru.fbw_assembled,
- "Local MAC": mac2str(myfru.fbw_local_mac),
- "Extended MAC Base": mac2str(myfru.fbw_mac_base),
- "Extended MAC Address Size": myfru.fbw_mac_size,
- "Location on Fabric": myfru.fbw_location,
- "CRC8": hex((myfru.fbw_crc8))
- }
-
- result = {
- "Information": fruinfo,
- "Actions": [],
- "Resources": [],
- }
-
- return result
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_gpios.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_gpios.py
deleted file mode 100644
index 340c5c3..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_gpios.py
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/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
-#
-
-from rest_fruid import get_fruid
-
-WEDGES = ["Wedge-AC-F", "Wedge-DC-F"]
-
-
-def read_gpio_sysfs(gpio):
- with open('/sys/class/gpio/gpio%d/value' % gpio, 'r') as f:
- val_string = f.read()
- if val_string == '1\n':
- return 1
- if val_string == '0\n':
- return 0
- return None
-
-
-def read_wedge_back_ports():
- bhinfo = { "port_1": { "pin_1": read_gpio_sysfs(120),
- "pin_2": read_gpio_sysfs(121),
- "pin_3": read_gpio_sysfs(122),
- "pin_4": read_gpio_sysfs(123)
- },
- "port_2": { "pin_1": read_gpio_sysfs(124),
- "pin_2": read_gpio_sysfs(125),
- "pin_3": read_gpio_sysfs(126),
- "pin_4": read_gpio_sysfs(52)
- }
- }
- return bhinfo
-
-
-def get_gpios():
- fruinfo = get_fruid()
- gpioinfo = {}
- if fruinfo["Information"]["Product Name"] in WEDGES:
- gpioinfo["back_ports"] = read_wedge_back_ports()
- return gpioinfo
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
deleted file mode 100644
index 9d213fc..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_modbus.py
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/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_psu_update.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_psu_update.py
deleted file mode 100644
index d0e57c7..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_psu_update.py
+++ /dev/null
@@ -1,81 +0,0 @@
-#!/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
-import os
-import os.path
-import json
-import uuid
-import urllib2
-from tempfile import mkstemp
-from bottle import HTTPError
-
-UPDATE_JOB_DIR = '/var/rackmond/update_jobs'
-UPDATERS = {'delta': '/usr/local/bin/psu-update-delta.py'}
-
-def get_jobs():
- jobs = []
- if not os.path.exists(UPDATE_JOB_DIR):
- os.makedirs(UPDATE_JOB_DIR)
- for f in os.listdir(UPDATE_JOB_DIR):
- fullpath = os.path.join(UPDATE_JOB_DIR, f)
- if f.endswith('.json') and os.path.isfile(fullpath):
- with open(fullpath, 'r') as fh:
- jdata = json.load(fh)
- jdata['job_id'] = os.path.splitext(f)[0]
- jobs.append(jdata)
- return {'jobs': jobs}
-
-updater_process = None
-def begin_job(jobdesc):
- global updater_process
- if updater_process is not None:
- if updater_process.poll() is not None:
- # Update complete
- updater_process = None
- else:
- body = {'error': 'update_already_running',
- 'pid': updater_process.pid }
- raise HTTPError(409, body)
- job_id = str(uuid.uuid1())
- (fwfd, fwfilepath) = mkstemp()
- if not os.path.exists(UPDATE_JOB_DIR):
- os.makedirs(UPDATE_JOB_DIR)
- statusfilepath = os.path.join(UPDATE_JOB_DIR, str(job_id) + '.json')
- status = {'pid': 0,
- 'state': 'fetching' }
- with open(statusfilepath, 'wb') as sfh:
- sfh.write(json.dumps(status))
- fwdata = urllib2.urlopen(jobdesc['fw_url'])
- with os.fdopen(fwfd, 'wb') as fwfile:
- fwfile.write(fwdata.read())
- fwfile.flush()
- updater = UPDATERS[jobdesc.get('updater', 'delta')]
- updater_process = Popen([updater,
- '--addr', str(jobdesc['address']),
- '--statusfile', statusfilepath,
- '--rmfwfile',
- fwfilepath])
- status = {'pid': updater_process.pid,
- 'state': 'starting' }
- with open(statusfilepath, 'wb') as sfh:
- sfh.write(json.dumps(status))
- return {'job_id': job_id, 'pid': updater_process.pid}
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
deleted file mode 100644
index 382513b..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_sensors.py
+++ /dev/null
@@ -1,57 +0,0 @@
-#!/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 json
-import re
-import subprocess
-import bmc_command
-
-# Handler for sensors resource endpoint
-def get_sensors():
- result = []
- proc = subprocess.Popen(['sensors'],
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- try:
- data, err = bmc_command.timed_communicate(proc)
- except bmc_command.TimeoutError as ex:
- data = ex.output
- err = ex.error
-
- data = re.sub(r'\(.+?\)', '', data)
- for edata in data.split('\n\n'):
- adata = edata.split('\n', 1)
- sresult = {}
- if (len(adata) < 2):
- break;
- sresult['name'] = adata[0]
- for sdata in adata[1].split('\n'):
- tdata = sdata.split(':')
- if (len(tdata) < 2):
- continue
- sresult[tdata[0].strip()] = tdata[1].strip()
- result.append(sresult)
-
- fresult = {
- "Information": result,
- "Actions": [],
- "Resources": [],
- }
- return fresult
diff --git a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_server.py b/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_server.py
deleted file mode 100644
index 0acba27..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_server.py
+++ /dev/null
@@ -1,68 +0,0 @@
-#!/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 os
-from subprocess import *
-
-# Handler for uServer resource endpoint
-def get_server():
- ret = Popen('/usr/local/bin/wedge_power.sh status', \
- shell=True, stdout=PIPE).stdout.read()
- status = ret.rsplit()[-1]
-
- result = {
- "Information": { "status": status },
- "Actions": ["power-on", "power-off", "power-reset"],
- "Resources": [],
- }
-
- return result
-
-def server_action(data):
- if data["action"] == 'power-on':
- ret = Popen('/usr/local/bin/wedge_power.sh status', \
- shell=True, stdout=PIPE).stdout.read()
- status = ret.rsplit()[-1]
- if status == 'on':
- res = 'failure'
- reason = 'already on'
- else:
- ret = Popen('/usr/local/bin/wedge_power.sh on', \
- shell=True, stdout=PIPE).stdout.read()
- res = "success"
- elif data["action"] == 'power-off':
- ret = Popen('/usr/local/bin/wedge_power.sh off', \
- shell=True, stdout=PIPE).stdout.read()
- res = "success"
- elif data["action"] == 'power-reset':
- ret = Popen('/usr/local/bin/wedge_power.sh reset', \
- shell=True, stdout=PIPE).stdout.read()
- res = "success"
- else:
- res = 'failure'
- reason = 'invalid action'
-
- if res == 'failure':
- result = { "result": res, "reason": reason}
- else:
- result = { "result": res }
-
- return result
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
deleted file mode 100644
index ee407ac..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/rest_slotid.py
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/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
deleted file mode 100644
index 2b274dc..0000000
--- a/meta-facebook/meta-wedge/recipes-wedge/rest-api/files/setup-rest-api.sh
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/bin/sh
-#
-# 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:
-# Required-Stop:
-# Default-Start: S
-# Default-Stop:
-# Short-Description: Set REST API handler
-### END INIT INFO
-
-# source function library
-. /etc/init.d/functions
-
-ACTION="$1"
-CMD="/usr/local/bin/rest.py"
-case "$ACTION" in
- start)
- echo -n "Setting up REST API handler: "
- pid=$(ps | grep -v grep | grep $CMD | awk '{print $1}')
- if [ $pid ]; then
- echo "already running"
- else
- $CMD > /tmp/rest_start.log 2>&1 &
- echo "done."
- fi
- ;;
- stop)
- echo -n "Stopping REST API handler: "
- pid=$(ps | grep -v grep | grep $CMD | awk '{print $1}')
- if [ $pid ]; then
- kill $pid
- fi
- echo "done."
- ;;
- restart)
- echo -n "Restarting REST API handler: "
- pid=$(ps | grep -v grep | grep $CMD | awk '{print $1}')
- if [ $pid ]; then
- kill $pid
- fi
- sleep 1
- $CMD > /tmp/rest_start.log 2>&1 &
- echo "done."
- ;;
- status)
- if [[ -n $(ps | grep -v grep | grep $CMD | awk '{print $1}') ]]; then
- echo "REST API handler is running"
- else
- echo "REST API is stopped"
- fi
- ;;
- *)
- N=${0##*/}
- N=${N#[SK]??}
- echo "Usage: $N {start|stop|status|restart}" >&2
- exit 1
- ;;
-esac
-
-exit 0
OpenPOWER on IntegriCloud