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
data/lib/MiqVm/MiqVm.rb
ADDED
@@ -0,0 +1,355 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'metadata/VmConfig/VmConfig'
|
3
|
+
require 'disk/MiqDisk'
|
4
|
+
require 'VolumeManager/MiqVolumeManager'
|
5
|
+
require 'fs/MiqMountManager'
|
6
|
+
require 'metadata/MIQExtract/MIQExtract'
|
7
|
+
|
8
|
+
class MiqVm
|
9
|
+
attr_reader :vmConfig, :vmConfigFile, :vim, :vimVm, :rhevm, :rhevmVm, :diskInitErrors, :wholeDisks
|
10
|
+
|
11
|
+
def initialize(vmCfg, ost = nil)
|
12
|
+
@ost = ost || OpenStruct.new
|
13
|
+
$log.debug "MiqVm::initialize: @ost = nil" if $log && !@ost
|
14
|
+
@vmDisks = nil
|
15
|
+
@wholeDisks = []
|
16
|
+
@rootTrees = nil
|
17
|
+
@volumeManager = nil
|
18
|
+
@applianceVolumeManager = nil
|
19
|
+
@vmConfigFile = ""
|
20
|
+
@diskInitErrors = {}
|
21
|
+
unless vmCfg.kind_of?(Hash)
|
22
|
+
@vmConfigFile = vmCfg
|
23
|
+
@vmDir = File.dirname(vmCfg)
|
24
|
+
end
|
25
|
+
|
26
|
+
$log.debug "MiqVm::initialize: @ost.openParent = #{@ost.openParent}" if $log
|
27
|
+
|
28
|
+
#
|
29
|
+
# If we're passed an MiqVim object, then use VIM to obtain the Vm's
|
30
|
+
# configuration through the instantiated server.
|
31
|
+
# If we're passed a snapshot ID, then obtain the configration of the
|
32
|
+
# VM when the snapshot was taken.
|
33
|
+
#
|
34
|
+
# TODO: move to MiqVmwareVm
|
35
|
+
if (@vim = @ost.miqVim)
|
36
|
+
$log.debug "MiqVm::initialize: accessing VM through server: #{@vim.server}" if $log.debug?
|
37
|
+
@vimVm = @vim.getVimVm(vmCfg)
|
38
|
+
$log.debug "MiqVm::initialize: setting @ost.miqVimVm = #{@vimVm.class}" if $log.debug?
|
39
|
+
@ost.miqVimVm = @vimVm
|
40
|
+
@vmConfig = VmConfig.new(@vimVm.getCfg(@ost.snapId))
|
41
|
+
# TODO: move this to MiqRhevmVm.
|
42
|
+
elsif (@rhevm = @ost.miqRhevm)
|
43
|
+
$log.debug "MiqVm::initialize: accessing VM through RHEVM server" if $log.debug?
|
44
|
+
$log.debug "MiqVm::initialize: vmCfg = #{vmCfg}"
|
45
|
+
@rhevmVm = @rhevm.get_vm(vmCfg)
|
46
|
+
$log.debug "MiqVm::initialize: setting @ost.miqRhevmVm = #{@rhevmVm.class}" if $log.debug?
|
47
|
+
@ost.miqRhevmVm = @rhevmVm
|
48
|
+
@vmConfig = VmConfig.new(getCfg(@ost.snapId))
|
49
|
+
$log.debug "MiqVm::initialize: @vmConfig.getHash = #{@vmConfig.getHash.inspect}"
|
50
|
+
$log.debug "MiqVm::initialize: @vmConfig.getDiskFileHash = #{@vmConfig.getDiskFileHash.inspect}"
|
51
|
+
# TODO: move this to miq_scvmm_vm
|
52
|
+
elsif (@scvmm = @ost.miq_scvmm)
|
53
|
+
$log.debug "MiqVm::initialize: accessing VM through HyperV server" if $log.debug?
|
54
|
+
@vmConfig = VmConfig.new(getCfg(@ost.snapId))
|
55
|
+
$log.debug "MiqVm::initialize: setting @ost.miq_scvmm_vm = #{@scvmm_vm.class}" if $log.debug?
|
56
|
+
else
|
57
|
+
@vimVm = nil
|
58
|
+
@vmConfig = VmConfig.new(vmCfg)
|
59
|
+
end
|
60
|
+
end # def initialize
|
61
|
+
|
62
|
+
def vmDisks
|
63
|
+
@vmDisks ||= begin
|
64
|
+
@volMgrPS = VolMgrPlatformSupport.new(@vmConfig.configFile, @ost)
|
65
|
+
@volMgrPS.preMount
|
66
|
+
|
67
|
+
openDisks(@vmConfig.getDiskFileHash)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def openDisks(diskFiles)
|
72
|
+
pVolumes = []
|
73
|
+
|
74
|
+
$log.debug "openDisks: no disk files supplied." unless diskFiles
|
75
|
+
|
76
|
+
#
|
77
|
+
# Build a list of the VM's physical volumes.
|
78
|
+
#
|
79
|
+
diskFiles.each do |dtag, df|
|
80
|
+
$log.debug "openDisks: processing disk file (#{dtag}): #{df}"
|
81
|
+
dInfo = OpenStruct.new
|
82
|
+
|
83
|
+
if @ost.miqVim
|
84
|
+
dInfo.vixDiskInfo = {}
|
85
|
+
dInfo.vixDiskInfo[:fileName] = @ost.miqVim.datastorePath(df)
|
86
|
+
if @ost.miqVimVm
|
87
|
+
@vdlConnection = @ost.miqVimVm.vdlVcConnection unless @vdlConnection
|
88
|
+
else
|
89
|
+
@vdlConnection = @ost.miqVim.vdlConnection unless @vdlConnection
|
90
|
+
end
|
91
|
+
$log.debug "openDisks: using disk file path: #{dInfo.vixDiskInfo[:fileName]}"
|
92
|
+
dInfo.vixDiskInfo[:connection] = @vdlConnection
|
93
|
+
elsif @ost.miq_hyperv
|
94
|
+
init_disk_info(dInfo, df)
|
95
|
+
else
|
96
|
+
dInfo.fileName = df
|
97
|
+
disk_format = @vmConfig.getHash["#{dtag}.format"] # Set by rhevm for iscsi and fcp disks
|
98
|
+
dInfo.format = disk_format unless disk_format.blank?
|
99
|
+
end
|
100
|
+
|
101
|
+
mode = @vmConfig.getHash["#{dtag}.mode"]
|
102
|
+
|
103
|
+
dInfo.hardwareId = dtag
|
104
|
+
dInfo.baseOnly = @ost.openParent unless mode && mode["independent"]
|
105
|
+
dInfo.rawDisk = @ost.rawDisk
|
106
|
+
$log.debug "MiqVm::openDisks: dInfo.baseOnly = #{dInfo.baseOnly}"
|
107
|
+
|
108
|
+
begin
|
109
|
+
d = applianceVolumeManager && applianceVolumeManager.lvHash[dInfo.fileName] if @rhevm
|
110
|
+
if d
|
111
|
+
$log.debug "MiqVm::openDisks: using applianceVolumeManager for #{dInfo.fileName}" if $log.debug?
|
112
|
+
d.dInfo.fileName = dInfo.fileName
|
113
|
+
d.dInfo.hardwareId = dInfo.hardwareId
|
114
|
+
d.dInfo.baseOnly = dInfo.baseOnly
|
115
|
+
d.dInfo.format = dInfo.format if dInfo.format
|
116
|
+
d.dInfo.applianceVolumeManager = applianceVolumeManager
|
117
|
+
#
|
118
|
+
# Here, we need to probe the disk to determine its data format,
|
119
|
+
# QCOW for example. If the disk format is not flat, push a disk
|
120
|
+
# supporting the format on top of this disk. Then set d to point
|
121
|
+
# to the new top disk.
|
122
|
+
#
|
123
|
+
d = d.pushFormatSupport
|
124
|
+
else
|
125
|
+
d = MiqDisk.getDisk(dInfo)
|
126
|
+
# I am not sure if getting a nil handle back should throw an error or not.
|
127
|
+
# For now I am just skipping to the next disk. (GMM)
|
128
|
+
next if d.nil?
|
129
|
+
end
|
130
|
+
rescue => err
|
131
|
+
$log.error "Couldn't open disk file: #{df}"
|
132
|
+
$log.error err.to_s
|
133
|
+
$log.debug err.backtrace.join("\n")
|
134
|
+
@diskInitErrors[df] = err.to_s
|
135
|
+
next
|
136
|
+
end
|
137
|
+
|
138
|
+
@wholeDisks << d
|
139
|
+
p = d.getPartitions
|
140
|
+
if p.empty?
|
141
|
+
#
|
142
|
+
# If the disk has no partitions, the whole disk can be a single volume.
|
143
|
+
#
|
144
|
+
pVolumes << d
|
145
|
+
else
|
146
|
+
#
|
147
|
+
# If the disk is partitioned, the partitions are physical volumes,
|
148
|
+
# but not the whild disk.
|
149
|
+
#
|
150
|
+
pVolumes.concat(p)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
pVolumes
|
155
|
+
end # def openDisks
|
156
|
+
|
157
|
+
def rootTrees
|
158
|
+
return @rootTrees if @rootTrees
|
159
|
+
@rootTrees = MiqMountManager.mountVolumes(volumeManager, @vmConfig, @ost)
|
160
|
+
volumeManager.rootTrees = @rootTrees
|
161
|
+
@rootTrees
|
162
|
+
end
|
163
|
+
|
164
|
+
def volumeManager
|
165
|
+
@volumeManager ||= MiqVolumeManager.new(vmDisks)
|
166
|
+
end
|
167
|
+
|
168
|
+
def applianceVolumeManager
|
169
|
+
return nil if @ost.nfs_storage_mounted
|
170
|
+
@applianceVolumeManager ||= MiqVolumeManager.fromNativePvs
|
171
|
+
end
|
172
|
+
|
173
|
+
def snapshots(refresh = false)
|
174
|
+
return nil unless @vimVm
|
175
|
+
return @vimVm.snapshotInfo(refresh) if @vimVm
|
176
|
+
end
|
177
|
+
|
178
|
+
def unmount
|
179
|
+
$log.info "MiqVm.unmount called."
|
180
|
+
@wholeDisks.each(&:close)
|
181
|
+
@wholeDisks.clear
|
182
|
+
if @volumeManager
|
183
|
+
@volumeManager.close
|
184
|
+
@volumeManager = nil
|
185
|
+
end
|
186
|
+
@applianceVolumeManager.closeAll if @applianceVolumeManager
|
187
|
+
@applianceVolumeManager = nil
|
188
|
+
@ost.miqVim.closeVdlConnection(@vdlConnection) if @vdlConnection
|
189
|
+
if @volMgrPS
|
190
|
+
@volMgrPS.postMount
|
191
|
+
@volMgrPS = nil
|
192
|
+
end
|
193
|
+
@vimVm.release if @vimVm
|
194
|
+
@rootTrees = nil
|
195
|
+
@vmDisks = nil
|
196
|
+
end
|
197
|
+
|
198
|
+
def miq_extract
|
199
|
+
@miq_extract ||= MIQExtract.new(self, @ost)
|
200
|
+
end
|
201
|
+
|
202
|
+
def extract(c)
|
203
|
+
xml = miq_extract.extract(c)
|
204
|
+
raise "Could not extract \"#{c}\" from VM" unless xml
|
205
|
+
(xml)
|
206
|
+
end
|
207
|
+
end # class MiqVm
|
208
|
+
|
209
|
+
if __FILE__ == $0
|
210
|
+
require 'log4r'
|
211
|
+
require 'metadata/util/win32/boot_info_win'
|
212
|
+
|
213
|
+
# vmDir = File.join(ENV.fetch("HOME", '.'), 'VMs')
|
214
|
+
vmDir = "/volumes/WDpassport/Virtual Machines"
|
215
|
+
puts "vmDir = #{vmDir}"
|
216
|
+
|
217
|
+
targetLv = "rpolv2"
|
218
|
+
rootLv = "LogVol00"
|
219
|
+
|
220
|
+
class ConsoleFormatter < Log4r::Formatter
|
221
|
+
def format(event)
|
222
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
toplog = Log4r::Logger.new 'toplog'
|
227
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::DEBUG, :formatter => ConsoleFormatter)
|
228
|
+
toplog.add 'err_console'
|
229
|
+
$log = toplog if $log.nil?
|
230
|
+
|
231
|
+
#
|
232
|
+
# *** Test start
|
233
|
+
#
|
234
|
+
|
235
|
+
# vmCfg = File.join(vmDir, "cacheguard/cacheguard.vmx")
|
236
|
+
# vmCfg = File.join(vmDir, "Red Hat Linux.vmwarevm/Red Hat Linux.vmx")
|
237
|
+
# vmCfg = File.join(vmDir, "MIQ Server Appliance - Ubuntu MD - small/MIQ Server Appliance - Ubuntu.vmx")
|
238
|
+
# vmCfg = File.join(vmDir, "winxpDev.vmwarevm/winxpDev.vmx")
|
239
|
+
vmCfg = File.join(vmDir, "Win2K_persistent/Windows 2000 Professional.vmx")
|
240
|
+
# vmCfg = File.join(vmDir, "Win2K_non_persistent/Windows 2000 Professional.vmx")
|
241
|
+
puts "VM config file: #{vmCfg}"
|
242
|
+
|
243
|
+
ost = OpenStruct.new
|
244
|
+
ost.openParent = true
|
245
|
+
|
246
|
+
vm = MiqVm.new(vmCfg, ost)
|
247
|
+
|
248
|
+
puts "\n*** Disk Files:"
|
249
|
+
vm.vmConfig.getDiskFileHash.each do |k, v|
|
250
|
+
puts "\t#{k}\t#{v}"
|
251
|
+
end
|
252
|
+
|
253
|
+
puts "\n*** configHash:"
|
254
|
+
vm.vmConfig.getHash.each do |k, v|
|
255
|
+
puts "\t#{k} => #{v}"
|
256
|
+
end
|
257
|
+
|
258
|
+
tlv = nil
|
259
|
+
rlv = nil
|
260
|
+
puts "\n*** Visible Volumes:"
|
261
|
+
vm.volumeManager.visibleVolumes.each do |vv|
|
262
|
+
puts "\tDisk type: #{vv.diskType}"
|
263
|
+
puts "\tDisk sig: #{vv.diskSig}"
|
264
|
+
puts "\tStart LBA: #{vv.lbaStart}"
|
265
|
+
if vv.respond_to?(:logicalVolume)
|
266
|
+
puts "\t\tLV name: #{vv.logicalVolume.lvName}"
|
267
|
+
puts "\t\tLV UUID: #{vv.logicalVolume.lvId}"
|
268
|
+
tlv = vv if vv.logicalVolume.lvName == targetLv
|
269
|
+
rlv = vv if vv.logicalVolume.lvName == rootLv
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
# raise "#{targetLv} not found" if !tlv
|
274
|
+
#
|
275
|
+
# tlv.seek(0, IO::SEEK_SET)
|
276
|
+
# rs = tlv.read(2040)
|
277
|
+
# puts "\n***** START *****"
|
278
|
+
# puts rs
|
279
|
+
# puts "****** END ******"
|
280
|
+
#
|
281
|
+
# tlv.seek(2048*512*5119, IO::SEEK_SET)
|
282
|
+
# rs = tlv.read(2040)
|
283
|
+
# puts "\n***** START *****"
|
284
|
+
# puts rs
|
285
|
+
# puts "****** END ******"
|
286
|
+
#
|
287
|
+
# raise "#{rootLv} not found" if !rlv
|
288
|
+
#
|
289
|
+
# puts "\n*** Mounting #{rootLv}"
|
290
|
+
# rfs = MiqFS.getFS(rlv)
|
291
|
+
# puts "\tFS Type: #{rfs.fsType}"
|
292
|
+
# puts "\t*** Root-level files and directories:"
|
293
|
+
# rfs.dirForeach("/") { |de| puts "\t\t#{de}" }
|
294
|
+
|
295
|
+
puts "\n***** Detected Guest OSs:"
|
296
|
+
raise "No OSs detected" if vm.rootTrees.length == 0
|
297
|
+
vm.rootTrees.each do |rt|
|
298
|
+
puts "\t#{rt.guestOS}"
|
299
|
+
if rt.guestOS == "Linux"
|
300
|
+
puts "\n\t\t*** /etc/fstab contents:"
|
301
|
+
rt.fileOpen("/etc/fstab", &:read).each_line do |fstl|
|
302
|
+
next if fstl =~ /^#.*$/
|
303
|
+
puts "\t\t\t#{fstl}"
|
304
|
+
end
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
vm.rootTrees.each do |rt|
|
309
|
+
if rt.guestOS == "Linux"
|
310
|
+
# tdirArr = [ "/", "/boot", "/var/www/miq", "/var/www/miq/vmdb/log", "/var/lib/mysql" ]
|
311
|
+
tdirArr = ["/", "/boot", "/etc/init.d", "/etc/rc.d/init.d", "/etc/rc.d/rc0.d"]
|
312
|
+
|
313
|
+
tdirArr.each do |tdir|
|
314
|
+
begin
|
315
|
+
puts "\n*** Listing #{tdir} directory (1):"
|
316
|
+
rt.dirForeach(tdir) { |de| puts "\t\t#{de}" }
|
317
|
+
puts "*** end"
|
318
|
+
|
319
|
+
puts "\n*** Listing #{tdir} directory (2):"
|
320
|
+
rt.chdir(tdir)
|
321
|
+
rt.dirForeach { |de| puts "\t\t#{de}" }
|
322
|
+
puts "*** end"
|
323
|
+
rescue => err
|
324
|
+
puts "*** #{err}"
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
# lf = rt.fileOpen("/etc/rc0.d/S01halt")
|
329
|
+
# puts "\n*** Contents of /etc/rc0.d/S01halt:"
|
330
|
+
# puts lf.read
|
331
|
+
# puts "*** END"
|
332
|
+
# lf.close
|
333
|
+
#
|
334
|
+
# lfn = "/etc/rc0.d/S01halt"
|
335
|
+
# puts "Is #{lfn} a symbolic link? #{rt.fileSymLink?(lfn)}"
|
336
|
+
# puts "#{lfn} => #{rt.getLinkPath(lfn)}"
|
337
|
+
else # Windows
|
338
|
+
tdirArr = ["c:/", "e:/", "e:/testE2", "f:/"]
|
339
|
+
|
340
|
+
tdirArr.each do |tdir|
|
341
|
+
puts "\n*** Listing #{tdir} directory (1):"
|
342
|
+
rt.dirForeach(tdir) { |de| puts "\t\t#{de}" }
|
343
|
+
puts "*** end"
|
344
|
+
|
345
|
+
puts "\n*** Listing #{tdir} directory (2):"
|
346
|
+
rt.chdir(tdir)
|
347
|
+
rt.dirForeach { |de| puts "\t\t#{de}" }
|
348
|
+
puts "*** end"
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
vm.unmount
|
354
|
+
puts "...done"
|
355
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'MiqVm/MiqVm'
|
2
|
+
require 'disk/modules/AzureBlobDisk'
|
3
|
+
require 'disk/modules/miq_disk_cache'
|
4
|
+
|
5
|
+
class MiqAzureVm < MiqVm
|
6
|
+
def initialize(azure_handle, args)
|
7
|
+
@azure_handle = azure_handle
|
8
|
+
@uri = nil
|
9
|
+
|
10
|
+
raise ArgumentError, "MiqAzureVm: missing required arg :name" unless (@name = args[:name])
|
11
|
+
|
12
|
+
if args[:image_uri]
|
13
|
+
@uri = args[:image_uri]
|
14
|
+
elsif args[:resource_group] && args[:name]
|
15
|
+
vm_obj = vm_svc.get(@name, args[:resource_group])
|
16
|
+
@uri = vm_obj.properties.storage_profile.os_disk.vhd.uri
|
17
|
+
else
|
18
|
+
raise ArgumentError, "MiqAzureVm: missing required args: :image_uri or :resource_group"
|
19
|
+
end
|
20
|
+
|
21
|
+
super(getCfg)
|
22
|
+
end
|
23
|
+
|
24
|
+
def getCfg
|
25
|
+
cfg_hash = {}
|
26
|
+
cfg_hash['displayname'] = @name
|
27
|
+
|
28
|
+
$log.debug "MiqAzureVm#getCfg: disk = #{@uri}"
|
29
|
+
|
30
|
+
tag = "scsi0:0"
|
31
|
+
cfg_hash["#{tag}.present"] = "true"
|
32
|
+
cfg_hash["#{tag}.devicetype"] = "disk"
|
33
|
+
cfg_hash["#{tag}.filename"] = @uri
|
34
|
+
|
35
|
+
cfg_hash
|
36
|
+
end
|
37
|
+
|
38
|
+
def openDisks(diskFiles)
|
39
|
+
p_volumes = []
|
40
|
+
|
41
|
+
$log.debug "openDisks: no disk files supplied." unless diskFiles
|
42
|
+
|
43
|
+
#
|
44
|
+
# Build a list of the VM's physical volumes.
|
45
|
+
#
|
46
|
+
diskFiles.each do |dtag, df|
|
47
|
+
$log.debug "openDisks: processing disk file (#{dtag}): #{df}"
|
48
|
+
dInfo = OpenStruct.new
|
49
|
+
|
50
|
+
dInfo.fileName = df
|
51
|
+
dInfo.hardwareId = dtag
|
52
|
+
disk_format = @vmConfig.getHash["#{dtag}.format"]
|
53
|
+
dInfo.format = disk_format unless disk_format.blank?
|
54
|
+
|
55
|
+
mode = @vmConfig.getHash["#{dtag}.mode"]
|
56
|
+
|
57
|
+
dInfo.hardwareId = dtag
|
58
|
+
dInfo.rawDisk = true
|
59
|
+
|
60
|
+
begin
|
61
|
+
d = MiqDiskCache.new(AzureBlobDisk.new(sa_svc, @uri, dInfo), 100, 128)
|
62
|
+
rescue => err
|
63
|
+
$log.error "Couldn't open disk file: #{df}"
|
64
|
+
$log.error err.to_s
|
65
|
+
$log.debug err.backtrace.join("\n")
|
66
|
+
@diskInitErrors[df] = err.to_s
|
67
|
+
next
|
68
|
+
end
|
69
|
+
|
70
|
+
@wholeDisks << d
|
71
|
+
p = d.getPartitions
|
72
|
+
if p.empty?
|
73
|
+
#
|
74
|
+
# If the disk has no partitions, the whole disk can be a single volume.
|
75
|
+
#
|
76
|
+
p_volumes << d
|
77
|
+
else
|
78
|
+
#
|
79
|
+
# If the disk is partitioned, the partitions are physical volumes,
|
80
|
+
# but not the whild disk.
|
81
|
+
#
|
82
|
+
p_volumes.concat(p)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
p_volumes
|
87
|
+
end # def openDisks
|
88
|
+
|
89
|
+
def vm_svc
|
90
|
+
@vm_svc ||= Azure::Armrest::VirtualMachineService.new(@azure_handle)
|
91
|
+
end
|
92
|
+
|
93
|
+
def sa_svc
|
94
|
+
@sa_svc ||= Azure::Armrest::StorageAccountService.new(@azure_handle)
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'MiqVm/MiqVm'
|
2
|
+
require 'Scvmm/miq_scvmm_vm_ssa_info'
|
3
|
+
|
4
|
+
class MiqScvmmVm < MiqVm
|
5
|
+
def getCfg(_snap = nil)
|
6
|
+
cfg_hash = {}
|
7
|
+
# Collect disk information
|
8
|
+
vhds = @scvmm.vm_all_harddisks(@ost.miq_vm)
|
9
|
+
raise "Unable to get Hard Disk Info from VM #{@ost.miq_vm}." unless vhds.any?
|
10
|
+
vhds.each do |vhd_attributes|
|
11
|
+
vhd = vhd_attributes["Path"]
|
12
|
+
type = vhd_attributes["ControllerType"].downcase
|
13
|
+
number = vhd_attributes["ControllerNumber"]
|
14
|
+
index = vhd_attributes["ControllerLocation"]
|
15
|
+
tag = "#{type}#{number}:#{index}"
|
16
|
+
cfg_hash["#{tag}.present"] = "true"
|
17
|
+
cfg_hash["#{tag}.devicetype"] = "disk"
|
18
|
+
cfg_hash["#{tag}.filename"] = vhd
|
19
|
+
end
|
20
|
+
cfg_hash
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def init_disk_info(disk_info, disk_file)
|
26
|
+
disk_info.hyperv_connection = {}
|
27
|
+
disk_info.fileName = disk_file
|
28
|
+
disk_info.driveType = @scvmm.get_drivetype(disk_file)
|
29
|
+
disk_info.hyperv_connection[:host] = @ost.miq_hyperv[:host]
|
30
|
+
disk_info.hyperv_connection[:port] = @ost.miq_hyperv[:port]
|
31
|
+
if @ost.miq_hyperv[:domain].nil?
|
32
|
+
disk_info.hyperv_connection[:user] = @ost.miq_hyperv[:user]
|
33
|
+
else
|
34
|
+
disk_info.hyperv_connection[:user] = @ost.miq_hyperv[:domain] + "\\" + @ost.miq_hyperv[:user]
|
35
|
+
end
|
36
|
+
disk_info.hyperv_connection[:password] = @ost.miq_hyperv[:password]
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'manageiq-gems-pending'
|
2
|
+
require 'openssl' # Required for 'Digest' in camcorder (< Ruby 2.1)
|
3
|
+
require 'camcorder'
|
4
|
+
require 'log4r'
|
5
|
+
require 'MiqVm/MiqVm'
|
6
|
+
|
7
|
+
class ConsoleFormatter < Log4r::Formatter
|
8
|
+
def format(event)
|
9
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
toplog = Log4r::Logger.new 'toplog'
|
14
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::DEBUG, :formatter => ConsoleFormatter)
|
15
|
+
toplog.add 'err_console'
|
16
|
+
$log = toplog if $log.nil?
|
17
|
+
|
18
|
+
#
|
19
|
+
# Path to RAW disk image.
|
20
|
+
#
|
21
|
+
VIRTUAL_DISK_FILE = "path to raw disk image file"
|
22
|
+
|
23
|
+
commit = true
|
24
|
+
|
25
|
+
begin
|
26
|
+
recorder = Camcorder::Recorder.new("#{File.dirname(__FILE__)}/foo.yml")
|
27
|
+
Camcorder.default_recorder = recorder
|
28
|
+
Camcorder.intercept_constructor(MiqLargeFile::MiqLargeFileOther) do
|
29
|
+
methods_with_side_effects :seek, :read, :write
|
30
|
+
end
|
31
|
+
Camcorder.intercept_constructor(MiqLargeFile::MiqLargeFileStat)
|
32
|
+
|
33
|
+
recorder.start
|
34
|
+
|
35
|
+
hardware = "scsi0:0.present = \"TRUE\"\n"
|
36
|
+
hardware += "scsi0:0.filename = \"#{VIRTUAL_DISK_FILE}\"\n"
|
37
|
+
|
38
|
+
ost = OpenStruct.new
|
39
|
+
ost.rawDisk = true
|
40
|
+
|
41
|
+
miqVm = MiqVm.new(hardware, ost)
|
42
|
+
|
43
|
+
%w(accounts services software system).each do |cat|
|
44
|
+
xml = miqVm.extract(cat)
|
45
|
+
xml.write($stdout, 4)
|
46
|
+
end
|
47
|
+
rescue => err
|
48
|
+
puts err.to_s
|
49
|
+
puts err.backtrace.join("\n")
|
50
|
+
commit = false # don't commit recording on error
|
51
|
+
ensure
|
52
|
+
miqVm.unmount if miqVm
|
53
|
+
puts "...done"
|
54
|
+
if recorder && commit
|
55
|
+
puts
|
56
|
+
puts "camcorder: committing recording..."
|
57
|
+
recorder.commit
|
58
|
+
puts "done."
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'manageiq-gems-pending'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'log4r'
|
4
|
+
require 'MiqVm/MiqVm'
|
5
|
+
|
6
|
+
class ConsoleFormatter < Log4r::Formatter
|
7
|
+
def format(event)
|
8
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
$log = Log4r::Logger.new 'toplog'
|
13
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::DEBUG, :formatter => ConsoleFormatter)
|
14
|
+
$log.add 'err_console'
|
15
|
+
|
16
|
+
VHD = raise "Please define VHD"
|
17
|
+
diskid = "ide0:0"
|
18
|
+
hardware = "#{diskid}.present = \"TRUE\"\n"
|
19
|
+
hardware += "#{diskid}.filename = \"#{VHD}\"\n"
|
20
|
+
|
21
|
+
begin
|
22
|
+
ost = OpenStruct.new
|
23
|
+
ost.fileName = VHD
|
24
|
+
vm = MiqVm.new(hardware, ost)
|
25
|
+
|
26
|
+
vm.rootTrees.each do |fs|
|
27
|
+
puts "*** Found root tree for #{fs.guestOS}"
|
28
|
+
puts "Listing files in #{fs.pwd} directory:"
|
29
|
+
fs.dirEntries.each { |de| puts "\t#{de}" }
|
30
|
+
puts
|
31
|
+
end
|
32
|
+
|
33
|
+
CATEGORIES = %w(accounts services software system)
|
34
|
+
CATEGORIES.each do |cat|
|
35
|
+
puts "Extracting: #{cat}:"
|
36
|
+
xml = vm.extract(cat)
|
37
|
+
xml.write($stdout, 4)
|
38
|
+
puts
|
39
|
+
end
|
40
|
+
|
41
|
+
vm.unmount
|
42
|
+
rescue => err
|
43
|
+
puts err.to_s
|
44
|
+
puts err.backtrace.join("\n")
|
45
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'manageiq-gems-pending'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'log4r'
|
4
|
+
require 'MiqVm/MiqVm'
|
5
|
+
require 'VmwareWebService/MiqVim'
|
6
|
+
|
7
|
+
class ConsoleFormatter < Log4r::Formatter
|
8
|
+
def format(event)
|
9
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
toplog = Log4r::Logger.new 'toplog'
|
14
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::INFO, :formatter => ConsoleFormatter)
|
15
|
+
toplog.add 'err_console'
|
16
|
+
$vim_log = $log = toplog if $log.nil?
|
17
|
+
|
18
|
+
SERVER = raise "please define SERVER"
|
19
|
+
USERNAME = raise "please define USERNAME"
|
20
|
+
PASSWORD = raise "please define PASSWORD"
|
21
|
+
vim = MiqVim.new(SERVER, USERNAME, PASSWORD)
|
22
|
+
|
23
|
+
vimVm = nil
|
24
|
+
vm = nil
|
25
|
+
|
26
|
+
alignment = 64 * 1024 # Check for alignment on a 64kB boundary
|
27
|
+
|
28
|
+
begin
|
29
|
+
|
30
|
+
vim.virtualMachinesByMor.values.each do |vmo|
|
31
|
+
begin
|
32
|
+
vimVm = vim.getVimVmByMor(vmo['MOR'])
|
33
|
+
|
34
|
+
vmx = vimVm.dsPath
|
35
|
+
puts "VM: #{vimVm.name}, VMX = #{vmx}"
|
36
|
+
|
37
|
+
if vimVm.poweredOn?
|
38
|
+
puts "\tSkipping running VM"
|
39
|
+
puts
|
40
|
+
next
|
41
|
+
end
|
42
|
+
|
43
|
+
ost = OpenStruct.new
|
44
|
+
ost.miqVim = vim
|
45
|
+
|
46
|
+
#
|
47
|
+
# Given an MiqVm object, we check to see if its partitions are aligned on a given boundary.
|
48
|
+
# This boundary is usually based on the logical block size of the underlying storage array;
|
49
|
+
# in this example, 64kB.
|
50
|
+
#
|
51
|
+
vm = MiqVm.new(vmx, ost)
|
52
|
+
|
53
|
+
#
|
54
|
+
# We check all of physical volumes of the VM. This Includes visible and hidden volumes, but excludes logical volumes.
|
55
|
+
# The alignment of hidden volumes affects the performance of the logical volumes that are based on them.
|
56
|
+
#
|
57
|
+
vm.volumeManager.allPhysicalVolumes.each do |pv|
|
58
|
+
vmdk = pv.dInfo.filename || pv.dInfo.vixDiskInfo[:fileName]
|
59
|
+
aligned = pv.startByteAddr % alignment == 0 ? "Yes" : "No"
|
60
|
+
puts "\t#{vmdk}, Partition: #{pv.partNum}, Partition type: #{pv.partType}, LBA: #{pv.lbaStart}, offset: #{pv.startByteAddr}, aligned: #{aligned}"
|
61
|
+
end
|
62
|
+
|
63
|
+
puts
|
64
|
+
ensure
|
65
|
+
vimVm.release if vimVm
|
66
|
+
vm.unmount if vm
|
67
|
+
vimVm = vm = nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
rescue => err
|
72
|
+
puts err.to_s
|
73
|
+
puts err.backtrace.join("\n")
|
74
|
+
ensure
|
75
|
+
vim.disconnect if vim
|
76
|
+
end
|