Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew committed May 17, 2019
2 parents ad5822e + 0e2048f commit 37ca16e
Show file tree
Hide file tree
Showing 30 changed files with 778 additions and 109 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source 'https://rubygems.org'
gem 'commander-openflighthpc', '~> 1.1.0'
gem 'erubis'
gem 'nodeattr_utils'
gem 'rerun'
gem 'recursive-open-struct'
gem 'rubyzip'
gem 'tty-editor'
Expand Down
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ GEM
equatable (0.5.0)
erubis (2.7.0)
escape_utils (1.2.1)
ffi (1.10.0)
highline (1.7.10)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.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)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
recursive-open-struct (1.1.0)
rerun (0.13.0)
listen (~> 3.0)
ruby_dep (1.5.0)
rubyzip (1.2.2)
timers (4.3.0)
tty-color (0.4.3)
Expand Down Expand Up @@ -49,6 +60,7 @@ DEPENDENCIES
nodeattr_utils
paint
recursive-open-struct
rerun
rubyzip
tty-editor
tty-prompt
Expand Down
16 changes: 5 additions & 11 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@ Note: Interactive editing requires `vim` be installed, this is available in most

## Installing with Flight Runway

Flight Runway (and Flight Tools) provides the Ruby environment and command-line helpers for running openflightHPC tools.
Flight Runway provides the Ruby environment and command-line helpers for running openflightHPC tools.

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>).
To install Flight Runway, see the [Flight Runway installation docs](https://github.com/openflighthpc/flight-runway#installation).

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.
These instructions assume that `flight-runway` has been installed from the openflightHPC yum repository and [system-wide integration](https://github.com/openflighthpc/flight-runway#system-wide-integration) enabled.

Integrate Flight Inventory to runway:
Install Flight Inventory:

```
[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.
[root@myhost ~]# yum -y install flight-inventory
```

Flight Inventory is now available via the `flight` tool::
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ a large recursive OpenStruct called `@asset_data`. The equivalent data is also a
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.

## Data Versioning

To support changes in data structure every asset file has a 'schema number'. The current schema number and
minimum accepted schema number can be found in `inventoryware/version.rb`. If an asset's schema number is
less than the minimum accepted execution will halt and the asset's file will need to be migrated.

Call the script with no arguments to process the entire store directory, migrating every old file.
Alternatively, pass an asset name or asset path to migrate just that file.
Currently supports schema 0 (no schema) to 1, will need to be updated with any further changes to the schema.

When developing a migration to move assets to a new schema please create a new file in the `scripts/migrations`
directory with the name `schema_x`. Within this file create a method with the name `migrate_schema_to_x`. Where
x is the schema version the file will migrate the asset to. This is the method that the central migration script
will call when migrating any assets to that schema version.

# Plugins

Flight Inventory also supports plugins. To render asset data in new and interesting ways place additional
Expand Down
1 change: 1 addition & 0 deletions etc/cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
active_cluster: default
2 changes: 1 addition & 1 deletion helpers/network_device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ def create_net(net_hash)
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] }
network_devices.sort_by {|hsh| hsh[:logicalname] || ''}
end
35 changes: 30 additions & 5 deletions lib/inventoryware/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def add_group_option(command)
end

command :'edit-map' do |c|
cli_syntax(c, '[ASSET_SPEC]')
cli_syntax(c, 'MAP_NAME [ASSET_SPEC]')
c.description = "Edit mapping data for one or more assets"
add_multi_node_options(c)
add_create_option(c)
Expand All @@ -112,9 +112,10 @@ def add_group_option(command)
command :list do |c|
cli_syntax(c)
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.option '-g', '--group [GROUP]',
"Optionally select assets in GROUP, specify comma-separated list for multiple groups"
c.option '-t', '--type [TYPE]',
"Optionally select assets in TYPE, specify comma-separated list for multiple types"
c.action Commands, :list
end

Expand All @@ -126,7 +127,7 @@ def add_group_option(command)
end

command :'list-map' do |c|
cli_syntax(c, 'ASSET INDEX')
cli_syntax(c, 'ASSET MAP_NAME 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
Expand Down Expand Up @@ -160,5 +161,29 @@ def add_group_option(command)
c.description = "Create a new asset"
c.action Commands, :create
end

command :'init-cluster' do |c|
cli_syntax(c, 'CLUSTER')
c.description = "Initialise a new cluster"
c.action Commands, :'cluster-init'
end

command :'delete-cluster' do |c|
cli_syntax(c, 'CLUSTER')
c.description = "Deletes the specified cluster and associated assets"
c.action Commands, :'cluster-delete'
end

command :'list-cluster' do |c|
cli_syntax(c)
c.description = "List the current and available clusters"
c.action Commands, :'cluster-list'
end

command :'switch-cluster' do |c|
cli_syntax(c, 'CLUSTER')
c.description = "Change the current cluster"
c.action Commands, :'cluster-switch'
end
end
end
4 changes: 4 additions & 0 deletions lib/inventoryware/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
require 'inventoryware/commands/modifys/groups'
require 'inventoryware/commands/import'
require 'inventoryware/commands/show'
require 'inventoryware/commands/cluster/init'
require 'inventoryware/commands/cluster/delete'
require 'inventoryware/commands/cluster/list'
require 'inventoryware/commands/cluster/switch'

module Inventoryware
module Commands
Expand Down
58 changes: 58 additions & 0 deletions lib/inventoryware/commands/cluster/delete.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# =============================================================================
# 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
# <https://www.eclipse.org/legal/epl-2.0>, or alternative license
# terms made available by Alces Flight Ltd - please direct inquiries
# about licensing to [email protected].
#
# 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 'fileutils'

module Inventoryware
module Commands
module Cluster
class Delete < Command
def run
cluster = @argv.first

prompt = TTY::Prompt.new
unless prompt.no?("Are you sure you want to delete '#{cluster}'?")
unless cluster == Config.active_cluster
puts "Cluster '#{cluster}' has been deleted" if delete_cluster(cluster)
else
puts "Can't delete the current cluster, please switch cluster first"
end
end
end

private

def delete_cluster(cluster)
cluster_path = File.join(Config.root_dir, 'var/store', cluster)
FileUtils.rm_rf(cluster_path, secure: true)
end
end
end
end
end
59 changes: 59 additions & 0 deletions lib/inventoryware/commands/cluster/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# =============================================================================
# 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
# <https://www.eclipse.org/legal/epl-2.0>, or alternative license
# terms made available by Alces Flight Ltd - please direct inquiries
# about licensing to [email protected].
#
# 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/utils'

require 'fileutils'

module Inventoryware
module Commands
module Cluster
class Init < Command
def run
cluster_config_path = Config.cluster_config_path
cluster_config = Utils.load_yaml(cluster_config_path)
cluster = @argv.first

if create_cluster_directory
cluster_config['active_cluster'] = cluster
Utils.save_yaml(cluster_config_path, cluster_config)

puts "The '#{cluster}' cluster has been successfully initialised and"\
" is now the active cluster"
end
end

private

def create_cluster_directory
FileUtils.mkdir(File.join(Config.root_dir, 'var/store', @argv))
end
end
end
end
end
64 changes: 64 additions & 0 deletions lib/inventoryware/commands/cluster/list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# =============================================================================
# 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
# <https://www.eclipse.org/legal/epl-2.0>, or alternative license
# terms made available by Alces Flight Ltd - please direct inquiries
# about licensing to [email protected].
#
# 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'

module Inventoryware
module Commands
module Cluster
class List < Command
def run
clusters = get_list_of_clusters

clusters.each do |cluster|
if cluster.start_with?('*')
puts cluster
else
puts " #{cluster}"
end
end
end

private

def get_list_of_clusters
Dir.glob(File.join(Config.root_dir, 'var/store/*')).select { |e|
File.directory? e
}.map { |dir|
File.basename(dir)
}.map { |cluster|
if cluster == Config.active_cluster
"* #{cluster}"
else
cluster
end
}.sort
end
end
end
end
end
Loading

0 comments on commit 37ca16e

Please sign in to comment.