our
$VERSION
=
'1.15.0.2'
;
sub
execute {
my
(
$class
,
$name
,
%opt
) =
@_
;
my
$opts
= \
%opt
;
$opts
->{name} =
$name
;
unless
(
$opts
) {
die
(
"You have to define the destroy options!"
);
}
Rex::Logger::debug(
"destroying container $opts->{name}"
);
my
$options
= _format_opts(
$opts
);
my
$destroy_command
=
"lxc-destroy $options"
;
i_run
$destroy_command
,
fail_ok
=> 1;
if
( $? != 0 ) {
die
(
"Error destroying container $opts->{name}"
);
}
return
$opts
->{name};
}
sub
_format_opts {
my
(
$opts
) =
@_
;
if
( !
exists
$opts
->{name} ) {
die
(
"You have to give a name."
);
}
my
$str
=
"-n $opts->{name}"
;
if
(
exists
$opts
->{snapshots} ) {
$str
.=
" -s"
;
}
if
(
exists
$opts
->{force} ) {
$str
.=
" -f"
;
}
return
$str
;
}
1;