Add 'amboar/obmc-scripts/' from commit '291f081c7dd6cd107ffcaa7af3ede7500b7f7e35'
git-subtree-dir: amboar/obmc-scripts
git-subtree-mainline: 87d27a16765f621cf2b4242bf70d4ce63b371bb0
git-subtree-split: 291f081c7dd6cd107ffcaa7af3ede7500b7f7e35
diff --git a/LICENSE b/LICENSE
index 78e3d2c..8dada3e 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,14 +1,201 @@
-Copyright 2017 IBM Corp.
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
-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
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
- http://www.apache.org/licenses/LICENSE-2.0
+ 1. Definitions.
-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.
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright {yyyy} {name of copyright owner}
+
+ 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/README.md b/README.md
new file mode 100644
index 0000000..20a7ab8
--- /dev/null
+++ b/README.md
@@ -0,0 +1,53 @@
+# The OpenBMC Tools Collection
+
+The goal of this repository is to collect the two-minute hacks you write to
+automate interactions with OpenBMC systems.
+
+It's highly likely the scripts don't meet your needs - they could be
+undocumented, dysfunctional, utterly broken, or sometimes casually `rm -rf ~`.
+Don't even think about looking for tests.
+
+## Repository Rules
+
+* _Always_ inspect what you will be executing
+* Some hacking on your part is to be expected
+
+You have been warned.
+
+## If you're still with us
+
+Then this repository aims to be the default destination for your otherwise
+un-homed scripts. As such we are setting the bar for submission pretty low,
+and we aim to make the process as easy as possible:
+
+## Sending patches
+
+However you want to send patches, we will probably cope:
+
+* Pull-requests [on github](https://github.com/openbmc/openbmc-tools)
+* Patches [sent to the mailing list](https://lists.ozlabs.org/listinfo/openbmc)
+* If you really must [use Gerrit](https://gerrit.openbmc-project.xyz/) we will
+ figure that out too
+
+## What we will do once we have your patches
+
+Look, the `rm -rf ~` thing was a joke, we will be keeping an eye on all of you
+for such shenanigans. But so long as your patches look sane with a cursory
+glance you can expect them to be applied. To be honest, even Perl will be
+considered moderately sane.
+
+## What you must have in your patches
+
+We don't ask for much, but you need to give us at least a
+[Signed-off-by](https://developercertificate.org/), and put your work under the
+Apache 2.0 license. Licensing everything under Apache 2.0 will just hurt our
+heads less. Lets keep the lawyers off our backs. ^
+
+^ Any exceptions must be accompanied by a LICENSE file in the relevant
+subdirectory, and be compatible with Apache 2.0. You thought you would get away
+without any fine print?
+
+## How you consume the repository
+
+Probably with difficulty. Don't expect the layout to remain static, or scripts
+to continue to exist from one commit to the next.
diff --git a/amboar/obmc-scripts/LICENSE b/amboar/obmc-scripts/LICENSE
new file mode 100644
index 0000000..78e3d2c
--- /dev/null
+++ b/amboar/obmc-scripts/LICENSE
@@ -0,0 +1,14 @@
+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/netboot/README.md b/amboar/obmc-scripts/netboot/README.md
similarity index 100%
rename from netboot/README.md
rename to amboar/obmc-scripts/netboot/README.md
diff --git a/netboot/netboot b/amboar/obmc-scripts/netboot/netboot
similarity index 100%
rename from netboot/netboot
rename to amboar/obmc-scripts/netboot/netboot
diff --git a/reboot/petitboot.exp b/amboar/obmc-scripts/reboot/petitboot.exp
similarity index 100%
rename from reboot/petitboot.exp
rename to amboar/obmc-scripts/reboot/petitboot.exp
diff --git a/reboot/reboot.sh b/amboar/obmc-scripts/reboot/reboot.sh
similarity index 100%
rename from reboot/reboot.sh
rename to amboar/obmc-scripts/reboot/reboot.sh
diff --git a/geissonator/openbmc-events/LICENSE b/geissonator/openbmc-events/LICENSE
new file mode 100644
index 0000000..cf1ab25
--- /dev/null
+++ b/geissonator/openbmc-events/LICENSE
@@ -0,0 +1,24 @@
+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/geissonator/openbmc-events/README.md b/geissonator/openbmc-events/README.md
new file mode 100644
index 0000000..5a2bef1
--- /dev/null
+++ b/geissonator/openbmc-events/README.md
@@ -0,0 +1,5 @@
+# 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/geissonator/openbmc-events/openbmc-events b/geissonator/openbmc-events/openbmc-events
new file mode 100755
index 0000000..49ba69d
--- /dev/null
+++ b/geissonator/openbmc-events/openbmc-events
@@ -0,0 +1,208 @@
+#!/bin/env python
+
+import argparse
+import requests
+import json
+
+import urllib3
+from warnings import catch_warnings
+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_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['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')
+ 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 + dump,
+ verify=False)
+ j = r.json()
+ if j['status'] != 'ok':
+ raise Exception("Failed to get dump " + event + ": \n" + r.text)
+
+ 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)
+
+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 'func' in args:
+ args.func(args)
+else:
+ parser.print_help()
diff --git a/geissonator/openbmc-events/openbmc-sensors b/geissonator/openbmc-events/openbmc-sensors
new file mode 100755
index 0000000..c54dc97
--- /dev/null
+++ b/geissonator/openbmc-events/openbmc-sensors
@@ -0,0 +1,75 @@
+#!/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.sort(key=lambda x: int(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():
+ print(e)
+
+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)
+
+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)
+
+args = parser.parse_args()
+
+if 'func' in args:
+ args.func(args)
+else:
+ parser.print_help()
diff --git a/geissonator/openbmc-events/openbmc-sfw b/geissonator/openbmc-events/openbmc-sfw
new file mode 100755
index 0000000..67a8ec3
--- /dev/null
+++ b/geissonator/openbmc-events/openbmc-sfw
@@ -0,0 +1,256 @@
+#!/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.post(
+ self.url + '/org/openbmc/control/bmc0/action/warmReset',
+ headers={'Content-Type': 'application/json'},
+ data='{"data":[]}',
+ 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()