Bugs fixed
This commit is contained in:
parent
94a4199ffb
commit
d4a8e6eb07
|
@ -1,4 +1,4 @@
|
||||||
vn-vmware (1.0.4) stable; urgency=low
|
vn-vmware (1.0.5) stable; urgency=low
|
||||||
|
|
||||||
* Initial Release.
|
* Initial Release.
|
||||||
|
|
||||||
|
|
94
vn-vmware.pl
94
vn-vmware.pl
|
@ -197,7 +197,7 @@ sub log_error {
|
||||||
my ($error) = @_;
|
my ($error) = @_;
|
||||||
|
|
||||||
if ($error->isa('SOAP::Fault')) {
|
if ($error->isa('SOAP::Fault')) {
|
||||||
$error = $error->faultcode.": ".$error->faultString;
|
$error = $error->faultcode.": ".$error->faultString."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
print color('red');
|
print color('red');
|
||||||
|
@ -250,6 +250,9 @@ sub main {
|
||||||
log_message "Connected to $vcenter_host.";
|
log_message "Connected to $vcenter_host.";
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
|
unless ($operation) {
|
||||||
|
die "Operation not defined.";
|
||||||
|
}
|
||||||
given ($operation) {
|
given ($operation) {
|
||||||
when ('backup-job') {
|
when ('backup-job') {
|
||||||
backup_job();
|
backup_job();
|
||||||
|
@ -385,7 +388,7 @@ sub backup_machine() {
|
||||||
my $service_content = Vim::get_service_content();
|
my $service_content = Vim::get_service_content();
|
||||||
my $file_manager = Vim::get_view(mo_ref => $service_content->fileManager);
|
my $file_manager = Vim::get_view(mo_ref => $service_content->fileManager);
|
||||||
my $dc = Vim::find_entity_view(
|
my $dc = Vim::find_entity_view(
|
||||||
view_type => "Datacenter",
|
view_type => 'Datacenter',
|
||||||
filter => {'name' => $config{datacenter}}
|
filter => {'name' => $config{datacenter}}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -410,7 +413,10 @@ sub backup_machine() {
|
||||||
my $vdm = Vim::get_view(mo_ref => $service_content->virtualDiskManager);
|
my $vdm = Vim::get_view(mo_ref => $service_content->virtualDiskManager);
|
||||||
my $devices = $vm->config->hardware->device;
|
my $devices = $vm->config->hardware->device;
|
||||||
|
|
||||||
|
log_message "Removing snapshots.";
|
||||||
$vm->RemoveAllSnapshots();
|
$vm->RemoveAllSnapshots();
|
||||||
|
|
||||||
|
log_message "Creating backup snapshot.";
|
||||||
$vm->CreateSnapshot(
|
$vm->CreateSnapshot(
|
||||||
name => "backup",
|
name => "backup",
|
||||||
description => "Scheduled backup",
|
description => "Scheduled backup",
|
||||||
|
@ -433,6 +439,7 @@ sub backup_machine() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_message "Removing snapshots.";
|
||||||
$vm->RemoveAllSnapshots();
|
$vm->RemoveAllSnapshots();
|
||||||
|
|
||||||
log_message "Compressing to TAR file: $tar_file";
|
log_message "Compressing to TAR file: $tar_file";
|
||||||
|
@ -446,6 +453,8 @@ sub backup_machine() {
|
||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
log_message "An error ocurred during '$vm_name' backup, aborting.";
|
log_message "An error ocurred during '$vm_name' backup, aborting.";
|
||||||
|
|
||||||
|
log_message "Removing snapshots.";
|
||||||
$vm->RemoveAllSnapshots();
|
$vm->RemoveAllSnapshots();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,6 +531,7 @@ sub rotate_backup() {
|
||||||
|
|
||||||
sub clone_machine {
|
sub clone_machine {
|
||||||
log_message "Cloning '$vm_name' to '$dst_name'.";
|
log_message "Cloning '$vm_name' to '$dst_name'.";
|
||||||
|
log_message "Doing some previous checkings.";
|
||||||
|
|
||||||
check_datastore();
|
check_datastore();
|
||||||
|
|
||||||
|
@ -532,8 +542,9 @@ sub clone_machine {
|
||||||
|
|
||||||
if ($original_vm) {
|
if ($original_vm) {
|
||||||
if ($overwrite) {
|
if ($overwrite) {
|
||||||
set_power_state($original_vm, "poweredOff");
|
set_power_state($original_vm, 'poweredOff');
|
||||||
sleep(20);
|
|
||||||
|
log_message "Deleting machine '$dst_name'.";
|
||||||
$original_vm->Destroy();
|
$original_vm->Destroy();
|
||||||
} else {
|
} else {
|
||||||
die "Machine with same name exists.";
|
die "Machine with same name exists.";
|
||||||
|
@ -556,14 +567,48 @@ sub clone_machine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_message "Defining clone specifications.";
|
||||||
|
|
||||||
|
# Hostname
|
||||||
|
|
||||||
|
my $extra_conf = OptionValue->new(
|
||||||
|
key => 'guestinfo.hostname',
|
||||||
|
value => $dst_name
|
||||||
|
);
|
||||||
|
|
||||||
|
# Operating system
|
||||||
|
|
||||||
|
my $guest_id = $vm->guest->guestId;
|
||||||
|
$guest_id = $guest_id ? $guest_id : undef;
|
||||||
|
|
||||||
|
# CPU & memory
|
||||||
|
|
||||||
|
my $cpu;
|
||||||
|
my $mem_res;
|
||||||
|
my $sl = SharesLevel->new('normal');
|
||||||
|
my $sh = SharesInfo->new(level => $sl, shares => 1);
|
||||||
|
|
||||||
|
if (defined($cpu_reservation)) {
|
||||||
|
$cpu = ResourceAllocationInfo->new(
|
||||||
|
reservation => $cpu_reservation,
|
||||||
|
limit => -1,
|
||||||
|
shares => $sh
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (defined($mem_reservation)) {
|
||||||
|
$mem_res = ResourceAllocationInfo->new(
|
||||||
|
reservation => $mem_reservation,
|
||||||
|
limit => -1,
|
||||||
|
shares => $sh
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Datastore
|
||||||
|
|
||||||
my $relocate_spec;
|
my $relocate_spec;
|
||||||
my $mac_type = 'Generated';
|
|
||||||
my $host_view = $vm->summary->runtime->host;
|
my $host_view = $vm->summary->runtime->host;
|
||||||
|
|
||||||
if (defined($mac)) {
|
if (defined($dst_host)) {
|
||||||
$mac_type = 'Manual';
|
|
||||||
}
|
|
||||||
if (defined ($dst_host)) {
|
|
||||||
$host_view = Vim::find_entity_view(
|
$host_view = Vim::find_entity_view(
|
||||||
view_type => 'HostSystem',
|
view_type => 'HostSystem',
|
||||||
filter => {'name' => $dst_host}
|
filter => {'name' => $dst_host}
|
||||||
|
@ -589,6 +634,14 @@ sub clone_machine {
|
||||||
host => $host_view
|
host => $host_view
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Network card
|
||||||
|
|
||||||
|
my $mac_type = 'Generated';
|
||||||
|
|
||||||
|
if (defined($mac)) {
|
||||||
|
$mac_type = 'Manual';
|
||||||
|
}
|
||||||
|
|
||||||
my $vnic_device;
|
my $vnic_device;
|
||||||
my $devices = $vm->config->hardware->device;
|
my $devices = $vm->config->hardware->device;
|
||||||
|
@ -603,7 +656,6 @@ sub clone_machine {
|
||||||
my $curr_mac = $vnic_device->macAddress;
|
my $curr_mac = $vnic_device->macAddress;
|
||||||
my $network = Vim::get_view(mo_ref => $vnic_device->backing->network, properties => ['name']);
|
my $network = Vim::get_view(mo_ref => $vnic_device->backing->network, properties => ['name']);
|
||||||
|
|
||||||
my $config_spec_operation = VirtualDeviceConfigSpecOperation->new('edit');
|
|
||||||
my $backing_info = VirtualEthernetCardNetworkBackingInfo->new(deviceName => $network->{'name'});
|
my $backing_info = VirtualEthernetCardNetworkBackingInfo->new(deviceName => $network->{'name'});
|
||||||
|
|
||||||
my $nic_type = ref($vnic_device);
|
my $nic_type = ref($vnic_device);
|
||||||
|
@ -619,6 +671,7 @@ sub clone_machine {
|
||||||
die "Unable to retrieve NIC type.";
|
die "Unable to retrieve NIC type.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $config_spec_operation = VirtualDeviceConfigSpecOperation->new('edit');
|
||||||
my $new_network_device = $nic_type->new(
|
my $new_network_device = $nic_type->new(
|
||||||
key => $vnic_device->key,
|
key => $vnic_device->key,
|
||||||
unitNumber => $vnic_device->unitNumber,
|
unitNumber => $vnic_device->unitNumber,
|
||||||
|
@ -627,24 +680,12 @@ sub clone_machine {
|
||||||
addressType => $mac_type,
|
addressType => $mac_type,
|
||||||
macAddress => $mac
|
macAddress => $mac
|
||||||
);
|
);
|
||||||
|
my $vm_dev_spec = VirtualDeviceConfigSpec->new(
|
||||||
my $sl = SharesLevel->new('normal');
|
operation => $config_spec_operation,
|
||||||
my $sh = SharesInfo->new(level => $sl, shares => 1);
|
device => $new_network_device
|
||||||
|
|
||||||
my $mem_res = ResourceAllocationInfo->new(
|
|
||||||
reservation => $mem_reservation,
|
|
||||||
limit => -1,
|
|
||||||
shares => $sh
|
|
||||||
);
|
|
||||||
my $cpu = ResourceAllocationInfo->new(
|
|
||||||
reservation => $cpu_reservation,
|
|
||||||
limit => -1,
|
|
||||||
shares => $sh
|
|
||||||
);
|
);
|
||||||
|
|
||||||
my $guest_id = ($vm->guest->guestId =~ m/^other/) ? "debian6_64Guest" : $vm->guest->guestId;
|
# Gathering specifications and cloning
|
||||||
my $vm_dev_spec = VirtualDeviceConfigSpec->new(device => $new_network_device, operation => $config_spec_operation);
|
|
||||||
my $extra_conf = OptionValue->new(key => "guestinfo.hostname", value => $dst_name);
|
|
||||||
|
|
||||||
my $change_spec = VirtualMachineConfigSpec->new(
|
my $change_spec = VirtualMachineConfigSpec->new(
|
||||||
deviceChange => [$vm_dev_spec],
|
deviceChange => [$vm_dev_spec],
|
||||||
|
@ -663,6 +704,7 @@ sub clone_machine {
|
||||||
config => $change_spec
|
config => $change_spec
|
||||||
);
|
);
|
||||||
|
|
||||||
|
log_message "Cloning machine.";
|
||||||
$vm->CloneVM(
|
$vm->CloneVM(
|
||||||
folder => $vm->parent,
|
folder => $vm->parent,
|
||||||
name => $dst_name,
|
name => $dst_name,
|
||||||
|
|
Reference in New Issue