blob: d3389b54a351369b176388b2918df1d8a7d6c4f9 [file] [log] [blame]
Gunnar Millsbff56842017-09-25 15:49:16 -05001#!/usr/bin/env perl
2use strict;
3use warnings;
4
5use mrw::Targets; # Set of APIs allowing access to parsed ServerWiz2 XML output
6use Getopt::Long; # For parsing command line arguments
7
8# Globals
9my $force = 0;
10my $serverwizFile = "";
11my $debug = 0;
12my $outputFile = "";
Gunnar Mills45765332017-09-26 16:19:32 -050013my $settingsFile = "";
Gunnar Millsbff56842017-09-25 15:49:16 -050014
15# Command line argument parsing
16GetOptions(
17"f" => \$force, # numeric
18"i=s" => \$serverwizFile, # string
19"o=s" => \$outputFile, # string
Gunnar Mills45765332017-09-26 16:19:32 -050020"s=s" => \$settingsFile, # string
Gunnar Millsbff56842017-09-25 15:49:16 -050021"d" => \$debug,
22)
23or printUsage();
24
Gunnar Mills45765332017-09-26 16:19:32 -050025if (($serverwizFile eq "") or ($outputFile eq "") or ($settingsFile eq "") )
Gunnar Millsbff56842017-09-25 15:49:16 -050026{
27 printUsage();
28}
29
30# API used to access parsed XML data
31my $targetObj = Targets->new;
32if($debug == 1)
33{
34 $targetObj->{debug} = 1;
35}
36
37if($force == 1)
38{
39 $targetObj->{force} = 1;
40}
41
42$targetObj->loadXML($serverwizFile);
43print "Loaded MRW XML: $serverwizFile \n";
44
Gunnar Mills45765332017-09-26 16:19:32 -050045open(my $inFh, '<', $settingsFile) or die "Could not open file '$settingsFile' $!";
46open(my $outFh, '>', $outputFile) or die "Could not open file '$outputFile' $!";
47
48# Process all the targets in the XML
49foreach my $target (sort keys %{$targetObj->getAllTargets()})
50{
51 # A future improvement could be to specify the MRW target.
52 next if ("SYS" ne $targetObj->getType($target, "TYPE"));
53 # Read the settings YAML replacing any MRW_<variable name> with their
54 # MRW value
55 while (my $row = <$inFh>)
56 {
57 while ($row =~ /MRW_(.*?)\W/g)
58 {
59 my $setting = $1;
60 my $settingValue = $targetObj->getAttribute($target, $setting);
61 $row =~ s/MRW_${setting}/$settingValue/g;
62 }
63 print $outFh $row;
64 }
65 last;
66 close $inFh;
67 close $outFh;
68}
69
Gunnar Millsbff56842017-09-25 15:49:16 -050070# Usage
71sub printUsage
72{
73 print "
Gunnar Mills45765332017-09-26 16:19:32 -050074 $0 -i [XML filename] -s [Settings YAML] -o [Output filename] [OPTIONS]
75
76Required:
77 -i = MRW XML filename
78 -s = The Setting YAML with MRW variables in MRW_<MRW variable name> format
79 -o = YAML output filename
Gunnar Millsbff56842017-09-25 15:49:16 -050080Options:
81 -f = force output file creation even when errors
82 -d = debug mode
Gunnar Millsbff56842017-09-25 15:49:16 -050083 \n";
84 exit(1);
85}