[Stgt-devel] [PATCH 2/7] Add option to delete all the targets

Richard Sharpe realrichardsharpe
Thu Jul 24 00:44:52 CEST 2008


On Tue, Jul 22, 2008 at 4:17 AM, Doron Shoham <dorons at voltaire.com> wrote:
> Add -d flag.
> Delete all the targets and backup the current conf file
>
> Signed-off-by: Doron Shoham <dorons at voltaire.com>

Acked-by: Richard Sharpe <realrichardsharpe at gmail.com>

> ---
>  scripts/tgt-admin |   18 ++++++++++++++++++
>  1 files changed, 18 insertions(+), 0 deletions(-)
>
> diff --git a/scripts/tgt-admin b/scripts/tgt-admin
> index b013d1d..278e93d 100755
> --- a/scripts/tgt-admin
> +++ b/scripts/tgt-admin
> @@ -27,6 +27,7 @@ tgt-admin [OPTION]...
>  This tool configures tgt targets.
>
>   -e, --execute   read $configfile and execute tgtadm commands
> +  -d, --delete    delete all the targets
>   -f, --force     don't exit on tgtadm errors
>   -p, --pretend   only print tgtadm options
>   -v, --verbose   increase verbosity (no effect in "pretend" mode)
> @@ -40,12 +41,14 @@ EOF
>  my $param = $ARGV[0];
>
>  my $execute = 0;
> +my $delete = 0;
>  my $force = 0;
>  my $pretend = 0;
>  my $verbose = 0;
>  my $help = 0;
>  my $result = GetOptions (
>        "e|execute" => \$execute,
> +       "d|delete"  => \$delete,
>        "f|force"   => \$force,
>        "p|pretend" => \$pretend,
>        "v|verbose" => \$verbose,
> @@ -258,6 +261,21 @@ if (($execute == 1) || ($pretend == 1)) {
>        &add_targets;
>
>        &remove_targets;
> +} elsif ($delete == 1) {
> +       &delete;
> +       %conf = ParseConfig(-ConfigFile => "$configfile", -UseApacheInclude => 1, -IncludeGlob => 1,);
> +       &remove_targets;
>  } else {
>        print "No action specified.\n";
>  }
> +
> +# Delete all the targets and backup the current conf file
> +sub delete {
> +       print "deleting targets...\n";
> +       print "a copy of the conf file is on:/etc/tgt/targets.conf.bkp\n";
> +       `mv $configfile /etc/tgt/targets.conf.bkp`;
> +       open FILE, ">", "$configfile" or die $!;
> +       print FILE "<target>\n";
> +       print FILE "</target>\n";
> +       close FILE;
> +}
> --
> 1.5.3.8
>
>
>
> _______________________________________________
> Stgt-devel mailing list
> Stgt-devel at lists.berlios.de
> https://lists.berlios.de/mailman/listinfo/stgt-devel
>



More information about the stgt mailing list