root/trunk/midgard/tools/yamp/replace_host.pl

Revision 6552, 2.8 kB (checked in by philipp, 8 years ago)
  • replace_host.pl: neues script zum ersetzen von hostname, port
    und prefix eines hostrecords
  • insert_login.pl: kleine verbesserungen (sauberes handling von
    CDATA-sections, usage output)
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/perl
2 # - - - - -
3 # $Id$
4 # - - - - -
5 #
6 # replace_host
7 #
8 # Replace a host entry in a repligard XML file
9 #
10 #
11 # Copyright (C) 2001 Linksystem Muenchen GmbH, Philipp Rotmann
12 #                    <ph.rotmann@buero.link-m.de>
13 #
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 # - - - - -
28
29 use XML::DOM;
30
31 if (@ARGV >= 2) {
32         ($guid, $new_name, $new_port, $new_prefix) = @ARGV;
33         $new_port = 0 unless ($new_port);
34         $new_prefix = "" unless ($new_prefix);
35
36 } else {
37         print <<"END_USAGE";
38
39 replace_host guid name port prefix < application.xml
40
41   guid       The Global Unique ID of the person record to change
42   name       The new hostname,
43   port       port and
44   prefix     prefix entries.
45
46 The XML stream is expected from STDIN.
47 END_USAGE
48
49         exit(0);
50 }
51
52 print STDERR "replace_host: Changing host record $guid to http://$new_name",
53   ($new_port ? ":$new_port" : ""), ($new_prefix ? "/$new_prefix" : "/") ,
54   " ...\n";
55
56 $xdp = new XML::DOM::Parser(Style => Tree, KeepCDATA => 1);
57 $xml = $xdp->parse(*STDIN);
58
59 foreach my $pnode ($xml->getElementsByTagName('host')) {
60         next unless ($pnode->getAttribute('id') eq $guid);
61
62         print STDERR "Found host record $guid:\n";
63
64         $nelement = ${$pnode->getElementsByTagName('name')}[0];
65         if ($name = $nelement->getFirstChild) {
66                 print STDERR "Old hostname: ", $name->getData, "\n";
67         } else {
68                 die "$!" unless ($name =
69                   $nelement->appendChild($xml->createTextNode("")));
70         }
71
72         $pelement = ${$pnode->getElementsByTagName('port')}[0];
73         if ($port = $pelement->getFirstChild) {
74                 print STDERR "Old port: ", $port->getData, "\n";
75         } else {
76                 die "$!" unless ($port =
77                 $pelement->appendChild($xml->createTextNode("")));
78         }
79
80         $pxelement = ${$pnode->getElementsByTagName('prefix')}[0];
81         if ($prefix = $pxelement->getFirstChild) {
82                 print STDERR "Old prefix: ", $prefix->getData, "\n";
83         } else {
84                 die "$!" unless ($prefix =
85                 $pxelement->appendChild($xml->createCDATASection("")));
86         }
87
88         print STDERR "Changing hostname, port and prefix ... ";
89         $name->setData($new_name); $port->setData($new_port);
90         $prefix->setData($new_prefix);
91         print STDERR "done.\n";
92 }
93
94 $xml->printToFileHandle(\*STDOUT);
95 $xml->dispose;
Note: See TracBrowser for help on using the browser.