Last change
on this file was
1322,
checked in by nanardon, 9 years ago
|
Add la-sql-exchange-hostname tools, fix some doc
|
-
Property svn:executable set to
*
|
File size:
1.5 KB
|
Rev | Line | |
---|
[1322] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use LATMOS::Accounts; |
---|
| 6 | use Getopt::Long; |
---|
| 7 | use Pod::Usage; |
---|
| 8 | |
---|
| 9 | =head1 NAME |
---|
| 10 | |
---|
| 11 | la-sql-exchange-ip - Exchange name between two host |
---|
| 12 | |
---|
| 13 | =head1 SYNOPSIS |
---|
| 14 | |
---|
| 15 | la-exchange-ip from to |
---|
| 16 | |
---|
| 17 | Example : la-sql-exchange-hostname foo bar |
---|
| 18 | |
---|
| 19 | =cut |
---|
| 20 | |
---|
| 21 | GetOptions( |
---|
| 22 | 'c|config=s' => \my $config, |
---|
| 23 | 'b|base=s' => \my $base, |
---|
| 24 | 'help' => sub { pod2usage(0) }, |
---|
| 25 | ) or pod2usage(); |
---|
| 26 | |
---|
| 27 | =head1 OPTIONS |
---|
| 28 | |
---|
| 29 | =over 4 |
---|
| 30 | |
---|
| 31 | =item -c|--config configdir |
---|
| 32 | |
---|
| 33 | Use this configuration directory instead of the default one. |
---|
| 34 | |
---|
| 35 | =item -b|--base basename |
---|
| 36 | |
---|
| 37 | Query this specific base instead of the default one. |
---|
| 38 | |
---|
| 39 | =back |
---|
| 40 | |
---|
| 41 | =cut |
---|
| 42 | |
---|
| 43 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
| 44 | my $labase = $LA->base($base); |
---|
| 45 | $labase && $labase->load or die "Cannot load base"; |
---|
| 46 | |
---|
| 47 | $labase->unexported(1); |
---|
| 48 | |
---|
| 49 | my ($from, $to) = @ARGV or pod2usage(); |
---|
| 50 | |
---|
| 51 | $labase->get_object('nethost', $from) or die "Cannot find host $from"; |
---|
| 52 | $labase->get_object('nethost', $to) or die "Cannot find host $to"; |
---|
| 53 | |
---|
| 54 | my $tempname; |
---|
| 55 | while (1) { |
---|
| 56 | $tempname = $from . '-' . join('', map { ('a' .. 'z')[rand(26)] } (0 .. 7)); |
---|
| 57 | $labase->get_object('nethost', $tempname) or last; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | $labase->rename_object('nethost', $from, $tempname) or die "Cannot rename $from to a temporary name\n"; |
---|
| 61 | $labase->rename_object('nethost', $to, $from) or die "Cannot rename $to to $from\n"; |
---|
| 62 | $labase->rename_object('nethost', $tempname, $to) or die "Cannot rename $from to a its final name $to\n"; |
---|
| 63 | |
---|
| 64 | $labase->commit; |
---|
| 65 | print "Exchange between $from and $to done\n"; |
---|
| 66 | |
---|
Note: See
TracBrowser
for help on using the repository browser.