|
83 | 83 |
|
84 | 84 |
|
85 | 85 | 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"; |
88 | 89 | pod2usage(-verbose => 1, -input=>\*DATA); |
89 | 90 | exit (1); |
90 | 91 | } |
|
124 | 125 | my $jobno; |
125 | 126 | my $jscontainers = new JS_container_obj ( $engine_obj, $template_ref, $debug); |
126 | 127 |
|
| 128 | + |
| 129 | + # actions for existing container |
127 | 130 | 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' ) ) { |
129 | 133 | my $jscontainer_ref = $jscontainers->getJSContainerByName($container_name); |
130 | 134 | if (! defined($jscontainer_ref)) { |
131 | 135 | print "Can't find container name $container_name\n"; |
|
158 | 162 | exit (1); |
159 | 163 | } |
160 | 164 | $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 | + |
161 | 213 | } |
162 | 214 | } |
163 | 215 |
|
164 | | - |
| 216 | + # create a new container only |
165 | 217 | if (lc $action eq 'create') { |
166 | 218 | if (!defined($container_def)) { |
167 | 219 | print "Container definition parameter -container_def is required to create container \n"; |
|
263 | 315 |
|
264 | 316 | } |
265 | 317 |
|
| 318 | + if ( ! ( (lc $action eq 'addowner' ) || (lc $action eq 'deleteowner' ) ) ) { |
266 | 319 |
|
| 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); |
267 | 323 |
|
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"; |
274 | 330 | $ret = $ret + 1; |
275 | 331 | } |
276 | | - } else { |
277 | | - print "Job for container is not created. \n"; |
278 | | - $ret = $ret + 1; |
| 332 | + |
279 | 333 | } |
280 | 334 |
|
281 | 335 | } |
|
290 | 344 | =head1 SYNOPSIS |
291 | 345 |
|
292 | 346 | 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 |
294 | 348 | -container_name container_name |
295 | 349 | [-container_def GroupName,VDBName] |
296 | 350 | [-container_owner username] |
@@ -341,6 +395,10 @@ =head1 ARGUMENTS |
341 | 395 | If ones want to restore container from template's point in time - template_name |
342 | 396 | and fromtemplate flag is required. |
343 | 397 |
|
| 398 | +=item B<-addowner> - Add owner to container |
| 399 | +
|
| 400 | +=item B<-deleteowner> - Remove owner from container |
| 401 | +
|
344 | 402 | =back |
345 | 403 |
|
346 | 404 | =item B<-container_name container_name> |
@@ -429,4 +487,10 @@ =head1 Examples |
429 | 487 | 0 - 100 |
430 | 488 | Job JOB-2434 finished with state: COMPLETED |
431 | 489 |
|
| 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 | +
|
432 | 496 | =cut |
0 commit comments