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,65 @@
|
|
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
|
+
SERVER = raise "please define SERVER"
|
14
|
+
PORT = 443
|
15
|
+
DOMAIN = raise "please define DOMAIN"
|
16
|
+
USERNAME = raise "please define USERNAME"
|
17
|
+
PASSWORD = raise "please define PASSWORD"
|
18
|
+
TARGET_VM = raise "please define TARGET_VM"
|
19
|
+
|
20
|
+
toplog = Log4r::Logger.new 'toplog'
|
21
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::INFO, :formatter => ConsoleFormatter)
|
22
|
+
toplog.add 'err_console'
|
23
|
+
$vim_log = $log = toplog if $log.nil?
|
24
|
+
|
25
|
+
vim = MiqVim.new(SERVER, USERNAME, PASSWORD)
|
26
|
+
|
27
|
+
begin
|
28
|
+
vim_vm = vim.getVimVmByFilter("config.name" => TARGET_VM)
|
29
|
+
|
30
|
+
unless vim_vm
|
31
|
+
puts "VM: #{TARGET_VM} not found"
|
32
|
+
vim.disconnect
|
33
|
+
exit
|
34
|
+
end
|
35
|
+
|
36
|
+
vmx = vim_vm.dsPath.to_s
|
37
|
+
puts "Found target VM: #{TARGET_VM}, VMX = #{vmx}"
|
38
|
+
|
39
|
+
ost = OpenStruct.new
|
40
|
+
ost.miqVim = vim
|
41
|
+
|
42
|
+
vm = MiqVm.new(vmx, ost)
|
43
|
+
|
44
|
+
vm.rootTrees.each do |fs|
|
45
|
+
puts "*** Found root tree for #{fs.guestOS}"
|
46
|
+
puts "Listing files in #{fs.pwd} directory:"
|
47
|
+
fs.dirEntries.each { |de| puts "\t#{de}" }
|
48
|
+
puts
|
49
|
+
end
|
50
|
+
|
51
|
+
CATEGORIES = %w(accounts services software system)
|
52
|
+
CATEGORIES.each do |cat|
|
53
|
+
puts "Extracting: #{cat}:"
|
54
|
+
xml = vm.extract(cat)
|
55
|
+
xml.write($stdout, 4)
|
56
|
+
puts
|
57
|
+
end
|
58
|
+
|
59
|
+
vm.unmount
|
60
|
+
|
61
|
+
vim.disconnect
|
62
|
+
rescue => err
|
63
|
+
puts err.to_s
|
64
|
+
puts err.backtrace.join("\n")
|
65
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#
|
2
|
+
# This test assumes the NFS share of the storage in question is mounted on the appliance.
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'manageiq-gems-pending'
|
6
|
+
require 'log4r'
|
7
|
+
require 'ostruct'
|
8
|
+
require 'MiqVm/MiqVm'
|
9
|
+
|
10
|
+
class ConsoleFormatter < Log4r::Formatter
|
11
|
+
def format(event)
|
12
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
toplog = Log4r::Logger.new 'toplog'
|
17
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::DEBUG, :formatter => ConsoleFormatter)
|
18
|
+
toplog.add 'err_console'
|
19
|
+
$log = toplog if $log.nil?
|
20
|
+
|
21
|
+
DDIR = "/mnt/vm/7fd0b9b2-e362-11e2-97b7-001a4aa8fcea/rhev/data-center/773f2ddf-7765-42fc-85d6-673b718541cd/aa7e70e5-40d0-43e2-a605-92ce6ba652a8/images/19449cf8-1905-4b8a-b45a-e845a693a3df"
|
22
|
+
BASE_FILE = "#{DDIR}/903306be-f676-4005-a813-daa6d7a6c33f"
|
23
|
+
REDO_FILE = "#{DDIR}/9e7075c5-a014-4ddf-a168-a33723d0c3cd"
|
24
|
+
|
25
|
+
# DISK_FILE = BASE_FILE
|
26
|
+
DISK_FILE = REDO_FILE
|
27
|
+
|
28
|
+
diskid = "scsi0:0"
|
29
|
+
hardware = "#{diskid}.present = \"TRUE\"\n"
|
30
|
+
hardware += "#{diskid}.filename = \"#{DISK_FILE}\"\n"
|
31
|
+
|
32
|
+
begin
|
33
|
+
puts
|
34
|
+
puts `file #{DISK_FILE}`
|
35
|
+
puts
|
36
|
+
|
37
|
+
ost = OpenStruct.new
|
38
|
+
ost.fileName = DISK_FILE
|
39
|
+
|
40
|
+
vm = MiqVm.new(hardware, ost)
|
41
|
+
|
42
|
+
raise "No filesystems detected." if vm.rootTrees.empty?
|
43
|
+
|
44
|
+
puts "\nChecking for file systems..."
|
45
|
+
vm.rootTrees.each do |fs|
|
46
|
+
puts "*** Found root tree for #{fs.guestOS}"
|
47
|
+
puts "Listing files in #{fs.pwd} directory:"
|
48
|
+
fs.dirEntries.each { |de| puts "\t#{de}" }
|
49
|
+
puts
|
50
|
+
end
|
51
|
+
|
52
|
+
["services", "software", "system", "vmconfig"].each do |c|
|
53
|
+
puts
|
54
|
+
puts "Extracting #{c}"
|
55
|
+
vm.extract(c) # .to_xml.write($stdout, 4)
|
56
|
+
end
|
57
|
+
rescue => err
|
58
|
+
$log.error err.to_s
|
59
|
+
$log.error err.backtrace.join("\n")
|
60
|
+
ensure
|
61
|
+
# vm.unmount if vm
|
62
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
#
|
2
|
+
# This test assumes the NFS share of the storage in question is mounted on the appliance.
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'manageiq-gems-pending'
|
6
|
+
require 'log4r'
|
7
|
+
require 'ostruct'
|
8
|
+
require 'MiqVm/MiqVm'
|
9
|
+
|
10
|
+
class ConsoleFormatter < Log4r::Formatter
|
11
|
+
def format(event)
|
12
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
toplog = Log4r::Logger.new 'toplog'
|
17
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::DEBUG, :formatter => ConsoleFormatter)
|
18
|
+
toplog.add 'err_console'
|
19
|
+
$log = toplog if $log.nil?
|
20
|
+
|
21
|
+
DDIR = "/mnt/vm/7fd0b9b2-e362-11e2-97b7-001a4aa8fcea/rhev/data-center/773f2ddf-7765-42fc-85d6-673b718541cd/aa7e70e5-40d0-43e2-a605-92ce6ba652a8/images/19449cf8-1905-4b8a-b45a-e845a693a3df"
|
22
|
+
BASE_FILE = "#{DDIR}/903306be-f676-4005-a813-daa6d7a6c33f"
|
23
|
+
REDO_FILE = "#{DDIR}/9e7075c5-a014-4ddf-a168-a33723d0c3cd"
|
24
|
+
|
25
|
+
# DISK_FILE = BASE_FILE
|
26
|
+
DISK_FILE = REDO_FILE
|
27
|
+
|
28
|
+
diskid = "scsi0:0"
|
29
|
+
hardware = "#{diskid}.present = \"TRUE\"\n"
|
30
|
+
hardware += "#{diskid}.filename = \"#{DISK_FILE}\"\n"
|
31
|
+
|
32
|
+
begin
|
33
|
+
puts
|
34
|
+
puts `file #{DISK_FILE}`
|
35
|
+
puts
|
36
|
+
|
37
|
+
ost = OpenStruct.new
|
38
|
+
ost.fileName = DISK_FILE
|
39
|
+
|
40
|
+
unless (disk = MiqDisk.getDisk(ost))
|
41
|
+
puts "Failed to open disk"
|
42
|
+
exit(1)
|
43
|
+
end
|
44
|
+
|
45
|
+
unless (parts = disk.getPartitions)
|
46
|
+
puts "No partitions detected"
|
47
|
+
exit(1)
|
48
|
+
end
|
49
|
+
|
50
|
+
unless (part = parts.detect { |p| p.partNum == 1 })
|
51
|
+
puts "Could not find partition 1"
|
52
|
+
exit(1)
|
53
|
+
end
|
54
|
+
|
55
|
+
unless (mfs = MiqFS.getFS(part))
|
56
|
+
puts "No filesystem detected"
|
57
|
+
exit(1)
|
58
|
+
end
|
59
|
+
|
60
|
+
puts "Found #{mfs.fsType} filesystem"
|
61
|
+
rescue => err
|
62
|
+
$log.error err.to_s
|
63
|
+
$log.error err.backtrace.join("\n")
|
64
|
+
ensure
|
65
|
+
# vm.unmount if vm
|
66
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'manageiq-gems-pending'
|
2
|
+
require 'log4r'
|
3
|
+
require 'ostruct'
|
4
|
+
require 'MiqVm/MiqVm'
|
5
|
+
require 'ovirt'
|
6
|
+
require 'manageiq/providers/ovirt/legacy/inventory'
|
7
|
+
Ovirt.logger = $rhevm_log if $rhevm_log
|
8
|
+
|
9
|
+
RHEVM_SERVER = raise "please define RHEVM_SERVER"
|
10
|
+
RHEVM_PORT = 443
|
11
|
+
RHEVM_DOMAIN = raise "please define RHEVM_DOMAIN"
|
12
|
+
RHEVM_USERNAME = raise "please define RHEVM_USERNAME"
|
13
|
+
RHEVM_PASSWORD = raise "please define RHEVM_PASSWORD"
|
14
|
+
VM_NAME = raise "please define VM_NAME"
|
15
|
+
|
16
|
+
class ConsoleFormatter < Log4r::Formatter
|
17
|
+
def format(event)
|
18
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect) + "\n"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
toplog = Log4r::Logger.new 'toplog'
|
23
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::DEBUG, :formatter => ConsoleFormatter)
|
24
|
+
toplog.add 'err_console'
|
25
|
+
$log = toplog if $log.nil?
|
26
|
+
|
27
|
+
begin
|
28
|
+
|
29
|
+
$rhevm = ManageIQ::Providers::Ovirt::Legacy::Inventory.new(
|
30
|
+
:server => RHEVM_SERVER,
|
31
|
+
:port => RHEVM_PORT,
|
32
|
+
:domain => RHEVM_DOMAIN,
|
33
|
+
:username => RHEVM_USERNAME,
|
34
|
+
:password => RHEVM_PASSWORD,
|
35
|
+
:verify_ssl => false
|
36
|
+
)
|
37
|
+
|
38
|
+
puts "Attempting to scan VM: #{VM_NAME}"
|
39
|
+
|
40
|
+
unless (rvm = Ovirt::Vm.find_by_name($rhevm.service, VM_NAME))
|
41
|
+
raise "Could not find VM: #{VM_NAME}"
|
42
|
+
end
|
43
|
+
|
44
|
+
ost = OpenStruct.new
|
45
|
+
ost.miqRhevm = $rhevm
|
46
|
+
ost.openParent = false
|
47
|
+
|
48
|
+
vm = MiqVm.new(rvm.api_endpoint, ost)
|
49
|
+
|
50
|
+
puts "\nChecking for file systems..."
|
51
|
+
vm.rootTrees.each do |fs|
|
52
|
+
puts "*** Found root tree for #{fs.guestOS}"
|
53
|
+
puts "Listing files in #{fs.pwd} directory:"
|
54
|
+
fs.dirEntries.each { |de| puts "\t#{de}" }
|
55
|
+
puts
|
56
|
+
end
|
57
|
+
|
58
|
+
["services", "software", "system", "vmconfig"].each do |c|
|
59
|
+
puts
|
60
|
+
puts "Extracting #{c}"
|
61
|
+
vm.extract(c) # .to_xml.write($stdout, 4)
|
62
|
+
end
|
63
|
+
|
64
|
+
vm.unmount
|
65
|
+
puts "...done"
|
66
|
+
|
67
|
+
rescue => err
|
68
|
+
$log.error err.to_s
|
69
|
+
$log.error err.backtrace.join("\n")
|
70
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module MiqOpenStackCommon
|
2
|
+
def disk_format_glance_v1(snapshot_image_id)
|
3
|
+
image_service.get_image(snapshot_image_id).headers['X-Image-Meta-Disk_format']
|
4
|
+
end
|
5
|
+
|
6
|
+
def disk_format_glance_v2(snapshot_image_id)
|
7
|
+
image_service.images.get(snapshot_image_id).disk_format
|
8
|
+
end
|
9
|
+
|
10
|
+
def disk_format(snapshot_image_id)
|
11
|
+
send("disk_format_glance_#{image_service.version}", snapshot_image_id)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_image_file_glance_v2(image_id)
|
15
|
+
log_prefix = "#{self.class.name}##{__method__}"
|
16
|
+
|
17
|
+
image = image_service.images.get(image_id)
|
18
|
+
raise "Image #{image_id} not found" unless image
|
19
|
+
$log.debug "#{log_prefix}: image = #{image.class.name}"
|
20
|
+
|
21
|
+
iname = image.name
|
22
|
+
isize = image.size.to_i
|
23
|
+
$log.debug "#{log_prefix}: iname = #{iname}"
|
24
|
+
$log.debug "#{log_prefix}: isize = #{isize}"
|
25
|
+
|
26
|
+
raise "Image: #{iname} (#{image_id}) is empty" unless isize > 0
|
27
|
+
|
28
|
+
tot = 0
|
29
|
+
tf = MiqTempfile.new(iname, :encoding => 'ascii-8bit')
|
30
|
+
$log.debug "#{log_prefix}: saving image to #{tf.path}"
|
31
|
+
response_block = lambda do |buf, _rem, sz|
|
32
|
+
tf.write buf
|
33
|
+
tot += buf.length
|
34
|
+
$log.debug "#{log_prefix}: response_block: #{tot} bytes written of #{sz}"
|
35
|
+
end
|
36
|
+
|
37
|
+
_rv = image.download_data(:response_block => response_block)
|
38
|
+
tf.close
|
39
|
+
|
40
|
+
# TODO(lsmola) Fog download_data doesn't support header returned, it returns body by hard. We need to wrap the
|
41
|
+
# result load_response like in Fog::OpenStack::Collection. The header will be accessible as rv.response.headers
|
42
|
+
# checksum = rv.headers['Content-Md5']
|
43
|
+
# $log.debug "#{log_prefix}: Checksum: #{checksum}" if $log.debug?
|
44
|
+
$log.debug "#{log_prefix}: #{`ls -l #{tf.path}`}" if $log.debug?
|
45
|
+
|
46
|
+
if tf.size != isize
|
47
|
+
$log.error "#{log_prefix}: Error downloading image #{iname}"
|
48
|
+
$log.error "#{log_prefix}: Downloaded size does not match image size #{tf.size} != #{isize}"
|
49
|
+
raise "Image download failed"
|
50
|
+
end
|
51
|
+
tf
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_image_file_glance_v1(image_id)
|
55
|
+
log_prefix = "#{self.class.name}##{__method__}"
|
56
|
+
|
57
|
+
image = image_service.get_image(image_id)
|
58
|
+
raise "Image #{image_id} not found" unless image
|
59
|
+
$log.debug "#{log_prefix}: image = #{image.class.name}"
|
60
|
+
|
61
|
+
iname = image.headers['X-Image-Meta-Name']
|
62
|
+
isize = image.headers['X-Image-Meta-Size'].to_i
|
63
|
+
$log.debug "#{log_prefix}: iname = #{iname}"
|
64
|
+
$log.debug "#{log_prefix}: isize = #{isize}"
|
65
|
+
|
66
|
+
raise "Image: #{iname} (#{image_id}) is empty" unless isize > 0
|
67
|
+
|
68
|
+
tot = 0
|
69
|
+
tf = MiqTempfile.new(iname, :encoding => 'ascii-8bit')
|
70
|
+
$log.debug "#{log_prefix}: saving image to #{tf.path}"
|
71
|
+
response_block = lambda do |buf, _rem, sz|
|
72
|
+
tf.write buf
|
73
|
+
tot += buf.length
|
74
|
+
$log.debug "#{log_prefix}: response_block: #{tot} bytes written of #{sz}"
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# We're calling the low-level request method here, because
|
79
|
+
# the Fog "get image" methods don't currently support passing
|
80
|
+
# a response block. We should attempt to remedy this in Fog
|
81
|
+
# upstream and modify this code accordingly.
|
82
|
+
#
|
83
|
+
rv = image_service.request(
|
84
|
+
:expects => [200, 204],
|
85
|
+
:method => 'GET',
|
86
|
+
:path => "images/#{image_id}",
|
87
|
+
:response_block => response_block
|
88
|
+
)
|
89
|
+
|
90
|
+
tf.close
|
91
|
+
|
92
|
+
checksum = rv.headers['X-Image-Meta-Checksum']
|
93
|
+
$log.debug "#{log_prefix}: Checksum: #{checksum}" if $log.debug?
|
94
|
+
$log.debug "#{log_prefix}: #{`ls -l #{tf.path}`}" if $log.debug?
|
95
|
+
|
96
|
+
if tf.size != isize
|
97
|
+
$log.error "#{log_prefix}: Error downloading image #{iname}"
|
98
|
+
$log.error "#{log_prefix}: Downloaded size does not match image size #{tf.size} != #{isize}"
|
99
|
+
raise "Image download failed"
|
100
|
+
end
|
101
|
+
tf
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_image_file_common(image_id)
|
105
|
+
send("get_image_file_glance_#{image_service.version}", image_id)
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'util/miq_tempfile'
|
2
|
+
require_relative '../../MiqVm/MiqVm'
|
3
|
+
require_relative 'MiqOpenStackCommon'
|
4
|
+
|
5
|
+
class MiqOpenStackImage
|
6
|
+
include MiqOpenStackCommon
|
7
|
+
|
8
|
+
attr_reader :vmConfigFile
|
9
|
+
|
10
|
+
SUPPORTED_METHODS = [:rootTrees, :extract, :diskInitErrors, :vmConfig, :volumeManager]
|
11
|
+
|
12
|
+
def initialize(image_id, args)
|
13
|
+
@image_id = image_id
|
14
|
+
@os_handle = args[:os_handle]
|
15
|
+
@args = args
|
16
|
+
@vmConfigFile = image_id
|
17
|
+
|
18
|
+
raise ArgumentError, "#{self.class.name}: required arg os_handle missing" unless @os_handle
|
19
|
+
@fog_image = @os_handle.detect_image_service
|
20
|
+
raise ArgumentError, "#{self.class.name}: required arg fog_image missing" unless @fog_image
|
21
|
+
end
|
22
|
+
|
23
|
+
def image_service
|
24
|
+
@image_service ||= @os_handle.detect_image_service
|
25
|
+
end
|
26
|
+
|
27
|
+
def unmount
|
28
|
+
return unless @miq_vm
|
29
|
+
@miq_vm.unmount
|
30
|
+
@temp_image_file.unlink
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def miq_vm
|
36
|
+
@miq_vm ||= begin
|
37
|
+
@temp_image_file = get_image_file
|
38
|
+
hardware = "scsi0:0.present = \"TRUE\"\n"
|
39
|
+
hardware += "scsi0:0.filename = \"#{@temp_image_file.path}\"\n"
|
40
|
+
|
41
|
+
diskFormat = disk_format(@image_id)
|
42
|
+
$log.debug "diskFormat = #{diskFormat}"
|
43
|
+
|
44
|
+
ost = OpenStruct.new
|
45
|
+
ost.rawDisk = diskFormat == "raw"
|
46
|
+
MiqVm.new(hardware, ost)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_image_file
|
51
|
+
get_image_file_common(@image_id)
|
52
|
+
end
|
53
|
+
|
54
|
+
def method_missing(sym, *args)
|
55
|
+
super unless SUPPORTED_METHODS.include? sym
|
56
|
+
return miq_vm.send(sym) if args.empty?
|
57
|
+
miq_vm.send(sym, args)
|
58
|
+
end
|
59
|
+
|
60
|
+
def respond_to_missing?(sym, *args)
|
61
|
+
if SUPPORTED_METHODS.include?(sym)
|
62
|
+
true
|
63
|
+
else
|
64
|
+
super
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'util/miq_tempfile'
|
2
|
+
require_relative '../../MiqVm/MiqVm'
|
3
|
+
require_relative 'MiqOpenStackCommon'
|
4
|
+
|
5
|
+
#
|
6
|
+
# TODO: Create common base class for MiqOpenStackInstance and MiqOpenStackImage
|
7
|
+
# and factor out common code. Also, refactor MiqVm so it can be a proper super class.
|
8
|
+
#
|
9
|
+
|
10
|
+
class MiqOpenStackInstance
|
11
|
+
include MiqOpenStackCommon
|
12
|
+
|
13
|
+
attr_reader :vmConfigFile
|
14
|
+
|
15
|
+
SUPPORTED_METHODS = [:rootTrees, :extract, :diskInitErrors, :vmConfig, :volumeManager]
|
16
|
+
|
17
|
+
def initialize(instance_id, openstack_handle)
|
18
|
+
@instance_id = instance_id
|
19
|
+
@openstack_handle = openstack_handle
|
20
|
+
@vmConfigFile = instance_id
|
21
|
+
end
|
22
|
+
|
23
|
+
def compute_service
|
24
|
+
@compute_service ||= @openstack_handle.compute_service
|
25
|
+
end
|
26
|
+
|
27
|
+
def image_service
|
28
|
+
@image_service ||= @openstack_handle.detect_image_service
|
29
|
+
end
|
30
|
+
|
31
|
+
def instance
|
32
|
+
@instance ||= compute_service.servers.get(@instance_id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def snapshot_metadata
|
36
|
+
@snapshot_metadata ||= instance.metadata.length > 0 && instance.metadata.get(:miq_snapshot)
|
37
|
+
end
|
38
|
+
|
39
|
+
def snapshot_image_id
|
40
|
+
@snapshot_image_id ||= snapshot_metadata && snapshot_metadata.value
|
41
|
+
end
|
42
|
+
|
43
|
+
def unmount
|
44
|
+
return unless @miq_vm
|
45
|
+
@miq_vm.unmount
|
46
|
+
@temp_image_file.unlink
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_snapshot(options = {})
|
50
|
+
log_prefix = "MIQ(#{self.class.name}##{__method__}) instance_id=[#{@instance_id}]"
|
51
|
+
|
52
|
+
$log.debug "#{log_prefix}: Snapshotting instance: #{instance.name}..."
|
53
|
+
|
54
|
+
snapshot = compute_service.create_image(instance.id, options[:name], :description => options[:desc])
|
55
|
+
|
56
|
+
$log.debug "#{log_prefix}: #{snapshot.status}"
|
57
|
+
$log.debug "#{log_prefix}: snapshot creation complete"
|
58
|
+
|
59
|
+
return snapshot.body["image"]
|
60
|
+
rescue => err
|
61
|
+
$log.error "#{log_prefix}, error: #{err}"
|
62
|
+
$log.debug err.backtrace.join("\n") if $log.debug?
|
63
|
+
raise
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete_snapshot(image_id)
|
67
|
+
delete_evm_snapshot(image_id)
|
68
|
+
end
|
69
|
+
|
70
|
+
def create_evm_snapshot(options = {})
|
71
|
+
log_prefix = "MIQ(#{self.class.name}##{__method__}) instance_id=[#{@instance_id}]"
|
72
|
+
|
73
|
+
miq_snapshot = nil
|
74
|
+
if snapshot_image_id
|
75
|
+
$log.debug "#{log_prefix}: Found pointer to existing snapshot: #{snapshot_image_id}"
|
76
|
+
miq_snapshot = begin
|
77
|
+
image_service.images.get(snapshot_image_id)
|
78
|
+
rescue => err
|
79
|
+
$log.debug "#{log_prefix}: #{err}"
|
80
|
+
$log.debug err.backtrace.join("\n")
|
81
|
+
nil
|
82
|
+
end
|
83
|
+
|
84
|
+
if miq_snapshot
|
85
|
+
raise "Already has an EVM snapshot: #{miq_snapshot.name}, with id: #{miq_snapshot.id}"
|
86
|
+
else
|
87
|
+
$log.debug "#{log_prefix}: Snapshot does not exist, deleting metadata"
|
88
|
+
snapshot_metadata.destroy
|
89
|
+
end
|
90
|
+
else
|
91
|
+
$log.debug "#{log_prefix}: No existing snapshot detected for: #{instance.name}"
|
92
|
+
end
|
93
|
+
|
94
|
+
$log.debug "#{log_prefix}: Snapshotting instance: #{instance.name}..."
|
95
|
+
# TODO: pass in snapshot name.
|
96
|
+
rv = compute_service.create_image(instance.id, "EvmSnapshot", :description => options[:desc])
|
97
|
+
rv.body['image'][:service] = image_service
|
98
|
+
|
99
|
+
miq_snapshot = image_service.images.get(rv.body['image']['id'])
|
100
|
+
|
101
|
+
until miq_snapshot.status.upcase == "ACTIVE"
|
102
|
+
$log.debug "#{log_prefix}: #{miq_snapshot.status}"
|
103
|
+
sleep 1
|
104
|
+
# TODO(lsmola) identity is missing in Glance V2 object, fix it in Fog, then miq_snapshot.reload will work
|
105
|
+
# miq_snapshot.reload
|
106
|
+
miq_snapshot = image_service.images.get(miq_snapshot.id)
|
107
|
+
end
|
108
|
+
$log.debug "#{log_prefix}: #{miq_snapshot.status}"
|
109
|
+
$log.debug "#{log_prefix}: EVM snapshot creation complete"
|
110
|
+
|
111
|
+
instance.metadata.update(:miq_snapshot => miq_snapshot.id)
|
112
|
+
return miq_snapshot
|
113
|
+
rescue => err
|
114
|
+
$log.error "#{log_prefix}, error: #{err}"
|
115
|
+
$log.debug err.backtrace.join("\n") if $log.debug?
|
116
|
+
raise
|
117
|
+
end
|
118
|
+
|
119
|
+
def delete_evm_snapshot(image_id)
|
120
|
+
log_prefix = "MIQ(#{self.class.name}##{__method__}) snapshot=[#{image_id}]"
|
121
|
+
|
122
|
+
snapshot = begin
|
123
|
+
image_service.images.get(image_id)
|
124
|
+
rescue => err
|
125
|
+
$log.debug "#{log_prefix}: #{err}"
|
126
|
+
$log.debug err.backtrace.join("\n")
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
|
130
|
+
if snapshot
|
131
|
+
begin
|
132
|
+
if snapshot_image_id != image_id
|
133
|
+
$log.warn "#{log_prefix}: pointer from instance doesn't match #{snapshot_image_id}"
|
134
|
+
end
|
135
|
+
$log.info "#{log_prefix}: deleting snapshot image"
|
136
|
+
snapshot.destroy
|
137
|
+
snapshot_metadata.destroy
|
138
|
+
rescue => err
|
139
|
+
$log.debug "#{log_prefix}: #{err}"
|
140
|
+
$log.debug err.backtrace.join("\n") if $log.debug?
|
141
|
+
end
|
142
|
+
else
|
143
|
+
$log.info "#{log_prefix}: no longer exists, deleting references"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
def miq_vm
|
150
|
+
raise "Instance: #{instance.id}, does not have snapshot reference." unless snapshot_image_id
|
151
|
+
@miq_vm ||= begin
|
152
|
+
@temp_image_file = get_image_file(snapshot_image_id)
|
153
|
+
hardware = "scsi0:0.present = \"TRUE\"\n"
|
154
|
+
hardware += "scsi0:0.filename = \"#{@temp_image_file.path}\"\n"
|
155
|
+
|
156
|
+
diskFormat = disk_format(snapshot_image_id)
|
157
|
+
$log.debug "diskFormat = #{diskFormat}"
|
158
|
+
|
159
|
+
ost = OpenStruct.new
|
160
|
+
ost.rawDisk = diskFormat == "raw"
|
161
|
+
MiqVm.new(hardware, ost)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def get_image_file(image_id)
|
166
|
+
get_image_file_common(image_id)
|
167
|
+
end
|
168
|
+
|
169
|
+
def method_missing(sym, *args)
|
170
|
+
return super unless SUPPORTED_METHODS.include? sym
|
171
|
+
return miq_vm.send(sym) if args.empty?
|
172
|
+
miq_vm.send(sym, args)
|
173
|
+
end
|
174
|
+
|
175
|
+
def respond_to_missing?(sym, *args)
|
176
|
+
if SUPPORTED_METHODS.include?(sym)
|
177
|
+
true
|
178
|
+
else
|
179
|
+
super
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|