Skip to content

Commit 5270616

Browse files
author
Marcin Przepiorowski
committed
add / delete JS owner added to dx_ctl_js_container - issue #49
1 parent ea04cad commit 5270616

File tree

2 files changed

+241
-83
lines changed

2 files changed

+241
-83
lines changed

bin/dx_ctl_js_container.pl

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@
8383

8484

8585
if (!defined($action) || ( ! ( (lc $action eq 'reset' ) || (lc $action eq 'refresh' ) || (lc $action eq 'restore' )
86-
|| (lc $action eq 'create' ) || (lc $action eq 'delete' ) ) ) ) {
87-
print "Action parameter not specified or has a wrong value - $action \n";
86+
|| (lc $action eq 'create' ) || (lc $action eq 'delete' ) || (lc $action eq 'enable' ) || (lc $action eq 'disable' )
87+
|| (lc $action eq 'addowner' ) || (lc $action eq 'deleteowner' ) ) ) ) {
88+
print "Action parameter not specified or has a wrong value\n";
8889
pod2usage(-verbose => 1, -input=>\*DATA);
8990
exit (1);
9091
}
@@ -124,8 +125,11 @@
124125
my $jobno;
125126
my $jscontainers = new JS_container_obj ( $engine_obj, $template_ref, $debug);
126127

128+
129+
# actions for existing container
127130
if ((lc $action eq 'reset' ) || (lc $action eq 'refresh' ) || (lc $action eq 'restore' )
128-
|| (lc $action eq 'delete' )) {
131+
|| (lc $action eq 'delete' ) || (lc $action eq 'enable' ) || (lc $action eq 'disable' )
132+
|| (lc $action eq 'addowner' ) || (lc $action eq 'deleteowner' ) ) {
129133
my $jscontainer_ref = $jscontainers->getJSContainerByName($container_name);
130134
if (! defined($jscontainer_ref)) {
131135
print "Can't find container name $container_name\n";
@@ -158,10 +162,58 @@
158162
exit (1);
159163
}
160164
$jobno = $jscontainers->deleteContainer($jscontainer_ref, $dropvdb);
165+
} elsif (lc $action eq 'enable') {
166+
$jobno = $jscontainers->enableContainer($jscontainer_ref);
167+
} elsif (lc $action eq 'disable') {
168+
$jobno = $jscontainers->disableContainer($jscontainer_ref);
169+
} elsif (lc $action eq 'addowner') {
170+
if (!defined($container_owners)) {
171+
print "Container_owner need to be defined\n";
172+
$ret = $ret + 1;
173+
next;
174+
}
175+
my $users = new Users ( $engine_obj, $debug );
176+
my $userobj;
177+
for my $cowner (@{$container_owners}) {
178+
my $userobj = $users->getUserByName($cowner);
179+
if (defined($userobj)) {
180+
if (($userobj->isJS()) || ($userobj->isAdmin())) {
181+
$jobno = $jscontainers->addOwner($jscontainer_ref, $userobj->getReference());
182+
$ret = $ret + Toolkit_helpers::waitForAction($engine_obj, $jobno, "Owner $cowner added", "There were problems with adding owner");
183+
undef $jobno;
184+
}
185+
} else {
186+
print "Delphix User $cowner not found\n";
187+
$ret = $ret + 1;
188+
}
189+
}
190+
191+
} elsif (lc $action eq 'deleteowner') {
192+
if (!defined($container_owners)) {
193+
print "Container_owner need to be defined\n";
194+
$ret = $ret + 1;
195+
next;
196+
}
197+
my $users = new Users ( $engine_obj, $debug );
198+
my $userobj;
199+
for my $cowner (@{$container_owners}) {
200+
my $userobj = $users->getUserByName($cowner);
201+
if (defined($userobj)) {
202+
if (($userobj->isJS()) || ($userobj->isAdmin())) {
203+
$jobno = $jscontainers->removeOwner($jscontainer_ref, $userobj->getReference());
204+
$ret = $ret + Toolkit_helpers::waitForAction($engine_obj, $jobno, "Owner $cowner removed", "There were problems with removing owner");
205+
undef $jobno;
206+
}
207+
} else {
208+
print "Delphix User $cowner not found\n";
209+
$ret = $ret + 1;
210+
}
211+
}
212+
161213
}
162214
}
163215

164-
216+
# create a new container only
165217
if (lc $action eq 'create') {
166218
if (!defined($container_def)) {
167219
print "Container definition parameter -container_def is required to create container \n";
@@ -263,19 +315,21 @@
263315

264316
}
265317

318+
if ( ! ( (lc $action eq 'addowner' ) || (lc $action eq 'deleteowner' ) ) ) {
266319

320+
if (defined ($jobno) ) {
321+
print "Starting job $jobno for container $container_name.\n";
322+
my $job = new Jobs_obj($engine_obj, $jobno, 'true', $debug);
267323

268-
if (defined ($jobno) ) {
269-
print "Starting job $jobno for container $container_name.\n";
270-
my $job = new Jobs_obj($engine_obj, $jobno, 'true', $debug);
271-
272-
my $jobstat = $job->waitForJob();
273-
if ($jobstat ne 'COMPLETED') {
324+
my $jobstat = $job->waitForJob();
325+
if ($jobstat ne 'COMPLETED') {
326+
$ret = $ret + 1;
327+
}
328+
} else {
329+
print "Job for container is not created. \n";
274330
$ret = $ret + 1;
275331
}
276-
} else {
277-
print "Job for container is not created. \n";
278-
$ret = $ret + 1;
332+
279333
}
280334

281335
}
@@ -290,7 +344,7 @@
290344
=head1 SYNOPSIS
291345
292346
dx_ctl_js_container [ -engine|d <delphix identifier> | -all ] [ -configfile file ]
293-
-action reset|refresh|restore|create
347+
-action reset|refresh|restore|create|addowner|deleteowner
294348
-container_name container_name
295349
[-container_def GroupName,VDBName]
296350
[-container_owner username]
@@ -341,6 +395,10 @@ =head1 ARGUMENTS
341395
If ones want to restore container from template's point in time - template_name
342396
and fromtemplate flag is required.
343397
398+
=item B<-addowner> - Add owner to container
399+
400+
=item B<-deleteowner> - Remove owner from container
401+
344402
=back
345403
346404
=item B<-container_name container_name>
@@ -429,4 +487,10 @@ =head1 Examples
429487
0 - 100
430488
Job JOB-2434 finished with state: COMPLETED
431489
490+
Adding owner to container
491+
492+
dx_ctl_js_container -d Landshark5 -action addowner -container_name test1 -container_owner js
493+
Waiting for all actions to complete. Parent action is ACTION-16427
494+
Owner js added
495+
432496
=cut

0 commit comments

Comments
 (0)