Skip to content

Commit 78900e4

Browse files
author
Marcin Przepiorowski
committed
Merge branch 'issue#96' into develop
2 parents 81e6547 + 9a01940 commit 78900e4

File tree

2 files changed

+151
-9
lines changed

2 files changed

+151
-9
lines changed

bin/dx_ctl_env.pl

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313
#
14-
# Copyright (c) 2014,2016 by Delphix. All rights reserved.
14+
# Copyright (c) 2014,2019 by Delphix. All rights reserved.
1515
#
1616
# Program Name : dx_ctl_env.pl
1717
# Description : Get database and host information
@@ -48,6 +48,8 @@
4848
'name|n=s' => \(my $envname),
4949
'reference|r=s' => \(my $reference),
5050
'action=s' => \(my $action),
51+
'host=s' => \(my $host),
52+
'newhost=s' => \(my $newhost),
5153
'username=s' => \(my $username),
5254
'authtype=s' => \(my $authtype),
5355
'password=s' => \(my $password),
@@ -98,14 +100,26 @@
98100
(lc $action eq 'addrepo') || (lc $action eq 'deleterepo') ||
99101
(lc $action eq 'adddatabase') || (lc $action eq 'deletedatabase') ||
100102
(lc $action eq 'addlistener') || (lc $action eq 'deletelistener') ||
101-
(lc $action eq 'adduser') || (lc $action eq 'deleteuser')
103+
(lc $action eq 'adduser') || (lc $action eq 'deleteuser') ||
104+
(lc $action eq 'updatehost')
102105
))
103106
{
104107
print "Unknown action $action\n";
105108
pod2usage(-verbose => 1, -input=>\*DATA);
106109
exit (1);
107110
}
108111

112+
if (lc $action eq 'updatehost') {
113+
if (!defined($newhost)) {
114+
print "New host has to be set\n";
115+
exit 1;
116+
}
117+
if ((!defined($envname)) && (!defined($host))) {
118+
print "Environment name or an existing host name has to be set for updatehost action\n";
119+
exit 1;
120+
}
121+
}
122+
109123
if (lc $action eq 'addrepo') {
110124
if (!defined($repotype)) {
111125
print "Repository type has to be set\n";
@@ -203,6 +217,7 @@
203217

204218
my @env_list;
205219
my @jobs;
220+
my $hostupdate;
206221

207222
if (defined($reference)) {
208223
push(@env_list, $reference);
@@ -227,7 +242,8 @@
227242

228243
my $env_name = $environments->getName($envitem);
229244

230-
if ((lc $action eq 'enable') || (lc $action eq 'disable') || (lc $action eq 'refresh')) {
245+
if ((lc $action eq 'enable') || (lc $action eq 'disable') || (lc $action eq 'refresh') ||
246+
(lc $action eq 'updatehost') ) {
231247

232248
if ( $action eq 'enable' ) {
233249
if ( $environments->getStatus($envitem) eq 'enabled' ) {
@@ -254,6 +270,14 @@
254270
$jobno = $environments->refresh($envitem);
255271
}
256272

273+
if ( lc $action eq 'updatehost' ) {
274+
print "Checking environment for host update $env_name ";
275+
$jobno = $environments->updatehost($envitem, $host, $newhost);
276+
if (defined($jobno)) {
277+
$hostupdate = 1;
278+
}
279+
}
280+
257281
if (defined ($jobno) ) {
258282
print "Starting job $jobno for environment $env_name.\n";
259283
my $job = new Jobs_obj($engine_obj, $jobno, 'true', $debug);
@@ -393,6 +417,8 @@
393417
}
394418
}
395419

420+
421+
396422
}
397423

398424
if (defined($parallel) && (scalar(@jobs) > 0)) {
@@ -402,6 +428,11 @@
402428
}
403429
}
404430

431+
if (!defined($hostupdate)) {
432+
# no environment found with a IP - need to report an error
433+
$ret = $ret + 1;
434+
}
435+
405436
}
406437

407438
exit $ret;
@@ -413,7 +444,8 @@ =head1 SYNOPSIS
413444
414445
dx_ctl_env [ -engine|d <delphix identifier> | -all ] [ -configfile file ]
415446
[ -name env_name | -reference reference ]
416-
-acton <enable|disable|refresh|adduser|addrepo|adddatabase|addlistener|deleteuser|deleterepo|deletedatabase|deletelistener>
447+
-acton <enable|disable|refresh|adduser|addrepo|adddatabase|addlistener
448+
|deleteuser|deleterepo|deletedatabase|deletelistener|updatehost>
417449
[-dbname dbname]
418450
[-instancename instancename]
419451
[-uniquename db_unique_name]
@@ -425,6 +457,8 @@ =head1 SYNOPSIS
425457
[-password password]
426458
[-repotype oracle|vfiles]
427459
[-repopath ORACLE_HOME]
460+
[-host name/ip of existing host to update]
461+
[-newhost new name/ip of the host]
428462
[-help|? ]
429463
[-debug ]
430464
@@ -457,7 +491,7 @@ =head2 Actions
457491
458492
=over 1
459493
460-
=item B<-action> <enable|disable|refresh|adduser|addrepo|adddatabase|addlistener|deleteuser|deleterepo|deletedatabase|deletelistener>
494+
=item B<-action> <enable|disable|refresh|adduser|addrepo|adddatabase|addlistener|deleteuser|deleterepo|deletedatabase|deletelistener|updatehost>
461495
Run an action specified for environments selected by filter or all environments deployed on Delphix Engine
462496
463497
=back
@@ -517,6 +551,13 @@ =head1 OPTIONS
517551
=item B<-oraclebase path>
518552
Oracle Base path
519553
554+
=item B<-host hostname/IP>
555+
Host name or IP from an environment to be updated.
556+
Not required if environment name is specified
557+
558+
=item B<-newhost hostname/IP>
559+
New Host name or IP of host being updated
560+
520561
=item B<-help>
521562
Print this screen
522563
@@ -608,4 +649,23 @@ =head1 EXAMPLES
608649
Deleting vfiles swingbench from environment LINUXSOURCE
609650
Database swingbench deleted from Unstructured Files
610651
652+
Chaging an IP of the environment
653+
654+
dx_ctl_env -d 53 -name linuxsource -newhost 172.16.200.130 -action updatehost
655+
Checking environment for host update linuxsource Starting job JOB-2850 for environment linuxsource.
656+
0 - 30 - 40 - 80 - 100
657+
Job JOB-2850 finished with state: COMPLETED
658+
659+
Chaging an IP of particular host
660+
661+
dx_ctl_env -d 53 -host 172.16.200.130 -newhost 172.16.180.129 -action updatehost
662+
Checking environment for host update racattack121 Host with IP 172.16.200.130 not found
663+
Checking environment for host update racattack Host with IP 172.16.200.130 not found
664+
Checking environment for host update oracle18tgt Host with IP 172.16.200.130 not found
665+
Checking environment for host update oracle18 Host with IP 172.16.200.130 not found
666+
Checking environment for host update linuxsource Starting job JOB-2852 for environment linuxsource.
667+
0 - 30 - 40 - 80 - 100
668+
Job JOB-2852 finished with state: COMPLETED
669+
Checking environment for host update linuxtarget Host with IP 172.16.200.130 not found
670+
611671
=cut

lib/Environment_obj.pm

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use strict;
3030
use Data::Dumper;
3131
use JSON;
3232
use Toolkit_helpers qw (logger);
33+
use lib '../lib';
34+
use Host_obj;
3335

3436
# constructor
3537
# parameters
@@ -499,12 +501,12 @@ sub getClusterName {
499501
return $ret;
500502
}
501503

502-
# Procedure getClusterNode
504+
# Procedure getClusterNodes
503505
# parameters:
504506
# - reference
505-
# Return environment cluster location for specific environment reference
507+
# Return all nodes from cluster
506508

507-
sub getClusterNode {
509+
sub getClusterNodes {
508510
my $self = shift;
509511
my $reference = shift;
510512

@@ -515,14 +517,32 @@ sub getClusterNode {
515517

516518
if (($environments->{$reference}->{'type'} eq 'OracleCluster') || ($environments->{$reference}->{'type'} eq 'WindowsCluster')) {
517519
my @nodes = grep { defined($environments->{$_}->{cluster}) && ( $environments->{$_}->{cluster} eq $reference ) } sort (keys %{$environments} );
518-
$ret = $nodes[0];
520+
$ret = \@nodes;
519521
} else {
520522
$ret = 'N/A';
521523
}
522524

523525
return $ret;
524526
}
525527

528+
# Procedure getClusterNode
529+
# parameters:
530+
# - reference
531+
# Return first node from cluster
532+
533+
sub getClusterNode {
534+
my $self = shift;
535+
my $reference = shift;
536+
537+
my $nodelist = $self->getClusterNodes($reference);
538+
539+
if ($nodelist eq 'N/A') {
540+
return 'N/A';
541+
} else {
542+
return $nodelist->[0];
543+
}
544+
}
545+
526546
# Procedure getASEUser
527547
# parameters:
528548
# - reference
@@ -1494,4 +1514,66 @@ sub deleteListener
14941514
}
14951515
}
14961516

1517+
1518+
sub updatehost {
1519+
my $self = shift;
1520+
my $envitem = shift;
1521+
my $hostip = shift;
1522+
my $newhost = shift;
1523+
1524+
logger($self->{_debug}, "Entering Environment_obj::updatehost",1);
1525+
my $hosts = new Host_obj($self->{_dlpxObject}, $self->{_debug});
1526+
my $hostobj;
1527+
my $host;
1528+
1529+
if (!defined($hostip)) {
1530+
$host = $self->getHost($envitem);
1531+
if ($host eq 'CLUSTER') {
1532+
print "Please specify which host in a cluster environment you want to change\n";
1533+
return undef;
1534+
}
1535+
$hostobj = $hosts->getHost($host);
1536+
} else {
1537+
$host = $self->getHost($envitem);
1538+
my @nodestocheck;
1539+
if ($host eq 'CLUSTER') {
1540+
my @clusternodes = @{$self->getClusterNodes($envitem)};
1541+
@nodestocheck = map { $self->{_environments}->{$_}->{host} } @clusternodes;
1542+
} else {
1543+
push(@nodestocheck, $host);
1544+
}
1545+
logger($self->{_debug}, "Looking for IP: ". $hostip,2);
1546+
my $foundhost;
1547+
for my $h (@nodestocheck) {
1548+
$hostobj = $hosts->getHost($h);
1549+
my $ip = $hostobj->{"address"};
1550+
logger($self->{_debug}, "Checking IP: ". $ip,2);
1551+
if ($hostip eq $ip) {
1552+
logger($self->{_debug}, "Found IP: ". $ip,2);
1553+
$foundhost = $h;
1554+
last;
1555+
}
1556+
}
1557+
1558+
if (defined($foundhost)) {
1559+
# host will be set to one depend on IP matching
1560+
$host = $foundhost;
1561+
} else {
1562+
print "Host with IP $hostip not found\n";
1563+
return undef;
1564+
}
1565+
1566+
}
1567+
1568+
my %hostupdate = (
1569+
"type" => $hostobj->{"type"},
1570+
"address" => $newhost
1571+
);
1572+
1573+
my $operation = "resources/json/delphix/host/" . $host;
1574+
1575+
return $self->runJobOperation($operation, to_json(\%hostupdate));
1576+
1577+
}
1578+
14971579
1;

0 commit comments

Comments
 (0)