#!/usr/bin/perl

use strict;
use warnings;
use lib '/usr/share/pve-ha-simulator';
use Getopt::Long;
use JSON;

use PVE::Tools;
use PVE::HA::Sim::TestHardware;
use PVE::HA::Sim::RTHardware;

my $opt_batch;

sub show_usage {
    print "usage: $0 <testdir> [--batch]\n";
    exit(-1);
};

if (!GetOptions ("batch"   => \$opt_batch)) {
    show_usage();
}

my $testdir = shift || show_usage();

my $hardware; 

if ($opt_batch) {
    $hardware = PVE::HA::Sim::TestHardware->new($testdir);
} else {
    $hardware = PVE::HA::Sim::RTHardware->new($testdir);
}

$hardware->log('info', "starting simulation");

eval { $hardware->run(); };
if (my $err = $@) {
    $hardware->log('err', "exit simulation - $err ");
} else {
    $hardware->log('info', "exit simulation - done");
}

exit(0);



