-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added export/import of SmartState Analysis Profiles
Fixes BZ #1344589 Based on code from https://bitbucket.org/tsinfinity/cfme-rhconsulting-scripts/src/master/rhconsulting_scanitems.rake Will be extracted into seperate files next for import/export
- Loading branch information
Julian Cheal
committed
May 16, 2018
1 parent
e915a3f
commit 0c54268
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module TaskHelpers | ||
class Exports | ||
class ScanProfiles | ||
def export(options) | ||
ScanItemSet.all.each do |p| | ||
# Skip read only entries | ||
if p.read_only | ||
next | ||
end | ||
# Also skip any entries that are using file defaults... | ||
uses_files = false | ||
p.members.each do |m| | ||
if m.filename | ||
uses_files = true | ||
end | ||
end | ||
if uses_files | ||
next | ||
end | ||
|
||
puts("Exporting Scan Profile: #{p.name} (#{p.description})") | ||
|
||
pname = TaskHelpers::Exports.safe_filename(p.name, options[:keep_spaces]) | ||
fname = "ScanProfile_#{pname}.yaml" | ||
|
||
# Clean-up data | ||
profile = ScanItem.get_profile(p.name).first.dup | ||
%w(id created_on updated_on).each { |k| profile.delete(k) } | ||
profile['definition'].each do |dd| | ||
%w(id created_on updated_on description).each { |k| dd.delete(k) } | ||
end | ||
|
||
s = profile.to_yaml | ||
s.gsub!(/\n\s*guid:\s+\S+\n/,"\n") | ||
File.write("#{options[:directory]}/#{fname}", s) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module TaskHelpers | ||
class Imports | ||
class ScanProfiles | ||
def import(options) | ||
Dir.glob("#{options[:source]}/ScanProfile_*yaml") do |filename| | ||
puts("Importing Scan Profile: #{File.basename(filename, '.yaml').gsub(/^ScanProfile_/, '')} ....") | ||
|
||
hash = YAML.load_file(filename) | ||
items = hash["definition"] | ||
hash.delete("definition") | ||
profile = ScanItemSet.find_by(:name => hash["name"]); | ||
if profile.nil? | ||
if hash["guid"].nil? | ||
hash["guid"] = SecureRandom.uuid | ||
end | ||
profile = ScanItemSet.new(hash) | ||
else | ||
profile.attributes = hash | ||
end | ||
profile.save! | ||
|
||
# Delete existing members | ||
profile.members.each do |one| | ||
if one.filename | ||
# OK, this was defined through yaml file... just skip it | ||
next | ||
#profile.delete(one) | ||
else | ||
one.destroy | ||
end | ||
end | ||
items.each do |i| | ||
if i['filename'] | ||
# OK, this rules refers to a file, just use it... | ||
next | ||
else | ||
if i['guid'].nil? | ||
i['guid'] = SecureRandom.uuid | ||
end | ||
#puts i.inspect | ||
si = ScanItem.create(i) | ||
end | ||
profile.add_member(si) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters