1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
#!/usr/bin/perl
# $Header: /cvsroot/systeminstaller/systeminstaller/bin/simigratedb,v 1.4 2003/04/11 20:44:29 mchasal Exp $
# Copyright (c) 2001 International Business Machines
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
use vars qw($config $VERSION);
$VERSION = sprintf("%d.%02d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/);
use lib "/usr/lib/systeminstaller";
use SIS::Client;
use SIS::Adapter;
use SIS::Image;
use SIS::DB;
use SystemInstaller::Env;
use SystemInstaller::Log qw(start_verbose stop_verbose verbose logger_file);
use Carp;
use AppConfig qw(:argcount);
use Data::Dumper;
use File::Path;
#Set the path
$ENV{PATH}=$config->binpath .":" . $ENV{PATH};
$config->define(
Help=>{ ARGCOUNT=> ARGCOUNT_NONE},
version=>{ARGCOUNT=> ARGCOUNT_NONE},
);
unless ($config->getopt()){
&usage;
exit 1;
}
if ($config->version){
&print_version($0,$VERSION);
exit 0;
}
if ($config->Help){
&usage;
exit 0;
}
unless (-e "/var/lib/clamdr") {
exit 0;
}
my %CLAMDR;
unless (%CLAMDR=read_old_db() ) {
print "Couldn't read old SIS database in /var/lib/clamdr.\n";
print "Unable to migrate to new database, after correcting the\n";
print "problem, run simigratedb to migrate the data.\n";
exit 0; # We don't want the %post to fail
}
if (%CLAMDR) {
make_images(%CLAMDR);
make_clients(%CLAMDR);
make_adapters(%CLAMDR);
}
rmtree("/var/lib/clamdr");
exit 0;
sub make_images {
my %CLAMDR=@_;
my @OBJS;
foreach my $image (keys%{$CLAMDR{IMAGES}}) {
my %O=%{$CLAMDR{IMAGES}{$image}};
if (exists_image($O{NAME})) {
print "Image $O{NAME} already exists.\n";
next;
} else {
my $obj = new SIS::Image($O{NAME});
$obj->location($O{LOCATION});
$obj->arch($O{ARCH});
push @OBJS,$obj;
}
}
if (@OBJS) {
set_image(@OBJS);
}
} #make_images
sub make_clients {
my %CLAMDR=@_;
my @OBJS;
foreach my $client (keys%{$CLAMDR{CLIENTS}}) {
my %O=%{$CLAMDR{CLIENTS}{$client}};
if (exists_client($O{NAME})) {
print "Client $O{NAME} already exists.\n";
next;
} else {
my $obj = new SIS::Client($O{NAME});
$obj->route($O{ROUTE});
$obj->hostname($O{HOSTNAME});
$obj->domainname($O{DOMAIN});
$obj->imagename($O{IMAGE});
$obj->proccount($O{NUMPROC});
push @OBJS,$obj;
}
}
if (@OBJS) {
set_client(@OBJS);
}
} #make_clients
sub make_adapters {
my %CLAMDR=@_;
my @OBJS;
foreach my $client (keys%{$CLAMDR{ADAPTERS}}) {
foreach my $dev (keys%{$CLAMDR{ADAPTERS}{$client}}) {
my %O=%{$CLAMDR{ADAPTERS}{$client}{$dev}};
if (exists_adapter($O{DEVICE},$O{CLIENT})) {
print "Adapter $O{DEVICE} for client $O{CLIENT} already exists.\n";
next;
} else {
my $obj = new SIS::Adapter($O{DEVICE});
$obj->client($O{CLIENT});
$obj->mac($O{MAC});
$obj->ip($O{IP});
$obj->netmask($O{NETMASK});
push @OBJS,$obj;
}
}
}
if (@OBJS) {
set_adapter(@OBJS);
}
} #make_adapters
sub read_old_db {
my %CLAMDR;
my $file="/var/lib/clamdr/Image";
if (-e $file) {
open(FILE,"<$file") or return;
while (<FILE>) {
chomp;
my ($name,$server,$loc,$arch)=split(/:/,$_);
$CLAMDR{IMAGES}{$name}{NAME}=$name;
$CLAMDR{IMAGES}{$name}{LOCATION}=$loc;
$CLAMDR{IMAGES}{$name}{ARCH}=$arch;
$CLAMDR{IMAGES}{$name}{SERVER}=$server;
}
close(FILE);
}
my $file="/var/lib/clamdr/Client";
if (-e $file) {
open(FILE,"<$file") or return;
while (<FILE>) {
chomp;
my ($name,$hostname,$domain,$route,$mode,$bootdev,$image,$numproc)=split(/:/,$_);
$CLAMDR{CLIENTS}{$name}{NAME}=$name;
$CLAMDR{CLIENTS}{$name}{HOSTNAME}=$hostname;
$CLAMDR{CLIENTS}{$name}{DOMAIN}=$domain;
$CLAMDR{CLIENTS}{$name}{ROUTE}=$route;
$CLAMDR{CLIENTS}{$name}{MODE}=$mode;
$CLAMDR{CLIENTS}{$name}{BOOTDEV}=$bootdev;
$CLAMDR{CLIENTS}{$name}{IMAGE}=$image;
$CLAMDR{CLIENTS}{$name}{NUMPROC}=$numproc;
}
close(FILE);
}
my $file="/var/lib/clamdr/Adapter";
if (-e $file) {
open(FILE,"<$file") or return;
while (<FILE>) {
chomp;
my ($client,$devname,$MAC,$ip,$netmask,$method,$rest);
if (/\"/){
($client,$devname,$rest)=split(/:/,$_,3);
$rest=~s/^"//;
($MAC,$rest)=split(/"/,$rest,2);
$rest=~s/^://;
($ip,$netmask,$method)=split(/:/,$rest);
} else {
($client,$devname,$MAC,$ip,$netmask,$method)=split(/:/,$_);
}
$CLAMDR{ADAPTERS}{$client}{$devname}{DEVICE}=$devname;
$CLAMDR{ADAPTERS}{$client}{$devname}{CLIENT}=$client;
$CLAMDR{ADAPTERS}{$client}{$devname}{MAC}=$MAC;
$CLAMDR{ADAPTERS}{$client}{$devname}{IP}=$ip;
$CLAMDR{ADAPTERS}{$client}{$devname}{NETMASK}=$netmask;
$CLAMDR{ADAPTERS}{$client}{$devname}{METHOD}=$method;
}
close(FILE);
}
return %CLAMDR;
} #read_old_db
sub usage {
my $progname = $0;
if ($progname =~ m/(.+\/)(\w+)/) {
$progname = $2;
}
print <<USAGE;
usage: $progname <options>
options
--Help Print help message.
--version Print file version info.
USAGE
}
__END__
=head1 NAME
simigratedb - command shell migrate the CLAMDR database to the MLDBM format
=head1 SYNOPSIS
simigratedb
=head1 DESCRIPTION
The simigratedb command is used to move the contents of the old SIS database
(CLAMDR) to the new one.
=head2 Syntax
simigratedb [ I<options> ]
=head2 Options
Recognized options include:
=over 4
=item --version
Prints version information
=item --help
Prints usage information
=head1 AUTHOR
Michael Chase-Salerno, mchasal@users.sf.net
=head1 SEE ALSO
perl(1), L<SIS::DB>
=cut
|