Skip to content

Commit

Permalink
Pluggable server roles
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Feb 28, 2024
1 parent 407bf80 commit 2e8ada6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
10 changes: 8 additions & 2 deletions app/models/server_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ class ServerRole < ApplicationRecord

def self.seed
server_roles = all.index_by(&:name)
CSV.foreach(fixture_path, :headers => true, :skip_lines => /^#/).each do |csv_row|
action = csv_row.to_hash

server_role_paths = [fixture_path] + Vmdb::Plugins.server_role_paths

csv_rows = server_role_paths.flat_map do |path|
CSV.read(path, :headers => true, :skip_lines => /^#/).map(&:to_hash)
end

csv_rows.each do |action|
rec = server_roles[action['name']]
if rec.nil?
_log.info("Creating Server Role [#{action['name']}]")
Expand All @@ -25,6 +30,7 @@ def self.seed
end
end
end

@zone_scoped_roles = @region_scoped_roles = nil
end

Expand Down
9 changes: 9 additions & 0 deletions lib/vmdb/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def asset_paths
end
end

def server_role_paths
@server_role_paths ||= begin
map do |engine|
file = engine.root.join("content/server_roles.csv")
file if file.exist?
end.compact
end
end

def systemd_units
@systemd_units ||= begin
flat_map { |engine| engine.root.join("systemd").glob("*.*") }
Expand Down
2 changes: 1 addition & 1 deletion spec/models/server_role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
web_services,Web Services,0,false,region
CSV

allow(File).to receive(:open).and_return(StringIO.new(@csv))
allow(File).to receive(:open).with(ServerRole.fixture_path, "r", any_args).and_return(StringIO.new(@csv))
ServerRole.seed
end

Expand Down

0 comments on commit 2e8ada6

Please sign in to comment.