diff --git a/config.pl b/config.pl index 6499fff..70dab1b 100644 --- a/config.pl +++ b/config.pl @@ -49,6 +49,8 @@ clone_jobs => { num_cpus => 2, mac => '00:50:56:BF:01:01', poweron => 1, + + # Be very careful with this option! It deletes destination machine if it exists. overwrite => 1 } } diff --git a/debian/control b/debian/control index 4901a44..da2474b 100644 --- a/debian/control +++ b/debian/control @@ -9,8 +9,7 @@ Vcs-Git: https://git.verdnatura.es/vn-vmware Package: vn-vmware Architecture: all -Depends: perl, tar -Suggests: pigz +Depends: perl, pigz Section: misc Priority: optional Description: Maintenance scripts for VMWare diff --git a/deploy.sh b/deploy.sh index cbe751a..49aed5e 100755 --- a/deploy.sh +++ b/deploy.sh @@ -2,10 +2,10 @@ pkg="vn-vmware_1.0.0" debPkg="${pkg}_all.deb" -host="root@bacula" +host="root@verdnatura.es" debuild -us -uc -b -#scp ../$debPkg $host:/root +scp ../$debPkg $host:/root #ssh $host dpkg -i /root/$debPkg #ssh $host rm /root/$debPkg debian/rules clean diff --git a/vn-vmware.pl b/vn-vmware.pl index 51b75a8..1d35c1c 100755 --- a/vn-vmware.pl +++ b/vn-vmware.pl @@ -2,6 +2,8 @@ use strict; use warnings; +use experimental qw(switch say); + use VMware::VIRuntime; use VMware::VICredStore; use VMware::VILib; @@ -15,7 +17,6 @@ use Net::SMTP; use Term::ANSIColor; use Net::OpenSSH; use XML::LibXML; -use feature qw(switch say); use constant false => 0; use constant true => 1; @@ -32,7 +33,7 @@ my %opts = ( }, 'vm-name' => { type => "=s", - variable => "vm_name", + variable => "VM_NAME", help => "Name of the virtual machine" }, 'rotation-days' => { @@ -100,7 +101,7 @@ my %opts = ( }, 'overwrite' => { type => "", - help => "Whether to remove the virtual machine if there is one with the same name", + help => "Whether to remove the destination machine if it exists; Be very careful with this option!", default => 0 }, 'poweron' => { @@ -127,7 +128,7 @@ my %opts = ( Opts::add_options(%opts); Opts::parse(); -Opts::validate(); +#Opts::validate(); my $operation = Opts::get_option('operation'); my $job = Opts::get_option('job'); @@ -438,7 +439,7 @@ sub backup_machine() { my $tar_status = system("tar -I pigz -cf $tar_file -C $local_tmp_dir ."); unless ($tar_status == 0) { - die "An error occurred when trying to compress the file." + die "An error occurred when trying to compress the file."; } }; my $err = $@; @@ -535,7 +536,7 @@ sub clone_machine { sleep(20); $original_vm->Destroy(); } else { - die "Machine with same name exists" + die "Machine with same name exists."; } } @@ -549,7 +550,7 @@ sub clone_machine { for my $nic (@nics) { if ($nic->macAddress eq $mac) { my $machineName = $vmRes->name; - die "Machine '$machineName' with same MAC exists" + die "Machine '$machineName' with same MAC exists."; } } } @@ -858,11 +859,11 @@ sub set_power_state { given ($state) { when ('poweredOff') { $vm_power->ShutdownGuest(); - log_message "Turning off ".$vm_power->name; + log_message "Turning off ".$vm_power->name."."; } when ('poweredOn') { $vm_power->PowerOnVM(); - log_message "Turning on ".$vm_power->name; + log_message "Turning on ".$vm_power->name."."; } } sleep(50); @@ -883,7 +884,7 @@ sub check_datastore { foreach my $moref ( @{ $host_view->datastore } ) { my $ds_view = Vim::get_view (mo_ref => $moref); if ($ds_view->name eq $dst_datastore) { - return; + return; } }