| 1 | package RackMan::Device::PDU::APC_RackPDU; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Config::IniFiles; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Cwd qw< getcwd >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use File::Path; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use File::Temp qw< tempdir >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Net::FTP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Net::SNMP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use RackMan; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use RackMan::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use RackMan::Utils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 2 | CONFIG_SECTION => "device:pdu:apc_rackpdu", | |||||||||||||||||||||||||||
| 19 | INTERFACE_NAME => "AC-out", | ||||||||||||||||||||||||||||
| 20 | CONFIG_FILENAME => "config.ini", | ||||||||||||||||||||||||||||
| 21 | EMPTY_VALUE => '""', | ||||||||||||||||||||||||||||
| 22 | PDU_RESTART_OID => ".1.3.6.1.4.1.318.2.2.1", | ||||||||||||||||||||||||||||
| 23 | 2 | }; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||
| 27 | # write_config() | ||||||||||||||||||||||||||||
| 28 | # ------------ | ||||||||||||||||||||||||||||
| 29 | 0 | ▶ | sub write_config { | ||||||||||||||||||||||||||
|
Subroutine
write_config: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $rackman = $args->{rackman}; | |||||||||||||||||||||||||||
| 33 | 0 | my $path = $rackman->config->val(general => "path"); | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # generate the configuration file | ||||||||||||||||||||||||||||
| 36 | 0 | my $file = $self->fetch_from_database($args); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # write the configuration file on disk, to its final path | ||||||||||||||||||||||||||||
| 39 | 0 | $file->path($path); | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | print " + writing ", $file->fullpath, $/ if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | my $scm = $rackman->get_scm({ path => $path }); | |||||||||||||||||||||||||||
| 42 | 0 | $scm->update; | |||||||||||||||||||||||||||
| 43 | 0 | $file->write; | |||||||||||||||||||||||||||
| 44 | 0 | $scm->add($file->name); | |||||||||||||||||||||||||||
| 45 | 0 | $scm->commit($file->name, "generated by ".__PACKAGE__ | |||||||||||||||||||||||||||
| 46 | . " / $::PROGRAM v$::VERSION"); | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||
| 51 | # diff_config() | ||||||||||||||||||||||||||||
| 52 | # ----------- | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub diff_config { | ||||||||||||||||||||||||||
|
Subroutine
diff_config: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # fetch config from the device | ||||||||||||||||||||||||||||
| 57 | 0 | my $actual = $self->fetch_from_device($args); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # generate the config from the database | ||||||||||||||||||||||||||||
| 60 | 0 | my $expected = $self->fetch_from_database($args); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # prepare the files | ||||||||||||||||||||||||||||
| 63 | 0 | my @cfg_actual = split $/, $actual->content; | |||||||||||||||||||||||||||
| 64 | 0 | my @cfg_expected = split $/, $expected->content; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # .. remove bits here and there that will generate useless diffs | ||||||||||||||||||||||||||||
| 67 | s|generated on \S+ at \S+|generated|, | ||||||||||||||||||||||||||||
| 68 | s|; Rack PDU Feature Not Supported *|| | ||||||||||||||||||||||||||||
| 69 | 0 | for @cfg_actual, @cfg_expected; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # computes the differences between the two files | ||||||||||||||||||||||||||||
| 72 | 0 | ▶ | print " - computing differences..." if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | my @diff = diff_lines(\@cfg_actual, \@cfg_expected); | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | print " done\n\n" if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | print @diff; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | RackMan->set_status(1) if @diff; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # | ||||||||||||||||||||||||||||
| 82 | # push_config() | ||||||||||||||||||||||||||||
| 83 | # ----------- | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub push_config { | ||||||||||||||||||||||||||
|
Subroutine
push_config: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my $rackman = $args->{rackman}; | |||||||||||||||||||||||||||
| 88 | 0 | my $path = $rackman->config->val(general => "path"); | |||||||||||||||||||||||||||
| 89 | 0 | my $file = RackMan::File->new({ path => $path, name => CONFIG_FILENAME }); | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # read the file from disk | ||||||||||||||||||||||||||||
| 92 | 0 | $file->read; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # store it on the device | ||||||||||||||||||||||||||||
| 95 | 0 | $self->store_to_device($args, $file); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||
| 100 | # fetch_from_database() | ||||||||||||||||||||||||||||
| 101 | # ------------------- | ||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub fetch_from_database { | ||||||||||||||||||||||||||
|
Subroutine
fetch_from_database: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||
| 103 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | my $rackman = $args->{rackman}; | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | my $host = $self->attributes->{FQDN} || $self->object_name; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->attributes->{'FQDN'} || $self->object_name
MC/DC0%0/2
$self->attributes->{'FQDN'} || $self->object_name
$self->attributes->{'FQDN'}
$self->object_name
Truth table0%0/3
A || B
A= $self->attributes->{'FQDN'}B= $self->object_name
| |||||||||||||||||||||||||||||
| 107 | 0 | my ($node, $domain) = split /\./, $host; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | # get the current device config | ||||||||||||||||||||||||||||
| 110 | 0 | my $file = $self->fetch_from_device($args); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | my $rt_url = $rackman->config->val(general => "racktables_url"); | |||||||||||||||||||||||||||
| 113 | 0 | my $short_url = $rackman->config->val(general => "short_url"); | |||||||||||||||||||||||||||
| 114 | 0 | my $nagios_url = $rackman->config->val(general => "nagios_url"); | |||||||||||||||||||||||||||
| 115 | 0 | s:/$:: for $nagios_url, $rt_url; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | # parse the config file | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my $config = Config::IniFiles->new(-file => $file->fullpath) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | or RackMan->error("can't parse config file: ", @Config::IniFiles::errors); | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # network settings | ||||||||||||||||||||||||||||
| 122 | 0 | $config->setval("NetworkTCP/IP", "HostName", $node); | |||||||||||||||||||||||||||
| 123 | 0 | $config->setval("NetworkTCP/IP", "DomainName", $domain); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # DNS settings | ||||||||||||||||||||||||||||
| 126 | 0 | my @dns_servers = split / +/, | |||||||||||||||||||||||||||
| 127 | $rackman->config->val(general => "dns_servers"); | ||||||||||||||||||||||||||||
| 128 | 0 | push @dns_servers, "0.0.0.0", "0.0.0.0"; | |||||||||||||||||||||||||||
| 129 | 0 | $config->setval("NetworkDNS", "DNSManualOverride", "enabled"); | |||||||||||||||||||||||||||
| 130 | 0 | $config->setval("NetworkDNS", "PrimaryDNSServerIP", $dns_servers[0]); | |||||||||||||||||||||||||||
| 131 | 0 | $config->setval("NetworkDNS", "SecondaryDNSServerIP", $dns_servers[1]); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # email settings | ||||||||||||||||||||||||||||
| 134 | 0 | my $mail_address = $rackman->config->val(CONFIG_SECTION, "mail_address"); | |||||||||||||||||||||||||||
| 135 | 0 | $config->setval("NetworkEMAIL", "EmailServerName", | |||||||||||||||||||||||||||
| 136 | $rackman->config->val(general => "mail_server")); | ||||||||||||||||||||||||||||
| 137 | 0 | $config->setval("NetworkEMAIL", "EmailFromName", $mail_address); | |||||||||||||||||||||||||||
| 138 | 0 | $config->setval("NetworkEMAIL", "EmailReceiver1Address", $mail_address); | |||||||||||||||||||||||||||
| 139 | 0 | $config->setval("NetworkEMAIL", "EmailReceiver1Enable", "enabled"); | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # system information | ||||||||||||||||||||||||||||
| 142 | 0 | $config->setval("SystemID", "Name", $host); | |||||||||||||||||||||||||||
| 143 | 0 | $config->setval("SystemID", "Contact", $mail_address); | |||||||||||||||||||||||||||
| 144 | $config->setval("SystemID", "Location", | ||||||||||||||||||||||||||||
| 145 | 0 | $self->rack->{name}.' @ '.$self->rack->{row_name}); | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # NTP settings | ||||||||||||||||||||||||||||
| 148 | 0 | my @ntp_servers = split / +/, | |||||||||||||||||||||||||||
| 149 | $rackman->config->val(general => "ntp_servers"); | ||||||||||||||||||||||||||||
| 150 | 0 | push @ntp_servers, "0.0.0.0", "0.0.0.0"; | |||||||||||||||||||||||||||
| 151 | 0 | $config->setval("SystemDate/Time", "NTPEnable", "enabled"); | |||||||||||||||||||||||||||
| 152 | 0 | $config->setval("SystemDate/Time", "NTPPrimaryServer", $ntp_servers[0]); | |||||||||||||||||||||||||||
| 153 | 0 | $config->setval("SystemDate/Time", "NTPSecondaryServer", $ntp_servers[1]); | |||||||||||||||||||||||||||
| 154 | 0 | $config->setval("SystemDate/Time", "NTPTimeZone", "+01:00"); | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # set the first bottom link to the corresponding page in RackTables | ||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ($rt_url) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 0 | my $url = sprintf "$rt_url/index.php?page=object&object_id=%d", | |||||||||||||||||||||||||||
| 159 | $self->object_id; | ||||||||||||||||||||||||||||
| 160 | 0 | $config->setval("SystemLinks", "LinkURL1", $url); | |||||||||||||||||||||||||||
| 161 | 0 | $config->setval("SystemLinks", "LinkDisplay1", "RackTables"); | |||||||||||||||||||||||||||
| 162 | 0 | $config->setval("SystemLinks", "LinkName1", | |||||||||||||||||||||||||||
| 163 | "link to $node\'s page on RackTables"); | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # set the second bottom link to the corresponding page in Nagios | ||||||||||||||||||||||||||||
| 167 | 0 | ▶ | if ($nagios_url) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | my $url = "$nagios_url/cgi-bin/extinfo.cgi?type=1&host=$host"; | |||||||||||||||||||||||||||
| 169 | 0 | $config->setval("SystemLinks", "LinkURL2", $url); | |||||||||||||||||||||||||||
| 170 | 0 | $config->setval("SystemLinks", "LinkDisplay2", "Nagios"); | |||||||||||||||||||||||||||
| 171 | 0 | $config->setval("SystemLinks", "LinkName2", | |||||||||||||||||||||||||||
| 172 | "link to $node\'s page on Nagios"); | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # set the third bottom link to the corresponding page on APC site | ||||||||||||||||||||||||||||
| 176 | $config->setval("SystemLinks", "LinkURL3", | ||||||||||||||||||||||||||||
| 177 | 0 | $self->attributes->{"HW type link"}); | |||||||||||||||||||||||||||
| 178 | $config->setval("SystemLinks", "LinkDisplay3", | ||||||||||||||||||||||||||||
| 179 | 0 | $self->attributes->{"HW type"}." specifications"); | |||||||||||||||||||||||||||
| 180 | 0 | $config->setval("SystemLinks", "LinkName3", | |||||||||||||||||||||||||||
| 181 | "link to this model's specifications page on APC site"); | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | # the config format differs mostly for outlets settings, so we | ||||||||||||||||||||||||||||
| 184 | # detect the format version by looking the section present in | ||||||||||||||||||||||||||||
| 185 | # the file | ||||||||||||||||||||||||||||
| 186 | 0 | ▶ | my ($outlet_sect, $outlet_name, $outlet_link) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | = $config->SectionExists("RackPDUOutlet") | ||||||||||||||||||||||||||||
| 188 | ? qw< RackPDUOutlet Name OutletLink > # Rack PDU v3 | ||||||||||||||||||||||||||||
| 189 | : qw< Outlet OUTLET_NAME_A OUTLET_EXTERNAL_LINK_A >; # Rack PDU v5 | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | # outlets settings | ||||||||||||||||||||||||||||
| 192 | 0 | for my $port (grep { $_->{oif_name} eq INTERFACE_NAME } @{ $self->ports }) { | |||||||||||||||||||||||||||
| 193 | 0 | my ($name, $url) = ("(unused)", "#"); | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if ($port->{peer_object_name}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | # note: an outlet name can be 23 chars max | ||||||||||||||||||||||||||||
| 197 | 0 | ($name) = split /\./, $port->{peer_object_name}; | |||||||||||||||||||||||||||
| 198 | 0 | my $max = 23 - 1 - length $port->{peer_port_name}; | |||||||||||||||||||||||||||
| 199 | 0 | ▶ | substr($name, $max-1) = "~" if length $name > $max; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | $name .= ":$port->{peer_port_name}"; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | # construct the RackTables url for the peer device, if any | ||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if ($short_url and $port->{peer_object_id}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$short_url and $port->{"peer_object_id"}
MC/DC0%0/2
$short_url and $port->{"peer_object_id"}
$short_url
$port->{"peer_object_id"}
Truth table0%0/3
A and B
A= $short_urlB= $port->{"peer_object_id"}
| |||||||||||||||||||||||||||||
| 205 | # note: an outlet URL can be 60 chars max | ||||||||||||||||||||||||||||
| 206 | 0 | $url = "$short_url?oi=$port->{peer_object_id}" | |||||||||||||||||||||||||||
| 207 | . "&pi=$port->{peer_port_id}"; | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | substr($url , 59) = "~" if length $url > 60; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | my $n = int $port->{name}; | |||||||||||||||||||||||||||
| 213 | 0 | $config->setval($outlet_sect, "$outlet_name$n", $name); | |||||||||||||||||||||||||||
| 214 | 0 | $config->setval($outlet_sect, "$outlet_link$n", $url); | |||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # write the modified config back on disk | ||||||||||||||||||||||||||||
| 218 | 0 | $config->RewriteConfig; | |||||||||||||||||||||||||||
| 219 | 0 | $file->read; | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | return $file | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | # | ||||||||||||||||||||||||||||
| 226 | # fetch_from_device() | ||||||||||||||||||||||||||||
| 227 | # ----------------- | ||||||||||||||||||||||||||||
| 228 | 0 | ▶ | sub fetch_from_device { | ||||||||||||||||||||||||||
|
Subroutine
fetch_from_device: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 229 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 0 | my $rackman = $args->{rackman}; | |||||||||||||||||||||||||||
| 232 | 0 | ▶ | my $host = $self->attributes->{FQDN} || $self->object_name; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->attributes->{'FQDN'} || $self->object_name
MC/DC0%0/2
$self->attributes->{'FQDN'} || $self->object_name
$self->attributes->{'FQDN'}
$self->object_name
Truth table0%0/3
A || B
A= $self->attributes->{'FQDN'}B= $self->object_name
| |||||||||||||||||||||||||||||
| 233 | my $login = $rackman->options->{device_login} | ||||||||||||||||||||||||||||
| 234 | 0 | ▶ | || $rackman->config->val(CONFIG_SECTION, "ftp_login", "apc"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$rackman->options->{'device_login'} || $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_login', 'apc')
MC/DC0%0/2
$rackman->options->{'device_login'} || $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_login', 'apc')
$rackman->options->{'device_login'}
$rackman->config->val('device:pdu:apc_rackpdu', 'ftp_login', 'apc')
Truth table0%0/3
A || B
A= $rackman->options->{'device_login'}B= $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_login', 'apc')
| |||||||||||||||||||||||||||||
| 235 | my $passwd = $rackman->options->{device_password} | ||||||||||||||||||||||||||||
| 236 | 0 | ▶ | || $rackman->config->val(CONFIG_SECTION, "ftp_password", "apc"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$rackman->options->{'device_password'} || $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_password', 'apc')
MC/DC0%0/2
$rackman->options->{'device_password'} || $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_password', 'apc')
$rackman->options->{'device_password'}
$rackman->config->val('device:pdu:apc_rackpdu', 'ftp_password', 'apc')
Truth table0%0/3
A || B
A= $rackman->options->{'device_password'}B= $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_password', 'apc')
| |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | # create a temporary directory to work in there | ||||||||||||||||||||||||||||
| 239 | 0 | my $olddir = getcwd(); | |||||||||||||||||||||||||||
| 240 | 0 | my $tmpdir = tempdir(CLEANUP => 1); | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | # fetch the config file from the device using FTP | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | print " < fetching from device via FTP." if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | # .. connect | ||||||||||||||||||||||||||||
| 245 | 0 | ▶ | my $ftp = Net::FTP->new($host) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 246 | or RackMan->error_n("could not connect to '$host': $@"); | ||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $ftp->login($login, $passwd) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | or RackMan->error_n("could not login: ", $ftp->message); | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | # .. configure, chdir | ||||||||||||||||||||||||||||
| 251 | 0 | ▶ | print "." if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 0 | $ftp->ascii; | |||||||||||||||||||||||||||
| 253 | 0 | ▶ | $ftp->cwd("/") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | or RackMan->error_n("could not change working directory: ", $ftp->message); | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | # .. fetch the file | ||||||||||||||||||||||||||||
| 257 | 0 | ▶ | print "." if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 0 | chdir $tmpdir; | |||||||||||||||||||||||||||
| 259 | 0 | ▶ | $ftp->get(CONFIG_FILENAME) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | or RackMan->error_n("could not fetch file: ", $ftp->message); | ||||||||||||||||||||||||||||
| 261 | 0 | chdir $olddir; | |||||||||||||||||||||||||||
| 262 | 0 | $ftp->quit; | |||||||||||||||||||||||||||
| 263 | 0 | ▶ | print " done\n" if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | # put the config file in a RackMan:File instance | ||||||||||||||||||||||||||||
| 266 | 0 | my $file = RackMan::File->new({ path => $tmpdir, name => CONFIG_FILENAME }); | |||||||||||||||||||||||||||
| 267 | 0 | $file->read; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 0 | return $file | |||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | # | ||||||||||||||||||||||||||||
| 275 | # store_to_device() | ||||||||||||||||||||||||||||
| 276 | # --------------- | ||||||||||||||||||||||||||||
| 277 | 0 | ▶ | sub store_to_device { | ||||||||||||||||||||||||||
|
Subroutine
store_to_device: not called CC=16 SCAR=56.1
Pod
documented
| |||||||||||||||||||||||||||||
| 278 | 0 | my ($self, $args, $file) = @_; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | my $rackman = $args->{rackman}; | |||||||||||||||||||||||||||
| 281 | 0 | my $me = $::COMMAND.": ".(caller(0))[3]; | |||||||||||||||||||||||||||
| 282 | 0 | ▶ | my $host = $self->attributes->{FQDN} || $self->object_name; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->attributes->{'FQDN'} || $self->object_name
MC/DC0%0/2
$self->attributes->{'FQDN'} || $self->object_name
$self->attributes->{'FQDN'}
$self->object_name
Truth table0%0/3
A || B
A= $self->attributes->{'FQDN'}B= $self->object_name
| |||||||||||||||||||||||||||||
| 283 | my $login = $rackman->options->{device_login} | ||||||||||||||||||||||||||||
| 284 | 0 | ▶ | || $rackman->config->val(CONFIG_SECTION, "ftp_login", "apc"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$rackman->options->{'device_login'} || $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_login', 'apc')
MC/DC0%0/2
$rackman->options->{'device_login'} || $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_login', 'apc')
$rackman->options->{'device_login'}
$rackman->config->val('device:pdu:apc_rackpdu', 'ftp_login', 'apc')
Truth table0%0/3
A || B
A= $rackman->options->{'device_login'}B= $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_login', 'apc')
| |||||||||||||||||||||||||||||
| 285 | my $passwd = $rackman->options->{device_password} | ||||||||||||||||||||||||||||
| 286 | 0 | ▶ | || $rackman->config->val(CONFIG_SECTION, "ftp_password", "apc"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$rackman->options->{'device_password'} || $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_password', 'apc')
MC/DC0%0/2
$rackman->options->{'device_password'} || $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_password', 'apc')
$rackman->options->{'device_password'}
$rackman->config->val('device:pdu:apc_rackpdu', 'ftp_password', 'apc')
Truth table0%0/3
A || B
A= $rackman->options->{'device_password'}B= $rackman->config->val('device:pdu:apc_rackpdu', 'ftp_password', 'apc')
| |||||||||||||||||||||||||||||
| 287 | my $community = $rackman->options->{write_community} | ||||||||||||||||||||||||||||
| 288 | 0 | ▶ | || $rackman->config->val(CONFIG_SECTION, "write_community", "private"); | ||||||||||||||||||||||||||
|
Condition0%0/3
$rackman->options->{'write_community'} || $rackman->config->val('device:pdu:apc_rackpdu', 'write_community', 'private')
MC/DC0%0/2
$rackman->options->{'write_community'} || $rackman->config->val('device:pdu:apc_rackpdu', 'write_community', 'private')
$rackman->options->{'write_community'}
$rackman->config->val('device:pdu:apc_rackpdu', 'write_community', 'private')
Truth table0%0/3
A || B
A= $rackman->options->{'write_community'}B= $rackman->config->val('device:pdu:apc_rackpdu', 'write_community', 'private')
| |||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | # check argument | ||||||||||||||||||||||||||||
| 291 | 0 | ▶ | eval { $file->isa("RackMan::File") } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | or croak "argument must be a RackMan::File instance"; | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | # ensure the file is written on disk | ||||||||||||||||||||||||||||
| 295 | 0 | $file->write; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | # store the config file to the device using FTP | ||||||||||||||||||||||||||||
| 298 | 0 | ▶ | print " > storing to device via FTP." if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | # .. connect | ||||||||||||||||||||||||||||
| 300 | 0 | ▶ | my $ftp = Net::FTP->new($host) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | or RackMan->error_n("could not connect to '$host': $@"); | ||||||||||||||||||||||||||||
| 302 | 0 | ▶ | $ftp->login($login, $passwd) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 303 | or RackMan->error_n("could not login: ", $ftp->message); | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | # .. configure, chdir | ||||||||||||||||||||||||||||
| 306 | 0 | ▶ | print "." if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 0 | $ftp->ascii; | |||||||||||||||||||||||||||
| 308 | 0 | ▶ | $ftp->cwd("/") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | or RackMan->error_n("could not change working directory: ", $ftp->message); | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | # .. send the file | ||||||||||||||||||||||||||||
| 312 | 0 | ▶ | print "." if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 0 | ▶ | $ftp->put($file->fullpath, CONFIG_FILENAME) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 314 | or RackMan->error_n("could not store file: ", $ftp->message); | ||||||||||||||||||||||||||||
| 315 | 0 | $ftp->quit; | |||||||||||||||||||||||||||
| 316 | 0 | ▶ | print " done\n" if $args->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | # send the SNMP request to make the PDU reboot | ||||||||||||||||||||||||||||
| 319 | # mcontrolRestartAgent = restartCurrentAgent(1) | ||||||||||||||||||||||||||||
| 320 | 0 | my ($session, $error); | |||||||||||||||||||||||||||
| 321 | 0 | ▶ | ($session, $error) = Net::SNMP->session( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | -hostname => $host, | ||||||||||||||||||||||||||||
| 323 | -community => $community, | ||||||||||||||||||||||||||||
| 324 | -version => 2, | ||||||||||||||||||||||||||||
| 325 | ) or RackMan->error("can't create SNMP session: $error"); | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | my $result = $session->set_request( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | -varbindlist => [ PDU_RESTART_OID, INTEGER, 1 ], | ||||||||||||||||||||||||||||
| 329 | ) or RackMan->error("could not execute SNMP set request: ", $session->error); | ||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 2 | __PACKAGE__ | |||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | __END__ | ||||||||||||||||||||||||||||