| 1 | package Conan::Configure::Xen; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 7 | 0 | my $class = shift; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 0 | my $args = { | |||||||||||||||||||
| 10 | basedir => '/xen/prod/etc/', | ||||||||||||||||||||
| 11 | @_, | ||||||||||||||||||||
| 12 | }; | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | # By default the IP isn't outputted, but rather | ||||||||||||||||||||
| 15 | # generated in the 'extra' field | ||||||||||||||||||||
| 16 | 0 | ▶ | unless( $args->{generators}->{ip} ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | 0 | ▶ | $args->{generators}->{ip} = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 18 | 0 | my $self = shift; | |||||||||||||||||||
| 19 | 0 | return sprintf "#ip = '%s'\n", $self->{settings}->{ip}; | |||||||||||||||||||
| 20 | 0 | }; | |||||||||||||||||||
| 21 | } | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 0 | ▶ | unless( $args->{generators}->{netmask} ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 0 | ▶ | $args->{generators}->{netmask} = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 25 | 0 | my $self = shift; | |||||||||||||||||||
| 26 | 0 | return sprintf "#netmask = '%s'\n", $self->{settings}->{netmask}; | |||||||||||||||||||
| 27 | 0 | }; | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | ▶ | unless( $args->{generators}->{gateway} ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 31 | 0 | ▶ | $args->{generators}->{gateway} = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||
| 33 | 0 | return sprintf "#gateway = '%s'\n", $self->{settings}->{gateway}; | |||||||||||||||||||
| 34 | 0 | }; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 0 | ▶ | unless( $args->{generators}->{extra} ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 0 | ▶ | $args->{generators}->{extra} = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 39 | 0 | my $self = shift; | |||||||||||||||||||
| 40 | return sprintf "extra = ' ip=%s::%s:%s::eth0:off NFS=%s= %s %s ro clocksource=jiffies'\n", | ||||||||||||||||||||
| 41 | $self->{settings}->{ip}, | ||||||||||||||||||||
| 42 | $self->{settings}->{gateway}, | ||||||||||||||||||||
| 43 | $self->{settings}->{netmask}, | ||||||||||||||||||||
| 44 | $self->{settings}->{nfsroot}, | ||||||||||||||||||||
| 45 | $self->{settings}->{postboot}, | ||||||||||||||||||||
| 46 | 0 | ▶ | $self->{settings}->{name} || $self->{name}; | ||||||||||||||||||
|
Condition0%0/3
$self->{'settings'}{'name'} || $self->{'name'}
MC/DC0%0/2
$self->{'settings'}{'name'} || $self->{'name'}
$self->{'settings'}{'name'}
$self->{'name'}
Truth table0%0/3
A || B
A= $self->{'settings'}{'name'}B= $self->{'name'}
| |||||||||||||||||||||
| 47 | 0 | }; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | bless $args => $class; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | ▶ | sub generate { | ||||||||||||||||||
|
Subroutine
generate: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||
| 56 | 0 | my $output = sprintf "# This was generated on %s by %s\n", scalar localtime( time() ), 'Conan::Configure::Xen'; | |||||||||||||||||||
| 57 | 0 | $output .= "# Please do not manually edit\n"; | |||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 0 | for my $key (qw/ | |||||||||||||||||||
| 60 | name | ||||||||||||||||||||
| 61 | kernel | ||||||||||||||||||||
| 62 | memory | ||||||||||||||||||||
| 63 | vcpus | ||||||||||||||||||||
| 64 | vif | ||||||||||||||||||||
| 65 | ip | ||||||||||||||||||||
| 66 | netmask | ||||||||||||||||||||
| 67 | gateway | ||||||||||||||||||||
| 68 | on_poweroff | ||||||||||||||||||||
| 69 | on_reboot | ||||||||||||||||||||
| 70 | on_crash | ||||||||||||||||||||
| 71 | extra/){ | ||||||||||||||||||||
| 72 | 0 | ▶ | if( exists $self->{generators}->{$key} ){ | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 73 | 0 | my $sub = $self->{generators}->{$key}; | |||||||||||||||||||
| 74 | 0 | $output .= $sub->($self); | |||||||||||||||||||
| 75 | } elsif( defined $self->{settings}->{$key} ){ | ||||||||||||||||||||
| 76 | 0 | ▶ | if( $key eq 'vif' ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | # This is the weird one | ||||||||||||||||||||
| 78 | 0 | $output .= $key . " = [ " . "'$self->{settings}->{$key}'" . " ]\n"; | |||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||
| 80 | 0 | $output .= $key . " = " . "'$self->{settings}->{$key}'" . "\n"; | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | } | ||||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | return $output; | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | ▶ | sub parse { | ||||||||||||||||||
|
Subroutine
parse: not called CC=7 SCAR=37.8
Pod
documented
| |||||||||||||||||||||
| 90 | 0 | my $self = shift; | |||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | 0 | my %hostsettings; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 0 | ▶ | my @files = glob "$self->{basedir}/*.cfg.tmpl $self->{basedir}/*.cfg"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 0 | s/\/{2,}/\//g for @files; | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | ▶ | croak "Name not defined" unless defined $self->{name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | # Get the hostconfig files | ||||||||||||||||||||
| 101 | 0 | my @hostconfig = grep { /$self->{name}/ } @files; | |||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | my $basename = $self->{name}; | |||||||||||||||||||
| 104 | 0 | $basename =~ s/\d+//g; | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | my @baseconfig = grep { /$basename\.cfg/ } @files; | |||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | for( @baseconfig ){ | |||||||||||||||||||
| 109 | 0 | my %hash2 = $self->parse_template( $_ ); | |||||||||||||||||||
| 110 | 0 | @hostsettings{keys %hash2} = values %hash2; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 0 | for( @hostconfig ){ | |||||||||||||||||||
| 114 | 0 | my %hash2 = $self->parse_template( $_ ); | |||||||||||||||||||
| 115 | 0 | @hostsettings{keys %hash2} = values %hash2; | |||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | $self->{settings} = \%hostsettings; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | # post parse stuff | ||||||||||||||||||||
| 121 | 0 | ▶ | if( $self->{settings}->{NFS} ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 122 | 0 | ▶ | if( $self->{settings}->{version} ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 123 | 0 | $self->{settings}->{NFS} .= "/" . $self->{settings}->{version}; | |||||||||||||||||||
| 124 | # Strip duplicate / | ||||||||||||||||||||
| 125 | 0 | $self->{settings}->{NFS} =~ s,/+,/,g; | |||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | 0 | $self->{settings}->{nfsroot} = $self->{settings}->{NFS}; | |||||||||||||||||||
| 128 | } | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 0 | return $self->{settings}; | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | 0 | ▶ | sub host_template { | ||||||||||||||||||
|
Subroutine
host_template: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 134 | 0 | my $self = shift; | |||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 0 | my $filename = shift; | |||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 0 | ▶ | sub parse_template { | ||||||||||||||||||
|
Subroutine
parse_template: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 140 | 0 | my $self = shift; | |||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | 0 | my $filename = shift; | |||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | my %settings; | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 0 | open my $fd, "<$filename"; | |||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 0 | ▶ | if( $fd ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 149 | 0 | my @lines = <$fd>; | |||||||||||||||||||
| 150 | 0 | chomp for @lines; | |||||||||||||||||||
| 151 | 0 | s/#.*//g for @lines; | |||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 0 | ▶ | %settings = map { ($1,$2) if /(\S+)\s*=\s*(?:\[\s*)?'(.*?)'/ } grep( ! /^\s*$/, @lines ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 154 | 0 | close $fd; | |||||||||||||||||||
| 155 | } | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | 0 | return %settings; | |||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 1 | 1; | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||