diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..429666f --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +*.swp +.vagrant/ +tmp/ +var/ +log/ +etc/config.* +!etc/config.yaml.example +!etc/config.yaml.travis +vendor/ +.bundle/ diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..fa0cba1 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behaviour that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behaviour by participants include: + +* The use of sexualised language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behaviour and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behaviour. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviours that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behaviour may be +reported by contacting the project team at [help@openflighthpc.org](help@openflighthpc.org). All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..6913e87 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,184 @@ +# Contributing to Flight Inventory + +:+1::tada: Thanks for taking the time to contribute! :tada::+1: + +You want to contribute to Flight Inventory? Welcome! Please read this +document to understand what you can do: + + * [Code of Conduct](#code-of-conduct) + * [Help Others](#help-others) + * [Analyse Issues](#analyse-issues) + * [Report an Issue](#report-an-issue) + * [Contribute Changes](#contribute-changes) + +When contributing to this repository, please first discuss the change +you wish to make via a Github issue or a post on the [OpenFlight +Community site](https://community.openflighthpc.org). + +Please note we have a [code of conduct](CODE_OF_CONDUCT.md), please +follow it in all your interactions with the project. + +## Code of Conduct + +This project and everyone participating in it is governed by the +[OpenFlight Code of Conduct](CODE_OF_CONDUCT.md). By participating, +you are expected to uphold this code. Please report unacceptable +behaviour to [help@openflighthpc.org](mailto:help@openflighthpc.org). + +## Help Others + +You can help Flight Inventory by helping others who use it and need support. + +## Analyse Issues + +Analysing issue reports can be a lot of effort. Any help is welcome! +Go to [the GitHub issue tracker](https://github.com/openflighthpc/flight-inventory/issues?state=open) +and find an open issue which needs additional work or a bugfix +(e.g. issues labeled with "help wanted" or "bug"). + +Additional work could include any further information, or a gist, or +it might be a hint that helps understanding the issue. Maybe you can +even find and [contribute](#contribute-changes) a bugfix? + +## Report an Issue + +If you find a bug - behaviour of Flight Inventory code or documentation +contradicting your expectation - you are welcome to report it. We can +only handle well-reported, actual bugs, so please follow the +guidelines below. + +Once you have familiarised with the guidelines, you can go to the +[GitHub issue tracker for Flight Inventory](https://github.com/openflighthpc/flight-inventory/issues/new) +to report the issue. + +### Quick Checklist for Bug Reports + +Issue report checklist: + + * Real, current bug + * No duplicate + * Reproducible + * Good summary + * Well-documented + * Minimal example + +### Issue handling process + +When an issue is reported, a committer will look at it and either +confirm it as a real issue, close it if it is not an issue, or ask for +more details. + +An issue that is about a real bug is closed as soon as the fix is committed. + +### Reporting Security Issues + +If you find a security issue, please act responsibly and report it not +in the public issue tracker, but directly to us, so we can fix it +before it can be exploited. Please send the related information to +[security@openflighthpc.org](mailto:security@openflighthpc.org). + +### Issue Reporting Disclaimer + +We want to improve the quality of Flight Inventory and good bug reports are +welcome! However, our capacity is limited, thus we reserve the right +to close or to not process bug reports with insufficient detail in +favour of those which are very cleanly documented and easy to +reproduce. Even though we would like to solve each well-documented +issue, there is always the chance that it will not happen - remember: +Flight Inventory is Open Source and comes without warranty. + +Bug report analysis support is very welcome! (e.g. pre-analysis or +proposing solutions) + +## Contribute Changes + +You are welcome to contribute code, content or documentation to +Flight Inventory in order to fix bugs or to implement new features. + +There are three important things to know: + +1. You must be aware of the Eclipse Public License 2.0 (which + describes contributions) and **agree to the Contributors License + Agreement**. This is common practice in all major Open Source + projects. +2. **Not all proposed contributions can be accepted**. Some features + may e.g. just fit a third-party add-on better. The change must fit + the overall direction of Flight Inventory and really improve it. The more + effort you invest, the better you should clarify in advance whether + the contribution fits: the best way would be to just open an issue + to discuss the feature you plan to implement (make it clear you + intend to contribute). + +### Contributor License Agreement + +When you contribute (code, documentation, or anything else), you have +to be aware that your contribution is covered by the same [Eclipse +Public License 2.0](https://opensource.org/licenses/EPL-2.0) that is +applied to Flight Inventory itself. + +In particular you need to agree to the Contributor License Agreement, +which can be [found +here](https://www.clahub.com/agreements/openflighthpc/flight-inventory). This +applies to all contributors, including those contributing on behalf of +a company. If you agree to its content, you simply have to click on +the link posted by the CLA assistant available on the pull +request. Click it to check the CLA, then accept it on the following +screen if you agree to it. CLA assistant will save this decision for +upcoming contributions and will notify you if there is any change to +the CLA in the meantime. + +## Pull Request Process + +1. Make sure the change would be welcome (e.g. a bugfix or a useful + feature); best do so by proposing it in a GitHub issue. +2. Fork, then clone the repo. +3. Make your changes ([see below](#making-changes)) and commit. +4. In the commit message: + - Describe the problem you fix with this change. + - Describe the effect that this change has from a user's point of + view. App crashes and lockups are pretty convincing for example, + but not all bugs are that obvious and should be mentioned in the + text. + - Describe the technical details of what you changed. It is + important to describe the change in a most understandable way so + the reviewer is able to verify that the code is behaving as you + intend it to. +5. If your change fixes an issue reported at GitHub, add the following + line to the commit message: + - `Fixes #(issueNumber)` + - Do NOT add a colon after "Fixes" - this prevents automatic closing. +6. Open a pull request! +7. Follow the link posted by the CLA assistant to your pull request + and accept it, as described in detail above. +8. Wait for our code review and approval, possibly enhancing your + change on request. + - Note that the Flight Inventory developers also have their regular + duties, so depending on the required effort for reviewing, + testing and clarification this may take a while. +9. Once the change has been approved we will inform you in a comment. +10. We will close the pull request; feel free to delete the now + obsolete branch. + +## Making Changes + +1. Create a topic branch from where you want to base your work. + * This is usually the `master` branch. + * Only target release branches if you are certain your fix must be + on that branch. + * To quickly create a topic branch based on master, run `git + checkout -b fix/master/my_contribution master`. Please avoid + working directly on the `master` branch. +2. Make commits of logical and atomic units. +3. Check for unnecessary whitespace with `git diff --check` before + committing. + +## Attribution + +These contribution guidelines are adapted from +[various](https://github.com/cla-assistant/cla-assistant/blob/master/CONTRIBUTING.md) +[previous](https://github.com/puppetlabs/puppet/blob/master/CONTRIBUTING.md) +[contribution](https://gist.github.com/PurpleBooth/b24679402957c63ec426) +[guideline](https://github.com/atom/atom/blob/master/CONTRIBUTING.md) +documents from other projects hosted on Github. Our thanks to the +respective authors for making contributing to Open Source projects a +more streamlined and efficient process! diff --git a/Gemfile b/Gemfile index 49bc6db..15effce 100644 --- a/Gemfile +++ b/Gemfile @@ -2,17 +2,12 @@ source 'https://rubygems.org' -gem 'commander', github: 'alces-software/commander', :tag => '4.4.4.alces3' +gem 'commander-openflighthpc', '~> 1.1.0' gem 'erubis' -gem 'nodeattr_utils', github: 'alces-software/nodeattr_utils' +gem 'nodeattr_utils' gem 'recursive-open-struct' gem 'rubyzip' gem 'tty-editor' +gem 'tty-prompt' gem 'xmlhasher' gem 'paint' - -group :development do - gem 'pry' - gem 'pry-byebug' -end - diff --git a/Gemfile.lock b/Gemfile.lock index b4c34b1..a468441 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,39 +1,20 @@ -GIT - remote: git://github.com/alces-software/commander.git - revision: 89523312cc16c5454d79b598bec05112ee529d5d - tag: 4.4.4.alces3 - specs: - commander (4.4.4.pre.alces2) - highline (~> 1.7.2) - -GIT - remote: git://github.com/alces-software/nodeattr_utils.git - revision: f5a390bd8701db67ee83284b0c4a900a97de2adf - specs: - nodeattr_utils (0.1.0) - GEM remote: https://rubygems.org/ specs: - byebug (10.0.2) - coderay (1.1.2) + commander-openflighthpc (1.1.0) + highline (~> 1.7.2) + paint (~> 2.1.0) equatable (0.5.0) erubis (2.7.0) escape_utils (1.2.1) highline (1.7.10) - method_source (0.9.2) necromancer (0.4.0) + nodeattr_utils (1.0.0) ox (2.10.0) paint (2.1.0) pastel (0.7.2) equatable (~> 0.5.0) tty-color (~> 0.4.0) - pry (0.12.2) - coderay (~> 1.1.0) - method_source (~> 0.9.0) - pry-byebug (3.6.0) - byebug (~> 10.0) - pry (~> 0.10) recursive-open-struct (1.1.0) rubyzip (1.2.2) timers (4.3.0) @@ -63,15 +44,14 @@ PLATFORMS ruby DEPENDENCIES - commander! + commander-openflighthpc (~> 1.1.0) erubis - nodeattr_utils! + nodeattr_utils paint - pry - pry-byebug recursive-open-struct rubyzip tty-editor + tty-prompt xmlhasher BUNDLED WITH diff --git a/INSTALL.md b/INSTALL.md index e1153fe..2d38eb1 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,12 +1,12 @@ -## Installation +# Installing Flight Inventory -### Generic +## Generic -Inventoryware requires a recent version of `ruby` (2.5.1<=) and `bundler`. +Flight Inventory requires a recent version of `ruby` (2.5.1<=) and `bundler`. The following will install from source using `git`: ``` -git clone https://github.com/alces-software/inventoryware.git -cd inventoryware +git clone https://github.com/openflighthpc/flight-inventory.git +cd flight-inventory bundle install ``` @@ -14,67 +14,41 @@ The entry script is located at `bin/inventory` Note: Interactive editing requires `vim` be installed, this is available in most standard package repositories (yum/zypper/apt/etc). -### Flight Core +## Installing with Flight Runway -Inventoryware can be installed as a tool to the flight-core environment. +Flight Runway (and Flight Tools) provides the Ruby environment and command-line helpers for running openflightHPC tools. -### Automated Installation +To install Flight Runway, see the [Flight Runway installation docs](https://github.com/openflighthpc/flight-runway#installation>) and for Flight Tools, see the [Flight Tools installation docs](https://github.com/openflighthpc/openflight-tools#installation>). -- Install Flight Core (if not already installed) +These instructions assume that `flight-runway` and `flight-tools` have been installed from the openflightHPC yum repository and [system-wide integration](https://github.com/openflighthpc/flight-runway#system-wide-integration) enabled. -``` -yum install https://s3-eu-west-1.amazonaws.com/alces-flight/rpms/flight-core-0.1.0%2B20190121150201-1.el7.x86_64.rpm -``` - -- **Note: If Flight Core has just been installed then logout and in again or source `/etc/profile.d/alces-flight.sh`** - -- The installation script (located at `scripts/install`) has variables that can be optionally set in the curl command. - - `alces_INSTALL_DIR` - The directory to clone the tool into - - `alces_VERSION` - The version of the tool to install - -- Run the installation script - -``` -# Standard install -curl https://raw.githubusercontent.com/alces-software/inventoryware/master/scripts/install |/bin/bash - -# Installation with variables -curl https://raw.githubusercontent.com/alces-software/inventoryware/master/scripts/install |alces_INSTALL_DIR=/my/install/path/ alces_VERSION=dev-release /bin/bash -``` - -### Local Installation - -Instead of depending on an upstream location, Inventoryware can be installed from a local copy of the repository in the following manner. - -- Install Flight Core (if not already installed) +Integrate Flight Inventory to runway: ``` -yum install https://s3-eu-west-1.amazonaws.com/alces-flight/rpms/flight-core-0.1.0%2B20190121150201-1.el7.x86_64.rpm +[root@myhost ~]# flintegrate /opt/flight/opt/openflight-tools/tools/flight-inventory.yml +Loading integration instructions ... OK. +Verifying instructions ... OK. +Downloading from URL: https://github.com/openflighthpc/flight-inventory/archive/master.zip ... OK. +Extracting archive ... OK. +Performing configuration ... OK. +Integrating ... OK. ``` -- **Note: If Flight Core has just been installed then logout and in again or source `/etc/profile.d/alces-flight.sh`** - -- Execute the install script from inside the `inventoryware` directory +Flight Inventory is now available via the `flight` tool:: ``` -bash scripts/install -``` - -*Note: Local installations will use the currently checked out branch instead of using the latest release. To override this do `alces_VERSION=branchname bash scripts/install`.* +[root@myhost ~]# flight inventory + NAME: -### Post Installation + flight inventory -- Now logout and in again or source `/etc/profile.d/alces-flight.sh` + DESCRIPTION: -- Inventoryware can now be run as follows + Parser of hardware information into unified formats. -``` -flight inventory -``` - -- Alternatively, a sandbox environment for Inventoryware can be entered as follows + COMMANDS: + delete Delete the stored data for one or more nodes + edit Edit stored data for a node + ``` -flight shell inventory -``` - diff --git a/LICENSE.txt b/LICENSE.txt index e48ad2f..c43ced4 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,25 +1,278 @@ -Copyright (C) 2018-19 Stephen F Norledge & Alces Software Ltd. - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU Affero General Public License as -published by the Free Software Foundation, either version 3 of the -License, or (at your option) any later version. - -This software 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 -Affero General Public License for more details. - -You should have received a copy of the GNU Affero General Public -License along with this software. If not, see -. - -This package is available under a dual licensing model whereby use of -the package in projects that are licensed so as to be compatible with -AGPL Version 3 may use the package under the terms of that -license. However, if AGPL Version 3.0 terms are incompatible with your -planned use of this package, alternative license terms are available -from Alces Software Ltd - please direct inquiries about licensing to -licensing@alces-software.com. - -For more information, please visit . +Eclipse Public License - v 2.0 + + THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE + PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION + OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + + a) in the case of the initial Contributor, the initial content + Distributed under this Agreement, and + + b) in the case of each subsequent Contributor: + i) changes to the Program, and + ii) additions to the Program; + where such changes and/or additions to the Program originate from + and are Distributed by that particular Contributor. A Contribution + "originates" from a Contributor if it was added to the Program by + such Contributor itself or anyone acting on such Contributor's behalf. + Contributions do not include changes or additions to the Program that + are not Modified Works. + +"Contributor" means any person or entity that Distributes the Program. + +"Licensed Patents" mean patent claims licensable by a Contributor which +are necessarily infringed by the use or sale of its Contribution alone +or when combined with the Program. + +"Program" means the Contributions Distributed in accordance with this +Agreement. + +"Recipient" means anyone who receives the Program under this Agreement +or any Secondary License (as applicable), including Contributors. + +"Derivative Works" shall mean any work, whether in Source Code or other +form, that is based on (or derived from) the Program and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. + +"Modified Works" shall mean any work in Source Code or other form that +results from an addition to, deletion from, or modification of the +contents of the Program, including, for purposes of clarity any new file +in Source Code form that contains any contents of the Program. Modified +Works shall not include works that contain only declarations, +interfaces, types, classes, structures, or files of the Program solely +in each case in order to link to, bind by name, or subclass the Program +or Modified Works thereof. + +"Distribute" means the acts of a) distributing or b) making available +in any manner that enables the transfer of a copy. + +"Source Code" means the form of a Program preferred for making +modifications, including but not limited to software source code, +documentation source, and configuration files. + +"Secondary License" means either the GNU General Public License, +Version 2.0, or any later versions of that license, including any +exceptions or additional permissions as identified by the initial +Contributor. + +2. GRANT OF RIGHTS + + a) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free copyright + license to reproduce, prepare Derivative Works of, publicly display, + publicly perform, Distribute and sublicense the Contribution of such + Contributor, if any, and such Derivative Works. + + b) Subject to the terms of this Agreement, each Contributor hereby + grants Recipient a non-exclusive, worldwide, royalty-free patent + license under Licensed Patents to make, use, sell, offer to sell, + import and otherwise transfer the Contribution of such Contributor, + if any, in Source Code or other form. This patent license shall + apply to the combination of the Contribution and the Program if, at + the time the Contribution is added by the Contributor, such addition + of the Contribution causes such combination to be covered by the + Licensed Patents. The patent license shall not apply to any other + combinations which include the Contribution. No hardware per se is + licensed hereunder. + + c) Recipient understands that although each Contributor grants the + licenses to its Contributions set forth herein, no assurances are + provided by any Contributor that the Program does not infringe the + patent or other intellectual property rights of any other entity. + Each Contributor disclaims any liability to Recipient for claims + brought by any other entity based on infringement of intellectual + property rights or otherwise. As a condition to exercising the + rights and licenses granted hereunder, each Recipient hereby + assumes sole responsibility to secure any other intellectual + property rights needed, if any. For example, if a third party + patent license is required to allow Recipient to Distribute the + Program, it is Recipient's responsibility to acquire that license + before distributing the Program. + + d) Each Contributor represents that to its knowledge it has + sufficient copyright rights in its Contribution, if any, to grant + the copyright license set forth in this Agreement. + + e) Notwithstanding the terms of any Secondary License, no + Contributor makes additional grants to any Recipient (other than + those set forth in this Agreement) as a result of such Recipient's + receipt of the Program under the terms of a Secondary License + (if permitted under the terms of Section 3). + +3. REQUIREMENTS + +3.1 If a Contributor Distributes the Program in any form, then: + + a) the Program must also be made available as Source Code, in + accordance with section 3.2, and the Contributor must accompany + the Program with a statement that the Source Code for the Program + is available under this Agreement, and informs Recipients how to + obtain it in a reasonable manner on or through a medium customarily + used for software exchange; and + + b) the Contributor may Distribute the Program under a license + different than this Agreement, provided that such license: + i) effectively disclaims on behalf of all other Contributors all + warranties and conditions, express and implied, including + warranties or conditions of title and non-infringement, and + implied warranties or conditions of merchantability and fitness + for a particular purpose; + + ii) effectively excludes on behalf of all other Contributors all + liability for damages, including direct, indirect, special, + incidental and consequential damages, such as lost profits; + + iii) does not attempt to limit or alter the recipients' rights + in the Source Code under section 3.2; and + + iv) requires any subsequent distribution of the Program by any + party to be under a license that satisfies the requirements + of this section 3. + +3.2 When the Program is Distributed as Source Code: + + a) it must be made available under this Agreement, or if the + Program (i) is combined with other material in a separate file or + files made available under a Secondary License, and (ii) the initial + Contributor attached to the Source Code the notice described in + Exhibit A of this Agreement, then the Program may be made available + under the terms of such Secondary Licenses, and + + b) a copy of this Agreement must be included with each copy of + the Program. + +3.3 Contributors may not remove or alter any copyright, patent, +trademark, attribution notices, disclaimers of warranty, or limitations +of liability ("notices") contained within the Program from any copy of +the Program which they Distribute, provided that Contributors may add +their own appropriate notices. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities +with respect to end users, business partners and the like. While this +license is intended to facilitate the commercial use of the Program, +the Contributor who includes the Program in a commercial product +offering should do so in a manner which does not create potential +liability for other Contributors. Therefore, if a Contributor includes +the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and indemnify every +other Contributor ("Indemnified Contributor") against any losses, +damages and costs (collectively "Losses") arising from claims, lawsuits +and other legal actions brought by a third party against the Indemnified +Contributor to the extent caused by the acts or omissions of such +Commercial Contributor in connection with its distribution of the Program +in a commercial product offering. The obligations in this section do not +apply to any claims or Losses relating to any actual or alleged +intellectual property infringement. In order to qualify, an Indemnified +Contributor must: a) promptly notify the Commercial Contributor in +writing of such claim, and b) allow the Commercial Contributor to control, +and cooperate with the Commercial Contributor in, the defense and any +related settlement negotiations. The Indemnified Contributor may +participate in any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those performance +claims and warranties, and if a court requires any other Contributor to +pay any damages as a result, the Commercial Contributor must pay +those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT +PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED 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. Each Recipient is solely responsible for determining the +appropriateness of using and distributing the Program and assumes all +risks associated with its exercise of rights under this Agreement, +including but not limited to the risks and costs of program errors, +compliance with applicable laws, damage to or loss of data, programs +or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT +PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS +SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST +PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE +EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further +action by the parties hereto, such provision shall be reformed to the +minimum extent necessary to make such provision valid and enforceable. + +If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other software +or hardware) infringes such Recipient's patent(s), then such Recipient's +rights granted under Section 2(b) shall terminate as of the date such +litigation is filed. + +All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of +time after becoming aware of such noncompliance. If all Recipient's +rights under this Agreement terminate, Recipient agrees to cease use +and distribution of the Program as soon as reasonably practicable. +However, Recipient's obligations under this Agreement and any licenses +granted by Recipient relating to the Program shall continue and survive. + +Everyone is permitted to copy and distribute copies of this Agreement, +but in order to avoid inconsistency the Agreement is copyrighted and +may only be modified in the following manner. The Agreement Steward +reserves the right to publish new versions (including revisions) of +this Agreement from time to time. No one other than the Agreement +Steward has the right to modify this Agreement. The Eclipse Foundation +is the initial Agreement Steward. The Eclipse Foundation may assign the +responsibility to serve as the Agreement Steward to a suitable separate +entity. Each new version of the Agreement will be given a distinguishing +version number. The Program (including Contributions) may always be +Distributed subject to the version of the Agreement under which it was +received. In addition, after a new version of the Agreement is published, +Contributor may elect to Distribute the Program (including its +Contributions) under the new version. + +Except as expressly stated in Sections 2(a) and 2(b) above, Recipient +receives no rights or licenses to the intellectual property of any +Contributor under this Agreement, whether expressly, by implication, +estoppel or otherwise. All rights in the Program not expressly granted +under this Agreement are reserved. Nothing in this Agreement is intended +to be enforceable by any entity that is not a Contributor or Recipient. +No third-party beneficiary rights are created under this Agreement. + +Exhibit A - Form of Secondary Licenses Notice + +"This Source Code may also be made available under the following +Secondary Licenses when the conditions for such availability set forth +in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), +version(s), and exceptions or additional permissions here}." + + Simply including a copy of this Agreement, including this Exhibit A + is not sufficient to license the Source Code under Secondary Licenses. + + If it is not possible or desirable to put the notice in a particular + file, then You may include the notice in a location (such as a LICENSE + file in a relevant directory) where a recipient would be likely to + look for such a notice. + + You may add additional accurate notices of copyright ownership. + diff --git a/Makefile b/Makefile index 7f744c5..3a8ff03 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ .PHONY: rsync watch-rsync -REMOTE_DIR='/tmp/inventoryware' +REMOTE_DIR='/tmp/flight-inventory' rsync: rsync \ diff --git a/README.md b/README.md index d9c3a3e..f7af7de 100644 --- a/README.md +++ b/README.md @@ -1,107 +1,144 @@ # Flight Inventory -## Use +Parser of various hardware information into workable unified formats. + +## Overview + +Flight Inventory is an asset management tool that parses various Linux command +outputs (e.g. `lshw` and `lsblk`) into YAML data which can be modified and used +to render asset documents. + +## Installation + +For installation instructions please read INSTALL.md + +## Configuration + +### Development + +It is recommended that Flight Inventory is developed locally (so you have all your local +development tools available) and synced, run, and tested in a clean remote environment (to +be in an environment close to what it will normally use in production, and to avoid polluting +or depending on things in your local environment). + +To aid this there is a MakeFile containing `watch-rsync` instructions +``` +gem install rerun # If you don't have this already. +make watch-rsync PASSWORD="password for machine" IP="ip of machine" +``` +This will keep your working directory synced to `/tmp/flight-inventory` + +## Operation The commands' syntax is as follows: ``` -parse DATA_LOCATION +import DATA_LOCATION -delete [NODE SPEC] +delete [ASSET SPEC] -edit NODE [-c] +create ASSET -list +edit ASSET [-c] -modify groups GROUP [NODE SPEC] [-p | -r] [-c] +list [--group GROUP] [--type TYPE] -modify location [NODE SPEC] [-c] +list-map ASSET INDEX -modify notes NODE [-c] +edit-notes ASSET [-c] -modify map NODE [-c] +edit-map ASSET [-c] -modify other KEY=[VALUE] [NODE SPEC] [-c] +modify-groups GROUP [ASSET SPEC] [-p | -r] [-c] -show data NODE +modify-other KEY=[VALUE] [ASSET SPEC] [-c] -show document TEMPLATE_LOCATION [NODE SPEC] [-l DESTINATION] +show [ASSET SPEC] [-l DESTINATION] [-t TEMPLATE | -f FORMAT] ``` -The `parse` command processes zips at the specified location to create files in the `store/` +The `import` command processes zips at the specified location to create files in the `store/` directory. If the location is a directory all '.zips' in it will be processed. Each of these zips are expanded -and any nested zips are processed. Only bottom level .zips are processed so don't allow any node's +and any nested zips are processed. Only bottom level .zips are processed so don't allow any asset's data to be sibling to a .zip. Each zip must contain a `lshw-xml` and a `lsblk-a-P` file. A `groups` file will be processed if it exists. -`delete` removes the data for one or more nodes after a confirmation message. +`create` opens an editor allowing for the creation of a new asset. -`edit` opens the node's data in an editor for manual input. +`delete` removes the data for one or more assets after a confirmation message. -`list` lists all nodes with data in the store. +`edit` opens the asset's data in an editor for manual input. -The `modify groups` command adds GROUP to the secondary groups of one or more nodes. If -p is set -their primary group is set to GROUP. If -r is set GROUP will be removed from the nodes' secondary groups. -Primary groups can't be removed, only overwritten. +`list` lists all assets with data in the store. Type and group switches taking comma separated lists are +available to filter the results. -The `modify location` command starts input prompts to enter one location information for one or more nodes. - -The `modify other` command allows the setting and un-setting of arbitrary fields for one or more nodes. -FIELD is set to VALUE and if VALUE is blank the field is removed from the nodes' data. -A node's groups cannot be set this way because of the special constraints for those fields; for groups please -use `modify groups`. +`list-map` lists all the assets names at the specified INDEX of the specified ASSET's map. -`modify notes` opens an editor for a node's 'notes' section. This is general data store that maintains text +`edit-notes` opens an editor for an asset's 'notes' section. This is general data store that maintains text formatting. -The `modify map` command opens an editor for a node's 'map' section. A 'map' is a key:value store where all +The `edit-map` command opens an editor for an asset's 'map' section. A 'map' is a key:value store where all the keys are numerical and represent port numbers and the values are text. The lines of the editor refer to the keys of the map, the editor has its line numbers set to 'on' to aid entry. -`show data` displays the selected node's data in the terminal. +The `modify-groups` command adds GROUP to the secondary groups of one or more assets. If -p is set +their primary group is set to GROUP. If -r is set GROUP will be removed from the assets' secondary groups. +Primary groups can't be removed, only overwritten. + +The `modify-other` command allows the setting and un-setting of arbitrary fields for one or more assets. +FIELD is set to VALUE and if VALUE is blank the field is removed from the assets' data. +An asset's groups cannot be set this way because of the special constraints for those fields; for groups please +use `modify groups`. -The `show document` command fills eRuby templates using stored data. The first argument is the template to -be filled, see 'Templates' section for details. First the argument's value will be used to search the -`templates/` directory then, if nothing is found, it will be used as a path. The output will be passed to stdout -unless a destination is specified with the `-l` option. +The `show` command fills eRuby templates using stored data. Either a path to a template can be passed with the +`-t`option or a template can be inferred from the assets' type and a format (given with `-f`). +The output will be passed to stdout unless a destination is specified with the `-l` option. -NODE_SPEC refers to specification of more than one node. This is done in the same way for all commands. -Either nodes names are given, separated by commas, or `--all` can be passed to supersede this process the -data for all nodes directory. Additionally groups can be selected with the `-g` option in which case all -nodes in the specified groups will be processed. +ASSET_SPEC refers to specification of more than one asset. This is done in the same way for all commands. +Either assets names are given, separated by commas, or `--all` can be passed to supersede this process the +data for all assets directory. Additionally groups can be selected with the `-g` option in which case all +assets in the specified groups will be processed. For all the editing and modifying commands if the `--create/-c` option is used a new file will be created -for each node if it doesn't already exist. +for each asset if it doesn't already exist. -## Installation +### Templates -For installation instructions please read INSTALL.md +Templates accepted by Flight Inventory are .erb templates filled using Erubis. The data is accessible through +a large recursive OpenStruct called `@asset_data`. The equivalent data is also available in a hash called +`@asset_hash`. There are helper methods for navigation and formatting this data in `erb_utils.rb`. Additionally, +in order to the accommodate all possible domains of use, the system will dynamically read any code stored in +the top level `helpers/` directory and utilise that for filling the specified template. -## Development +# Plugins -It is recommended that Flight Inventory is developed locally (so you have all your local -development tools available) and synced, run, and tested in a clean remote environment (to -be in an environment close to what it will normally use in production, and to avoid polluting -or depending on things in your local environment). +Flight Inventory also supports plugins. To render asset data in new and interesting ways place additional +code in the `plugins/` directory. These plugins must have an `etc/templates.yml` file specifying formats for +rendered templates and all ruby files will be evaluated as source code. -To aid this there is a MakeFile containing `watch-rsync` instructions -``` -gem install rerun # If you don't have this already. -make watch-rsync PASSWORD="password for machine" IP="ip of machine" -``` -This will keep your working directory synced to `/tmp/inventoryware` +# Contributing -## Templates +Fork the project. Make your feature addition or bug fix. Send a pull +request. Bonus points for topic branches. -Templates accepted by Flight Inventory are .erb templates filled using Erubis. The data is accessible through -a large recursive OpenStruct called `@node_data`. The equivalent data is also available in a hash called -`@node_hash`. There are helper methods for navigation and formatting this data in `erb_utils.rb`. Additionally, -in order to the accommodate all possible domains of use, the system will dynamically read any code stored in -the top level `helpers/` directory and utilise that for filling the specified template. +Read [CONTRIBUTING.md](CONTRIBUTING.md) for more details. + +# Copyright and License + +Eclipse Public License 2.0, see [LICENSE.txt](LICENSE.txt) for details. -# License +Copyright (C) 2019-present Alces Flight Ltd. -AGPLv3+ License, see LICENSE.txt for details. +This program and the accompanying materials are made available under +the terms of the Eclipse Public License 2.0 which is available at +[https://www.eclipse.org/legal/epl-2.0](https://www.eclipse.org/legal/epl-2.0), +or alternative license terms made available by Alces Flight Ltd - +please direct inquiries about licensing to +[licensing@alces-flight.com](mailto:licensing@alces-flight.com). -Copyright (C) 2017 Alces Software Ltd. +Flight Inventory is distributed in the hope that it will be +useful, but 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. See the [Eclipse Public License 2.0](https://opensource.org/licenses/EPL-2.0) for more +details. diff --git a/bin/inventory b/bin/inventory index 85411b6..ea462b2 100755 --- a/bin/inventory +++ b/bin/inventory @@ -1,5 +1,30 @@ #!/usr/bin/env ruby - +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== lib_dir = File.join(__FILE__, '../../lib') $LOAD_PATH << lib_dir ENV['BUNDLE_GEMFILE'] ||= File.join(__FILE__, '../../Gemfile') @@ -10,4 +35,5 @@ require 'bundler' Bundler.setup(:default) require 'inventoryware/cli' +Dir.chdir(ENV.fetch('FLIGHT_CWD','.')) Inventoryware::CLI.run! diff --git a/etc/templates.yml b/etc/templates.yml new file mode 100644 index 0000000..8f08239 --- /dev/null +++ b/etc/templates.yml @@ -0,0 +1,12 @@ +default: + default: server.md.erb +data: + default: asset.yml.erb +markdown: + default: server.md.erb + server: server.md.erb + switch: switch.md.erb +flightcenter: + default: serverFC.md.erb + server: serverFC.md.erb + switch: switchFC.md.erb diff --git a/helpers/bios_selector.rb b/helpers/bios_selector.rb index 7d11f98..91055d2 100644 --- a/helpers/bios_selector.rb +++ b/helpers/bios_selector.rb @@ -1,5 +1,31 @@ +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== def select_bios - product = @node_data.lshw.list.node.product rescue '' + product = @asset_data.lshw.list.node.product rescue '' product = product.downcase.split(' ') # we look for sub templates with increasingly short names diff --git a/helpers/checks.rb b/helpers/checks.rb index 8166534..6ea3e1c 100644 --- a/helpers/checks.rb +++ b/helpers/checks.rb @@ -1,25 +1,30 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== def imported? - @node_hash.key?('lshw') and @node_hash.key?('lsblk') + @asset_hash.key?('lshw') and @asset_hash.key?('lsblk') end diff --git a/helpers/cpu.rb b/helpers/cpu.rb index fa8c23e..27f4205 100644 --- a/helpers/cpu.rb +++ b/helpers/cpu.rb @@ -1,3 +1,29 @@ +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== def cpus def create_cpu(cpu_hash) OpenStruct.new(cpu_hash).tap do |o| @@ -5,7 +31,7 @@ def create_cpu(cpu_hash) end end cpus = [] - find_hashes_with_key_value(@node_hash, 'class', 'processor').each do |cpu_hash| + find_hashes_with_key_value(@asset_hash, 'class', 'processor').each do |cpu_hash| cpus << create_cpu(cpu_hash) end cpus diff --git a/helpers/finders.rb b/helpers/finders.rb index d4d10e4..06424c5 100644 --- a/helpers/finders.rb +++ b/helpers/finders.rb @@ -1,26 +1,31 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== -#value' can be a regular expression or a plain old string +#'value' can be a regular expression or a plain old string def find_hashes_with_key_value(obj, key, value, store = []) if obj.respond_to?(:key?) && obj.key?(key) && /#{value}/.match(obj[key]) store.push(obj) diff --git a/helpers/formatters.rb b/helpers/formatters.rb index 4a7791e..f298c7b 100644 --- a/helpers/formatters.rb +++ b/helpers/formatters.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== # convert decimal amount of bits to a human readable format def format_bits_value(bits_value) diff --git a/helpers/memory.rb b/helpers/memory.rb index eadd6cd..c263d69 100644 --- a/helpers/memory.rb +++ b/helpers/memory.rb @@ -1,7 +1,33 @@ +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== # sum the size of each bank of each memory node def find_total_memory total = 0 - find_hashes_with_key_value(@node_hash, 'class', 'memory').each do |mem| + find_hashes_with_key_value(@asset_hash, 'class', 'memory').each do |mem| find_hashes_with_key_value(mem, 'id', '^(bank:).*').each do |bank| total += bank['size'].to_i end diff --git a/helpers/network_device.rb b/helpers/network_device.rb index d9d2829..6591499 100644 --- a/helpers/network_device.rb +++ b/helpers/network_device.rb @@ -1,3 +1,29 @@ +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== def network_devices def create_net(net_hash) OpenStruct.new(net_hash).tap do |o| @@ -5,7 +31,7 @@ def create_net(net_hash) end end network_devices = [] - find_hashes_with_key_value(@node_hash, 'class', 'network')&.each do |net| + find_hashes_with_key_value(@asset_hash, 'class', 'network')&.each do |net| network_devices << create_net(net) end network_devices.sort_by {|hsh| hsh[:logicalname] } diff --git a/helpers/templaters.rb b/helpers/templaters.rb index 3e2e64e..41f779e 100644 --- a/helpers/templaters.rb +++ b/helpers/templaters.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== # all subtemplates are to be held in a specific directory of `templates/` def render_sub_template(subdir, name) diff --git a/lib/inventoryware/cli.rb b/lib/inventoryware/cli.rb index a3f8e5d..6f7203f 100644 --- a/lib/inventoryware/cli.rb +++ b/lib/inventoryware/cli.rb @@ -1,72 +1,50 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/commands' +require 'inventoryware/version' require 'commander' require 'ostruct' require 'yaml' -require 'paint' module Inventoryware module CLI PROGRAM_NAME = ENV.fetch('FLIGHT_PROGRAM_NAME','inventory') extend Commander::Delegates + program :application, "Flight Inventory" program :name, PROGRAM_NAME - program :version, '1.0.0' + program :version, "Release 2019.1 (v#{Inventoryware::VERSION})" program :description, 'Parser of hardware information into unified formats.' program :help_paging, false - - # Display the help if there is no input arguments - ARGV.push '--help' if ARGV.empty? - + default_command :help silent_trace! - error_handler do |e| - $stderr.puts "#{Paint[PROGRAM_NAME, '#2794d8']}: #{Paint[e.to_s, :red]}" - case e - when OptionParser::InvalidOption, - Commander::Runner::InvalidCommandError, - Commander::Patches::CommandUsageError - $stderr.puts "\nUsage:\n\n" - args = ARGV.reject{|o| o[0] == '-'} - if command(topic = args[0..1].join(" ")) - command("help").run(topic) - elsif command(args[0]) - command("help").run(args[0]) - else - command("help").run - end - end - exit(1) - end - class << self - def action(command, klass) - command.action do |args, options| - klass.new(args, options).run! - end - end - def cli_syntax(command, args_str = nil) command.syntax = [ PROGRAM_NAME, @@ -76,116 +54,111 @@ def cli_syntax(command, args_str = nil) end def add_multi_node_options(command) - command.option '--all', "Select all nodes" - command.option '-g', '--group GROUP', - "Select nodes in GROUP, specify commma-separated list for multiple groups" + command.option '--all', "Select all assets" + add_group_option(command) end def add_create_option(command) command.option '-c', '--create', - "Create specified node(s) if they don't exist" + "Create specified asset(s) if they don't exist" + end + + def add_group_option(command) + command.option '-g', '--group GROUP', + "Select assets in GROUP, specify comma-separated list for multiple groups" end end - command :parse do |c| + command :import do |c| cli_syntax(c, 'FILE') c.description = 'Parse and store inventory information' - action(c, Commands::Parse) + c.action Commands, :import end - command :modify do |c| - cli_syntax(c, 'SUBCOMMAND') - c.description = 'Change mutable node data' - c.configure_sub_command(self) - end - - command :'modify other' do |c| - cli_syntax(c, 'KEY=VALUE [NODE_SPEC]') - c.description = "Modify arbitrary data for one or more nodes" - c.hidden = true + command :'modify-other' do |c| + cli_syntax(c, 'KEY=VALUE [ASSET_SPEC]') + c.description = "Modify arbitrary data for one or more assets" add_multi_node_options(c) add_create_option(c) - action(c, Commands::Modifys::Other) + c.action Commands, :'modifys-other' end - command :'modify location' do |c| - cli_syntax(c, '[NODE_SPEC]') - c.description = "Modify location data for one or more nodes" - c.hidden = true + command :'modify-groups' do |c| + cli_syntax(c, 'GROUP [ASSET_SPEC]') + c.description = "Modify group data for one or more assets" add_multi_node_options(c) add_create_option(c) - action(c, Commands::Modifys::Location) + c.option '-p', '--primary', "Modify the primary group of one or more assets" + c.option '-r', '--remove', "Remove one or more assets from this group" + c.action Commands, :'modifys-groups' end - command :'modify groups' do |c| - cli_syntax(c, 'GROUP [NODE_SPEC]') - c.description = "Modify group data for one or more nodes" - c.hidden = true + command :'edit-map' do |c| + cli_syntax(c, '[ASSET_SPEC]') + c.description = "Edit mapping data for one or more assets" add_multi_node_options(c) add_create_option(c) - c.option '-p', '--primary', "Modify the primary group of one or more nodes" - c.option '-r', '--remove', "Remove one or more nodes from this group" - action(c, Commands::Modifys::Groups) - end - - command :'modify map' do |c| - cli_syntax(c, 'NODE') - c.description = "Modify mapping data for a node" - c.hidden = true - add_create_option(c) - action(c, Commands::Modifys::Map) + c.action Commands, :'modifys-map' end - command :'modify notes' do |c| - cli_syntax(c, 'NODE') - c.description = "Modify miscellaneous notes for a node" - c.hidden = true + command :'edit-notes' do |c| + cli_syntax(c, '[ASSET_SPEC]') + c.description = "Edit miscellaneous notes for one or more assets" + add_multi_node_options(c) add_create_option(c) - action(c, Commands::Modifys::Notes) + c.action Commands, :'modifys-notes' end command :list do |c| cli_syntax(c) - c.description = "List all nodes that have stored data" - action(c, Commands::List) + c.description = "List all assets that have stored data" + add_group_option(c) + c.option '-t', '--type TYPE', + "Select assets in TYPE, specify comma-separated list for multiple types" + c.action Commands, :list end command :edit do |c| - cli_syntax(c, 'NODE') - c.description = "Edit stored data for a node" + cli_syntax(c, 'ASSET') + c.description = "Edit stored data for an asset" add_create_option(c) - action(c, Commands::Edit) + c.action Commands, :edit end - command :show do |c| - cli_syntax(c, 'SUBCOMMAND') - c.description = "View data" - c.configure_sub_command(self) - end - - command :'show data' do |c| - cli_syntax(c, 'NODE') - c.description = "View stored data for a node" - c.hidden = true - action(c, Commands::Shows::Data) + command :'list-map' do |c| + cli_syntax(c, 'ASSET INDEX') + c.summary = "List assets stored within mapping data" + c.description = "View asset names stored for ASSET at the specified map INDEX." + c.action Commands, :list_map end - command :'show document' do |c| - cli_syntax(c, 'TEMPLATE [NODE_SPEC]') - c.description = "Render a document template for one or more nodes" + command :show do |c| + cli_syntax(c, '[ASSET_SPEC]') + c.description = "Render a template for one or more assets" + c.option '-t', '--template TEMPLATE', + "Render this specific template\n"\ + "Otherwise use the asset's type to determine the target template "\ + "from a config file." c.option '-l', '--location LOCATION', "Output the rendered template to the specified location" c.option '-d', '--debug', "Display rendering errors" + c.option '-f', '--format FORMAT', + 'Specify the type of template you would like to render' add_multi_node_options(c) - c.hidden = true - action(c, Commands::Shows::Document) + c.action Commands, :show end command :delete do |c| - cli_syntax(c, '[NODE_SPEC]') - c.description = "Delete the stored data for one or more nodes" + cli_syntax(c, '[ASSET_SPEC]') + c.description = "Delete the stored data for one or more assets" add_multi_node_options(c) - action(c, Commands::Delete) + c.action Commands, :delete + end + + command :create do |c| + cli_syntax(c, 'ASSET') + c.description = "Create a new asset" + c.action Commands, :create end end end diff --git a/lib/inventoryware/command.rb b/lib/inventoryware/command.rb index 5099efe..97a5fe1 100644 --- a/lib/inventoryware/command.rb +++ b/lib/inventoryware/command.rb @@ -1,28 +1,33 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== module Inventoryware class Command - def initialize(argv, options) + def initialize(argv, options, command_name = nil) @argv = argv.freeze @options = OpenStruct.new(options.__hash__) end diff --git a/lib/inventoryware/commands.rb b/lib/inventoryware/commands.rb index 42ddef1..bbb8b42 100644 --- a/lib/inventoryware/commands.rb +++ b/lib/inventoryware/commands.rb @@ -1,32 +1,65 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/commands/delete' require 'inventoryware/commands/edit' +require 'inventoryware/commands/create' require 'inventoryware/commands/list' -require 'inventoryware/commands/modifys/location' +require 'inventoryware/commands/list_map' require 'inventoryware/commands/modifys/map' require 'inventoryware/commands/modifys/other' require 'inventoryware/commands/modifys/notes' require 'inventoryware/commands/modifys/groups' -require 'inventoryware/commands/parse' -require 'inventoryware/commands/shows/data' -require 'inventoryware/commands/shows/document' +require 'inventoryware/commands/import' +require 'inventoryware/commands/show' + +module Inventoryware + module Commands + class << self + def method_missing(s, *a, &b) + if clazz = to_class(s) + clazz.new(*a).run! + else + raise 'command not defined' + end + end + + def respond_to_missing?(s) + !!to_class(s) + end + + private + def to_class(s) + s.to_s.split('-').reduce(self) do |clazz, p| + p.gsub!(/_(.)/) {|a| a[1].upcase} + clazz.const_get(p[0].upcase + p[1..-1]) + end + rescue NameError + nil + end + end + end +end diff --git a/lib/inventoryware/commands/create.rb b/lib/inventoryware/commands/create.rb new file mode 100644 index 0000000..24fee61 --- /dev/null +++ b/lib/inventoryware/commands/create.rb @@ -0,0 +1,36 @@ +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== +module Inventoryware + module Commands + class Create < Edit + def run + @options.create = true + super + end + end + end +end diff --git a/lib/inventoryware/commands/delete.rb b/lib/inventoryware/commands/delete.rb index 217a35a..0799d89 100644 --- a/lib/inventoryware/commands/delete.rb +++ b/lib/inventoryware/commands/delete.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/commands/multi_node_command' require 'fileutils' @@ -26,21 +31,17 @@ module Inventoryware module Commands class Delete < MultiNodeCommand def run - node_locations = find_nodes() + nodes = fetch_nodes() - unless node_locations.empty? - prefix = "You are about to delete" - node_locations.map! { |loc| File.expand_path(loc) } - if node_locations.length > 1 - node_msg = "#{prefix}:\n#{node_locations.join("\n")}\nProceed? (y/n)" - else - node_msg = "#{prefix} #{node_locations[0]} - proceed? (y/n)" - end - if $terminal.agree(node_msg) - node_locations.each { |node| FileUtils.rm node } - end + prefix = "You are about to delete" + node_paths = nodes.map { |n| File.expand_path(n.path) } + if node_paths.length > 1 + node_msg = "#{prefix}:\n#{node_paths.join("\n")}\nProceed? (y/n)" else - puts "No nodes found" + node_msg = "#{prefix} #{node_paths[0]} - proceed? (y/n)" + end + if $terminal.agree(node_msg) + node_paths.each { |path| FileUtils.rm path } end end end diff --git a/lib/inventoryware/commands/edit.rb b/lib/inventoryware/commands/edit.rb index 9c8afe4..c0ea096 100644 --- a/lib/inventoryware/commands/edit.rb +++ b/lib/inventoryware/commands/edit.rb @@ -1,36 +1,46 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/commands/single_node_command' require 'tty-editor' module Inventoryware module Commands class Edit < SingleNodeCommand + def create + @options.create = true + run! + end + def action(node) # output to create the node's file if it doesn't yet exist node.save # maybe don't create unless saved? i.e. don't create the file above # instead save as closing - TTY::Editor.open(node.location, command: :rvim) + TTY::Editor.open(node.path, command: :rvim) end end end diff --git a/lib/inventoryware/commands/parse.rb b/lib/inventoryware/commands/import.rb similarity index 70% rename from lib/inventoryware/commands/parse.rb rename to lib/inventoryware/commands/import.rb index 6edfc23..303fe02 100644 --- a/lib/inventoryware/commands/parse.rb +++ b/lib/inventoryware/commands/import.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/command' require 'inventoryware/config' require 'inventoryware/exceptions' @@ -27,12 +32,13 @@ require 'fileutils' require 'xmlhasher' +require 'pathname' require 'yaml' require 'zip' module Inventoryware module Commands - class Parse < Command + class Import < Command def run unless @argv.length() == 1 raise ArgumentError, <<-ERROR.chomp @@ -46,11 +52,27 @@ def run config.string_keys = true end + # determine if given path is absolute + file_name = @argv[0] + file_path = File.expand_path(file_name) + + if file_path.nil? + raise ArgumentError, <<-ERROR.chomp +Please refine your search and try again. + ERROR + else + if not Utils.check_file_readable?(file_path) + raise ArgumentError, <<-ERROR.chomp +Zip file at #{file_path} inaccessible. + ERROR + end + end + begin top_dir = Dir.mktmpdir('inv_ware_') # get all zips in in the source, if it's a dir or not - top_lvl_zip_paths = expand_dir(@argv[0]) + top_lvl_zip_paths = expand_dir(file_path) # for each of these, extract to /tmp/ top_lvl_zip_paths.each { |zip_path| extract_zip(zip_path, top_dir) } @@ -147,16 +169,19 @@ def process_dir(dir) return false end - node_data = {} - node_data['name'] = node_name - node_data['mutable'] = {} + node_data = { + 'name' => node_name, + 'type' => 'server', + 'mutable' => {}, + # extract data from lshw + 'lshw' => XmlHasher.parse(File.read(file_locations['lshw-xml'])), + # extract data from lsblk + 'lsblk' => LsblkParser.new(file_locations['lsblk-a-P']).hashify(), + } + if file_locations['groups'] node_data['mutable'] = YAML.load(File.read(file_locations['groups'])) end - # extract data from lshw - node_data['lshw'] = XmlHasher.parse(File.read(file_locations['lshw-xml'])) - # extract data from lsblk - node_data['lsblk'] = LsblkParser.new(file_locations['lsblk-a-P']).hashify() Utils.exit_unless_dir(Config.yaml_dir) yaml_out_name = "#{node_name}.yaml" diff --git a/lib/inventoryware/commands/list.rb b/lib/inventoryware/commands/list.rb index 9ff3205..43d3073 100644 --- a/lib/inventoryware/commands/list.rb +++ b/lib/inventoryware/commands/list.rb @@ -1,37 +1,77 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/command' require 'inventoryware/config' +require 'inventoryware/node' module Inventoryware module Commands class List < Command def run - #TODO format this to have as many results fit on one line as poss. - #puts files.join(" ") - files = Dir.glob(File.join(Config.yaml_dir, '*.yaml')).map! do |file| - File.basename(file, '.yaml') + # note: this process has become quite time intensive when options are + # passed - taking suggestions on speeding it up + nodes = if not @options.group and not @options.type + Node.find_all_nodes + else + found = [] + all_nodes = Node.find_all_nodes + if @options.group + groups = @options.group.split(',') + found.concat(Node.find_nodes_in_groups(groups, all_nodes)) + end + if @options.type + types = @options.type.split(',') + found.concat(Node.find_nodes_with_types(types, all_nodes)) + end + Node.make_unique(found) + end + + unless nodes.empty? + type_hash = create_hash_of_types(nodes) + type_hash.each do |k,v| + puts "\n##{k.upcase}" + puts v.sort + end + else + return if @options.group or @options.type + $stderr.puts "No asset files found within #{File.expand_path(Config.yaml_dir)}" + end + end + + private + + def create_hash_of_types(nodes) + type_hash = {} + nodes.each do |node| + type = node.type + type_hash[type] = [] unless type_hash.key?(type) + type_hash[type] << node.name end - files.each_slice(3).each { |grp| puts grp.join(" ") } + return type_hash.sort.to_h end end end diff --git a/lib/inventoryware/commands/list_map.rb b/lib/inventoryware/commands/list_map.rb new file mode 100644 index 0000000..2b1ece1 --- /dev/null +++ b/lib/inventoryware/commands/list_map.rb @@ -0,0 +1,71 @@ +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== +require 'inventoryware/commands/single_node_command' + +module Inventoryware + module Commands + class ListMap < SingleNodeCommand + def action(node) + index = @argv[1] + + unless index.to_i.to_s == index + raise ArgumentError, <<-ERROR.chomp +Please provide an integer index + ERROR + end + + index = index.to_i + + unless node.data.dig('mutable', 'map') + raise InventorywareError, <<-ERROR.chomp +Asset '#{node.name}' does not have map data + ERROR + end + + unless node.data.dig('mutable', 'map', index) + raise InventorywareError, <<-ERROR.chomp +Map for asset '#{node.name}' does not have index #{index} + ERROR + end + + line = node.data['mutable']['map'][index] + + asset_names = Dir[File.join(Config.yaml_dir, '*')].map do |p| + p = File.basename(p, File.extname(p)) + end + + asset_names.select! { |name| line.include?(name) } + + if asset_names.empty? + puts "No assets found under that index" + else + puts asset_names + end + end + end + end +end diff --git a/lib/inventoryware/commands/modifys/groups.rb b/lib/inventoryware/commands/modifys/groups.rb index 906d453..304431b 100644 --- a/lib/inventoryware/commands/modifys/groups.rb +++ b/lib/inventoryware/commands/modifys/groups.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/commands/multi_node_command' require 'inventoryware/exceptions' require 'inventoryware/node' @@ -36,9 +41,7 @@ def run group = @argv[0] - find_nodes("group").each do |location| - node= Node.new(location) - node.create_if_non_existent + fetch_nodes("group").each do |node| if @options.primary node.data['mutable']['primary_group'] = group else diff --git a/lib/inventoryware/commands/modifys/location.rb b/lib/inventoryware/commands/modifys/location.rb deleted file mode 100644 index 3cabeeb..0000000 --- a/lib/inventoryware/commands/modifys/location.rb +++ /dev/null @@ -1,61 +0,0 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. -# -# This file/package is part of Alces Inventoryware. -# -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. -# -# Alces Inventoryware 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 -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . -# -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== -require 'inventoryware/commands/multi_node_command' -require 'inventoryware/node' - -module Inventoryware - module Commands - module Modifys - class Location < MultiNodeCommand - def run - node_locations = find_nodes() - - fields = { - 'site' => {'name' => nil, 'value' => nil}, - 'room' => {'name' => nil, 'value' => nil}, - 'rack' => {'name' => nil, 'value' => nil}, - 'start_unit' => {'name' => 'starting rack unit', 'value' => nil}, - } - - # Get input REPL style - fields.each do |field, hash| - name = hash['name'] ? hash['name'] : field - value = $terminal.ask("Enter a #{name} or press enter to skip") - hash['value'] = value unless value == '' - end - - # save data - node_locations.each do |location| - node = Node.new(location) - node.create_if_non_existent - fields.each do |field, hash| - if hash['value'] - node.data['mutable'][field] = hash['value'] - end - end - node.save - end - end - end - end - end -end diff --git a/lib/inventoryware/commands/modifys/map.rb b/lib/inventoryware/commands/modifys/map.rb index 3399222..6051cd9 100644 --- a/lib/inventoryware/commands/modifys/map.rb +++ b/lib/inventoryware/commands/modifys/map.rb @@ -1,36 +1,54 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== -require 'inventoryware/commands/single_node_command' +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== +require 'inventoryware/commands/multi_node_command' require 'inventoryware/exceptions' +require 'inventoryware/node' module Inventoryware module Commands module Modifys - class Map < SingleNodeCommand - def action(node) + class Map < MultiNodeCommand + def run + nodes = fetch_nodes() + node = nodes.first + + prompt = TTY::Prompt.new + unless prompt.no?('Would you like to add map metadata? (Default: No)') + get_map_metadata_from_user(nodes, prompt) + end + map = map_to_string(node.data['mutable']['map']) - map = string_to_map(edit_with_tmp_file(map, :"rvim +'set number'")) - node.data['mutable']['map'] = map - node.save + map = string_to_map(Utils.edit_with_tmp_file(map, + :"rvim +'set number'")) + + nodes.each do |node| + node.data['mutable']['map'] = map + node.save + end end # takes a hash with numerical keys @@ -58,11 +76,37 @@ def map_to_string(map) # returns a hash with each line being a different numerical key def string_to_map(str) map = Hash.new - str.split("\n").each_with_index do |line, i| - map[i+1] = line unless line.empty? + str.lines.map(&:chomp).each_with_index do |line, i| + map[i+1] = line end return map end + + def get_map_metadata_from_user(nodes, prompt) + prompt.say('Enter integer values for the dimensions of the map:') + + x = prompt.ask('Width:') do |q| + q.validate(/^[0-9]+$/, 'Value must be an integer') + end + + y = prompt.ask('Height:') do |q| + q.validate(/^[0-9]+$/, 'Value must be an integer') + end + + choices = { + 'Down then right (starting at top-left)' => 't-l-v', + 'Right the down (starting at top-left)' => 't-l-h', + 'Up then right (starting at bottom-left)' => 'b-l-v', + 'Right then up (starting at bottom-left)' => 'b-l-h' + } + layout = prompt.select('Choose the pattern for the map:', choices) + + nodes.each do |node| + node.data['mutable']['map_height'] = y + node.data['mutable']['map_width'] = x + node.data['mutable']['map_layout'] = layout + end + end end end end diff --git a/lib/inventoryware/commands/modifys/notes.rb b/lib/inventoryware/commands/modifys/notes.rb index a6e961b..f3145e8 100644 --- a/lib/inventoryware/commands/modifys/notes.rb +++ b/lib/inventoryware/commands/modifys/notes.rb @@ -1,35 +1,47 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== -require 'inventoryware/commands/single_node_command' +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== +require 'inventoryware/commands/multi_node_command' +require 'inventoryware/node' module Inventoryware module Commands module Modifys - class Notes < SingleNodeCommand - def action(node) + class Notes < MultiNodeCommand + def run + nodes = fetch_nodes() + node = nodes.first + notes = node.data['mutable'].fetch('notes', '') - notes = edit_with_tmp_file(notes, :rvim).strip - node.data['mutable']['notes'] = notes - node.save + notes = Utils.edit_with_tmp_file(notes, :rvim).strip + + nodes.each do |node| + node.data['mutable']['notes'] = notes + node.save + end end end end diff --git a/lib/inventoryware/commands/modifys/other.rb b/lib/inventoryware/commands/modifys/other.rb index d6c7629..21567e0 100644 --- a/lib/inventoryware/commands/modifys/other.rb +++ b/lib/inventoryware/commands/modifys/other.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/commands/multi_node_command' require 'inventoryware/exceptions' require 'inventoryware/node' @@ -44,9 +49,7 @@ def run ERROR end - find_nodes("modification").each do |location| - node = Node.new(location) - node.create_if_non_existent + fetch_nodes("modification").each do |node| if value node.data['mutable'][field] = value else diff --git a/lib/inventoryware/commands/multi_node_command.rb b/lib/inventoryware/commands/multi_node_command.rb index b885a2e..be32d5d 100644 --- a/lib/inventoryware/commands/multi_node_command.rb +++ b/lib/inventoryware/commands/multi_node_command.rb @@ -1,39 +1,46 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/command' require 'inventoryware/exceptions' -require 'inventoryware/utils' +require 'inventoryware/node' require 'nodeattr_utils' module Inventoryware module Commands class MultiNodeCommand < Command - def find_nodes(*args) + def fetch_nodes(*args) resolve_node_options(@argv, @options, args) - nodes = @argv[args.length] + node_names = @argv[args.length] - node_locations = locate_nodes(nodes, @options) + nodes = find_nodes(node_names, @options) + nodes = Node.make_unique(nodes) + return nodes end private @@ -46,11 +53,11 @@ def resolve_node_options(argv, options, other_args) unless argv.length == other_args.length unless other_args.length == 0 raise ArgumentError, <<-ERROR.chomp -#{arg_str} should be the only argument(s) - all nodes are being parsed +#{arg_str} should be the only argument(s) - all assets are being parsed ERROR else raise ArgumentError, <<-ERROR.chomp -There should be no arguments - all nodes are being parsed +There should be no arguments - all assets are being parsed ERROR end end @@ -59,95 +66,21 @@ def resolve_node_options(argv, options, other_args) # given a set of nodes and relevant options returns an expanded list # of all the necessary nodes - def locate_nodes(nodes, options) - node_locations = [] + def find_nodes(node_names, options) + nodes = [] if options.all - node_locations = find_all_nodes + nodes = Node.find_all_nodes else - if nodes - node_locations.push(*find_single_nodes(nodes, !!options.create)) + if node_names + nodes.push(*Node.find_single_nodes(node_names, !!options.create)) end if options.group - node_locations.push(*find_nodes_in_groups(options.group.split(','))) - end - end - return node_locations - end - - # retrieves all .yaml files in the storage dir - def find_all_nodes() - node_locations = Dir.glob(File.join(Config.yaml_dir, '*.yaml')) - if node_locations.empty? - $stderr.puts "No node data found "\ - "in #{File.expand_path(Config.yaml_dir)}" - end - return node_locations - end - - # retreives all nodes in the given groups - # this quite an intensive method of way to go about searching the yaml - # each file is converted to a sting and then searched - # seems fine as it stands but if speed becomes an issue could stand to - # be changed - def find_nodes_in_groups(groups) - nodes = [] - find_all_nodes().each do |location| - found = [] - File.open(location) do |file| - contents = file.read - m = contents.match(/primary_group: (.*?)$/) - found.append(m[1]) if m - m = contents.match(/secondary_groups: (.*?)$/) - found = found + (m[1].split(',')) if m - end - unless (found & groups).empty? - nodes.append(location) + nodes.push(*Node.find_nodes_in_groups(options.group.split(','))) end end if nodes.empty? - $stderr.puts "No nodes found in #{groups.join(' or ')}." - end - return nodes - end - - # retreives the .yaml file for each of the given nodes - # expands node ranges if they exist - # if return missing is passed, returns paths to the .yamls of non-existent - # nodes - def find_single_nodes(node_str, return_missing = false) - nodes = expand_asterisks(NodeattrUtils::NodeParser.expand(node_str)) - $stderr.puts "No nodes found for '#{node_str}'" if nodes.empty? - node_locations = [] - nodes.each do |node| - node_yaml = "#{node}.yaml" - node_yaml_location = File.join(Config.yaml_dir, node_yaml) - unless Utils.check_file_readable?(node_yaml_location) - $stderr.puts "File #{node_yaml} not found within "\ - "#{File.expand_path(Config.yaml_dir)}" - if return_missing - $stderr.puts "Creating..." - else - $stderr.puts "Skipping." - next - end - end - node_locations.append(node_yaml_location) - end - return node_locations - end - - def expand_asterisks(nodes) - new_nodes = [] - nodes.each do |node| - if node.match(/\*/) - node_names = Dir.glob(File.join(Config.yaml_dir, node)).map { |file| - File.basename(file, '.yaml') - } - new_nodes.push(*node_names) - end + raise ArgumentError, "No assets found" end - nodes.delete_if { |node| node.match(/\*/) } - nodes.push(*new_nodes) return nodes end end diff --git a/lib/inventoryware/commands/show.rb b/lib/inventoryware/commands/show.rb new file mode 100644 index 0000000..b87b0d5 --- /dev/null +++ b/lib/inventoryware/commands/show.rb @@ -0,0 +1,168 @@ +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== +require 'inventoryware/commands/multi_node_command' +require 'inventoryware/config' +require 'inventoryware/exceptions' +require 'inventoryware/node' +require 'inventoryware/templates_config' +require 'inventoryware/utils' + +require 'erubis' +require 'recursive-open-struct' + +module Inventoryware + module Commands + class Show < MultiNodeCommand + def run + nodes = fetch_nodes() + nodes = nodes.sort_by { |node| node.name } + + output(nodes, @options.location) + end + + private + def output(nodes, out_dest) + out = "" + # check, will loading all output cause issues with memory size? + # probably fine - 723 nodes was 350Kb + nodes.each do |node| + out += fill_template(node, find_template(node), render_env) + # $stderr.puts "Rendered #{File.basename(node.path, '.yaml')}" + end + + if out_dest + # Confirm file location exists. + # I decided against creating location if it did not exist as it + # requires sudo execution - it may be that this would be better + # changed. + unless Utils.check_file_writable?(out_dest) + raise ArgumentError, <<-ERROR.chomp +Invalid destination '#{out_dest}' + ERROR + end + File.open(out_dest, 'w') do |file| + file.write(out) + end + elsif not out.empty? + $stdout.puts out + end + end + + def render_env + render_env = Module.new do + class << self + attr_reader :asset_data + end + end + + Dir[File.join(Config.helpers_dir, '*.rb')].each do |file| + render_env.instance_eval(File.read(file)) + end + Dir["#{Config.plugins_dir}/*"].each do |plugin| + Dir["#{plugin}/helpers/*.rb"].each do |file| + render_env.instance_eval(File.read(file), file) + end + end + + return render_env + end + + #If we want to speed up execution we should try only calling this + # method once for all nodes when '@options.template' has a value + # as the result will always been the same so it's wasted computation + def find_template(node) + template = if @options.template + find_template_as_path(@options.template) + else + TemplatesConfig.find(@options.format, node.type) + end + + if ! File.readable?(template) + template_file = File.join(Config.templates_dir, template) + if File.readable?(template_file) + template = template_file + else + plugin = Dir["#{Config.plugins_dir}/*"].find do |plugin| + File.readable?(File.join(plugin,'templates', template)) + end + if plugin + template = File.join(plugin, 'templates', template) + else + raise RuntimeError, <<-ERROR.chomp +Template '#{template}' was not found + ERROR + end + end + end + + return template + end + + def find_template_as_path(template_arg) + found = Utils.find_file(template_arg, Config.templates_dir) + if found.length == 1 + template = found[0] + elsif found.length > 1 + raise ArgumentError, <<-ERROR.chomp +Please refine your search and try again. + ERROR + else + template = template_arg + end + end + + # fill the template for a single node + def fill_template(node, template, render_env) + template_contents = File.read(template) + eruby = Erubis::Eruby.new(template_contents) + + asset_hash = node.data + asset_data = RecursiveOpenStruct.new( + asset_hash, + recurse_over_arrays: true, + preserve_original_keys: true + ) + render_env.instance_variable_set(:@asset_data, asset_data) + render_env.instance_variable_set(:@asset_hash, asset_hash) + ctx = render_env.instance_eval { binding } + + begin + return eruby.result(ctx) + rescue StandardError => e + unless @options.debug + raise ParseError, <<-ERROR.chomp +Error filling template using #{File.basename(node.path)}. +Use '--debug' for more information + ERROR + else + raise e + end + end + end + end + end +end diff --git a/lib/inventoryware/commands/shows/data.rb b/lib/inventoryware/commands/shows/data.rb deleted file mode 100644 index 3846233..0000000 --- a/lib/inventoryware/commands/shows/data.rb +++ /dev/null @@ -1,36 +0,0 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. -# -# This file/package is part of Alces Inventoryware. -# -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. -# -# Alces Inventoryware 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 -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . -# -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== -require 'inventoryware/commands/single_node_command' - -module Inventoryware - module Commands - module Shows - class Data < SingleNodeCommand - def action(node) - File.open(node.location) do |file| - puts file.read - end - end - end - end - end -end diff --git a/lib/inventoryware/commands/shows/document.rb b/lib/inventoryware/commands/shows/document.rb deleted file mode 100644 index c1fc202..0000000 --- a/lib/inventoryware/commands/shows/document.rb +++ /dev/null @@ -1,132 +0,0 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. -# -# This file/package is part of Alces Inventoryware. -# -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. -# -# Alces Inventoryware 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 -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . -# -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== -require 'inventoryware/commands/multi_node_command' -require 'inventoryware/config' -require 'inventoryware/exceptions' -require 'inventoryware/node' -require 'inventoryware/utils' - -require 'erubis' -require 'recursive-open-struct' - -module Inventoryware - module Commands - module Shows - class Document < MultiNodeCommand - def run - template_arg = @argv[0] - - found = Utils.find_file(template_arg, Config.templates_dir) - - if found.length == 1 - template = found[0] - elsif found.length > 1 - raise ArgumentError, <<-ERROR.chomp -Please refine your search and try again. - ERROR - else - if not Utils.check_file_readable?(template_arg) - raise ArgumentError, <<-ERROR.chomp -Template at #{template_arg} inaccessible - ERROR - end - template = template_arg - end - - node_locations = find_nodes('template') - node_locations = node_locations.uniq - node_locations = node_locations.sort_by do |location| - File.basename(location) - end - - output(node_locations, template, @options.location) - end - - def output(node_locations, template, out_dest) - template_contents = File.read(template) - eruby = Erubis::Eruby.new(template_contents) - - render_env = Module.new do - class << self - attr_reader :node_data - end - end - - Dir[File.join(Config.helpers_dir, '*.rb')].each do |file| - render_env.instance_eval(File.read(file)) - end - - out = "" - # check, will loading all output cause issues with memory size? - # probably fine - 723 nodes was 350Kb - node_locations.each do |location| - out += fill_template(Node.new(location), eruby, render_env) - $stderr.puts "Rendered #{File.basename(location, '.yaml')}" - end - - if out_dest - # Confirm file location exists. - # I decided against creating location if it did not exist as it - # requires sudo execution - it may be that this would be better - # changed. - unless Utils.check_file_writable?(out_dest) - raise ArgumentError, <<-ERROR.chomp -Invalid destination '#{out_dest}' - ERROR - end - File.open(out_dest, 'w') do |file| - file.write(out) - end - elsif not out.empty? - $stdout.puts out - end - end - - # fill the template for a single node - def fill_template(node, eruby, render_env) - node_hash = node.data - node_data = RecursiveOpenStruct.new( - node_hash, - recurse_over_arrays: true, - preserve_original_keys: true - ) - render_env.instance_variable_set(:@node_data, node_data) - render_env.instance_variable_set(:@node_hash, node_hash) - ctx = render_env.instance_eval { binding } - - begin - return eruby.result(ctx) - rescue StandardError => e - unless @options.debug - raise ParseError, <<-ERROR.chomp -Error filling template using #{File.basename(node_location)}. -Use '--debug' for more information - ERROR - else - raise e - end - end - end - end - end - end -end diff --git a/lib/inventoryware/commands/single_node_command.rb b/lib/inventoryware/commands/single_node_command.rb index e21fce7..78d1b6b 100644 --- a/lib/inventoryware/commands/single_node_command.rb +++ b/lib/inventoryware/commands/single_node_command.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/command' require 'inventoryware/exceptions' require 'inventoryware/node' @@ -33,17 +38,18 @@ module Commands class SingleNodeCommand < Command def run name = @argv[0] + # error to prevent confusion if attempting to provide >1 node if NodeattrUtils::NodeParser.expand(name).length > 1 raise ArgumentError, <<-ERROR.chomp -Issue with argument name, please only provide a single node +Issue with argument name, please only provide a single asset ERROR end if @options.create location = File.join(Config.yaml_dir, "#{name}.yaml") node = Node.new(location) - node.create_if_non_existent + node.create_if_non_existent(Utils.get_new_asset_type) else found = Utils.find_file(name, Config.yaml_dir) unless found.length == 1 @@ -60,20 +66,6 @@ def run def action raise NotImplementedError end - - def edit_with_tmp_file(text, command) - tmp_file = Tempfile.new('inv_ware_file_') - begin - TTY::Editor.open(tmp_file.path, - content: text, - command: command) - edited = tmp_file.read - ensure - tmp_file.close - tmp_file.unlink - end - return edited - end end end end diff --git a/lib/inventoryware/config.rb b/lib/inventoryware/config.rb index 9975da5..fd697ba 100644 --- a/lib/inventoryware/config.rb +++ b/lib/inventoryware/config.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== module Inventoryware class Config @@ -29,9 +34,9 @@ def instance def method_missing(s, *a, &b) if instance.respond_to?(s) - instance.send(s) + instance.send(s, *a, &b) else - raise + super end end @@ -41,13 +46,16 @@ def respond_to_missing?(s) end attr_reader :root_dir, :yaml_dir, :templates_dir, :helpers_dir, :req_files, - :other_files, :all_files + :other_files, :all_files, :templates_config_path, :plugins_dir def initialize @root_dir = File.expand_path(File.join(File.dirname(__FILE__), '../..')) @yaml_dir = File.join(@root_dir, 'var/store') @templates_dir = File.join(@root_dir, 'templates') @helpers_dir = File.join(@root_dir, 'helpers') + @plugins_dir = File.join(@root_dir, 'plugins') + + @templates_config_path = File.join(@root_dir, 'etc/templates.yml') @req_files = ["lshw-xml", "lsblk-a-P"] @other_files = ["groups"] diff --git a/lib/inventoryware/exceptions.rb b/lib/inventoryware/exceptions.rb index c143693..b6b44db 100644 --- a/lib/inventoryware/exceptions.rb +++ b/lib/inventoryware/exceptions.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== module Inventoryware InventorywareError = Class.new(RuntimeError) diff --git a/lib/inventoryware/lsblk_parser.rb b/lib/inventoryware/lsblk_parser.rb index c57c518..8d3d6fe 100644 --- a/lib/inventoryware/lsblk_parser.rb +++ b/lib/inventoryware/lsblk_parser.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== # Only designed on lsblk output with the -a (all) and # -P (key/value pairs) options diff --git a/lib/inventoryware/node.rb b/lib/inventoryware/node.rb index 92f242e..ed7c7b3 100644 --- a/lib/inventoryware/node.rb +++ b/lib/inventoryware/node.rb @@ -1,57 +1,202 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/exceptions' require 'inventoryware/utils' module Inventoryware class Node - def initialize(location) - @location = location - @name = File.basename(location, File.extname(location)) + class << self + # retrieves all .yaml files in the storage dir + def find_all_nodes() + node_paths = Dir.glob(File.join(Config.yaml_dir, '*.yaml')) + if node_paths.empty? + $stderr.puts "No asset data found "\ + "in #{File.expand_path(Config.yaml_dir)}" + end + return node_paths.map { |p| Node.new(p) } + end + + # retreives all nodes in the given groups + # note: if speed becomes an issue this should be reverted back to the old + # method of converting the yaml to a string and searching with regex + def find_nodes_in_groups(groups, node_list = find_all_nodes()) + groups = *groups unless groups.is_a?(Array) + nodes = [] + node_list.each do |node| + found = [] + found = found << node.primary_group if node.primary_group + found = found + node.secondary_groups if node.secondary_groups + unless (found & groups).empty? + nodes.append(node) + end + end + if nodes.empty? + $stderr.puts "No assets found in #{groups.join(' or ')}." + end + return nodes + end + + # retreives all nodes with the given type + # This cannot easily be done by converting the yaml to a string and + # searching with regex as the `lshw` hash has keys called 'type' + def find_nodes_with_types(target_types, node_list = find_all_nodes()) + key = ['type'] + target_types = *target_types unless target_types.is_a?(Array) + target_types.map! { |t| t.downcase } + nodes = [] + node_list.each do |node| + if target_types.include?(node.type.downcase) + nodes.append(node) + end + end + if nodes.empty? + $stderr.puts "No assets found with type #{target_types.join(' or ')}." + end + return nodes + end + + # retreives the .yaml file for each of the given nodes + # expands node ranges if they exist + # if return missing is passed, returns paths to the .yamls of non-existent + # nodes + def find_single_nodes(node_str, return_missing = false) + node_names = expand_asterisks(NodeattrUtils::NodeParser.expand(node_str)) + $stderr.puts "No assets found for '#{node_str}'" if node_names.empty? + + type = nil + nodes = [] + node_names.each do |node_name| + node_yaml = "#{node_name}.yaml" + node_yaml_location = File.join(Config.yaml_dir, node_yaml) + unless Utils.check_file_readable?(node_yaml_location) + $stderr.puts "File #{node_yaml} not found within "\ + "#{File.expand_path(Config.yaml_dir)}" + if return_missing + $stderr.puts "Creating..." + type = type || Utils.get_new_asset_type + else + $stderr.puts "Skipping." + next + end + end + node = Node.new(node_yaml_location) + node.create_if_non_existent(type) + nodes.append(node) + end + return nodes + end + + def expand_asterisks(nodes) + new_nodes = [] + nodes.each do |node| + if node.match(/\*/) + node_names = Dir.glob(File.join(Config.yaml_dir, node)).map { |file| + File.basename(file, '.yaml') + } + new_nodes.push(*node_names) + end + end + nodes.delete_if { |node| node.match(/\*/) } + nodes.push(*new_nodes) + return nodes + end + + def make_unique(nodes) + nodes.uniq { |n| [n.path] } + end + end + + def initialize(path) + @path = path + @name = File.basename(path, File.extname(path)) end def data @data ||= open end + def type + # hack-y method to save time - rather than load the node's data into mem + # as a hash if the data isn't going to be used for anything, just grep. + # This time saving add up if listing 100s of nodes + # TODO UPDATE THIS WHEN THE YAML FORMAT IS CHANGED (issue #119) + # this will alter the amount of whitespace prepending 'type' and as such + # the regex will need to be changed + if @data + type = @data['type'] + else + type = nil + IO.foreach(@path) do | line| + if m = line.match(/^ type: (.*)$/) + type = m[1] + break + end + end + end + type = 'server' unless type + return type + end + + #TODO as with `.type` + def primary_group + return @data.dig('mutable','primary_group') if @data + pri_group = nil + IO.foreach(@path) do | line| + if m = line.match(/^ primary_group: (.*)$/) + pri_group = m[1] + break + end + end + return pri_group + end + + #TODO as with `.type` + def secondary_groups + return @data.dig('mutable','secondary_groups') if @data + sec_groups = nil + IO.foreach(@path) do | line| + if m = line.match(/^ secondary_groups: (.*)$/) + sec_groups = m[1].split(',') + break + end + end + return sec_groups + end + def data=(value) @data = value end def open - node_data = nil - begin - File.open(@location) do |f| - node_data = YAML.safe_load(f) - end - rescue Psych::SyntaxError - raise ParseError, <<-ERROR.chomp -Error parsing yaml in #{@location} - aborting - ERROR - end + node_data = Utils.load_yaml(@path) # condition for if the .yaml is empty unless node_data raise ParseError, <<-ERROR.chomp -Yaml in #{@location} is empty - aborting +Yaml in #{@path} is empty - aborting ERROR end @data = node_data.values[0] @@ -59,25 +204,26 @@ def open end def save - unless Utils.check_file_writable?(@location) + unless Utils.check_file_writable?(@path) raise FileSysError, <<-ERROR.chomp -Output file #{@location} not accessible - aborting +Output file #{@path} not accessible - aborting ERROR end yaml_hash = {data['name'] => data} - File.open(@location, 'w') { |file| file.write(yaml_hash.to_yaml) } + File.open(@path, 'w') { |file| file.write(yaml_hash.to_yaml) } end - def create_if_non_existent - unless Utils.check_file_readable?(@location) + def create_if_non_existent(type = '') + unless Utils.check_file_readable?(@path) @data = { 'name' => @name, 'mutable' => {}, + 'type' => type, } save end end - attr_reader :location, :name + attr_reader :path, :name end end diff --git a/lib/inventoryware/templates_config.rb b/lib/inventoryware/templates_config.rb new file mode 100644 index 0000000..e148473 --- /dev/null +++ b/lib/inventoryware/templates_config.rb @@ -0,0 +1,83 @@ +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== + +require 'inventoryware/config' +require 'inventoryware/exceptions' + +module Inventoryware + module TemplatesConfig + class << self + def find(format, type) + format ||= 'default' + if t = templates.dig(format, type) || + templates.dig(format, 'default') + t + else + not_found_error(format, type) + end + end + + private + def templates + @templates ||= load + end + + def load + unless File.readable?(Config.templates_config_path) + raise FileSysError, <<-ERROR.chomp +Template config at #{@path} is inaccessible + ERROR + end + template_data = {} + Dir["#{Config.plugins_dir}/*"].each do |plugin| + templates_config_file = File.join(plugin,'etc','templates.yml') + if File.readable?(templates_config_file) + template_data.merge!(load_template_config(templates_config_file)) + end + end + template_data.merge!(load_template_config(Config.templates_config_path)) + end + + def load_template_config(f) + Utils.load_yaml(f).tap do |contents| + unless contents.is_a?(Hash) + raise ParseError, <<-ERROR.chomp +Template config at #{f} is in an incorrect format + ERROR + end + end + end + + def not_found_error(format, type) + tag = format ? "Output format '#{format}' with a": 'A' + raise ParseError, <<-ERROR.chomp +#{tag}sset type '#{type}' is not included in template config file + ERROR + end + end + end +end diff --git a/lib/inventoryware/utils.rb b/lib/inventoryware/utils.rb index b90218b..0de8233 100644 --- a/lib/inventoryware/utils.rb +++ b/lib/inventoryware/utils.rb @@ -1,24 +1,29 @@ -#============================================================================== -# Copyright (C) 2018-19 Stephen F. Norledge and Alces Software Ltd. +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. # -# This file/package is part of Alces Inventoryware. +# This file is part of Flight Inventory. # -# Alces Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. # -# Alces Inventoryware 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 -# Affero General Public License for more details. +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. # -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: # -# For more information on Alces Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== require 'inventoryware/exceptions' module Inventoryware @@ -31,6 +36,7 @@ def self.check_zip?(path) File.extname(path) == ".zip" end + #TODO refine these methods, they're mostly unnecessary def self.check_file_writable?(path) return false unless check_file_location?(path) return false if File.exist?(path) and not File.writable?(path) @@ -78,5 +84,41 @@ def self.find_file(search_val, dir) end return results end + + def self.get_new_asset_type + type = '' + while type.empty? + type = $terminal.ask('Enter the type of the new assets being created') + end + return type + end + + def self.load_yaml(path) + data = nil + begin + File.open(path) do |f| + data = YAML.safe_load(f) + end + rescue Psych::SyntaxError + raise ParseError, <<-ERROR.chomp +Error parsing yaml in #{path} - aborting + ERROR + end + return data + end + + def self.edit_with_tmp_file(text, command) + tmp_file = Tempfile.new('inv_ware_file_') + begin + TTY::Editor.open(tmp_file.path, + content: text, + command: command) + edited = tmp_file.open.read + ensure + tmp_file.close + tmp_file.unlink + end + return edited + end end end diff --git a/lib/inventoryware/version.rb b/lib/inventoryware/version.rb new file mode 100644 index 0000000..7c7ae5b --- /dev/null +++ b/lib/inventoryware/version.rb @@ -0,0 +1,29 @@ +# ============================================================================= +# Copyright (C) 2019-present Alces Flight Ltd. +# +# This file is part of Flight Inventory. +# +# This program and the accompanying materials are made available under +# the terms of the Eclipse Public License 2.0 which is available at +# , or alternative license +# terms made available by Alces Flight Ltd - please direct inquiries +# about licensing to licensing@alces-flight.com. +# +# Flight Inventory is distributed in the hope that it will be useful, but +# 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. See the Eclipse Public License 2.0 for more +# details. +# +# You should have received a copy of the Eclipse Public License 2.0 +# along with Flight Inventory. If not, see: +# +# https://opensource.org/licenses/EPL-2.0 +# +# For more information on Flight Inventory, please visit: +# https://github.com/openflighthpc/flight-inventory +# ============================================================================== +module Inventoryware + VERSION = '1.0.0' +end diff --git a/plugins/.gitignore b/plugins/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/plugins/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/scripts/install b/scripts/install deleted file mode 100644 index b91b5c1..0000000 --- a/scripts/install +++ /dev/null @@ -1,106 +0,0 @@ -#!/bin/bash -#============================================================================== -# Copyright (C) 2019 Stephen F. Norledge and Alces Software Ltd. -# -# This file/package is part of Inventoryware. -# -# Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. -# -# Inventoryware 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 -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . -# -# For more information on the Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== -initial_env=$(env) -alces_INSTALL_DIR="${alces_INSTALL_DIR:-/opt/flight/tools}" -alces_VERSION="${alces_VERSION:-2019.1.0}" - -#============================================================================== -# DON'T EDIT ANYTHING UNDER HERE -#============================================================================== - -# Check for Flight Core -if [ ! -x /opt/flight/bin/bundle ]; then - echo "Unable to install; no Flight Core environment was found." - exit 1 -fi - - -# Detect whether script is being curled or run locally from within `scripts` directory -SCRIPT_PARENT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd) -SCRIPT_PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -SCRIPT_BASE=$(basename $SCRIPT_PATH) - -if [[ $SCRIPT_BASE != "scripts" ]] ; then - CLONE=true - CHECKOUT=true -else - CLONE="" - alces_INSTALL_DIR=$SCRIPT_PARENT_PATH - # Check if alces_VERSION was specified on CLI - if echo "$initial_env" |grep -q '^alces_VERSION' ; then - CHECKOUT=true - else - CHECKOUT="" - fi -fi - -# Create install dir -mkdir -p $alces_INSTALL_DIR -cd $alces_INSTALL_DIR - -if [ ! -z $CLONE ] ; then - # Install tool - git clone https://github.com/alces-software/inventoryware -fi - -cd inventoryware - -if [ ! -z $CHECKOUT ] ; then - git checkout $alces_VERSION -fi - -# Install dependencies -flexec bundle install --path=vendor --without development test - -# Setup command file -cat << EOF > /opt/flight/libexec/commands/inventory -: ' -: NAME: inventory -: SYNOPSIS: A tool for collecting and parsing cluster inventory data -: VERSION: $alces_VERSION -: ' -#============================================================================== -# Copyright (C) 2019 Stephen F. Norledge and Alces Software Ltd. -# -# This file/package is part of Inventoryware. -# -# Inventoryware is free software: you can redistribute it and/or -# modify it under the terms of the GNU Affero General Public License -# as published by the Free Software Foundation, either version 3 of -# the License, or (at your option) any later version. -# -# Inventoryware 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 -# Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this package. If not, see . -# -# For more information on the Inventoryware, please visit: -# https://github.com/alces-software/inventoryware -#============================================================================== -cd $alces_INSTALL_DIR/inventoryware -export FLIGHT_PROGRAM_NAME="\${flight_NAME} \$(basename \$0)" -flexec bundle exec bin/inventory "\$@" -EOF diff --git a/support/README.md b/support/README.md deleted file mode 100644 index 5d17726..0000000 --- a/support/README.md +++ /dev/null @@ -1,17 +0,0 @@ -## About - -This directory contains static binaries of the system commands used by the gatherer script. - -All binaries have been compiled on CentOS 7 and are tested to run on: -- CentOS 6 -- CentOS 7 -- SLES 11 -- Ubuntu 14.04 - -With assumption that if it works on these older OSes then it will be portable to later SLES and Ubuntu versions. - -Build instructions for each static library can be found within the directory `build/` - -## Gathering Data - -To run the script simply execute the `gather-data.sh` script. As long as the `bin/` directory lives next to the `gather-data.sh` script then the binaries then the script will execute without issue. diff --git a/support/bin/dmidecode b/support/bin/dmidecode deleted file mode 100755 index 38db3df..0000000 Binary files a/support/bin/dmidecode and /dev/null differ diff --git a/support/bin/fdisk b/support/bin/fdisk deleted file mode 100755 index 6dad3fc..0000000 Binary files a/support/bin/fdisk and /dev/null differ diff --git a/support/bin/ifconfig b/support/bin/ifconfig deleted file mode 100755 index 161173a..0000000 Binary files a/support/bin/ifconfig and /dev/null differ diff --git a/support/bin/ip b/support/bin/ip deleted file mode 100755 index 41a1281..0000000 Binary files a/support/bin/ip and /dev/null differ diff --git a/support/bin/lsblk b/support/bin/lsblk deleted file mode 100755 index 67a77ce..0000000 Binary files a/support/bin/lsblk and /dev/null differ diff --git a/support/bin/lscpu b/support/bin/lscpu deleted file mode 100755 index 95b8ba7..0000000 Binary files a/support/bin/lscpu and /dev/null differ diff --git a/support/bin/lshw-static b/support/bin/lshw-static deleted file mode 100755 index d622526..0000000 Binary files a/support/bin/lshw-static and /dev/null differ diff --git a/support/bin/lspci b/support/bin/lspci deleted file mode 100755 index 745d60b..0000000 Binary files a/support/bin/lspci and /dev/null differ diff --git a/support/bin/lsscsi b/support/bin/lsscsi deleted file mode 100755 index 3462a99..0000000 Binary files a/support/bin/lsscsi and /dev/null differ diff --git a/support/bin/os-release b/support/bin/os-release deleted file mode 100755 index 0bc9dbb..0000000 --- a/support/bin/os-release +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -# -# This script provides OS release information in a similar -# way to that of `lsb_release` but without the platform -# inconsistencies encountered when using one lsb_release -# script on Ubuntu, CentOS and SLES. -# - -FILE="/etc/os-release" - -if [ ! -f $FILE ] ; then - FILE="/etc/system-release" - NAME=$(cat $FILE |awk '{print $1}') - PRETTY_NAME=$(cat $FILE) - VERSION_ID=$(cat $FILE |awk '{print $3}') -else - source $FILE -fi - -echo -e "Distributor ID:\t$NAME -Description:\t$PRETTY_NAME -Release:\t$VERSION_ID" diff --git a/support/bin/uname b/support/bin/uname deleted file mode 100755 index 9d89907..0000000 Binary files a/support/bin/uname and /dev/null differ diff --git a/support/bin/zip b/support/bin/zip deleted file mode 100755 index 9435189..0000000 Binary files a/support/bin/zip and /dev/null differ diff --git a/support/build/BUILD_DMIDECODE.md b/support/build/BUILD_DMIDECODE.md deleted file mode 100644 index 4b3e4c3..0000000 --- a/support/build/BUILD_DMIDECODE.md +++ /dev/null @@ -1,15 +0,0 @@ - -## EL7 - -``` -cd /tmp/build -wget http://ftp.igh.cnrs.fr/pub/nongnu/dmidecode/dmidecode-3.2.tar.xz -cd dmidecode-3.2 -export VERBOSE=1 -make -# GCC command from the above make -gcc -static -W -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wmissing-prototypes -Winline -Wundef -D_FILE_OFFSET_BITS=64 -O2 -c dmidecode.c -o dmidecode.o -gcc -static dmidecode.o dmiopt.o dmioem.o util.o -o dmidecode - -# Binary is now at ./dmidecode -``` diff --git a/support/build/BUILD_IFCONFIG.md b/support/build/BUILD_IFCONFIG.md deleted file mode 100644 index 34fe20a..0000000 --- a/support/build/BUILD_IFCONFIG.md +++ /dev/null @@ -1,4 +0,0 @@ - -## EL7 - -`ifconfig` was built with a lot of source hackery by Ruan. diff --git a/support/build/BUILD_IP.md b/support/build/BUILD_IP.md deleted file mode 100644 index 5c2ddc5..0000000 --- a/support/build/BUILD_IP.md +++ /dev/null @@ -1,4 +0,0 @@ - -## EL7 - -`ip` was built with a lot of source hackery by Ruan. diff --git a/support/build/BUILD_LSBLK-LSCPU-FDISK.md b/support/build/BUILD_LSBLK-LSCPU-FDISK.md deleted file mode 100644 index 3319222..0000000 --- a/support/build/BUILD_LSBLK-LSCPU-FDISK.md +++ /dev/null @@ -1,42 +0,0 @@ - -## EL7 - -- Util Linux configuration -``` -yum groupinstall "Development Tools" -yum install ncurses-static readline-static -mkdir /tmp/build -cd /tmp/build -git clone git://git.kernel.org/pub/scm/utils/util-linux/util-linux.git -cd util-linux -git checkout stable/RELEASE-VERSION -./autogen.sh - -# Configure and build static libraries for creating the binaries -./configure --enable-static --enable-static-programs='fdisk,blkid' - -make -``` - -- Manually compile lsblk -``` -gcc -std=gnu99 -DHAVE_CONFIG_H -I. -include config.h -I./include -DLOCALEDIR=\"/tmp/build/libblkidtest/share/locale\" -D_PATH_RUNSTATEDIR=\"/tmp/build/libblkidtest/var/run\" -fsigned-char -fno-common -Wall -Werror=sequence-point -Wextra -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wno-missing-field-initializers -Wredundant-decls -Wsign-compare -Wtype-limits -Wuninitialized -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-parameter -Wunused-result -Wunused-variable -Wnested-externs -Wpointer-arith -Wstrict-prototypes -Wimplicit-function-declaration -I./libblkid/src -I./libmount/src -I./libsmartcols/src -g -O2 -MT misc-utils/lsblk-lsblk.o -MD -MP -MF misc-utils/.deps/lsblk-lsblk.Tpo -c -o misc-utils/lsblk-lsblk.o `test -f 'misc-utils/lsblk.c' || echo './'`misc-utils/lsblk.c -gcc -static -std=gnu99 -fsigned-char -fno-common -Wall -Werror=sequence-point -Wextra -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wno-missing-field-initializers -Wredundant-decls -Wsign-compare -Wtype-limits -Wuninitialized -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-parameter -Wunused-result -Wunused-variable -Wnested-externs -Wpointer-arith -Wstrict-prototypes -Wimplicit-function-declaration -I./libblkid/src -I./libmount/src -I./libsmartcols/src -g -O2 -o .libs/lsblk misc-utils/lsblk-lsblk.o ./.libs/libblkid.a ./.libs/libmount.a /tmp/build/util-linux/.libs/libblkid.a /tmp/build/util-linux/.libs/libuuid.a -lrt ./.libs/libcommon.a ./.libs/libsmartcols.a -Wl,-rpath -Wl,/tmp/build/libblkidtest/lib - -# The binary can now be found at `.libs/lsblk` -``` - -- Manually compile lscpu - -``` -gcc -static -std=gnu99 -fsigned-char -fno-common -Wall -Werror=sequence-point -Wextra -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wno-missing-field-initializers -Wredundant-decls -Wsign-compare -Wtype-limits -Wuninitialized -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-parameter -Wunused-result -Wunused-variable -Wnested-externs -Wpointer-arith -Wstrict-prototypes -Wimplicit-function-declaration -I./libsmartcols/src -g -O2 -o .libs/lscpu sys-utils/lscpu-lscpu.o sys-utils/lscpu-lscpu-arm.o sys-utils/lscpu-lscpu-dmi.o ./.libs/libcommon.a ./.libs/libsmartcols.a - -# The binary can now be found at `.libs/lscpu` -``` - -- Manually compile fdisk -``` -gcc -static -std=gnu99 -fsigned-char -fno-common -Wall -Werror=sequence-point -Wextra -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wno-missing-field-initializers -Wredundant-decls -Wsign-compare -Wtype-limits -Wuninitialized -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-parameter -Wunused-result -Wunused-variable -Wnested-externs -Wpointer-arith -Wstrict-prototypes -Wimplicit-function-declaration -I./libfdisk/src -I./libsmartcols/src -g -O2 -o fdisk disk-utils/fdisk-fdisk.o disk-utils/fdisk-fdisk-menu.o disk-utils/fdisk-fdisk-list.o .libs/libcommon.a .libs/libfdisk.a .libs/libsmartcols.a .libs/libtcolors.a .libs/libblkid.a .libs/libuuid.a -lreadline -ltinfo - -# The binary can now be found at `./fdisk` -``` diff --git a/support/build/BUILD_LSHW.md b/support/build/BUILD_LSHW.md deleted file mode 100644 index 326e314..0000000 --- a/support/build/BUILD_LSHW.md +++ /dev/null @@ -1,12 +0,0 @@ - -## EL7 - -``` -yum groupinstall "Development Tools" -yum install upx compat-glibc glibc-static libstdc++-static -mkdir /tmp/build -cd /tmp/build -git clone https://github.com/lyonel/lshw -cd lshw/src -make static -``` diff --git a/support/build/BUILD_LSPCI.md b/support/build/BUILD_LSPCI.md deleted file mode 100644 index 8552adc..0000000 --- a/support/build/BUILD_LSPCI.md +++ /dev/null @@ -1,11 +0,0 @@ - -## EL7 - -``` -yum groupinstall "Development Tools" -yum install zlib-static -cd /tmp/build -git clone https://github.com/gittup/pciutils -cd pciutils -make CC="gcc -static" -``` diff --git a/support/build/BUILD_LSSCSI.md b/support/build/BUILD_LSSCSI.md deleted file mode 100644 index 6f0f83e..0000000 --- a/support/build/BUILD_LSSCSI.md +++ /dev/null @@ -1,18 +0,0 @@ - -## EL7 - -``` -cd /tmp/build -git clone https://github.com/hreinecke/lsscsi -cd lsscsi -git checkout v0.28 -./configure -export VERBOSE=1 -make -# GCC line copied from make output -cd src -gcc -static -DHAVE_CONFIG_H -I. -I.. -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -W -g -O2 -MT lsscsi.o -MD -MP -MF .deps/lsscsi.Tpo -c -o lsscsi.o lsscsi.c -gcc -static -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -W -g -O2 -o lsscsi lsscsi.o - -# Binary is at ./lsscsi -``` diff --git a/support/build/BUILD_UNAME.md b/support/build/BUILD_UNAME.md deleted file mode 100644 index 9964ee9..0000000 --- a/support/build/BUILD_UNAME.md +++ /dev/null @@ -1,10 +0,0 @@ - -## EL7 - -`uname` was built with a lot of source hackery by Ruan. - -The large gcc commands are: -``` -gcc -static -std=gnu11 -I. -I./lib -Ilib -I./lib -Isrc -I./src -fno-common -W -Waddress -Waggressive-loop-optimizations -Wall -Wattributes -Wbad-function-cast -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcomments -Wcoverage-mismatch -Wcpp -Wdeprecated -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion -Wempty-body -Wendif-labels -Wenum-compare -Wextra -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wformat-zero-length -Wfree-nonheap-object -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-memory-model -Winvalid-pch -Wmain -Wmaybe-uninitialized -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-parameter-type -Wmissing-prototypes -Wmultichar -Wnarrowing -Wnonnull -Wold-style-declaration -Wold-style-definition -Woverflow -Woverlength-strings -Woverride-init -Wpacked -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wpsabi -Wreturn-local-addr -Wreturn-type -Wsequence-point -Wshadow -Wsizeof-pointer-memaccess -Wstrict-aliasing -Wstrict-overflow -Wstrict-prototypes -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch -Wsync-nand -Wtrampolines -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvolatile-register-var -Wwrite-strings -Wnormalized=nfc -Wno-sign-compare -Wno-type-limits -Wno-unused-parameter -Wno-format-nonliteral -Wlogical-op -fdiagnostics-show-option -funit-at-a-time -g -O2 -MT src/uname.o -MD -MP -MF $depbase.Tpo -c -o src/uname.o src/uname.c -gcc -static -std=gnu11 -fno-common -W -Waddress -Waggressive-loop-optimizations -Wall -Wattributes -Wbad-function-cast -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcomments -Wcoverage-mismatch -Wcpp -Wdeprecated -Wdeprecated-declarations -Wdisabled-optimization -Wdiv-by-zero -Wdouble-promotion -Wempty-body -Wendif-labels -Wenum-compare -Wextra -Wformat-contains-nul -Wformat-extra-args -Wformat-security -Wformat-y2k -Wformat-zero-length -Wfree-nonheap-object -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Winit-self -Wint-to-pointer-cast -Winvalid-memory-model -Winvalid-pch -Wmain -Wmaybe-uninitialized -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-parameter-type -Wmissing-prototypes -Wmultichar -Wnarrowing -Wnonnull -Wold-style-declaration -Wold-style-definition -Woverflow -Woverlength-strings -Woverride-init -Wpacked -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wpsabi -Wreturn-local-addr -Wreturn-type -Wsequence-point -Wshadow -Wsizeof-pointer-memaccess -Wstrict-aliasing -Wstrict-overflow -Wstrict-prototypes -Wsuggest-attribute=const -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wswitch -Wsync-nand -Wtrampolines -Wtrigraphs -Wuninitialized -Wunknown-pragmas -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvolatile-register-var -Wwrite-strings -Wnormalized=nfc -Wno-sign-compare -Wno-type-limits -Wno-unused-parameter -Wno-format-nonliteral -Wlogical-op -fdiagnostics-show-option -funit-at-a-time -g -O2 -Wl,--as-needed -o src/uname src/uname.o src/uname-uname.o src/libver.a lib/libcoreutils.a lib/libcoreutils.a -``` diff --git a/support/build/BUILD_ZIP.md b/support/build/BUILD_ZIP.md deleted file mode 100644 index 68527e4..0000000 --- a/support/build/BUILD_ZIP.md +++ /dev/null @@ -1,10 +0,0 @@ - -## EL7 - -``` -cd /tmp/build -git clone https://github.com/LuaDist/zip -cd zip -git checkout 3.0 -make -f unix/Makefile generic CC='gcc -static' -``` diff --git a/support/gather-data.sh b/support/gather-data.sh deleted file mode 100755 index a7b484c..0000000 --- a/support/gather-data.sh +++ /dev/null @@ -1,182 +0,0 @@ -#!/bin/bash - -# -# Global Vars -# -TYPES="logical physical" - -BASEDIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)" -BINDIR="$BASEDIR/bin" - -DMIDECODE="$BINDIR/dmidecode" -FDISK="$BINDIR/fdisk" -IFCONFIG="$BINDIR/ifconfig" -IP="$BINDIR/ip" -LSBLK="$BINDIR/lsblk" -LSCPU="$BINDIR/lscpu" -LSHW="$BINDIR/lshw-static" -LSPCI="$BINDIR/lspci" -LSSCSI="$BINDIR/lsscsi" -OS_RELEASE="$BINDIR/os-release" -UNAME="$BINDIR/uname" -ZIP="$BINDIR/zip" - -# -# Functions -# -print_help() { - echo "Gather Data - Collect physical and logical system configuration information" - echo "" - echo "./gather-data.sh [-p PRIMARY_GROUP] [-g comma,separate,secondary,groups] [-t check_type] [-v]" - echo "" - echo "Options:" - echo " -h, --help Show this help page" - echo " -p, --primary Primary group for the node" - echo " -g, --groups Comma-separated list of secondary groups for the node" - echo " -t, --type Type of check to run (physical or logical), if not provided" - echo " then both types will be collected" - echo " -v, --verbose Print additional debug information" -} - -# -# Arg Parsing -# -while test $# -gt 0 ; do - case "$1" in - -h|--help) - print_help - exit 0 - ;; - -p|--primary) - shift - - # Ensure argument passed - if test $# -gt 0 ; then - export PRIGROUP=$1 - else - echo -e "ERROR: No primary groups provided\n" - print_help - exit 1 - fi - shift - ;; - -g|--groups) - shift - - # Ensure argument passed - if test $# -gt 0 ; then - export SECGROUPS=$1 - else - echo -e "ERROR: No secondary groups provided\n" - print_help - exit 1 - fi - shift - ;; - -t|--type) - shift - - # Ensure argument passed - if test $# -gt 0 ; then - export TYPE=$1 - if [[ ! $TYPES == *"$TYPE"* ]] ; then - echo -e "ERROR: $TYPE is an invalid type, must be one of: $TYPES\n" - print_help - exit 1 - fi - TYPES="$TYPE" - else - echo -e "ERROR: No type provided\n" - print_help - exit 1 - fi - shift - ;; - -v|--verbose) - shift - VERBOSE=true - ;; - *) - echo -e "ERROR: Unrecognised argument provided\n" - print_help - exit 1 - ;; - esac -done - -# -# Validation -# -if [ ! -z $VERBOSE ] ; then - echo "PRIGROUP = $PRIGROUP" - echo "SECGROUPS = $SECGROUPS" - echo "TYPES = $TYPES" -fi - -# -# Collect data -# -TMPDIR=$(mktemp -d) -pushd $TMPDIR - -# Command Versions -cat << EOF > command_versions -$(if [[ $TYPES == *"physical"* ]] ; then -echo "# Physical -dmidecode: $($DMIDECODE --version 2>&1) -fdisk: $($FDISK -v 2>&1) -lsblk: $($LSBLK --version 2>&1) -lscpu: $($LSCPU --version 2>&1) -lshw: $($LSHW -version 2>/dev/null) -lspci: $($LSPCI --version 2>&1) -lsscsi: $($LSSCSI --version 2>&1)" -fi ) -$(if [[ $TYPES == *"logical"* ]] ; then -echo "# Logical -ifconfig: $($IFCONFIG --version 2>&1) -ip: $($IP -V 2>&1) -packager: $(rpm --version 2>/dev/null || dpkg --version 2>/dev/null |head -1) -uname: $($UNAME --version 2>&1 |head -1)" -fi) -EOF - -# Groups -cat << EOF > groups -primary_group: $PRIGROUP -secondary_groups: $SECGROUPS -EOF - -# Physical -if [[ $TYPES == *"physical"* ]] ; then -$DMIDECODE > dmidecode -$FDISK -l > fdisk-l -$LSBLK -a -P > lsblk-a-P -$LSCPU > lscpu -$LSHW -short > lshw-short -$LSHW -xml > lshw-xml -$LSPCI -v -mm > lspci-v-mm -$LSSCSI > lsscsi -cat /sys/kernel/debug/usb/devices > usb-devices -fi - -# Logical -if [[ $TYPES == *"logical"* ]] ; then -$IFCONFIG -a > ifconfig-a -$IP -o addr > ip-o-addr -$OS_RELEASE > os-release -$UNAME -a > uname-a -(rpm -qa || dpkg -l) > packages -fi - -popd - -# -# Zip data -# -ZIPFILE="/tmp/$(hostname -s).zip" -pushd $TMPDIR -$ZIP -r $ZIPFILE ./* -popd - -rm -rf $TMPDIR -echo "Data written to $ZIPFILE" diff --git a/templates/asset.yml.erb b/templates/asset.yml.erb new file mode 100644 index 0000000..f678545 --- /dev/null +++ b/templates/asset.yml.erb @@ -0,0 +1,2 @@ +<%= @asset_data.name %>: + <%= @asset_data.to_hash.to_yaml.split("\n").tap {|a| a.shift}.join("\n ") %> diff --git a/templates/example_template.md.erb b/templates/example_template.md.erb index 9229f0f..cdae17d 100644 --- a/templates/example_template.md.erb +++ b/templates/example_template.md.erb @@ -1,7 +1,7 @@ -<%= @node_data.name %>: - name: <%= @node_data.name %> - primary_group: <%= @node_data.mutable.primary_group %> - secondary_group: <%= @node_data.mutable.secondary_groups %> +<%= @asset_data.name %>: + name: <%= @asset_data.name %> + primary_group: <%= @asset_data.mutable.primary_group %> + secondary_group: <%= @asset_data.mutable.secondary_groups %> info: | # Sections @@ -10,7 +10,7 @@ 1. [Network Devices](#network-devices) 1. [Disks](#disks) <% end %> - <% if @node_data.mutable.notes -%>1. [Notes](#notes)<% end -%> + <% if @asset_data.mutable.notes -%>1. [Notes](#notes)<% end -%> <% if select_bios %>1. [BIOS Information](#bios-information)<% end %> <% if imported? %> @@ -18,15 +18,15 @@ ## Model - <%= @node_data.lshw.list.node.product %> + <%= @asset_data.lshw.list.node.product %> ## BIOS Version - <%= find_hashes_with_key_value(@node_hash, 'id', 'firmware')&.first['version'] %> + <%= find_hashes_with_key_value(@asset_hash, 'id', 'firmware')&.first['version'] %> ## System Serial Number - <%= @node_data.lshw.list.node.serial %> + <%= @asset_data.lshw.list.node.serial %> ## CPU(s) @@ -55,15 +55,15 @@ | Device | Size | |--------|------| - <% @node_data.lsblk.disk&.each_pair do |disk, values| %> + <% @asset_data.lsblk.disk&.each_pair do |disk, values| %> | <%= disk %> | <%= values['SIZE'] %> | <% end %> <% end %> - <% if @node_data.mutable.notes -%> + <% if @asset_data.mutable.notes -%> # Notes - <%= @node_data.mutable.notes.split("\n").join("\n ") %> + <%= @asset_data.mutable.notes.split("\n").join("\n ") %> <% end -%> <% if select_bios %> diff --git a/templates/server.md.erb b/templates/server.md.erb new file mode 100644 index 0000000..ba15952 --- /dev/null +++ b/templates/server.md.erb @@ -0,0 +1,71 @@ +# <%= @asset_data.name %> + +## Sections + +<% if imported? %> +1. [System](#system) +1. [Network Devices](#network-devices) +1. [Disks](#disks) +<% end %> +<% if @asset_data.mutable.notes -%>1. [Notes](#notes)<% end -%> +<% if select_bios %>1. [BIOS Information](#bios-information)<% end %> + +<% if imported? %> +## System + +### Model + +<%= @asset_data.lshw.list.node.product %> + +### BIOS Version + +<%= find_hashes_with_key_value(@asset_hash, 'id', 'firmware')&.first['version'] %> + +### System Serial Number + +<%= @asset_data.lshw.list.node.serial %> + +### CPU(s) + +<% cpus.each do |cpu| %> +#### <%= cpu.id.upcase %> + +Model: <%= cpu.model %> +Slot: <%= cpu.slot %> + +<% end %> +### RAM + +- Total: <%= format_bytes_value(find_total_memory) %> + + +## Network Devices + +| Interface | Speed | MAC | +|-----------|-------|-----| +<% network_devices.each do |net| %> +| <%= net.logicalname %> | <%= net.speed %> | <%= net.serial %> | +<% end %> + + +## Disks + +| Device | Size | +|--------|------| +<% @asset_data.lsblk.disk&.each_pair do |disk, values| %> +| <%= disk %> | <%= values['SIZE'] %> | +<% end %> + +<% end %> +<% if @asset_data.mutable.notes -%> +## Notes + +<%= @asset_data.mutable.notes.split("\n").join("\n ") %> +<% end -%> + +<% if select_bios %> +## BIOS Information + +<%= select_bios.split("\n").join("\n ") %> +<% end %> + diff --git a/templates/serverFC.md.erb b/templates/serverFC.md.erb new file mode 100644 index 0000000..cdae17d --- /dev/null +++ b/templates/serverFC.md.erb @@ -0,0 +1,74 @@ +<%= @asset_data.name %>: + name: <%= @asset_data.name %> + primary_group: <%= @asset_data.mutable.primary_group %> + secondary_group: <%= @asset_data.mutable.secondary_groups %> + info: | + # Sections + + <% if imported? %> + 1. [System](#system) + 1. [Network Devices](#network-devices) + 1. [Disks](#disks) + <% end %> + <% if @asset_data.mutable.notes -%>1. [Notes](#notes)<% end -%> + <% if select_bios %>1. [BIOS Information](#bios-information)<% end %> + +<% if imported? %> + # System + + ## Model + + <%= @asset_data.lshw.list.node.product %> + + ## BIOS Version + + <%= find_hashes_with_key_value(@asset_hash, 'id', 'firmware')&.first['version'] %> + + ## System Serial Number + + <%= @asset_data.lshw.list.node.serial %> + + ## CPU(s) + + <% cpus.each do |cpu| %> + ### <%= cpu.id.upcase %> + + Model: <%= cpu.model %> + Slot: <%= cpu.slot %> + + <% end %> + ## RAM + + - Total: <%= format_bytes_value(find_total_memory) %> + + + # Network Devices + + | Interface | Speed | MAC | + |-----------|-------|-----| + <% network_devices.each do |net| %> + | <%= net.logicalname %> | <%= net.speed %> | <%= net.serial %> | + <% end %> + + + # Disks + + | Device | Size | + |--------|------| + <% @asset_data.lsblk.disk&.each_pair do |disk, values| %> + | <%= disk %> | <%= values['SIZE'] %> | + <% end %> + +<% end %> + <% if @asset_data.mutable.notes -%> + # Notes + + <%= @asset_data.mutable.notes.split("\n").join("\n ") %> + <% end -%> + + <% if select_bios %> + # BIOS Information + + <%= select_bios.split("\n").join("\n ") %> + <% end %> + diff --git a/templates/switch.md.erb b/templates/switch.md.erb new file mode 100644 index 0000000..9d2866b --- /dev/null +++ b/templates/switch.md.erb @@ -0,0 +1,7 @@ +# <%= @asset_data.name %> + +## Port Layout + +<% @asset_hash['mutable']['map'].each do |port, asset| %> +<%= port %>: <%= asset %> +<% end %> diff --git a/templates/switchFC.md.erb b/templates/switchFC.md.erb new file mode 100644 index 0000000..8f8b646 --- /dev/null +++ b/templates/switchFC.md.erb @@ -0,0 +1,10 @@ +<%= @asset_data.name %>: + name: <%= @asset_data.name %> + primary_group: <%= @asset_data.mutable.primary_group %> + secondary_group: <%= @asset_data.mutable.secondary_groups %> + info: | + ## Port Layout + + <% @asset_hash['mutable']['map'].each do |port, asset| %> + <%= port %>: <%= asset %> + <% end %>