#!/usr/bin/perl

use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case);
use Perun::Agent;
use Perun::Common qw(printMessage);

sub help {
	return qq{
	Deletes an host. Host id or host name is required.
	--------------------------------------------------------------
	Available options:
	--hostId   | -i host id
	--hostName | -H host name
	--batch    | -b batch
	--help     | -h prints this help

	};
}

my ($hostId, $hostName, $batch);
GetOptions ("help|h" => sub {
		print help();
		exit 0;
	}, "batch|b"     => \$batch,
	"hostId|i=i"     => \$hostId, "hostName|H=s" => \$hostName) || die help();

# Check options
unless (defined($hostId) or defined($hostName)) { die "ERROR: hostId or hostName is required \n";}

my $agent = Perun::Agent->new();
my $facilitiesAgent = $agent->getFacilitiesAgent;

if ($hostId) {
	$facilitiesAgent->removeHost->( host => $hostId );
	printMessage("Host Id:$hostId successfully deleted", $batch);
} else {
	$facilitiesAgent->removeHostByHostname( hostname => $hostName );
	printMessage("Host Name:$hostName successfully deleted", $batch);
}
