nodeattr_utils 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nodeattr_utils.rb +11 -0
- data/lib/nodeattr_utils/config.rb +127 -0
- data/lib/nodeattr_utils/exceptions.rb +2 -0
- data/lib/nodeattr_utils/version.rb +1 -1
- data/nodeattr_utils.gemspec +2 -0
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 167cc1e6ee18b4dba9038c19fe44b526834ddbe4a60f4dfc1ce97787c0181e73
|
4
|
+
data.tar.gz: 63d2c6ed0f8d386243733b951b9676785806ca6600f0e7c1b1575e97713c764c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0b8f32802e049dd7683337ef9b57f4c46a2880edc6ba1e3191e4026d161c280a2cb15f4dd378acf2380dc1d62a758a4e0d5e2deef2346573ab8f89449d60e3a
|
7
|
+
data.tar.gz: 43b9ede227685ede6e33c958d479515fafad34025f8e7fcf52c8e096c6a29c6821531983c0f0a0a34b000a47f5286944efda250afdf6e73872b860aed707d87f
|
data/lib/nodeattr_utils.rb
CHANGED
@@ -29,5 +29,16 @@ require 'nodeattr_utils/node_parser'
|
|
29
29
|
require 'nodeattr_utils/exceptions'
|
30
30
|
|
31
31
|
module NodeattrUtils
|
32
|
+
module Nodes
|
33
|
+
def self.expand(string)
|
34
|
+
NodeattrUtils::NodeParser.expand(string)
|
35
|
+
end
|
36
|
+
|
37
|
+
# TODO: Actually collapse the nodes array instead of joining them as a single
|
38
|
+
# string
|
39
|
+
def self.collapse(*nodes)
|
40
|
+
nodes.flatten.join(',')
|
41
|
+
end
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#==============================================================================
|
4
|
+
# Copyright (C) 2019-present Alces Flight Ltd.
|
5
|
+
#
|
6
|
+
# This file is part of flight-metal.
|
7
|
+
#
|
8
|
+
# This program and the accompanying materials are made available under
|
9
|
+
# the terms of the Eclipse Public License 2.0 which is available at
|
10
|
+
# <https://www.eclipse.org/legal/epl-2.0>, or alternative license
|
11
|
+
# terms made available by Alces Flight Ltd - please direct inquiries
|
12
|
+
# about licensing to licensing@alces-flight.com.
|
13
|
+
#
|
14
|
+
# This project is distributed in the hope that it will be useful, but
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
|
16
|
+
# IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS
|
17
|
+
# OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
|
18
|
+
# PARTICULAR PURPOSE. See the Eclipse Public License 2.0 for more
|
19
|
+
# details.
|
20
|
+
#
|
21
|
+
# You should have received a copy of the Eclipse Public License 2.0
|
22
|
+
# along with this project. If not, see:
|
23
|
+
#
|
24
|
+
# https://opensource.org/licenses/EPL-2.0
|
25
|
+
#
|
26
|
+
# For more information on flight-account, please visit:
|
27
|
+
# https://github.com/alces-software/flight-metal
|
28
|
+
#===============================================================================
|
29
|
+
|
30
|
+
require 'flight_config'
|
31
|
+
require 'nodeattr_utils/exceptions'
|
32
|
+
|
33
|
+
module NodeattrUtils
|
34
|
+
class Config
|
35
|
+
include FlightConfig::Updater
|
36
|
+
|
37
|
+
def self.path(_cluster)
|
38
|
+
raise NotImplementedError
|
39
|
+
end
|
40
|
+
|
41
|
+
def __data__
|
42
|
+
super().tap { |d| d.set_if_empty(:groups, value: ['orphan']) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def cluster
|
46
|
+
__inputs__.first
|
47
|
+
end
|
48
|
+
|
49
|
+
def raw_groups
|
50
|
+
__data__.fetch(:groups)
|
51
|
+
end
|
52
|
+
|
53
|
+
def raw_nodes
|
54
|
+
__data__.fetch(:nodes, default: {})
|
55
|
+
end
|
56
|
+
|
57
|
+
def nodes_list
|
58
|
+
raw_nodes.keys
|
59
|
+
end
|
60
|
+
|
61
|
+
def groups_hash
|
62
|
+
raw_groups.reject(&:nil?).map do |group|
|
63
|
+
[group, group_index(group)]
|
64
|
+
end.to_h
|
65
|
+
end
|
66
|
+
|
67
|
+
def group_index(group)
|
68
|
+
return nil if group.nil?
|
69
|
+
raw_groups.find_index(group)
|
70
|
+
end
|
71
|
+
|
72
|
+
def groups_for_node(node)
|
73
|
+
__data__.fetch(:nodes, node, default: []).dup.tap do |groups|
|
74
|
+
groups.push 'orphan' if groups.empty?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def nodes_in_group(group)
|
79
|
+
nodes_list.select { |node| groups_for_node(node).include?(group) }
|
80
|
+
end
|
81
|
+
|
82
|
+
def nodes_in_primary_group(group)
|
83
|
+
nodes_list.select { |n| groups_for_node(n).first == group }
|
84
|
+
end
|
85
|
+
|
86
|
+
def add_group(group_name)
|
87
|
+
return if raw_groups.include?(group_name)
|
88
|
+
__data__.append(group_name, to: :groups)
|
89
|
+
end
|
90
|
+
|
91
|
+
def remove_group(group_name)
|
92
|
+
error_if_removing_orphan_group(group_name)
|
93
|
+
nodes_list.select { |n| groups_for_node(n).first == group_name }
|
94
|
+
.join(',')
|
95
|
+
.tap { |node_str| remove_nodes(node_str) }
|
96
|
+
__data__.fetch(:groups).map! { |g| g == group_name ? nil : g }
|
97
|
+
end
|
98
|
+
|
99
|
+
def add_nodes(node_string, groups: [])
|
100
|
+
groups = groups.is_a?(Array) ? groups : [groups]
|
101
|
+
add_group(groups.first) unless groups.empty?
|
102
|
+
NodeattrUtils::Nodes.expand(node_string).each do |node|
|
103
|
+
__data__.set(:nodes, node, value: groups)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def remove_nodes(node_string)
|
108
|
+
NodeattrUtils::Nodes.expand(node_string).map do |node|
|
109
|
+
__data__.delete(:nodes, node)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def orphans
|
114
|
+
nodes_in_group('orphan')
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def error_if_removing_orphan_group(group)
|
120
|
+
return unless group == 'orphan'
|
121
|
+
raise RemovingOrphanGroupError, <<~ERROR.chomp
|
122
|
+
Can not remove the orphan group
|
123
|
+
ERROR
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
data/nodeattr_utils.gemspec
CHANGED
@@ -46,6 +46,8 @@ Gem::Specification.new do |spec|
|
|
46
46
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
47
47
|
spec.require_paths = ["lib"]
|
48
48
|
|
49
|
+
spec.add_runtime_dependency 'flight_config', '~>0.2'
|
50
|
+
|
49
51
|
spec.add_development_dependency "bundler", "~> 1.16"
|
50
52
|
spec.add_development_dependency "rake", "~> 10.0"
|
51
53
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nodeattr_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alces Flight Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: flight_config
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -97,6 +111,7 @@ files:
|
|
97
111
|
- README.md
|
98
112
|
- Rakefile
|
99
113
|
- lib/nodeattr_utils.rb
|
114
|
+
- lib/nodeattr_utils/config.rb
|
100
115
|
- lib/nodeattr_utils/exceptions.rb
|
101
116
|
- lib/nodeattr_utils/node_parser.rb
|
102
117
|
- lib/nodeattr_utils/version.rb
|
@@ -120,8 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
135
|
- !ruby/object:Gem::Version
|
121
136
|
version: '0'
|
122
137
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.7.6
|
138
|
+
rubygems_version: 3.0.3
|
125
139
|
signing_key:
|
126
140
|
specification_version: 4
|
127
141
|
summary: Ruby implementation of nodeattr behaviour
|