Skip to content

Commit

Permalink
Merge pull request #94 from hadfl/force
Browse files Browse the repository at this point in the history
add option for non-interactive uninstall/delete
  • Loading branch information
citrus-it authored Nov 19, 2021
2 parents cc3b4d1 + a3a068c commit 7574f9a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 34 deletions.
28 changes: 20 additions & 8 deletions bin/zadm
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ sub main {
/^uninstall$/ && do {
my $zName = pop @ARGV or pod2usage(1);

my $zone = $zones->zone($zName);
my $opts = {};
{
local $SIG{__WARN__} = sub { };
GetOptions($opts, qw(force|f)) or pod2usage(1);
}

my $zone = $zones->zone($zName, opts => $opts);

die "ERROR: zone '$zName' is 'running'. Shut it down first.\n"
if $zone->is('running');
Expand All @@ -178,7 +184,13 @@ sub main {
/^delete$/ && do {
my $zName = pop @ARGV or pod2usage(1);

my $zone = $zones->zone($zName);
my $opts = {};
{
local $SIG{__WARN__} = sub { };
GetOptions($opts, qw(force|f)) or pod2usage(1);
}

my $zone = $zones->zone($zName, opts => $opts);

$zone->remove;

Expand Down Expand Up @@ -403,11 +415,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:
create -b <brand> [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down Expand Up @@ -454,7 +466,7 @@ B<zadm doc -b E<lt>brandE<gt>>.
=head2 B<delete>
deletes zone B<zone_name>.
deletes zone B<zone_name>. You can use the B<-f> flag to force the action.
=head2 B<edit>
Expand All @@ -474,7 +486,7 @@ be provided in order to first uninstall the zone.
=head2 B<uninstall>
uninstalls a zone.
uninstalls a zone. You can use the B<-f> flag to force the action.
=head2 B<show>
Expand All @@ -489,8 +501,8 @@ Available options are:
-F <format> Specify an alternative output format.
The value of format can be json, yaml or toml.
-H Omit the headers from the listing.
-b|--brand <brand> List status of zones of brand B<brand>.
-s|--state <state> List status of zones in state B<state>.
-b|--brand <brand> List status of zones with brand <brand>.
-s|--state <state> List status of zones in state <state>.
=head2 B<memstat>
Expand Down
28 changes: 14 additions & 14 deletions doc/zadm.pod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:

create -b <brand> [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down Expand Up @@ -44,11 +44,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:

create -b <brand> [-i <image_uuid|image_path_or_uri>] [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install [-i <image_uuid|image_path_or_uri>] [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down Expand Up @@ -81,11 +81,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:

create -b <brand> -i <image_uuid|image_path_or_uri> [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install -i <image_uuid|image_path_or_uri> [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down Expand Up @@ -115,11 +115,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:

create -b <brand> [-i <image_uuid|image_path_or_uri>] [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install [-i <image_uuid|image_path_or_uri>] [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down Expand Up @@ -151,11 +151,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:

create -b <brand> -i <image_uuid|image_path_or_uri> [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install -i <image_uuid|image_path_or_uri> [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down Expand Up @@ -202,7 +202,7 @@ B<zadm doc -b E<lt>brandE<gt>>.

=head2 B<delete>

deletes zone B<zone_name>.
deletes zone B<zone_name>. You can use the B<-f> flag to force the action.

=head2 B<edit>

Expand All @@ -222,7 +222,7 @@ be provided in order to first uninstall the zone.

=head2 B<uninstall>

uninstalls a zone.
uninstalls a zone. You can use the B<-f> flag to force the action.

=head2 B<show>

Expand All @@ -237,8 +237,8 @@ Available options are:
-F <format> Specify an alternative output format.
The value of format can be json, yaml or toml.
-H Omit the headers from the listing.
-b|--brand <brand> List status of zones of brand B<brand>.
-s|--state <state> List status of zones in state B<state>.
-b|--brand <brand> List status of zones with brand <brand>.
-s|--state <state> List status of zones in state <state>.

=head2 B<memstat>

Expand Down
4 changes: 2 additions & 2 deletions lib/Zadm/Zone/Bhyve.pm
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:
create -b <brand> [-i <image_uuid|image_path_or_uri>] [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install [-i <image_uuid|image_path_or_uri>] [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down
4 changes: 2 additions & 2 deletions lib/Zadm/Zone/Illumos.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:
create -b <brand> -i <image_uuid|image_path_or_uri> [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install -i <image_uuid|image_path_or_uri> [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down
4 changes: 2 additions & 2 deletions lib/Zadm/Zone/KVM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:
create -b <brand> [-i <image_uuid|image_path_or_uri>] [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install [-i <image_uuid|image_path_or_uri>] [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down
4 changes: 2 additions & 2 deletions lib/Zadm/Zone/LX.pm
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:
create -b <brand> -i <image_uuid|image_path_or_uri> [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install -i <image_uuid|image_path_or_uri> [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down
10 changes: 6 additions & 4 deletions lib/Zadm/Zone/base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,9 @@ sub create($self, $props) {
}

sub delete($self) {
$self->utils->exec('zonecfg', [ '-z', $self->name, 'delete' ]);
$self->utils->exec('zonecfg', [
'-z', $self->name, 'delete', $self->opts->{force} ? qw(-F) : ()
]);
}

sub install($self, @args) {
Expand All @@ -614,7 +616,7 @@ sub uninstall($self) {
$self->log->warn('Cannot uninstall a zone inside an alternate root.');
return 1;
};
$self->$zoneCmd('uninstall');
$self->$zoneCmd('uninstall', $self->opts->{force} ? [ qw(-F) ] : []);
}

sub remove($self) {
Expand Down Expand Up @@ -860,11 +862,11 @@ B<zadm> I<command> [I<options...>]
where 'command' is one of the following:
create -b <brand> [-t <template_path>] <zone_name>
delete <zone_name>
delete [-f] <zone_name>
edit <zone_name>
set <zone_name> <property=value>
install [-f] <zone_name>
uninstall <zone_name>
uninstall [-f] <zone_name>
show [zone_name [property[,property]...]]
list [-H] [-F <format>] [-b <brand>] [-s <state>] [zone_name]
memstat
Expand Down

0 comments on commit 7574f9a

Please sign in to comment.