| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
use strict; |
|---|
| 6 |
use warnings; |
|---|
| 7 |
|
|---|
| 8 |
use Data::Dumper; |
|---|
| 9 |
use HoneyClient::Util::Config qw(getVar); |
|---|
| 10 |
use HoneyClient::Manager::Database; |
|---|
| 11 |
use Sys::Hostname::Long; |
|---|
| 12 |
use Log::Log4perl qw(:easy); |
|---|
| 13 |
|
|---|
| 14 |
our $LOG = get_logger(); |
|---|
| 15 |
|
|---|
| 16 |
my $args = { |
|---|
| 17 |
hostname => Sys::Hostname::Long::hostname_long, |
|---|
| 18 |
}; |
|---|
| 19 |
|
|---|
| 20 |
my $datastore_path = getVar(name => "datastore_path", namespace => "HoneyClient::Manager::VM"); |
|---|
| 21 |
my $snapshot_path = getVar(name => "snapshot_path", namespace => "HoneyClient::Manager::VM"); |
|---|
| 22 |
|
|---|
| 23 |
my $clients = HoneyClient::Manager::Database::get_broken_clients($args); |
|---|
| 24 |
|
|---|
| 25 |
while (my ($cid, $id) = each %{$clients}) { |
|---|
| 26 |
|
|---|
| 27 |
$LOG->info("Deleting VM (" . $cid . ")"); |
|---|
| 28 |
|
|---|
| 29 |
$LOG->info("Executing: vmware-cmd " . $datastore_path . "/" . $cid . "/*.vmx stop hard"); |
|---|
| 30 |
system("vmware-cmd " . $datastore_path . "/" . $cid . "/*.vmx stop hard"); |
|---|
| 31 |
|
|---|
| 32 |
$LOG->info("Executing: vmware-cmd " . $datastore_path . "/" . $cid . "/*.cfg stop hard"); |
|---|
| 33 |
system("vmware-cmd " . $datastore_path . "/" . $cid . "/*.cfg stop hard"); |
|---|
| 34 |
|
|---|
| 35 |
$LOG->info("Executing: vmware-cmd -s unregister " . $datastore_path . "/" . $cid . "/*.vmx"); |
|---|
| 36 |
system("vmware-cmd -s unregister " . $datastore_path . "/" . $cid . "/*.vmx"); |
|---|
| 37 |
|
|---|
| 38 |
$LOG->info("Executing: vmware-cmd -s unregister " . $datastore_path . "/" . $cid . "/*.cfg"); |
|---|
| 39 |
system("vmware-cmd -s unregister " . $datastore_path . "/" . $cid . "/*.cfg"); |
|---|
| 40 |
|
|---|
| 41 |
$LOG->info("Executing: rm -rf " . $datastore_path . "/" . $cid); |
|---|
| 42 |
system("rm -rf " . $datastore_path . "/" . $cid); |
|---|
| 43 |
|
|---|
| 44 |
$LOG->info("Executing: rm -f " . $snapshot_path . "/" . $cid . "*"); |
|---|
| 45 |
system("rm -f " . $snapshot_path . "/" . $cid . "*"); |
|---|
| 46 |
|
|---|
| 47 |
HoneyClient::Manager::Database::set_client_deleted($id); |
|---|
| 48 |
|
|---|
| 49 |
print "\n"; |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|