source: trunk/LATMOS-Accounts/bin/la-sql-exchange-hostname @ 1907

Last change on this file since 1907 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
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use 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
17Example : la-sql-exchange-hostname foo bar
18
19=cut
20
21GetOptions(
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
33Use this configuration directory instead of the default one.
34
35=item -b|--base basename
36
37Query this specific base instead of the default one.
38
39=back
40
41=cut
42
43my $LA = LATMOS::Accounts->new($config, noacl => 1);
44my $labase = $LA->base($base);
45$labase && $labase->load or die "Cannot load base";
46
47$labase->unexported(1);
48
49my ($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
54my $tempname;
55while (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;
65print "Exchange between $from and $to done\n";
66
Note: See TracBrowser for help on using the repository browser.