manageiq-smartstate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +4 -0
- data/.rspec_ci +4 -0
- data/.travis.yml +15 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +202 -0
- data/README.md +45 -0
- data/Rakefile +23 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/MiqContainerGroup/MiqContainerGroup.rb +31 -0
- data/lib/MiqVm/MiqLocalVm.rb +50 -0
- data/lib/MiqVm/MiqRhevmVm.rb +179 -0
- data/lib/MiqVm/MiqVm.rb +355 -0
- data/lib/MiqVm/miq_azure_vm.rb +96 -0
- data/lib/MiqVm/miq_scvmm_vm.rb +38 -0
- data/lib/MiqVm/test/camcorder_fleece_test.rb +60 -0
- data/lib/MiqVm/test/localVm.rb +45 -0
- data/lib/MiqVm/test/partitionAlignmentCheck.rb +76 -0
- data/lib/MiqVm/test/remoteVm.rb +65 -0
- data/lib/MiqVm/test/rhevmNfsTest.rb +62 -0
- data/lib/MiqVm/test/rhevmNfsTest2.rb +66 -0
- data/lib/MiqVm/test/rhevmTest.rb +70 -0
- data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackCommon.rb +107 -0
- data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackImage.rb +67 -0
- data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackInstance.rb +182 -0
- data/lib/Scvmm/miq_hyperv_disk.rb +273 -0
- data/lib/Scvmm/miq_scvmm_parse_powershell.rb +75 -0
- data/lib/Scvmm/miq_scvmm_vm_ssa_info.rb +135 -0
- data/lib/Scvmm/test/miq_hyperv_disk_test.rb +33 -0
- data/lib/Scvmm/test/miq_scvmm_vm_ssa_info_test.rb +41 -0
- data/lib/VmLocalDiskAccess/test/localCfg.rb +97 -0
- data/lib/VolumeManager/LVM/logical_volume.rb +75 -0
- data/lib/VolumeManager/LVM/lv_segment.rb +43 -0
- data/lib/VolumeManager/LVM/lvm2disk.rb +158 -0
- data/lib/VolumeManager/LVM/parser.rb +138 -0
- data/lib/VolumeManager/LVM/physical_volume.rb +19 -0
- data/lib/VolumeManager/LVM/scanner.rb +156 -0
- data/lib/VolumeManager/LVM/thin/btree.rb +83 -0
- data/lib/VolumeManager/LVM/thin/constants.rb +86 -0
- data/lib/VolumeManager/LVM/thin/data_map.rb +44 -0
- data/lib/VolumeManager/LVM/thin/mapping_tree.rb +19 -0
- data/lib/VolumeManager/LVM/thin/space_maps.rb +58 -0
- data/lib/VolumeManager/LVM/thin/superblock.rb +136 -0
- data/lib/VolumeManager/LVM/thin.rb +6 -0
- data/lib/VolumeManager/LVM/volume_group.rb +97 -0
- data/lib/VolumeManager/LVM.rb +8 -0
- data/lib/VolumeManager/MiqLdm.rb +546 -0
- data/lib/VolumeManager/MiqLvm.rb +17 -0
- data/lib/VolumeManager/MiqNativeVolumeManager.rb +150 -0
- data/lib/VolumeManager/MiqVolumeManager.rb +277 -0
- data/lib/VolumeManager/VolMgrPlatformSupport.rb +18 -0
- data/lib/VolumeManager/VolMgrPlatformSupportLinux.rb +77 -0
- data/lib/VolumeManager/VolMgrPlatformSupportWin.rb +17 -0
- data/lib/VolumeManager/test/blockDevTest.rb +40 -0
- data/lib/VolumeManager/test/ldm.rb +97 -0
- data/lib/blackbox/VmBlackBox.rb +103 -0
- data/lib/blackbox/xmlStorage.rb +180 -0
- data/lib/db/MiqBdb/MiqBdb.rb +309 -0
- data/lib/db/MiqBdb/MiqBdbBtree.rb +219 -0
- data/lib/db/MiqBdb/MiqBdbHash.rb +199 -0
- data/lib/db/MiqBdb/MiqBdbPage.rb +159 -0
- data/lib/db/MiqBdb/MiqBdbUtil.rb +18 -0
- data/lib/db/MiqSqlite/MiqSqlite3.rb +330 -0
- data/lib/db/MiqSqlite/MiqSqlite3Cell.rb +167 -0
- data/lib/db/MiqSqlite/MiqSqlite3Page.rb +151 -0
- data/lib/db/MiqSqlite/MiqSqlite3Table.rb +124 -0
- data/lib/db/MiqSqlite/MiqSqlite3Util.rb +32 -0
- data/lib/disk/DiskProbe.rb +68 -0
- data/lib/disk/MiqDisk.rb +317 -0
- data/lib/disk/camcorder_test.rb +90 -0
- data/lib/disk/dos_mbr.img +0 -0
- data/lib/disk/modules/AzureBlobDisk.rb +101 -0
- data/lib/disk/modules/LocalDevMod.rb +47 -0
- data/lib/disk/modules/LocalDevProbe.rb +6 -0
- data/lib/disk/modules/MSCommon.rb +352 -0
- data/lib/disk/modules/MSVSDiffDisk.rb +91 -0
- data/lib/disk/modules/MSVSDiskProbe.rb +61 -0
- data/lib/disk/modules/MSVSDynamicDisk.rb +42 -0
- data/lib/disk/modules/MSVSFixedDisk.rb +45 -0
- data/lib/disk/modules/MiqLargeFile.rb +63 -0
- data/lib/disk/modules/MiqLargeFileWin32.rb +107 -0
- data/lib/disk/modules/QcowDisk.rb +692 -0
- data/lib/disk/modules/QcowDiskProbe.rb +34 -0
- data/lib/disk/modules/RawBlockIO.rb +116 -0
- data/lib/disk/modules/RawDisk.rb +45 -0
- data/lib/disk/modules/RawDiskProbe.rb +7 -0
- data/lib/disk/modules/RhevmDescriptor.rb +167 -0
- data/lib/disk/modules/RhevmDiskProbe.rb +52 -0
- data/lib/disk/modules/VMWareCowdDisk.rb +207 -0
- data/lib/disk/modules/VMWareDescriptor.rb +214 -0
- data/lib/disk/modules/VMWareDiskProbe.rb +74 -0
- data/lib/disk/modules/VMWareSparseDisk.rb +189 -0
- data/lib/disk/modules/VhdxDisk.rb +625 -0
- data/lib/disk/modules/VhdxDiskProbe.rb +46 -0
- data/lib/disk/modules/VixDiskMod.rb +54 -0
- data/lib/disk/modules/VixDiskProbe.rb +6 -0
- data/lib/disk/modules/miq_disk_cache.rb +135 -0
- data/lib/disk/modules/miq_dummy_disk.rb +41 -0
- data/lib/disk/modules/vhdx_bat_entry.rb +10 -0
- data/lib/disk/test.rb +66 -0
- data/lib/fs/MetakitFS/MetakitFS.rb +530 -0
- data/lib/fs/MetakitFS/test/Makefile +14 -0
- data/lib/fs/MetakitFS/test/MkCollectFiles.rb +165 -0
- data/lib/fs/MetakitFS/test/MkSelectFiles.rb +30 -0
- data/lib/fs/MetakitFS/test/collect_files.yaml +70 -0
- data/lib/fs/MetakitFS/test/init.rb +3 -0
- data/lib/fs/MetakitFS/test/mk2vmdk.rb +64 -0
- data/lib/fs/MetakitFS/test/mk4test.c +92 -0
- data/lib/fs/MetakitFS/test/mkFsTest.rb +113 -0
- data/lib/fs/MetakitFS/test/proto.rb +97 -0
- data/lib/fs/MiqFS/FsProbe.rb +39 -0
- data/lib/fs/MiqFS/MiqFS.rb +515 -0
- data/lib/fs/MiqFS/modules/AUFSProbe.rb +26 -0
- data/lib/fs/MiqFS/modules/Ext3.rb +305 -0
- data/lib/fs/MiqFS/modules/Ext3Probe.rb +25 -0
- data/lib/fs/MiqFS/modules/Ext4.rb +304 -0
- data/lib/fs/MiqFS/modules/Ext4Probe.rb +25 -0
- data/lib/fs/MiqFS/modules/Fat32.rb +318 -0
- data/lib/fs/MiqFS/modules/Fat32Probe.rb +30 -0
- data/lib/fs/MiqFS/modules/HFSProbe.rb +18 -0
- data/lib/fs/MiqFS/modules/Iso9660.rb +293 -0
- data/lib/fs/MiqFS/modules/Iso9660Probe.rb +18 -0
- data/lib/fs/MiqFS/modules/LocalFS.rb +105 -0
- data/lib/fs/MiqFS/modules/NTFS.rb +287 -0
- data/lib/fs/MiqFS/modules/NTFSProbe.rb +21 -0
- data/lib/fs/MiqFS/modules/NativeFS.rb +155 -0
- data/lib/fs/MiqFS/modules/ReFSProbe.rb +17 -0
- data/lib/fs/MiqFS/modules/RealFS.rb +79 -0
- data/lib/fs/MiqFS/modules/RealFSProbe.rb +6 -0
- data/lib/fs/MiqFS/modules/Reiser4Probe.rb +18 -0
- data/lib/fs/MiqFS/modules/ReiserFS.rb +315 -0
- data/lib/fs/MiqFS/modules/ReiserFSProbe.rb +42 -0
- data/lib/fs/MiqFS/modules/UnionFSProbe.rb +18 -0
- data/lib/fs/MiqFS/modules/WebDAV.rb +127 -0
- data/lib/fs/MiqFS/modules/WebDAVFile.rb +68 -0
- data/lib/fs/MiqFS/modules/XFS.rb +300 -0
- data/lib/fs/MiqFS/modules/XFSProbe.rb +26 -0
- data/lib/fs/MiqFS/modules/ZFSProbe.rb +18 -0
- data/lib/fs/MiqFS/test.rb +59 -0
- data/lib/fs/MiqFsUtil.rb +383 -0
- data/lib/fs/MiqMountManager.rb +209 -0
- data/lib/fs/MiqNativeMountManager.rb +101 -0
- data/lib/fs/MountManagerProbe.rb +29 -0
- data/lib/fs/ReiserFS/block.rb +209 -0
- data/lib/fs/ReiserFS/directory.rb +136 -0
- data/lib/fs/ReiserFS/directory_entry.rb +140 -0
- data/lib/fs/ReiserFS/file_data.rb +111 -0
- data/lib/fs/ReiserFS/superblock.rb +140 -0
- data/lib/fs/ReiserFS/utils.rb +95 -0
- data/lib/fs/VimDatastoreFS/VimDatastoreFS.rb +192 -0
- data/lib/fs/ext3/alloc_bitmap.rb +38 -0
- data/lib/fs/ext3/block_pointers_path.rb +130 -0
- data/lib/fs/ext3/directory.rb +51 -0
- data/lib/fs/ext3/directory_entry.rb +67 -0
- data/lib/fs/ext3/ex_attrib_header.rb +14 -0
- data/lib/fs/ext3/ex_attrib_name.rb +23 -0
- data/lib/fs/ext3/file_data.rb +130 -0
- data/lib/fs/ext3/group_descriptor_entry.rb +65 -0
- data/lib/fs/ext3/group_descriptor_table.rb +54 -0
- data/lib/fs/ext3/hash_tree_entry.rb +18 -0
- data/lib/fs/ext3/hash_tree_header.rb +15 -0
- data/lib/fs/ext3/inode.rb +228 -0
- data/lib/fs/ext3/posix_acl_entry.rb +29 -0
- data/lib/fs/ext3/posix_acl_header.rb +11 -0
- data/lib/fs/ext3/superblock.rb +406 -0
- data/lib/fs/ext3/test/tc_Ext3BlockPointersPath.rb +74 -0
- data/lib/fs/ext4/alloc_bitmap.rb +38 -0
- data/lib/fs/ext4/directory.rb +87 -0
- data/lib/fs/ext4/directory_entry.rb +77 -0
- data/lib/fs/ext4/ex_attrib_header.rb +14 -0
- data/lib/fs/ext4/ex_attrib_name.rb +23 -0
- data/lib/fs/ext4/extent.rb +35 -0
- data/lib/fs/ext4/extent_header.rb +40 -0
- data/lib/fs/ext4/extent_index.rb +33 -0
- data/lib/fs/ext4/group_descriptor_entry.rb +69 -0
- data/lib/fs/ext4/group_descriptor_table.rb +54 -0
- data/lib/fs/ext4/hash_tree_entry.rb +58 -0
- data/lib/fs/ext4/hash_tree_header.rb +35 -0
- data/lib/fs/ext4/inode.rb +465 -0
- data/lib/fs/ext4/posix_acl_entry.rb +29 -0
- data/lib/fs/ext4/posix_acl_header.rb +11 -0
- data/lib/fs/ext4/superblock.rb +412 -0
- data/lib/fs/fat32/boot_sect.rb +379 -0
- data/lib/fs/fat32/directory.rb +222 -0
- data/lib/fs/fat32/directory_entry.rb +540 -0
- data/lib/fs/fat32/file_data.rb +128 -0
- data/lib/fs/iso9660/boot_sector.rb +170 -0
- data/lib/fs/iso9660/directory.rb +90 -0
- data/lib/fs/iso9660/directory_entry.rb +147 -0
- data/lib/fs/iso9660/file_data.rb +78 -0
- data/lib/fs/iso9660/rock_ridge.rb +329 -0
- data/lib/fs/iso9660/util.rb +57 -0
- data/lib/fs/modules/LinuxMount.rb +300 -0
- data/lib/fs/modules/LinuxMountProbe.rb +29 -0
- data/lib/fs/modules/WinMount.rb +97 -0
- data/lib/fs/modules/WinMountProbe.rb +24 -0
- data/lib/fs/ntfs/attrib_attribute_list.rb +131 -0
- data/lib/fs/ntfs/attrib_bitmap.rb +26 -0
- data/lib/fs/ntfs/attrib_data.rb +74 -0
- data/lib/fs/ntfs/attrib_file_name.rb +110 -0
- data/lib/fs/ntfs/attrib_header.rb +194 -0
- data/lib/fs/ntfs/attrib_index_allocation.rb +19 -0
- data/lib/fs/ntfs/attrib_index_root.rb +247 -0
- data/lib/fs/ntfs/attrib_object_id.rb +40 -0
- data/lib/fs/ntfs/attrib_standard_information.rb +107 -0
- data/lib/fs/ntfs/attrib_type.rb +49 -0
- data/lib/fs/ntfs/attrib_volume_information.rb +53 -0
- data/lib/fs/ntfs/attrib_volume_name.rb +31 -0
- data/lib/fs/ntfs/boot_sect.rb +253 -0
- data/lib/fs/ntfs/data_run.rb +358 -0
- data/lib/fs/ntfs/directory_index_node.rb +114 -0
- data/lib/fs/ntfs/index_node_header.rb +69 -0
- data/lib/fs/ntfs/index_record_header.rb +85 -0
- data/lib/fs/ntfs/mft_entry.rb +288 -0
- data/lib/fs/ntfs/utils.rb +43 -0
- data/lib/fs/test/camcorder_fs_test.rb +108 -0
- data/lib/fs/test/collect_files_direct.yaml +22 -0
- data/lib/fs/test/collect_files_in.yaml +24 -0
- data/lib/fs/test/collect_files_in_nc.yaml +22 -0
- data/lib/fs/test/collect_files_out.yaml +6 -0
- data/lib/fs/test/collect_files_rm.yaml +6 -0
- data/lib/fs/test/copyTest.rb +126 -0
- data/lib/fs/test/fsTest.rb +87 -0
- data/lib/fs/test/updateTest.rb +184 -0
- data/lib/fs/xfs/allocation_group.rb +160 -0
- data/lib/fs/xfs/bmap_btree_block.rb +125 -0
- data/lib/fs/xfs/bmap_btree_record.rb +80 -0
- data/lib/fs/xfs/bmap_btree_root_node.rb +72 -0
- data/lib/fs/xfs/directory.rb +133 -0
- data/lib/fs/xfs/directory2_data_header.rb +27 -0
- data/lib/fs/xfs/directory3_data_header.rb +34 -0
- data/lib/fs/xfs/directory_block_tail.rb +22 -0
- data/lib/fs/xfs/directory_data_header.rb +46 -0
- data/lib/fs/xfs/directory_entry.rb +106 -0
- data/lib/fs/xfs/inode.rb +532 -0
- data/lib/fs/xfs/inode_map.rb +100 -0
- data/lib/fs/xfs/short_form_directory_entry.rb +91 -0
- data/lib/fs/xfs/short_form_header.rb +44 -0
- data/lib/fs/xfs/superblock.rb +556 -0
- data/lib/lib/tasks/azure.rake +52 -0
- data/lib/manageiq/smartstate/version.rb +5 -0
- data/lib/manageiq/smartstate.rb +7 -0
- data/lib/manageiq-smartstate.rb +1 -0
- data/lib/metadata/MIQExtract/MIQExtract.rb +297 -0
- data/lib/metadata/MIQExtract/test/extractTest.rb +41 -0
- data/lib/metadata/MIQExtract/test/full_extract_test.rb +68 -0
- data/lib/metadata/ScanProfile/HostScanItem.rb +4 -0
- data/lib/metadata/ScanProfile/HostScanProfile.rb +4 -0
- data/lib/metadata/ScanProfile/HostScanProfiles.rb +41 -0
- data/lib/metadata/ScanProfile/ScanItemBase.rb +63 -0
- data/lib/metadata/ScanProfile/ScanProfileBase.rb +51 -0
- data/lib/metadata/ScanProfile/ScanProfilesBase.rb +60 -0
- data/lib/metadata/ScanProfile/VmScanItem.rb +4 -0
- data/lib/metadata/ScanProfile/VmScanProfile.rb +4 -0
- data/lib/metadata/ScanProfile/VmScanProfiles.rb +38 -0
- data/lib/metadata/ScanProfile/modules/HostScanItemFile.rb +51 -0
- data/lib/metadata/ScanProfile/modules/HostScanItemNteventlog.rb +84 -0
- data/lib/metadata/ScanProfile/modules/VmScanItemFile.rb +39 -0
- data/lib/metadata/ScanProfile/modules/VmScanItemNteventlog.rb +34 -0
- data/lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb +64 -0
- data/lib/metadata/VMMount/VMMount.rb +81 -0
- data/lib/metadata/VMMount/VMPlatformMount.rb +18 -0
- data/lib/metadata/VMMount/VMPlatformMountLinux.rb +75 -0
- data/lib/metadata/VMMount/VMPlatformMountWin.rb +13 -0
- data/lib/metadata/VmConfig/GetNativeCfg.rb +45 -0
- data/lib/metadata/VmConfig/VmConfig.rb +947 -0
- data/lib/metadata/VmConfig/cfgConfig.rb +45 -0
- data/lib/metadata/VmConfig/ovfConfig.rb +99 -0
- data/lib/metadata/VmConfig/test/GetVMwareCfgTest.rb +40 -0
- data/lib/metadata/VmConfig/vmcConfig.rb +116 -0
- data/lib/metadata/VmConfig/vmtxConfig.rb +4 -0
- data/lib/metadata/VmConfig/vmxConfig.rb +162 -0
- data/lib/metadata/VmConfig/xmlConfig.rb +79 -0
- data/lib/metadata/VmConfig/xmlMsHyperVConfig.rb +41 -0
- data/lib/metadata/linux/InitProcHash.rb +632 -0
- data/lib/metadata/linux/LinuxInitProcs.rb +142 -0
- data/lib/metadata/linux/LinuxOSInfo.rb +237 -0
- data/lib/metadata/linux/LinuxPackages.rb +209 -0
- data/lib/metadata/linux/LinuxSystemd.rb +130 -0
- data/lib/metadata/linux/LinuxUsers.rb +289 -0
- data/lib/metadata/linux/LinuxUtils.rb +197 -0
- data/lib/metadata/linux/MiqConaryPackages.rb +41 -0
- data/lib/metadata/linux/MiqRpmPackages.rb +160 -0
- data/lib/metadata/linux/test/Name +0 -0
- data/lib/metadata/linux/test/Packages +0 -0
- data/lib/metadata/linux/test/rpoTest.rb +5 -0
- data/lib/metadata/linux/test/tc_LinuxUtils.rb +4157 -0
- data/lib/metadata/util/event_log_filter.rb +61 -0
- data/lib/metadata/util/md5deep.rb +280 -0
- data/lib/metadata/util/win32/Win32Accounts.rb +764 -0
- data/lib/metadata/util/win32/Win32EventLog.rb +743 -0
- data/lib/metadata/util/win32/Win32Services.rb +86 -0
- data/lib/metadata/util/win32/Win32Software.rb +326 -0
- data/lib/metadata/util/win32/Win32System.rb +333 -0
- data/lib/metadata/util/win32/boot_info_win.rb +59 -0
- data/lib/metadata/util/win32/fleece_hives.rb +220 -0
- data/lib/metadata/util/win32/ms-registry.rb +650 -0
- data/lib/metadata/util/win32/peheader.rb +868 -0
- data/lib/metadata/util/win32/remote-registry.rb +142 -0
- data/lib/metadata/util/win32/system_path_win.rb +103 -0
- data/lib/metadata/util/win32/versioninfo.rb +17 -0
- data/manageiq-smartstate.gemspec +35 -0
- metadata +486 -0
@@ -0,0 +1,273 @@
|
|
1
|
+
# encoding: US-ASCII
|
2
|
+
|
3
|
+
require 'util/miq_winrm'
|
4
|
+
require 'Scvmm/miq_scvmm_parse_powershell'
|
5
|
+
require 'base64'
|
6
|
+
require 'securerandom'
|
7
|
+
require 'memory_buffer'
|
8
|
+
|
9
|
+
require 'rufus/lru'
|
10
|
+
|
11
|
+
class MiqHyperVDisk
|
12
|
+
MIN_SECTORS_TO_CACHE = 64
|
13
|
+
DEF_BLOCK_CACHE_SIZE = 1200
|
14
|
+
DEBUG_CACHE_STATS = false
|
15
|
+
BREAD_RETRIES = 3
|
16
|
+
OPEN_ERRORS = %w( Exception\ calling At\ line: ).freeze
|
17
|
+
|
18
|
+
attr_reader :hostname, :virtual_disk, :file_offset, :file_size, :parser, :vm_name, :temp_snapshot_name
|
19
|
+
|
20
|
+
def initialize(hyperv_host, user, pass, port = nil, network = false)
|
21
|
+
@hostname = hyperv_host
|
22
|
+
@winrm = MiqWinRM.new
|
23
|
+
port ||= 5985
|
24
|
+
@winrm.connect(:port => port, :user => user, :password => pass, :hostname => @hostname)
|
25
|
+
@parser = MiqScvmmParsePowershell.new
|
26
|
+
@block_size = 4096
|
27
|
+
@file_size = 0
|
28
|
+
@block_cache = LruHash.new(DEF_BLOCK_CACHE_SIZE)
|
29
|
+
@cache_hits = Hash.new(0)
|
30
|
+
@cache_misses = Hash.new(0)
|
31
|
+
@network = network
|
32
|
+
@total_read_execution_time = @total_copy_from_remote_time = 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def open(vm_disk)
|
36
|
+
@virtual_disk = vm_disk
|
37
|
+
@file_offset = 0
|
38
|
+
|
39
|
+
unless @network
|
40
|
+
open_script = <<-OPEN_EOL
|
41
|
+
$file_stream = [System.IO.File]::Open("#{@virtual_disk}", "Open", "Read", "Read")
|
42
|
+
$file_stream.seek(0, 0)
|
43
|
+
OPEN_EOL
|
44
|
+
@winrm.run_powershell_script(open_script)
|
45
|
+
end
|
46
|
+
|
47
|
+
stat_script = <<-STAT_EOL
|
48
|
+
(Get-Item "#{@virtual_disk}").length
|
49
|
+
STAT_EOL
|
50
|
+
file_size, stderr = @parser.parse_single_powershell_value(run_correct_powershell(stat_script))
|
51
|
+
|
52
|
+
if @network && stderr.include?("RegisterTaskDefinition")
|
53
|
+
raise "Unable to obtain virtual disk size for #{vm_disk}. Check Hyper-V Host Domain Credentials"
|
54
|
+
end
|
55
|
+
OPEN_ERRORS.each { |error| raise "Unable to obtain virtual disk size for #{vm_disk}" if stderr.include?(error) }
|
56
|
+
@file_size = file_size.to_i
|
57
|
+
@end_byte_addr = @file_size - 1
|
58
|
+
@size_in_blocks, rem = @file_size.divmod(@block_size)
|
59
|
+
@size_in_blocks += 1 if rem > 0
|
60
|
+
@lba_end = @size_in_blocks - 1
|
61
|
+
end
|
62
|
+
|
63
|
+
def size
|
64
|
+
@file_size
|
65
|
+
end
|
66
|
+
|
67
|
+
def close
|
68
|
+
hit_or_miss if DEBUG_CACHE_STATS
|
69
|
+
@file_offset = 0
|
70
|
+
unless @network
|
71
|
+
close_script = <<-CLOSE_EOL
|
72
|
+
$file_stream.Close()
|
73
|
+
CLOSE_EOL
|
74
|
+
run_correct_powershell(close_script)
|
75
|
+
end
|
76
|
+
@winrm.close
|
77
|
+
@winrm = nil
|
78
|
+
end
|
79
|
+
|
80
|
+
def hit_or_miss
|
81
|
+
$log.debug "\nmiq_hyperv_disk cache hits:"
|
82
|
+
@cache_hits.keys.sort.each do |block|
|
83
|
+
$log.debug "block #{block} - #{@cache_hits[block]}"
|
84
|
+
end
|
85
|
+
$log.debug "\nmiq_hyperv_disk cache misses:"
|
86
|
+
@cache_misses.keys.sort.each do |block|
|
87
|
+
$log.debug "block #{block} - #{@cache_misses[block]}"
|
88
|
+
end
|
89
|
+
$log.debug "Total time spent copying reads from remote system is #{@total_copy_from_remote_time}"
|
90
|
+
$log.debug "Total time spent transferring and decoding reads on local system is #{@total_read_execution_time - @total_copy_from_remote_time}"
|
91
|
+
$log.debug "Total time spent processing remote reads is #{@total_read_execution_time}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def seek(offset, whence = IO::SEEK_SET)
|
95
|
+
$log.debug "miq_hyperv_disk.seek(#{offset})"
|
96
|
+
case whence
|
97
|
+
when IO::SEEK_CUR
|
98
|
+
@file_offset += offset
|
99
|
+
when IO::SEEK_END
|
100
|
+
@file_offset = @end_byte_addr + offset
|
101
|
+
when IO::SEEK_SET
|
102
|
+
@file_offset = offset
|
103
|
+
end
|
104
|
+
@file_offset
|
105
|
+
end
|
106
|
+
|
107
|
+
def read(size)
|
108
|
+
$log.debug "miq_hyperv_disk.read(#{size})"
|
109
|
+
return nil if @file_offset >= @file_size
|
110
|
+
size = @file_size - @file_offset if (@file_offset + size) > @file_size
|
111
|
+
|
112
|
+
start_sector, start_offset = @file_offset.divmod(@block_size)
|
113
|
+
end_sector = (@file_offset + size - 1) / @block_size
|
114
|
+
number_sectors = end_sector - start_sector + 1
|
115
|
+
|
116
|
+
@file_offset += size
|
117
|
+
bread_cached(start_sector, number_sectors)[start_offset, size]
|
118
|
+
end
|
119
|
+
|
120
|
+
def bread_cached(start_sector, number_sectors)
|
121
|
+
$log.debug "miq_hyperv_disk.bread_cached(#{start_sector}, #{number_sectors})"
|
122
|
+
@block_cache.keys.each do |block_range|
|
123
|
+
sector_offset = start_sector - block_range.first
|
124
|
+
buffer_offset = sector_offset * @block_size
|
125
|
+
if block_range.include?(start_sector) && block_range.include?(start_sector + number_sectors - 1)
|
126
|
+
length = number_sectors * @block_size
|
127
|
+
@cache_hits[start_sector] += 1
|
128
|
+
return @block_cache[block_range][buffer_offset, length]
|
129
|
+
elsif block_range.include?(start_sector)
|
130
|
+
# This range overlaps the start of our requested read, but more data is required at the end of the request
|
131
|
+
sectors_in_range = block_range.last - start_sector
|
132
|
+
length = sectors_in_range * @block_size
|
133
|
+
remaining_blocks = number_sectors - sectors_in_range
|
134
|
+
@cache_hits[start_sector] += 1
|
135
|
+
# The "+" operator is required rather than "<<" so as not to modify the @block_cache object.
|
136
|
+
return @block_cache[block_range][buffer_offset, length] + bread_cached(block_range.last + 1, remaining_blocks)
|
137
|
+
elsif block_range.include?(start_sector + number_sectors - 1)
|
138
|
+
# This range overlaps the end of our requested read, but more data is required at the start of the request
|
139
|
+
sectors_in_range = (start_sector + number_sectors) - block_range.first
|
140
|
+
length = sectors_in_range * @block_size
|
141
|
+
remaining_blocks = number_sectors - sectors_in_range
|
142
|
+
@cache_hits[start_sector] += 1
|
143
|
+
# The "<<" operator is valid and more efficient here
|
144
|
+
return bread_cached(start_sector, remaining_blocks) << @block_cache[block_range][0, length]
|
145
|
+
elsif block_range.first > start_sector && block_range.last < start_sector + number_sectors
|
146
|
+
# This range overlaps our requested read but more data is required both before and after the range
|
147
|
+
sectors_in_range = block_range.last - block_range.first + 1
|
148
|
+
sectors_pre_range = block_range.first - start_sector
|
149
|
+
sectors_post_range = number_sectors - sectors_in_range - sectors_pre_range
|
150
|
+
# Note the mixed use of operators below.
|
151
|
+
# The first "<<" operator is valid and more efficient while the second "+" operator
|
152
|
+
# is required instead so as not to modify the in-place @block_cache object.
|
153
|
+
return bread_cached(start_sector, sectors_pre_range) <<
|
154
|
+
@block_cache[block_range] +
|
155
|
+
bread_cached(block_range.last + 1, sectors_post_range)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
block_range = entry_range(start_sector, number_sectors)
|
159
|
+
@block_cache[block_range] = bread(block_range.first, block_range.last - block_range.first + 1)
|
160
|
+
@cache_misses[start_sector] += 1
|
161
|
+
|
162
|
+
sector_offset = start_sector - block_range.first
|
163
|
+
buffer_offset = sector_offset * @block_size
|
164
|
+
length = number_sectors * @block_size
|
165
|
+
|
166
|
+
@block_cache[block_range][buffer_offset, length]
|
167
|
+
end
|
168
|
+
|
169
|
+
def bread(start_sector, number_sectors)
|
170
|
+
log_header = "MIQ(#{self.class.name}.#{__method__}:"
|
171
|
+
$log.debug "#{log_header} (#{start_sector}, #{number_sectors})"
|
172
|
+
return nil if start_sector > @lba_end
|
173
|
+
number_sectors = @size_in_blocks - start_sector if (start_sector + number_sectors) > @size_in_blocks
|
174
|
+
expected_bytes = number_sectors * @block_size
|
175
|
+
read_script = if @network
|
176
|
+
|
177
|
+
<<-READ_NETWORK_EOL
|
178
|
+
$file_stream = [System.IO.File]::Open("#{@virtual_disk}", "Open", "Read", "Read")
|
179
|
+
$bufsize = #{number_sectors * @block_size}
|
180
|
+
$buffer = New-Object System.Byte[] $bufsize
|
181
|
+
$encodedbuflen = $bufsize * 4 / 3
|
182
|
+
if (($encodedbuflen % 4) -ne 0)
|
183
|
+
{
|
184
|
+
$encodedbuflen += 4 - ($encodedbuflen % 4)
|
185
|
+
}
|
186
|
+
$encodedarray = New-Object Char[] $encodedbuflen
|
187
|
+
$file_stream.seek(#{start_sector * @block_size}, 0)
|
188
|
+
$file_stream.read($buffer, 0, #{expected_bytes})
|
189
|
+
[System.Convert]::ToBase64CharArray($buffer, 0, $bufsize, $encodedarray, 0)
|
190
|
+
[string]::join("", $encodedarray)
|
191
|
+
$file_stream.Close()
|
192
|
+
READ_NETWORK_EOL
|
193
|
+
else
|
194
|
+
|
195
|
+
<<-READ_EOL
|
196
|
+
if ($bufsize -ne #{number_sectors * @block_size})
|
197
|
+
{
|
198
|
+
$bufsize = #{number_sectors * @block_size}
|
199
|
+
$buffer = New-Object System.Byte[] $bufsize
|
200
|
+
$encodedbuflen = $bufsize * 4 / 3
|
201
|
+
if (($encodedbuflen % 4) -ne 0)
|
202
|
+
{
|
203
|
+
$encodedbuflen += 4 - ($encodedbuflen % 4)
|
204
|
+
}
|
205
|
+
$encodedarray = New-Object Char[] $encodedbuflen
|
206
|
+
}
|
207
|
+
$file_stream.seek(#{start_sector * @block_size}, 0)
|
208
|
+
$file_stream.read($buffer, 0, #{expected_bytes})
|
209
|
+
[System.Convert]::ToBase64CharArray($buffer, 0, $bufsize, $encodedarray, 0)
|
210
|
+
[string]::join("", $encodedarray)
|
211
|
+
READ_EOL
|
212
|
+
end
|
213
|
+
|
214
|
+
i = 0
|
215
|
+
(0...BREAD_RETRIES).each do
|
216
|
+
t1 = Time.now.getlocal
|
217
|
+
encoded_data = @parser.output_to_attribute(run_correct_powershell(read_script))
|
218
|
+
if encoded_data.empty?
|
219
|
+
$log.debug "#{log_header} no encoded data returned on attempt #{i}"
|
220
|
+
i += 1
|
221
|
+
continue
|
222
|
+
end
|
223
|
+
t2 = Time.now.getlocal
|
224
|
+
decoded_data = Base64.decode64(encoded_data)
|
225
|
+
@total_copy_from_remote_time += t2 - t1
|
226
|
+
@total_read_execution_time += Time.now.getlocal - t1
|
227
|
+
decoded_size = decoded_data.size
|
228
|
+
return decoded_data if expected_bytes == decoded_size
|
229
|
+
$log.debug "#{log_header} expected #{expected_bytes} bytes - got #{decoded_size} on attempt #{i}"
|
230
|
+
i += 1
|
231
|
+
end
|
232
|
+
raise "#{log_header} expected #{expected_bytes} bytes - got #{decoded_size}"
|
233
|
+
end
|
234
|
+
|
235
|
+
def snap(vm_name)
|
236
|
+
@vm_name = vm_name
|
237
|
+
@temp_snapshot_name = vm_name + SecureRandom.hex
|
238
|
+
snap_script = <<-SNAP_EOL
|
239
|
+
Checkpoint-VM -Name #{@vm_name} -SnapshotName #{@temp_snapshot_name}
|
240
|
+
SNAP_EOL
|
241
|
+
@vm_name = vm_name
|
242
|
+
@temp_snapshot_name = vm_name + SecureRandom.hex
|
243
|
+
@winrm.run_powershell_script(snap_script)
|
244
|
+
end
|
245
|
+
|
246
|
+
def delete_snap
|
247
|
+
delete_snap_script = <<-DELETE_SNAP_EOL
|
248
|
+
Remove-VMSnapShot -VMName #{@vm_name} -Name #{@temp_snapshot_name}
|
249
|
+
DELETE_SNAP_EOL
|
250
|
+
@winrm.run_powershell_script(delete_snap_script)
|
251
|
+
end
|
252
|
+
|
253
|
+
private
|
254
|
+
|
255
|
+
def run_correct_powershell(script)
|
256
|
+
return @winrm.run_elevated_powershell_script(script) if @network
|
257
|
+
@winrm.run_powershell_script(script)
|
258
|
+
end
|
259
|
+
|
260
|
+
def entry_range(start_sector, number_sectors)
|
261
|
+
# Cache entries are *multiples* of MIN_SECTORS_TO_CACHE * @blocksize in length,
|
262
|
+
# aligned to MIN_SECTORS_TO_CACHE * @blocksize byte boundaries.
|
263
|
+
# real_start_block is the aligned cache block based on the start_sector, and
|
264
|
+
# real_start_sector is the disk sector for that cache block.
|
265
|
+
real_start_block = start_sector / MIN_SECTORS_TO_CACHE
|
266
|
+
real_end_block = (start_sector + number_sectors) / MIN_SECTORS_TO_CACHE
|
267
|
+
number_cache_blocks = real_end_block - real_start_block + 1
|
268
|
+
sectors_to_read = number_cache_blocks * MIN_SECTORS_TO_CACHE
|
269
|
+
real_start_sector = real_start_block * MIN_SECTORS_TO_CACHE
|
270
|
+
end_sector = real_start_sector + sectors_to_read - 1
|
271
|
+
Range.new(real_start_sector, end_sector)
|
272
|
+
end
|
273
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
class MiqScvmmParsePowershell
|
2
|
+
def output_to_attribute(winrm_output)
|
3
|
+
attribute, stderr = stdout_stderr(winrm_output)
|
4
|
+
if stderr =~ /Exception/ || stderr =~ /At line:/
|
5
|
+
raise "Error running PowerShell command.\n #{stderr}"
|
6
|
+
end
|
7
|
+
$log.debug "MiqScvmmParsePowershell: STDERR is \"#{stderr}\"" unless stderr.nil? || $log.nil?
|
8
|
+
attribute.split("\r\n").last
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# This method handles one or more lines of exactly one attribute.
|
13
|
+
#
|
14
|
+
def parse_single_attribute_values(output)
|
15
|
+
parse_attribute_values(output)
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_multiple_attribute_values(output)
|
19
|
+
parse_attribute_values(output, true)
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# This method handles one or more lines of one or more attributes.
|
24
|
+
#
|
25
|
+
def parse_attribute_values(output, multiple = nil)
|
26
|
+
stdout, stderr = parse_powershell_value(output)
|
27
|
+
lines = stdout.split("\r\n")
|
28
|
+
dashes = nil
|
29
|
+
attributes = []
|
30
|
+
attribute_names = []
|
31
|
+
lines.each do |line|
|
32
|
+
next if line.nil? || line == ""
|
33
|
+
if line =~ /^-+/
|
34
|
+
dashes = true
|
35
|
+
next
|
36
|
+
end
|
37
|
+
if dashes.nil?
|
38
|
+
attribute_names = line.split(" ")
|
39
|
+
next
|
40
|
+
end
|
41
|
+
line_parts = multiple.nil? ? [line.rstrip] : line.split(" ")
|
42
|
+
raise "Incorrect number of PowerShell Output Attributes Found" if line_parts.size != attribute_names.size
|
43
|
+
i = 0
|
44
|
+
line_hash = {}
|
45
|
+
attribute_names.each do |attribute|
|
46
|
+
line_hash[attribute] = line_parts[i]
|
47
|
+
i += 1
|
48
|
+
end
|
49
|
+
attributes << line_hash
|
50
|
+
end
|
51
|
+
return attributes, stderr
|
52
|
+
end
|
53
|
+
|
54
|
+
def parse_single_powershell_value(output)
|
55
|
+
stdout, stderr = parse_powershell_value(output)
|
56
|
+
return stdout.split("\r\n").first, stderr
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_powershell_value(output)
|
60
|
+
stdout, stderr = stdout_stderr(output)
|
61
|
+
$log.debug "MiqScvmmParsePowershell: STDOUT is \"#{stdout}\"" unless stdout.nil? || $log.nil?
|
62
|
+
$log.debug "MiqScvmmParsePowershell: STDERR is \"#{stderr}\"" unless stderr.nil? || $log.nil?
|
63
|
+
return stdout, stderr
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def stdout_stderr(output)
|
69
|
+
stdout = ""
|
70
|
+
stderr = ""
|
71
|
+
stdout << output.stdout unless output.stdout.nil?
|
72
|
+
stderr << output.stderr unless output.stderr.nil?
|
73
|
+
return stdout, stderr
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# encoding: US-ASCII
|
2
|
+
|
3
|
+
require 'util/miq_winrm'
|
4
|
+
require 'Scvmm/miq_scvmm_parse_powershell'
|
5
|
+
|
6
|
+
class MiqScvmmVmSSAInfo
|
7
|
+
attr_reader :vhds, :hostname, :checkpoints, :vhd_type
|
8
|
+
def initialize(provider, user, pass, port = nil)
|
9
|
+
@checkpoints = []
|
10
|
+
@vhds = []
|
11
|
+
@hostname = nil
|
12
|
+
@vhd_type = nil
|
13
|
+
@winrm = MiqWinRM.new
|
14
|
+
winrmport = port.nil? ? 5985 : port
|
15
|
+
options = {:port => winrmport, :user => user, :password => pass, :hostname => provider}
|
16
|
+
@elevated = nil
|
17
|
+
|
18
|
+
@winrm.connect(options)
|
19
|
+
@parser = MiqScvmmParsePowershell.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def close
|
23
|
+
@winrm.close
|
24
|
+
end
|
25
|
+
|
26
|
+
# Note the following method returns *all* hard disks and some common attributes from the Hyper-V host
|
27
|
+
def vm_all_harddisks(vm_name, snapshot = nil, check_snapshot = TRUE)
|
28
|
+
vhds = vm_get_disks(vm_name, snapshot, check_snapshot)
|
29
|
+
properties = vm_get_properties(vm_name)
|
30
|
+
raise "Error getting VHD(s) and Attributes for #{vm_name}" if vhds.size != properties.size
|
31
|
+
raise "No Virtual Hard Disk found for VM #{vm_name}" unless vhds.any?
|
32
|
+
|
33
|
+
i = 0
|
34
|
+
new_vhds = []
|
35
|
+
$log.debug "vm_all_harddisks: #{vhds.size} vhds found:\n"
|
36
|
+
vhds.each do |vhd|
|
37
|
+
vhd.merge!(properties[i])
|
38
|
+
new_vhds << vhd
|
39
|
+
i += 1
|
40
|
+
end
|
41
|
+
new_vhds
|
42
|
+
end
|
43
|
+
|
44
|
+
def vm_get_checkpoint(vm_name, snapshot)
|
45
|
+
get_checkpoint_script = <<-GETCHECKPOINT_EOL
|
46
|
+
Get-VMSnapShot -ComputerName localhost -VMName "#{vm_name}" -Name "#{snapshot}"| \
|
47
|
+
Select-Object -ExpandProperty Name
|
48
|
+
GETCHECKPOINT_EOL
|
49
|
+
|
50
|
+
checkpoint, stderr = @parser.parse_single_powershell_value(@winrm.run_powershell_script(get_checkpoint_script))
|
51
|
+
if stderr =~ /Unable to find a snapshot/
|
52
|
+
return nil
|
53
|
+
else
|
54
|
+
raise "Error finding Snapshot for #{vm_name}: #{stderr}" unless stderr.empty?
|
55
|
+
end
|
56
|
+
checkpoint
|
57
|
+
end
|
58
|
+
|
59
|
+
def vm_create_evm_checkpoint(vm_name, snapshot = nil)
|
60
|
+
snapshot = vm_name + "__EVM_SNAPSHOT" if snapshot.nil?
|
61
|
+
raise "Checkpoint for VM #{vm_name} Already Exists" unless vm_get_checkpoint(vm_name, snapshot).nil?
|
62
|
+
|
63
|
+
checkpoint_script = <<-CHECKPOINT_EOL
|
64
|
+
Checkpoint-VM -ComputerName localhost -Name "#{vm_name}" -SnapshotName "#{snapshot}"
|
65
|
+
CHECKPOINT_EOL
|
66
|
+
|
67
|
+
_stdout, stderr = @parser.parse_single_powershell_value(@winrm.run_powershell_script(checkpoint_script))
|
68
|
+
unless stderr.empty?
|
69
|
+
@elevated = true
|
70
|
+
_stdout, stderr = @parser.parse_single_powershell_value(@winrm.run_elevated_powershell_script(checkpoint_script))
|
71
|
+
end
|
72
|
+
raise "Unable to create Snapshot for #{vm_name}: #{stderr}" unless stderr.empty?
|
73
|
+
snapshot
|
74
|
+
end
|
75
|
+
|
76
|
+
def vm_remove_evm_checkpoint(vm_name, snapshot = nil)
|
77
|
+
snapshot = vm_name + "__EVM_SNAPSHOT" if snapshot.nil?
|
78
|
+
rm_checkpt_script = <<-RM_CHECKPOINT_EOL
|
79
|
+
Remove-VMSnapshot -ComputerName localhost -VMName "#{vm_name}" -Name "#{snapshot}"
|
80
|
+
RM_CHECKPOINT_EOL
|
81
|
+
|
82
|
+
if @elevated
|
83
|
+
_stdout, stderr = @parser.parse_single_powershell_value(@winrm.run_elevated_powershell_script(rm_checkpt_script))
|
84
|
+
else
|
85
|
+
_stdout, stderr = @parser.parse_single_powershell_value(@winrm.run_powershell_script(rm_checkpt_script))
|
86
|
+
end
|
87
|
+
raise "Unable to remove Snapshot for #{vm_name}: #{stderr}" unless stderr.empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_drivetype(vhd_path)
|
91
|
+
return "Network" if vhd_path[0, 2] == '\\\\'
|
92
|
+
raise "Invalid Drive Letter for Hard Drive #{vhd_path}" unless vhd_path[1, 1] == ":"
|
93
|
+
drive_letter = vhd_path[0, 1]
|
94
|
+
|
95
|
+
drivetype_script = <<-DRIVETYPE_EOL
|
96
|
+
([System.IO.DriveInfo]("#{drive_letter}")).DriveType
|
97
|
+
DRIVETYPE_EOL
|
98
|
+
drive_type, stderr = @parser.parse_single_powershell_value(@winrm.run_powershell_script(drivetype_script))
|
99
|
+
raise "Unable to get drive letter for disk #{vhd_path}: #{stderr}" unless stderr.empty? || drive_type.nil?
|
100
|
+
drive_type
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def vm_get_properties(vm_name)
|
106
|
+
properties_script = <<-PROPERTIES_EOL
|
107
|
+
Get-VMHardDiskDrive -VMName "#{vm_name}" | \
|
108
|
+
Format-Table -Property ControllerType,ControllerNumber,ControllerLocation -Autosize
|
109
|
+
PROPERTIES_EOL
|
110
|
+
|
111
|
+
properties, stderr = @parser.parse_multiple_attribute_values(@winrm.run_powershell_script(properties_script))
|
112
|
+
raise "Error getting VHD(s) and Attributes for #{vm_name}: #{stderr}" unless stderr.empty?
|
113
|
+
properties
|
114
|
+
end
|
115
|
+
|
116
|
+
def vm_get_disks(vm_name, snapshot, check_snapshot)
|
117
|
+
if check_snapshot.nil?
|
118
|
+
vhd_script = <<-VHD_EOL
|
119
|
+
Get-VMHardDiskDrive -VMName "#{vm_name}" | \
|
120
|
+
Format-Table -Property Path | out-string -Width 200
|
121
|
+
VHD_EOL
|
122
|
+
else
|
123
|
+
snapshot = vm_name + "__EVM_SNAPSHOT" if snapshot.nil?
|
124
|
+
raise "Checkpoint #{snapshot} for VM #{vm_name} missing" if vm_get_checkpoint(vm_name, snapshot).nil?
|
125
|
+
vhd_script = <<-SNAP_EOL
|
126
|
+
Get-VMSnapShot -VMName "#{vm_name}" -Name "#{snapshot}" | Get-VMHardDiskDrive | \
|
127
|
+
Format-Table -Property Path | out-string -Width 200
|
128
|
+
SNAP_EOL
|
129
|
+
end
|
130
|
+
|
131
|
+
vhds, stderr = @parser.parse_single_attribute_values(@winrm.run_powershell_script(vhd_script))
|
132
|
+
raise "Unable to obtain VHD Name(s) for #{vm_name}: #{stderr}" unless stderr.empty?
|
133
|
+
vhds
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'manageiq-gems-pending'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'log4r'
|
4
|
+
require 'Scvmm/miq_hyperv_disk'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Formatter to output log messages to the console.
|
8
|
+
#
|
9
|
+
class ConsoleFormatter < Log4r::Formatter
|
10
|
+
def format(event)
|
11
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$log = Log4r::Logger.new 'toplog'
|
16
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::DEBUG, :formatter => ConsoleFormatter)
|
17
|
+
$log.add 'err_console'
|
18
|
+
|
19
|
+
HOST = raise "Please define SERVERNAME"
|
20
|
+
PORT = raise "Please define PORT"
|
21
|
+
USER = raise "Please define USER"
|
22
|
+
PASS = raise "Please define PASS"
|
23
|
+
DISK = raise "Please define DISK"
|
24
|
+
|
25
|
+
hyperv_disk = MiqHyperVDisk.new(HOST, USER, PASS, PORT)
|
26
|
+
|
27
|
+
$log.debug "Reading 256 byte slices"
|
28
|
+
hyperv_disk.open(DISK)
|
29
|
+
hyperv_disk.seek(0)
|
30
|
+
(1..8).each do |i|
|
31
|
+
buffer = hyperv_disk.read(256)
|
32
|
+
$log.debug "Buffer #{i}: \n#{buffer}\n"
|
33
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'manageiq-gems-pending'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'log4r'
|
4
|
+
require 'Scvmm/miq_scvmm_vm_ssa_info'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Formatter to output log messages to the console.
|
8
|
+
#
|
9
|
+
class ConsoleFormatter < Log4r::Formatter
|
10
|
+
def format(event)
|
11
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$log = Log4r::Logger.new 'toplog'
|
16
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::DEBUG, :formatter => ConsoleFormatter)
|
17
|
+
$log.add 'err_console'
|
18
|
+
|
19
|
+
HOST = raise "Please define SERVERNAME"
|
20
|
+
PORT = raise "Please define PORT"
|
21
|
+
USER = raise "Please define USER"
|
22
|
+
PASS = raise "Please define PASS"
|
23
|
+
VM = raise "Please define VM"
|
24
|
+
|
25
|
+
vm_info_handle = MiqScvmmVmSSAInfo.new(HOST, USER, PASS, PORT)
|
26
|
+
$log.debug "Getting Hyper-V Host for VM #{VM}"
|
27
|
+
hyperv_host = vm_info_handle.vm_host(VM)
|
28
|
+
$log.debug "Hyper-V Host is #{hyperv_host}"
|
29
|
+
$log.debug "Getting VHD Type for VM #{VM}"
|
30
|
+
vhd_type = vm_info_handle.vm_vhdtype(VM)
|
31
|
+
$log.debug "VHD Type is #{vhd_type}"
|
32
|
+
vhd = vm_info_handle.vm_harddisks(VM)
|
33
|
+
$log.debug "VHD is #{vhd}"
|
34
|
+
vm_info_handle.vm_create_checkpoint(VM)
|
35
|
+
checkpoint = vm_info_handle.vm_get_checkpoint(VM)
|
36
|
+
$log.debug "Checkpoint for #{vhd} is #{checkpoint}"
|
37
|
+
vm_info_handle.vm_remove_checkpoint(VM)
|
38
|
+
vm_info_handle.vm_create_checkpoint(VM)
|
39
|
+
checkpoint = vm_info_handle.vm_get_checkpoint(VM)
|
40
|
+
$log.debug "Checkpoint for #{vhd} is #{checkpoint}"
|
41
|
+
vm_info_handle.vm_remove_checkpoint(VM)
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'util/miq-xml'
|
3
|
+
require 'util/runcmd'
|
4
|
+
require 'metadata/VmConfig/VmConfig'
|
5
|
+
require 'VolumeManager/MiqNativeVolumeManager'
|
6
|
+
require 'fs/MiqMountManager'
|
7
|
+
|
8
|
+
module MiqNativeMountManager
|
9
|
+
LSHW = "lshw"
|
10
|
+
|
11
|
+
def self.mountVolumes
|
12
|
+
lshwXml = MiqUtil.runcmd("#{LSHW} -xml")
|
13
|
+
nodeHash = Hash.new { |h, k| h[k] = [] }
|
14
|
+
doc = MiqXml.load(lshwXml)
|
15
|
+
doc.find_match("//node").each { |n| nodeHash[n.attributes["id"].split(':', 2)[0]] << n }
|
16
|
+
|
17
|
+
hardware = ""
|
18
|
+
|
19
|
+
nodeHash["disk"].each do |d|
|
20
|
+
diskid = d.find_first('businfo').get_text.to_s
|
21
|
+
next unless diskid
|
22
|
+
sn = d.find_first('size')
|
23
|
+
# If there's no size node, assume it's a removable drive.
|
24
|
+
next unless sn
|
25
|
+
busType, busAddr = diskid.split('@', 2)
|
26
|
+
if busType == "scsi"
|
27
|
+
f1, f2 = busAddr.split(':', 2)
|
28
|
+
f2 = f2.split('.')[1]
|
29
|
+
busAddr = "#{f1}:#{f2}"
|
30
|
+
else
|
31
|
+
busAddr['.'] = ':'
|
32
|
+
end
|
33
|
+
diskid = busType + busAddr
|
34
|
+
filename = d.find_first('logicalname').get_text.to_s
|
35
|
+
hardware += "#{diskid}.present = \"TRUE\"\n"
|
36
|
+
hardware += "#{diskid}.filename = \"#{filename}\"\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
cfg = VmConfig.new(hardware)
|
40
|
+
volMgr = MiqNativeVolumeManager.new(cfg)
|
41
|
+
|
42
|
+
(MiqMountManager.mountVolumes(volMgr, cfg))
|
43
|
+
end
|
44
|
+
end # module MiqNativeMountManager
|
45
|
+
|
46
|
+
if __FILE__ == $0
|
47
|
+
#
|
48
|
+
# Formatter to output log messages to the console.
|
49
|
+
#
|
50
|
+
class ConsoleFormatter < Log4r::Formatter
|
51
|
+
def format(event)
|
52
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
$log = Log4r::Logger.new 'toplog'
|
56
|
+
$log.level = Log4r::DEBUG
|
57
|
+
Log4r::StderrOutputter.new('err_console', :formatter => ConsoleFormatter)
|
58
|
+
$log.add 'err_console'
|
59
|
+
|
60
|
+
puts "Log debug?: #{$log.debug?}"
|
61
|
+
|
62
|
+
rootTrees = MiqNativeMountManager.mountVolumes
|
63
|
+
|
64
|
+
if rootTrees.nil? || rootTrees.empty?
|
65
|
+
puts "No root filesystems detected"
|
66
|
+
exit
|
67
|
+
end
|
68
|
+
|
69
|
+
$miqOut = $stdout
|
70
|
+
rootTrees.each do |r|
|
71
|
+
r.toXml(nil)
|
72
|
+
end
|
73
|
+
|
74
|
+
rootTree = rootTrees[0]
|
75
|
+
|
76
|
+
if rootTree.guestOS == "Linux"
|
77
|
+
puts
|
78
|
+
puts "Files in /:"
|
79
|
+
rootTree.dirForeach("/") { |f| puts "\t#{f}" }
|
80
|
+
|
81
|
+
puts
|
82
|
+
puts "All files in /test_mount:"
|
83
|
+
rootTree.findEach("/test_mount") { |f| puts "\t#{f}" }
|
84
|
+
elsif rootTree.guestOS == "Windows"
|
85
|
+
puts
|
86
|
+
puts "Files in C:/"
|
87
|
+
rootTree.dirForeach("C:/") { |f| puts "\t#{f}" }
|
88
|
+
|
89
|
+
["E:/", "F:/"].each do |drive|
|
90
|
+
puts
|
91
|
+
puts "All files in #{drive}"
|
92
|
+
rootTree.findEach(drive) { |f| puts "\t#{f}" }
|
93
|
+
end
|
94
|
+
else
|
95
|
+
puts "Unknown guest OS: #{rootTree.guestOS}"
|
96
|
+
end
|
97
|
+
end
|