1
我正在爲此敲打我的頭。已經2天了,我覺得我已經嘗試了至少六打組合來完成這個子程序。如何獲取此循環以顯示來自VMSD文件的所有關聯磁盤信息
問題: 該子程序是功能性的,但如在密鑰「nas」下的散列輸出中所見,應該有2個磁盤列出但只有一個顯示出來,我已驗證該磁盤實際上列在文件,我約98%確定我的正則表達式能夠匹配名爲「nas_1.vmdk」的第二個磁盤。第一個被稱爲「nas.vmdk」供參考。
這是我的輸出樣子;
$VAR1 = {
'server02' => {
'nas' => {
'SCSI0' => {
'Disk1' => 'nas.vmdk'
}
}
},
'server01' => {
'NS02' => {
'SCSI0' => {
'Disk0' => 'NS02.vmdk'
}
},
'MX01' => {
'SCSI0' => {
'Disk0' => 'MX01.vmdk'
}
},
'NS01' => {
'SCSI0' => {
'Disk0' => 'NS01.vmdk'
}
},
'SQL01' => {
'SCSI0' => {
'Disk0' => 'SQL01.vmdk'
}
}
}
};
就像我說的VM「NAS」應該有一個Disk0上和disk1的,但只有disk1的被顯示出來,這讓我相信,對於Disk0上的值是通過對磁盤1的值纔可以覆蓋掉了寫出來的散列,但我不知道它出錯的地方。
我的代碼:
sub discovery_find_snapshots {
foreach my $server_label (keys %virtual_machines) {
# Set the current server address to esx_host
my $esx_host = $config_file{$server_label}{address};
# Create a hash for storing the options needed by Net::OpenSSH
my %ssh_options = (
port => $config_file{$server_label}{port},
user => $config_file{$server_label}{user},
password => $config_file{$server_label}{password}
);
# Print the name of the server currently being discovered
print "Discovering snapshots for $esx_host\n";
# Create a new Net::OpenSSH object
my $ssh = Net::OpenSSH->new($esx_host, %ssh_options);
foreach my $vm (keys %{$virtual_machines{$server_label}}) {
# Create new scalars for ide port, ide disk, vmdk file and vmdk location
my $snapshot0_adapter_number;
my $snapshot0_disk_number;
my $snapshot0_file;
my $vmsd_source = $ssh->capture("cat $virtual_machines{$server_label}{$vm}{VMSD}");
if (! $vmsd_source eq '') {
while ($vmsd_source =~ m/^snapshot0\.disk([0-9]|1[0-5])\.node\s+=\s+"scsi(?<ADAPTER>[0-3])\:(?<DISK>([0-9]|1[0-5]))"/xmg) {
$snapshot0_adapter_number = "$+{ADAPTER}";
$snapshot0_disk_number = "$+{DISK}";
if ($vmsd_source =~ m/^snapshot0\.disk([0-9|1[0-5])\.fileName\s+=\s+"(?<VMDK_FILE>[^"]+?\.vmdk)"/xm) {
$snapshot0_file = "$+{VMDK_FILE}";
}
$vmsd_disks{$server_label}{$vm}{"SCSI$snapshot0_adapter_number"}{"Disk$snapshot0_disk_number"} = "$snapshot0_file";
}
} else {
print "$vm, no snapshot metadata found\n";
}
}
}
debug();
}
子程序「調試」只是我做,讓我集中使用數據::自卸車額外的子程序。
噢,我差點忘了。這是我想要匹配的信息。
snapshot.lastUID = "1"
snapshot.numSnapshots = "1"
snapshot.current = "1"
snapshot0.uid = "1"
snapshot0.filename = "nas-Snapshot1.vmsn"
snapshot0.displayName = "Milestone - Test"
snapshot0.description = "Test for my script"
snapshot0.type = "1"
snapshot0.createTimeHigh = "301769"
snapshot0.createTimeLow = "-826832731"
snapshot0.numDisks = "2"
snapshot0.disk0.fileName = "nas.vmdk"
snapshot0.disk0.node = "scsi0:0"
snapshot0.disk1.fileName = "nas_1.vmdk"
snapshot0.disk1.node = "scsi0:1"
哦,我的上帝,你是一個理智的救星。它的作品完美無瑕,爲我帶來了深夜。 – ianc1215 2011-01-29 02:41:22