python2: remove old scripts
These scripts are python2 and have not been updated after a few years,
so I assume they're not really used at this point. Delete them.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I6d86088e3790c62bb18cc59696d5d804a5074317
diff --git a/expectedJsonChecker/expectedJsonChecker.py b/expectedJsonChecker/expectedJsonChecker.py
deleted file mode 100755
index d232a4f..0000000
--- a/expectedJsonChecker/expectedJsonChecker.py
+++ /dev/null
@@ -1,200 +0,0 @@
-#!/usr/bin/python
-
-"""
-This script reads in JSON files containing a set of expected entries to be
-found within a given input JSON file. An optional "filtering" JSON
-file may also be provided that contains a set of data that will be used to
-filter configured expected entries from being checked in the input JSON.
-"""
-
-import os
-import sys
-import json
-from argparse import ArgumentParser
-
-
-def findEntry(entry, jsonObject):
-
- if isinstance(jsonObject, dict):
- for key in jsonObject:
- if key == entry:
- return jsonObject[key]
- else:
- found = findEntry(entry, jsonObject[key])
- if found:
- return found
-
-
-def buildDict(entry, jsonObject, resultDict):
-
- key = list(entry)[0]
- jsonObject = findEntry(key, jsonObject)
- if jsonObject is None:
- return {}
- entry = entry[key]
- if isinstance(entry, dict):
- resultDict[key] = buildDict(entry, jsonObject, resultDict)
- else:
- return {key: jsonObject}
-
-
-def doAnd(andList, filters):
-
- allTrue = True
- for entry in andList:
- # $and entries must be atleast a single layer dict
- value = dict()
- buildDict(entry, filters, value)
- if value != entry:
- allTrue = False
-
- return allTrue
-
-
-def doOr(orList, filters):
-
- anyTrue = False
- for entry in orList:
- # $or entries must be atleast a single layer dict
- value = dict()
- buildDict(entry, filters, value)
- if value == entry:
- anyTrue = True
- break
-
- return anyTrue
-
-
-def doNor(norList, filters):
-
- allFalse = True
- for entry in norList:
- # $nor entries must be atleast a single layer dict
- value = dict()
- buildDict(entry, filters, value)
- if value == entry:
- allFalse = False
-
- return allFalse
-
-
-def doNot(notDict, filters):
-
- # $not entry must be atleast a single layer dict
- value = dict()
- buildDict(notDict, filters, value)
- if value == notDict:
- return False
-
- return True
-
-
-def applyFilters(expected, filters):
-
- switch = {
- # $and - Performs an AND operation on an array with at least two
- # expressions and returns the document that meets all the
- # expressions. i.e.) {"$and": [{"age": 5}, {"name": "Joe"}]}
- "$and": doAnd,
- # $or - Performs an OR operation on an array with at least two
- # expressions and returns the documents that meet at least one of
- # the expressions. i.e.) {"$or": [{"age": 4}, {"name": "Joe"}]}
- "$or": doOr,
- # $nor - Performs a NOR operation on an array with at least two
- # expressions and returns the documents that do not meet any of
- # the expressions. i.e.) {"$nor": [{"age": 3}, {"name": "Moe"}]}
- "$nor": doNor,
- # $not - Performs a NOT operation on the specified expression and
- # returns the documents that do not meet the expression.
- # i.e.) {"$not": {"age": 4}}
- "$not": doNot
- }
-
- isExpected = {}
- for entry in expected:
- expectedList = list()
- if entry == "$op":
- addInput = True
- for op in expected[entry]:
- if op != "$input":
- func = switch.get(op)
- if not func(expected[entry][op], filters):
- addInput = False
- if addInput:
- expectedList = expected[entry]["$input"]
- else:
- expectedList = [dict({entry: expected[entry]})]
-
- for i in expectedList:
- for key in i:
- isExpected[key] = i[key]
-
- return isExpected
-
-
-def findExpected(expected, input):
-
- result = {}
- for key in expected:
- jsonObject = findEntry(key, input)
- if isinstance(expected[key], dict) and expected[key] and jsonObject:
- notExpected = findExpected(expected[key], jsonObject)
- if notExpected:
- result[key] = notExpected
- else:
- # If expected value is not "dont care" and
- # does not equal what's expected
- if str(expected[key]) != "{}" and expected[key] != jsonObject:
- if jsonObject is None:
- result[key] = None
- else:
- result[key] = expected[key]
- return result
-
-
-if __name__ == '__main__':
- parser = ArgumentParser(
- description="Expected JSON cross-checker. Similar to a JSON schema \
- validator, however this cross-checks a set of expected \
- property states against the contents of a JSON input \
- file with the ability to apply an optional set of \
- filters against what's expected based on the property \
- states within the provided filter JSON.")
-
- parser.add_argument('index',
- help='Index name into a set of entries within the \
- expected JSON file')
- parser.add_argument('expected_json',
- help='JSON input file containing the expected set of \
- entries, by index name, to be contained within \
- the JSON input file')
- parser.add_argument('input_json',
- help='JSON input file containing the JSON data to be \
- cross-checked against what is expected')
- parser.add_argument('-f', '--filters', dest='filter_json',
- help='JSON file containing path:property:value \
- associations to optional filters configured \
- within the expected set of JSON entries')
-
- args = parser.parse_args()
-
- with open(args.expected_json, 'r') as expected_json:
- expected = json.load(expected_json) or {}
- with open(args.input_json, 'r') as input_json:
- input = json.load(input_json) or {}
-
- filters = {}
- if args.filter_json:
- with open(args.filter_json, 'r') as filters_json:
- filters = json.load(filters_json) or {}
-
- if args.index in expected and expected[args.index] is not None:
- expected = applyFilters(expected[args.index], filters)
- result = findExpected(expected, input)
- if result:
- print("NOT FOUND:")
- for key in result:
- print(key + ": " + str(result[key]))
- else:
- print("Error: " + args.index + " not found in " + args.expected_json)
- sys.exit(1)
diff --git a/openbmc-events/LICENSE b/openbmc-events/LICENSE
deleted file mode 100644
index cf1ab25..0000000
--- a/openbmc-events/LICENSE
+++ /dev/null
@@ -1,24 +0,0 @@
-This is free and unencumbered software released into the public domain.
-
-Anyone is free to copy, modify, publish, use, compile, sell, or
-distribute this software, either in source code form or as a compiled
-binary, for any purpose, commercial or non-commercial, and by any
-means.
-
-In jurisdictions that recognize copyright laws, the author or authors
-of this software dedicate any and all copyright interest in the
-software to the public domain. We make this dedication for the benefit
-of the public at large and to the detriment of our heirs and
-successors. We intend this dedication to be an overt act of
-relinquishment in perpetuity of all present and future rights to this
-software under copyright law.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
-OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
-ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.
-
-For more information, please refer to <http://unlicense.org>
diff --git a/openbmc-events/README.md b/openbmc-events/README.md
deleted file mode 100644
index 5a2bef1..0000000
--- a/openbmc-events/README.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# openbmc-events
-
-openbmc-event: Tool to query error events on the target server
-
-openbmc-sfw: Tool to query and update HOST and BMC images on the target server
diff --git a/openbmc-events/openbmc-events b/openbmc-events/openbmc-events
deleted file mode 100755
index e679837..0000000
--- a/openbmc-events/openbmc-events
+++ /dev/null
@@ -1,215 +0,0 @@
-#!/bin/env python
-
-import argparse
-import requests
-import json
-
-import urllib3
-
-class BMC:
- def __init__(self, server):
- self.url = "https://{0}/".format(server)
- self.session = requests.Session()
- self.login()
-
- def login(self):
- r = self.session.post(self.url + 'login',
- json={'data': ['root', '0penBmc']},
- verify=False)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to login: \n" + r.text)
-
- def list_events(self):
- r = self.session.get(self.url + 'xyz/openbmc_project/logging/entry/',
- verify=False)
- j = r.json()
- if j['message'] == '404 Not Found':
- print "No error logs on system\n"
- return
- if j['status'] != 'ok':
- raise Exception("Failed to query entries: \n" + r.text)
-
- events = j['data']
- events.sort(key=lambda x: int(x.split("/")[-1]))
-
- return events
-
- def get_event(self, event):
- r = self.session.get(self.url + event, verify=False)
-
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to get event " + event + ": \n" + r.text)
-
- return j['data']
-
- def clear_event(self,event):
- r = self.session.delete(self.url + event)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to clear event " + event + ": \n" + r.text)
-
- def clear_all_events(self):
- r = self.session.post(self.url + 'xyz/openbmc_project/logging/action/deleteall',
- headers={'Content-Type': 'application/json'},
- data='{"data":[]}',
- verify=False)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to clear all events\n" + r.text)
-
- def list_dumps(self):
- r = self.session.get(self.url + 'xyz/openbmc_project/dump/entry/',
- verify=False)
- j = r.json()
- if j['message'] == '404 Not Found':
- print "No dumps on system\n"
- return []
- if j['status'] != 'ok':
- raise Exception("Failed to list dumps: \n" + r.text)
-
- dumps = j['data']
- dumps.sort(key=lambda x: int(x.split("/")[-1]))
-
- return dumps
-
- def create_dump(self):
- r = self.session.post(self.url + 'xyz/openbmc_project/dump/action/CreateDump',
- headers={'Content-Type': 'application/json'},
- data='{"data":[]}')
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to create dump: \n" + r.text)
-
- def get_dump(self,dump):
- r = self.session.get(self.url + "/download/dump/" + dump,
- verify=False)
- with open("dump" + dump + ".tar.gz","wb") as dump:
- dump.write(r.content)
-
- def clear_dump(self,dump):
- r = self.session.delete(self.url + dump)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to clear dump " + dump + ": \n" + r.text)
-
-def do_list_events(args):
- s = BMC(server=args.server)
- try:
- for e in s.list_events():
- print(e)
- except:
- # ignore if we get nothing back
- return;
-
-
-def do_view_event(args):
- s = BMC(server=args.server)
- print json.dumps(s.get_event(args.event), indent=4)
-
-def do_clear_event(args):
- s = BMC(server=args.server)
- s.clear_event(args.event)
-
-def do_clear_all_events(args):
- s = BMC(server=args.server)
- s.clear_all_events()
-
-def do_list_dumps(args):
- s = BMC(server=args.server)
- for e in s.list_dumps():
- print(e)
-
-def do_create_dump(args):
- s = BMC(server=args.server)
- s.create_dump()
-
-def do_get_dump(args):
- s = BMC(server=args.server)
- s.get_dump(args.dump)
-
-def do_clear_dump(args):
- s = BMC(server=args.server)
- s.clear_dump(args.dump)
-
-def do_get_esel(args):
- s = BMC(server=args.server)
- e = s.get_event(args.event)
- if e['Message'] != 'org.open_power.Error.Host.Event' and\
- e['Message'] != 'org.open_power.Error.Host.Event.Event':
- raise Exception("Event is not from Host: " + e['Message'])
- for d in e['AdditionalData']:
- data = d.split("=")
- tag = data.pop(0)
- if tag != 'ESEL':
- continue
- data = "=".join(data)
- if args.binary:
- data = data.split(" ")
- if '' == data[-1]:
- data.pop()
- data = "".join(map(lambda x: chr(int(x, 16)), data))
- print(data)
-
-
-parser = argparse.ArgumentParser()
-parser.add_argument('--server', help='hostname or IP of BMC', type=str,
- required=True)
-parser.add_argument('--suppress-insecure-warnings', '-I', action="store_true",
- default=False)
-
-subparsers = parser.add_subparsers()
-
-list_events = subparsers.add_parser('list', help='List all events on BMC')
-list_events.set_defaults(func=do_list_events)
-
-view_event = subparsers.add_parser(
- 'view', help='View all data for an individual event')
-view_event.add_argument('event', help='The event to view')
-view_event.set_defaults(func=do_view_event)
-
-get_esel = subparsers.add_parser(
- 'get-esel', help='Extract OpenPOWER eSEL data for an individual event')
-get_esel.add_argument('event', help='The event to get eSEL from')
-get_esel.add_argument('--binary', help='Print event in raw binary',
- action='store_const', const=True)
-get_esel.set_defaults(func=do_get_esel)
-
-clear_event = subparsers.add_parser(
- 'clear', help="Clear individual event")
-clear_event.add_argument('event', help="The event to clear")
-clear_event.set_defaults(func=do_clear_event)
-
-clear_all_events = subparsers.add_parser(
- 'clear-all', help="Clear all event")
-clear_all_events.set_defaults(func=do_clear_all_events)
-
-list_dumps = subparsers.add_parser(
- 'list-dumps', help="List all dumps")
-list_dumps.set_defaults(func=do_list_dumps)
-
-create_dump = subparsers.add_parser(
- 'create-dump', help="Create a dump")
-create_dump.set_defaults(func=do_create_dump)
-
-get_dump = subparsers.add_parser(
- 'get-dump', help="Get a dump")
-get_dump.add_argument('dump', help="The dump to get")
-get_dump.set_defaults(func=do_get_dump)
-
-clear_dump = subparsers.add_parser(
- 'clear-dump', help="Clear individual dump")
-clear_dump.add_argument('dump', help="The dump to clear")
-clear_dump.set_defaults(func=do_clear_dump)
-
-args = parser.parse_args()
-
-if args.suppress_insecure_warnings:
- from requests.packages.urllib3.exceptions import InsecureRequestWarning
- requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
-
-if 'func' in args:
- args.func(args)
-else:
- parser.print_help()
diff --git a/openbmc-events/openbmc-sensors b/openbmc-events/openbmc-sensors
deleted file mode 100755
index 4b6aa92..0000000
--- a/openbmc-events/openbmc-sensors
+++ /dev/null
@@ -1,105 +0,0 @@
-#!/bin/env python
-
-import argparse
-import requests
-import json
-
-import urllib3
-urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
-
-
-class BMC:
- def __init__(self, server):
- self.url = "https://{0}/".format(server)
- self.session = requests.Session()
- self.login()
-
- def login(self):
- r = self.session.post(self.url + 'login',
- json={'data': ['root', '0penBmc']},
- verify=False)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to login: \n" + r.text)
-
- def list_all(self):
- r = self.session.get(self.url + 'xyz/openbmc_project/sensors/enumerate',
- verify=False)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to query sensors: \n" + r.text)
-
- sensors = j['data']
- sensors = sorted(sensors,key=lambda x: x.split("/")[-1])
-
- return sensors
-
- def occ_all(self):
- r = self.session.get(self.url + 'org/open_power/control/enumerate',
- verify=False)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to query occ sensors: \n" + r.text)
-
- sensors = j['data']
- #sensors = sorted(sensors,key=lambda x: x.split("/")[-1])
-
- return sensors
-
- def get_sensor(self, sensor):
- r = self.session.get(self.url + sensor, verify=False)
-
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to get sensor " + sensor + ": \n" + r.text)
-
- return j['data']
-
-def do_list_all(args):
- s = BMC(server=args.server)
- for e in s.list_all():
- if (args.value):
- value = s.get_sensor(e)
- print(e + ' : '+ str(value["Value"]))
- else:
- print(e)
-
-def do_occ_all(args):
- s = BMC(server=args.server)
- print json.dumps(s.occ_all(), indent=4)
-
-
-def do_view_sensor(args):
- s = BMC(server=args.server)
- print(s.get_sensor(args.sensor))
- print json.dumps(s.get_sensor(args.sensor), indent=4)
-
-parser = argparse.ArgumentParser()
-parser.add_argument('--server', help='hostname or IP of BMC', type=str,
- required=True)
-
-subparsers = parser.add_subparsers()
-
-list_all_sensors = subparsers.add_parser('list', help='List all sensors on BMC')
-list_all_sensors.set_defaults(func=do_list_all)
-list_all_sensors.add_argument(
- '--value',
- action='store_true',
- default=False,
- help='Provide current value of sensor')
-
-view_sensor = subparsers.add_parser(
- 'view', help='View all data for an individual sensor')
-view_sensor.add_argument('sensor', help='The sensor to view')
-view_sensor.set_defaults(func=do_view_sensor)
-
-# occ has some 'special' sensors not in the sensor namespace
-occ_sensors = subparsers.add_parser('occ', help='List the special occ sensors')
-occ_sensors.set_defaults(func=do_occ_all)
-
-args = parser.parse_args()
-
-if 'func' in args:
- args.func(args)
-else:
- parser.print_help()
diff --git a/openbmc-events/openbmc-sfw b/openbmc-events/openbmc-sfw
deleted file mode 100755
index 46a131a..0000000
--- a/openbmc-events/openbmc-sfw
+++ /dev/null
@@ -1,256 +0,0 @@
-#!/usr/bin/env python
-
-import argparse
-import requests
-import tarfile
-import time
-import json
-
-class BMC:
- def __init__(self, server):
- self.url = "https://{0}/".format(server)
- self.session = requests.Session()
- self.login()
-
- def login(self):
- r = self.session.post(self.url + 'login',
- json={'data': ['root', '0penBmc']},
- verify=False)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to login: \n" + r.text)
-
- def list_sfw(self):
- r = self.session.get(self.url + 'xyz/openbmc_project/software/',
- verify=False)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to query software: \n" + r.text)
-
- events = j['data']
-
- return events
-
- def get_image(self, image):
- r = self.session.get(self.url + image, verify=False)
-
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to get image " + image + ": \n" + r.text)
-
- return j['data']
-
- def upload_image(self, image):
-
- data = open(image,'rb').read()
- r = self.session.post(self.url + "/upload/image",
- data=data,
- headers={'Content-Type': 'application/octet-stream'},
- verify=False)
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to get event " + image + ": \n" + r.text)
-
- return j['data']
-
- def activate_image(self, image_id):
- r = self.session.put(self.url + "/xyz/openbmc_project/software/" + image_id + "/attr/RequestedActivation",
- json={'data': 'xyz.openbmc_project.Software.Activation.RequestedActivations.Active'},
- verify=False)
-
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to activate image " + image_id + ": \n" + r.text)
-
- return j['data']
-
- def set_priority(self, image_id, priority):
- r = self.session.put(self.url + "/xyz/openbmc_project/software/" + image_id + "/attr/Priority",
- json={'data': int(priority)},
- verify=False)
-
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to set priority of image " + image_id + ": \n" + r.text)
-
- return j['data']
-
- def delete_image(self, image_id):
- r = self.session.post(self.url + "/xyz/openbmc_project/software/" + image_id + "/action/delete",
- headers={'Content-Type': 'application/json'},
- data='{"data":[]}',
- verify=False)
-
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to delete image " + image_id + ": \n" + r.text)
-
- return j['data']
-
- def update_auto(self, image, reboot):
- image_version = self.__get_image_version(image)
- self.upload_image(image)
- image_id = self.__wait_for_image_id(image_version)
- self.activate_image(image_id)
- self.__wait_for_activation(image_id)
- if reboot:
- self.reboot()
-
- def reboot(self):
- r = self.session.put(
- self.url + '/xyz/openbmc_project/state/bmc0/attr/RequestedBMCTransition',
- headers={'Content-Type': 'application/json'},
- data='{"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"}',
- verify=False)
-
- j = r.json()
- if j['status'] != 'ok':
- raise Exception("Failed to reboot BMC:\n" + r.text)
-
- def __get_image_version(self, image_file_path):
- # Open up the manfest file.
- image_tar = tarfile.open(name=image_file_path, mode='r')
- manifest = image_tar.extractfile('MANIFEST')
-
- # Find version line.
- for line in manifest:
- if line.startswith('version='):
- manifest.close()
- image_tar.close()
- return line.split('version=', 1)[1].strip()
-
- # If we didn't find the version line, print an error and return false.
- manifest.close()
- image_tar.close()
- raise Exception("Could not find version line in image manifest")
-
- def __wait_for_image_id(self, image_version):
- # Try 8 times, once every 15 seconds.
- for attempt in range(8):
- software = self.list_sfw()
- # Look for our the image with the given version in software
- for path in software:
- image = self.get_image(path)
- if 'Version' in image and image_version == image['Version']:
- return path.split('/')[-1]
- time.sleep(15)
- return False
-
- def __wait_for_activation(self, image_id):
- # Keep waiting until the image is active or activation fails.
- active = False
- while not active:
- image = self.get_image("/xyz/openbmc_project/software/" + image_id)
- if 'xyz.openbmc_project.Software.Activation.Activations.Active' \
- == image['Activation']:
- print 'Activation Progress: 100%'
- active = True
- elif 'xyz.openbmc_project.Software.Activation.Activations.Activating' \
- == image['Activation']:
- print 'Activation Progress: ' + str(image['Progress']) + '%'
- else:
- raise Exception("Image activation failed. The BMC has set " \
- + "the'Activation' property to " + image['Activation'])
- time.sleep(15)
-
-def do_list_sfw(args):
- s = BMC(server=args.server)
- for e in s.list_sfw():
- if (e == '/xyz/openbmc_project/software/active'):
- continue
- if (e == '/xyz/openbmc_project/software/functional'):
- continue
- info = s.get_image(e)
- if (((info['Purpose'] == 'xyz.openbmc_project.Software.Version.VersionPurpose.BMC') and
- (args.bmc or not args.host)) or \
- ((info['Purpose'] == 'xyz.openbmc_project.Software.Version.VersionPurpose.Host') and
- (args.host or not args.bmc))):
- print(e)
- print json.dumps(info, indent=4)
-
-def do_view_image(args):
- s = BMC(server=args.server)
- print json.dumps(s.get_image(args.image), indent=4)
-
-def do_upload_image(args):
- s = BMC(server=args.server)
- s.upload_image(args.image)
-
-def do_activate_image(args):
- s = BMC(server=args.server)
- s.activate_image(args.image_id)
-
-def do_update_auto(args):
- s = BMC(server=args.server)
- s.update_auto(args.image, args.reboot)
-
-def do_delete_image(args):
- s = BMC(server=args.server)
- s.delete_image(args.image_id)
-
-def do_set_priority(args):
- s = BMC(server=args.server)
- s.set_priority(args.image_id,args.priority)
-
-parser = argparse.ArgumentParser()
-parser.add_argument('--server', help='hostname or IP of BMC', type=str,
- required=True)
-parser.add_argument('--suppress-insecure-warnings', '-I', action="store_true",
- default=False)
-
-subparsers = parser.add_subparsers()
-list_events = subparsers.add_parser('list', help='List all software images on BMC')
-list_events.set_defaults(func=do_list_sfw)
-list_events.add_argument(
- '--bmc',
- action='store_true',
- default=False,
- help='Set if you want to see BMC images')
-list_events.add_argument(
- '--host',
- action='store_true',
- default=False,
- help='Set if you want to see Host images')
-
-image_view = subparsers.add_parser('view', help='View info of input image')
-image_view.add_argument('image', help='The image to analyze')
-image_view.set_defaults(func=do_view_image)
-
-image_upload = subparsers.add_parser('upload', help='Upload input image')
-image_upload.add_argument('image', help='The image to upload')
-image_upload.set_defaults(func=do_upload_image)
-
-image_activate = subparsers.add_parser('activate', help='Activate input image id')
-image_activate.add_argument('image_id', help='The image id to activate')
-image_activate.set_defaults(func=do_activate_image)
-
-image_update_auto = subparsers.add_parser('update_auto', help='Upload and '
- + 'activate an image, and then reboot the BMC to apply the update '
- + 'if necessary')
-image_update_auto.add_argument('image', help='The image to update to')
-image_update_auto.add_argument(
- '--reboot',
- action='store_true',
- default=False,
- help='Set if the BMC should reboot after the update')
-image_update_auto.set_defaults(func=do_update_auto)
-
-image_delete = subparsers.add_parser('delete', help='Delete input image id')
-image_delete.add_argument('image_id', help='The image id to delete')
-image_delete.set_defaults(func=do_delete_image)
-
-image_priority = subparsers.add_parser('priority', help='Set priority of input image')
-image_priority.add_argument('image_id', help='The image id to set priority of')
-image_priority.add_argument('priority', help='The priority to set')
-image_priority.set_defaults(func=do_set_priority)
-
-args = parser.parse_args()
-
-if args.suppress_insecure_warnings:
- from requests.packages.urllib3.exceptions import InsecureRequestWarning
- requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
-
-if 'func' in args:
- args.func(args)
-else:
- parser.print_help()
diff --git a/upload_and_update/LICENSE b/upload_and_update/LICENSE
deleted file mode 100644
index 78e3d2c..0000000
--- a/upload_and_update/LICENSE
+++ /dev/null
@@ -1,14 +0,0 @@
-Copyright 2017 IBM Corp.
-
-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
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-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.
-
diff --git a/upload_and_update/README.md b/upload_and_update/README.md
deleted file mode 100644
index 161a29f..0000000
--- a/upload_and_update/README.md
+++ /dev/null
@@ -1,30 +0,0 @@
-# openbmc-utils
-
-* `upload_and_update.py`
-A tool to upload a tarball to TFTP server and update BMC with it.
-**Note**: It uses legacy methods to update BMC so it may break in future when the code update is refactored.
-
-* `sensor_yaml_config.py`
-A tool to help write IPMI sensor yaml config.
-**Note**: This script requires python3.6 or above.
-
- * To sort the yaml config:
- ```
- sensor_yaml_config.py -i <input.yaml> -o <output.yaml>
- ```
- * To add the missing enityID, entityInstance, and sensorNamePattern:
- ```
- sensor_yaml_config.py -i <input.yaml> -o <output.yaml> -f
- ```
- * To add missing core/dimm temperature sensors based on RPT (generated by OpenPOWER op-build):
- ```
- sensor_yaml_config.py -i <input.yaml> -o <output.yaml> -f -r <machine.rpt>
- ```
- * To generate a sensor map from example yaml config, which could be used for future:
- ```
- sensor_yaml_config.py -i <sample.yaml> -o <sensor_map.yaml> -g
- ```
- * To generate a DCMI sensor json config, which is used by phosphor-ipmi-config:
- ```
- sensor_yaml_config.py -i <input.yaml> -o <output.json> -d
- ```
diff --git a/upload_and_update/upload_and_update.py b/upload_and_update/upload_and_update.py
deleted file mode 100755
index 8a73b8f..0000000
--- a/upload_and_update/upload_and_update.py
+++ /dev/null
@@ -1,230 +0,0 @@
-#!/usr/bin/env python
-"""
-Usage: upload_and_update.py <--file tarball>
- <--tftp user@tftp-ip:/path/to/tftproot>
- [--password SSH-PASSWORD-TO-TFTP]
- --bmc <bmc-ip>
- [--noprepare]
- [-v]
-
-This scripts copies OpenBMC tarball to TFTP server,
-and uses REST APIs to update the tarball to BMC.
-
-Note on tftp server the tarball will be renamed to tarball_<user>
-"""
-
-import argparse
-import json
-import os
-import subprocess
-from subprocess import check_call, CalledProcessError
-from time import sleep
-
-
-def get_tftp_ip(tftp):
- if '@' in tftp:
- ip = tftp.split('@')[1].split(':')[0]
- else:
- ip = tftp.split(':')[0]
- return ip
-
-
-def get_filename(tarball):
- return os.path.basename(tarball)
-
-def get_server_filename(tftp, tarball):
- if '@' in tftp:
- user = tftp.split('@')[0]
- else:
- import getpass
- user = getpass.getuser()
- return get_filename(tarball) + "_" + user
-
-
-def checkBmcAlive(bmc):
- cmds = ['ping', '-c', '1', bmc]
- try:
- check_call(cmds, stdout=FNULL, stderr=FNULL)
- except CalledProcessError:
- return False
- else:
- return True
-
-
-def login(bmc):
- url = 'https://%s/login' % bmc
- cmds = ['curl', '-s', '-c', 'cjar', '-k', '-X', 'POST', '-H',
- 'Content-Type: application/json', '-d',
- '{"data": [ "root", "0penBmc"]}', url]
- try:
- check_call(cmds, stdout=FNULL, stderr=FNULL)
- except CalledProcessError:
- return False
- else:
- return True
-
-
-def prepare(bmc):
- url = 'https://%s/org/openbmc/control/flash/bmc/action/prepareForUpdate' % bmc
- cmds = ['curl', '-s', '-b', 'cjar', '-k', '-X', 'POST', '-H',
- 'Content-Type: application/json', '-d',
- '{"data": []}', url]
- check_call(cmds, stdout=FNULL, stderr=FNULL)
-
-
-def preserveNetwork(bmc):
- url = 'https://%s/org/openbmc/control/flash/bmc/attr/preserve_network_settings' % bmc
- cmds = ['curl', '-s', '-b', 'cjar', '-k', '-X', 'PUT', '-H',
- 'Content-Type: application/json', '-d',
- '{"data": 1}', url]
- check_call(cmds, stdout=FNULL, stderr=FNULL)
-
-
-def updateViaTFTP(tftp, tarball, bmc):
- tftp_ip = get_tftp_ip(tftp)
- serverfile = get_server_filename(tftp, tarball)
- url = 'https://%s/org/openbmc/control/flash/bmc/action/updateViaTftp' % bmc
- cmds = ['curl', '-s', '-b', 'cjar', '-k', '-X', 'POST', '-H',
- 'Content-Type: application/json', '-d',
- '{"data": ["%s", "%s"]}' % (tftp_ip, serverfile), url]
- check_call(cmds, stdout=FNULL, stderr=FNULL)
-
-
-def applyUpdate(bmc):
- url = 'https://%s/org/openbmc/control/flash/bmc/action/Apply' % bmc
- cmds = ['curl', '-s', '-b', 'cjar', '-k', '-X', 'POST', '-H',
- 'Content-Type: application/json', '-d',
- '{"data": []}', url]
- check_call(cmds, stdout=FNULL, stderr=FNULL)
-
-
-def getProgress(bmc):
- url = 'https://%s/org/openbmc/control/flash/bmc/action/GetUpdateProgress' % bmc
- cmds = ['curl', '-s', '-b', 'cjar', '-k', '-X', 'POST', '-H',
- 'Content-Type: application/json', '-d',
- '{"data": []}', url]
- try:
- output = subprocess.check_output(cmds, stderr=FNULL)
- except CalledProcessError as e:
- # Sometimes curl fails with timeout error, let's ignore it
- return ''
- if FNULL is None: # Do not print log when FNULL is devnull
- print output
- return json.loads(output)['data']
-
-
-def reboot(bmc):
- url = 'https://%s/xyz/openbmc_project/state/bmc0/attr/RequestedBMCTransition' % bmc
- cmds = ['curl', '-s', '-b', 'cjar', '-k', '-X', 'PUT', '-H',
- 'Content-Type: application/json', '-d',
- '{"data": "xyz.openbmc_project.State.BMC.Transition.Reboot"}', url]
- check_call(cmds, stdout=FNULL, stderr=FNULL)
-
-
-def waitForState(state, bmc):
- status = getProgress(bmc)
- while state not in status:
- if 'Error' in status:
- raise Exception(status)
- print 'Still waiting for status: \'%s\', current: \'%s\'' % (state, status.split('\n', 1)[0])
- sleep(5)
- status = getProgress(bmc)
-
-
-def upload(tftp, password, tarball):
- target = "%s/%s" % (tftp, get_server_filename(tftp, tarball))
- print 'Uploading \'%s\' to \'%s\' ...' % (tarball, target)
- if password is None:
- cmds = ['scp', tarball, target]
- else:
- cmds = ['sshpass', '-p', password, 'scp', tarball, target]
- # print cmds
- check_call(cmds, stdout=FNULL, stderr=FNULL)
-
-
-def update(tftp, tarball, bmc, noprepare):
- print 'Update...'
-
- if not noprepare:
- login(bmc)
-
- print 'Prepare BMC to update'
- prepare(bmc)
-
- # After prepare, BMC will reboot, let's wait for it
- print 'Waiting BMC to reboot...'
- sleep(30)
- while not checkBmcAlive(bmc):
- sleep(5)
- print 'BMC is back'
-
- while not login(bmc):
- print 'Login fails, retry...'
- sleep(5)
-
- print 'Logged in'
-
- print 'Preserve network...'
- preserveNetwork(bmc)
-
- print 'Update via TFTP...'
- updateViaTFTP(tftp, tarball, bmc)
-
- print 'Waiting for downloading...'
- sleep(10)
- waitForState('Image ready to apply', bmc)
-
- print 'Apply image...'
- applyUpdate(bmc)
- sleep(10)
- waitForState('Apply Complete', bmc)
-
- print 'Reboot BMC...'
- reboot(bmc)
- sleep(30)
- while not checkBmcAlive(bmc):
- sleep(5)
- pass
-
-
-def main():
- parser = argparse.ArgumentParser(
- description='Upload tarball to remote TFTP server and update it on BMC')
- parser.add_argument('-f', '--file', required=True, dest='tarball',
- help='The tarball to upload and update')
- parser.add_argument('-t', '--tftp', required=True, dest='tftp',
- help='The TFTP address including username and full path')
- parser.add_argument('-p', '--password', dest='password',
- help='The password of TFTP server')
- parser.add_argument('-b', '--bmc', required=True, dest='bmc',
- help='The BMC IP address')
- parser.add_argument('-n', '--noprepare', action='store_true',
- help='Do not invoke prepare, update directly')
- parser.add_argument('-v', '--verbose', action='store_true',
- help='Print verbose log')
-
- args = parser.parse_args()
- args = vars(args)
-
- if args['tftp'] is None or args['tarball'] is None or args['bmc'] is None:
- parser.print_help()
- exit(1)
- global FNULL
- if args['verbose']:
- FNULL = None # Print log to stdout/stderr, for debug purpose
- else:
- FNULL = open(os.devnull, 'w') # Redirect stdout/stderr to devnull
-
- if checkBmcAlive(args['bmc']):
- print 'BMC is alive'
- else:
- print 'BMC is down, check it first'
- exit(1)
-
- upload(args['tftp'], args['password'], args['tarball'])
- update(args['tftp'], args['tarball'], args['bmc'], args['noprepare'])
-
- print 'Completed!'
-
-if __name__ == "__main__":
- main()