manageiq-smartstate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +4 -0
  4. data/.rspec_ci +4 -0
  5. data/.travis.yml +15 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE.txt +202 -0
  8. data/README.md +45 -0
  9. data/Rakefile +23 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/MiqContainerGroup/MiqContainerGroup.rb +31 -0
  13. data/lib/MiqVm/MiqLocalVm.rb +50 -0
  14. data/lib/MiqVm/MiqRhevmVm.rb +179 -0
  15. data/lib/MiqVm/MiqVm.rb +355 -0
  16. data/lib/MiqVm/miq_azure_vm.rb +96 -0
  17. data/lib/MiqVm/miq_scvmm_vm.rb +38 -0
  18. data/lib/MiqVm/test/camcorder_fleece_test.rb +60 -0
  19. data/lib/MiqVm/test/localVm.rb +45 -0
  20. data/lib/MiqVm/test/partitionAlignmentCheck.rb +76 -0
  21. data/lib/MiqVm/test/remoteVm.rb +65 -0
  22. data/lib/MiqVm/test/rhevmNfsTest.rb +62 -0
  23. data/lib/MiqVm/test/rhevmNfsTest2.rb +66 -0
  24. data/lib/MiqVm/test/rhevmTest.rb +70 -0
  25. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackCommon.rb +107 -0
  26. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackImage.rb +67 -0
  27. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackInstance.rb +182 -0
  28. data/lib/Scvmm/miq_hyperv_disk.rb +273 -0
  29. data/lib/Scvmm/miq_scvmm_parse_powershell.rb +75 -0
  30. data/lib/Scvmm/miq_scvmm_vm_ssa_info.rb +135 -0
  31. data/lib/Scvmm/test/miq_hyperv_disk_test.rb +33 -0
  32. data/lib/Scvmm/test/miq_scvmm_vm_ssa_info_test.rb +41 -0
  33. data/lib/VmLocalDiskAccess/test/localCfg.rb +97 -0
  34. data/lib/VolumeManager/LVM/logical_volume.rb +75 -0
  35. data/lib/VolumeManager/LVM/lv_segment.rb +43 -0
  36. data/lib/VolumeManager/LVM/lvm2disk.rb +158 -0
  37. data/lib/VolumeManager/LVM/parser.rb +138 -0
  38. data/lib/VolumeManager/LVM/physical_volume.rb +19 -0
  39. data/lib/VolumeManager/LVM/scanner.rb +156 -0
  40. data/lib/VolumeManager/LVM/thin/btree.rb +83 -0
  41. data/lib/VolumeManager/LVM/thin/constants.rb +86 -0
  42. data/lib/VolumeManager/LVM/thin/data_map.rb +44 -0
  43. data/lib/VolumeManager/LVM/thin/mapping_tree.rb +19 -0
  44. data/lib/VolumeManager/LVM/thin/space_maps.rb +58 -0
  45. data/lib/VolumeManager/LVM/thin/superblock.rb +136 -0
  46. data/lib/VolumeManager/LVM/thin.rb +6 -0
  47. data/lib/VolumeManager/LVM/volume_group.rb +97 -0
  48. data/lib/VolumeManager/LVM.rb +8 -0
  49. data/lib/VolumeManager/MiqLdm.rb +546 -0
  50. data/lib/VolumeManager/MiqLvm.rb +17 -0
  51. data/lib/VolumeManager/MiqNativeVolumeManager.rb +150 -0
  52. data/lib/VolumeManager/MiqVolumeManager.rb +277 -0
  53. data/lib/VolumeManager/VolMgrPlatformSupport.rb +18 -0
  54. data/lib/VolumeManager/VolMgrPlatformSupportLinux.rb +77 -0
  55. data/lib/VolumeManager/VolMgrPlatformSupportWin.rb +17 -0
  56. data/lib/VolumeManager/test/blockDevTest.rb +40 -0
  57. data/lib/VolumeManager/test/ldm.rb +97 -0
  58. data/lib/blackbox/VmBlackBox.rb +103 -0
  59. data/lib/blackbox/xmlStorage.rb +180 -0
  60. data/lib/db/MiqBdb/MiqBdb.rb +309 -0
  61. data/lib/db/MiqBdb/MiqBdbBtree.rb +219 -0
  62. data/lib/db/MiqBdb/MiqBdbHash.rb +199 -0
  63. data/lib/db/MiqBdb/MiqBdbPage.rb +159 -0
  64. data/lib/db/MiqBdb/MiqBdbUtil.rb +18 -0
  65. data/lib/db/MiqSqlite/MiqSqlite3.rb +330 -0
  66. data/lib/db/MiqSqlite/MiqSqlite3Cell.rb +167 -0
  67. data/lib/db/MiqSqlite/MiqSqlite3Page.rb +151 -0
  68. data/lib/db/MiqSqlite/MiqSqlite3Table.rb +124 -0
  69. data/lib/db/MiqSqlite/MiqSqlite3Util.rb +32 -0
  70. data/lib/disk/DiskProbe.rb +68 -0
  71. data/lib/disk/MiqDisk.rb +317 -0
  72. data/lib/disk/camcorder_test.rb +90 -0
  73. data/lib/disk/dos_mbr.img +0 -0
  74. data/lib/disk/modules/AzureBlobDisk.rb +101 -0
  75. data/lib/disk/modules/LocalDevMod.rb +47 -0
  76. data/lib/disk/modules/LocalDevProbe.rb +6 -0
  77. data/lib/disk/modules/MSCommon.rb +352 -0
  78. data/lib/disk/modules/MSVSDiffDisk.rb +91 -0
  79. data/lib/disk/modules/MSVSDiskProbe.rb +61 -0
  80. data/lib/disk/modules/MSVSDynamicDisk.rb +42 -0
  81. data/lib/disk/modules/MSVSFixedDisk.rb +45 -0
  82. data/lib/disk/modules/MiqLargeFile.rb +63 -0
  83. data/lib/disk/modules/MiqLargeFileWin32.rb +107 -0
  84. data/lib/disk/modules/QcowDisk.rb +692 -0
  85. data/lib/disk/modules/QcowDiskProbe.rb +34 -0
  86. data/lib/disk/modules/RawBlockIO.rb +116 -0
  87. data/lib/disk/modules/RawDisk.rb +45 -0
  88. data/lib/disk/modules/RawDiskProbe.rb +7 -0
  89. data/lib/disk/modules/RhevmDescriptor.rb +167 -0
  90. data/lib/disk/modules/RhevmDiskProbe.rb +52 -0
  91. data/lib/disk/modules/VMWareCowdDisk.rb +207 -0
  92. data/lib/disk/modules/VMWareDescriptor.rb +214 -0
  93. data/lib/disk/modules/VMWareDiskProbe.rb +74 -0
  94. data/lib/disk/modules/VMWareSparseDisk.rb +189 -0
  95. data/lib/disk/modules/VhdxDisk.rb +625 -0
  96. data/lib/disk/modules/VhdxDiskProbe.rb +46 -0
  97. data/lib/disk/modules/VixDiskMod.rb +54 -0
  98. data/lib/disk/modules/VixDiskProbe.rb +6 -0
  99. data/lib/disk/modules/miq_disk_cache.rb +135 -0
  100. data/lib/disk/modules/miq_dummy_disk.rb +41 -0
  101. data/lib/disk/modules/vhdx_bat_entry.rb +10 -0
  102. data/lib/disk/test.rb +66 -0
  103. data/lib/fs/MetakitFS/MetakitFS.rb +530 -0
  104. data/lib/fs/MetakitFS/test/Makefile +14 -0
  105. data/lib/fs/MetakitFS/test/MkCollectFiles.rb +165 -0
  106. data/lib/fs/MetakitFS/test/MkSelectFiles.rb +30 -0
  107. data/lib/fs/MetakitFS/test/collect_files.yaml +70 -0
  108. data/lib/fs/MetakitFS/test/init.rb +3 -0
  109. data/lib/fs/MetakitFS/test/mk2vmdk.rb +64 -0
  110. data/lib/fs/MetakitFS/test/mk4test.c +92 -0
  111. data/lib/fs/MetakitFS/test/mkFsTest.rb +113 -0
  112. data/lib/fs/MetakitFS/test/proto.rb +97 -0
  113. data/lib/fs/MiqFS/FsProbe.rb +39 -0
  114. data/lib/fs/MiqFS/MiqFS.rb +515 -0
  115. data/lib/fs/MiqFS/modules/AUFSProbe.rb +26 -0
  116. data/lib/fs/MiqFS/modules/Ext3.rb +305 -0
  117. data/lib/fs/MiqFS/modules/Ext3Probe.rb +25 -0
  118. data/lib/fs/MiqFS/modules/Ext4.rb +304 -0
  119. data/lib/fs/MiqFS/modules/Ext4Probe.rb +25 -0
  120. data/lib/fs/MiqFS/modules/Fat32.rb +318 -0
  121. data/lib/fs/MiqFS/modules/Fat32Probe.rb +30 -0
  122. data/lib/fs/MiqFS/modules/HFSProbe.rb +18 -0
  123. data/lib/fs/MiqFS/modules/Iso9660.rb +293 -0
  124. data/lib/fs/MiqFS/modules/Iso9660Probe.rb +18 -0
  125. data/lib/fs/MiqFS/modules/LocalFS.rb +105 -0
  126. data/lib/fs/MiqFS/modules/NTFS.rb +287 -0
  127. data/lib/fs/MiqFS/modules/NTFSProbe.rb +21 -0
  128. data/lib/fs/MiqFS/modules/NativeFS.rb +155 -0
  129. data/lib/fs/MiqFS/modules/ReFSProbe.rb +17 -0
  130. data/lib/fs/MiqFS/modules/RealFS.rb +79 -0
  131. data/lib/fs/MiqFS/modules/RealFSProbe.rb +6 -0
  132. data/lib/fs/MiqFS/modules/Reiser4Probe.rb +18 -0
  133. data/lib/fs/MiqFS/modules/ReiserFS.rb +315 -0
  134. data/lib/fs/MiqFS/modules/ReiserFSProbe.rb +42 -0
  135. data/lib/fs/MiqFS/modules/UnionFSProbe.rb +18 -0
  136. data/lib/fs/MiqFS/modules/WebDAV.rb +127 -0
  137. data/lib/fs/MiqFS/modules/WebDAVFile.rb +68 -0
  138. data/lib/fs/MiqFS/modules/XFS.rb +300 -0
  139. data/lib/fs/MiqFS/modules/XFSProbe.rb +26 -0
  140. data/lib/fs/MiqFS/modules/ZFSProbe.rb +18 -0
  141. data/lib/fs/MiqFS/test.rb +59 -0
  142. data/lib/fs/MiqFsUtil.rb +383 -0
  143. data/lib/fs/MiqMountManager.rb +209 -0
  144. data/lib/fs/MiqNativeMountManager.rb +101 -0
  145. data/lib/fs/MountManagerProbe.rb +29 -0
  146. data/lib/fs/ReiserFS/block.rb +209 -0
  147. data/lib/fs/ReiserFS/directory.rb +136 -0
  148. data/lib/fs/ReiserFS/directory_entry.rb +140 -0
  149. data/lib/fs/ReiserFS/file_data.rb +111 -0
  150. data/lib/fs/ReiserFS/superblock.rb +140 -0
  151. data/lib/fs/ReiserFS/utils.rb +95 -0
  152. data/lib/fs/VimDatastoreFS/VimDatastoreFS.rb +192 -0
  153. data/lib/fs/ext3/alloc_bitmap.rb +38 -0
  154. data/lib/fs/ext3/block_pointers_path.rb +130 -0
  155. data/lib/fs/ext3/directory.rb +51 -0
  156. data/lib/fs/ext3/directory_entry.rb +67 -0
  157. data/lib/fs/ext3/ex_attrib_header.rb +14 -0
  158. data/lib/fs/ext3/ex_attrib_name.rb +23 -0
  159. data/lib/fs/ext3/file_data.rb +130 -0
  160. data/lib/fs/ext3/group_descriptor_entry.rb +65 -0
  161. data/lib/fs/ext3/group_descriptor_table.rb +54 -0
  162. data/lib/fs/ext3/hash_tree_entry.rb +18 -0
  163. data/lib/fs/ext3/hash_tree_header.rb +15 -0
  164. data/lib/fs/ext3/inode.rb +228 -0
  165. data/lib/fs/ext3/posix_acl_entry.rb +29 -0
  166. data/lib/fs/ext3/posix_acl_header.rb +11 -0
  167. data/lib/fs/ext3/superblock.rb +406 -0
  168. data/lib/fs/ext3/test/tc_Ext3BlockPointersPath.rb +74 -0
  169. data/lib/fs/ext4/alloc_bitmap.rb +38 -0
  170. data/lib/fs/ext4/directory.rb +87 -0
  171. data/lib/fs/ext4/directory_entry.rb +77 -0
  172. data/lib/fs/ext4/ex_attrib_header.rb +14 -0
  173. data/lib/fs/ext4/ex_attrib_name.rb +23 -0
  174. data/lib/fs/ext4/extent.rb +35 -0
  175. data/lib/fs/ext4/extent_header.rb +40 -0
  176. data/lib/fs/ext4/extent_index.rb +33 -0
  177. data/lib/fs/ext4/group_descriptor_entry.rb +69 -0
  178. data/lib/fs/ext4/group_descriptor_table.rb +54 -0
  179. data/lib/fs/ext4/hash_tree_entry.rb +58 -0
  180. data/lib/fs/ext4/hash_tree_header.rb +35 -0
  181. data/lib/fs/ext4/inode.rb +465 -0
  182. data/lib/fs/ext4/posix_acl_entry.rb +29 -0
  183. data/lib/fs/ext4/posix_acl_header.rb +11 -0
  184. data/lib/fs/ext4/superblock.rb +412 -0
  185. data/lib/fs/fat32/boot_sect.rb +379 -0
  186. data/lib/fs/fat32/directory.rb +222 -0
  187. data/lib/fs/fat32/directory_entry.rb +540 -0
  188. data/lib/fs/fat32/file_data.rb +128 -0
  189. data/lib/fs/iso9660/boot_sector.rb +170 -0
  190. data/lib/fs/iso9660/directory.rb +90 -0
  191. data/lib/fs/iso9660/directory_entry.rb +147 -0
  192. data/lib/fs/iso9660/file_data.rb +78 -0
  193. data/lib/fs/iso9660/rock_ridge.rb +329 -0
  194. data/lib/fs/iso9660/util.rb +57 -0
  195. data/lib/fs/modules/LinuxMount.rb +300 -0
  196. data/lib/fs/modules/LinuxMountProbe.rb +29 -0
  197. data/lib/fs/modules/WinMount.rb +97 -0
  198. data/lib/fs/modules/WinMountProbe.rb +24 -0
  199. data/lib/fs/ntfs/attrib_attribute_list.rb +131 -0
  200. data/lib/fs/ntfs/attrib_bitmap.rb +26 -0
  201. data/lib/fs/ntfs/attrib_data.rb +74 -0
  202. data/lib/fs/ntfs/attrib_file_name.rb +110 -0
  203. data/lib/fs/ntfs/attrib_header.rb +194 -0
  204. data/lib/fs/ntfs/attrib_index_allocation.rb +19 -0
  205. data/lib/fs/ntfs/attrib_index_root.rb +247 -0
  206. data/lib/fs/ntfs/attrib_object_id.rb +40 -0
  207. data/lib/fs/ntfs/attrib_standard_information.rb +107 -0
  208. data/lib/fs/ntfs/attrib_type.rb +49 -0
  209. data/lib/fs/ntfs/attrib_volume_information.rb +53 -0
  210. data/lib/fs/ntfs/attrib_volume_name.rb +31 -0
  211. data/lib/fs/ntfs/boot_sect.rb +253 -0
  212. data/lib/fs/ntfs/data_run.rb +358 -0
  213. data/lib/fs/ntfs/directory_index_node.rb +114 -0
  214. data/lib/fs/ntfs/index_node_header.rb +69 -0
  215. data/lib/fs/ntfs/index_record_header.rb +85 -0
  216. data/lib/fs/ntfs/mft_entry.rb +288 -0
  217. data/lib/fs/ntfs/utils.rb +43 -0
  218. data/lib/fs/test/camcorder_fs_test.rb +108 -0
  219. data/lib/fs/test/collect_files_direct.yaml +22 -0
  220. data/lib/fs/test/collect_files_in.yaml +24 -0
  221. data/lib/fs/test/collect_files_in_nc.yaml +22 -0
  222. data/lib/fs/test/collect_files_out.yaml +6 -0
  223. data/lib/fs/test/collect_files_rm.yaml +6 -0
  224. data/lib/fs/test/copyTest.rb +126 -0
  225. data/lib/fs/test/fsTest.rb +87 -0
  226. data/lib/fs/test/updateTest.rb +184 -0
  227. data/lib/fs/xfs/allocation_group.rb +160 -0
  228. data/lib/fs/xfs/bmap_btree_block.rb +125 -0
  229. data/lib/fs/xfs/bmap_btree_record.rb +80 -0
  230. data/lib/fs/xfs/bmap_btree_root_node.rb +72 -0
  231. data/lib/fs/xfs/directory.rb +133 -0
  232. data/lib/fs/xfs/directory2_data_header.rb +27 -0
  233. data/lib/fs/xfs/directory3_data_header.rb +34 -0
  234. data/lib/fs/xfs/directory_block_tail.rb +22 -0
  235. data/lib/fs/xfs/directory_data_header.rb +46 -0
  236. data/lib/fs/xfs/directory_entry.rb +106 -0
  237. data/lib/fs/xfs/inode.rb +532 -0
  238. data/lib/fs/xfs/inode_map.rb +100 -0
  239. data/lib/fs/xfs/short_form_directory_entry.rb +91 -0
  240. data/lib/fs/xfs/short_form_header.rb +44 -0
  241. data/lib/fs/xfs/superblock.rb +556 -0
  242. data/lib/lib/tasks/azure.rake +52 -0
  243. data/lib/manageiq/smartstate/version.rb +5 -0
  244. data/lib/manageiq/smartstate.rb +7 -0
  245. data/lib/manageiq-smartstate.rb +1 -0
  246. data/lib/metadata/MIQExtract/MIQExtract.rb +297 -0
  247. data/lib/metadata/MIQExtract/test/extractTest.rb +41 -0
  248. data/lib/metadata/MIQExtract/test/full_extract_test.rb +68 -0
  249. data/lib/metadata/ScanProfile/HostScanItem.rb +4 -0
  250. data/lib/metadata/ScanProfile/HostScanProfile.rb +4 -0
  251. data/lib/metadata/ScanProfile/HostScanProfiles.rb +41 -0
  252. data/lib/metadata/ScanProfile/ScanItemBase.rb +63 -0
  253. data/lib/metadata/ScanProfile/ScanProfileBase.rb +51 -0
  254. data/lib/metadata/ScanProfile/ScanProfilesBase.rb +60 -0
  255. data/lib/metadata/ScanProfile/VmScanItem.rb +4 -0
  256. data/lib/metadata/ScanProfile/VmScanProfile.rb +4 -0
  257. data/lib/metadata/ScanProfile/VmScanProfiles.rb +38 -0
  258. data/lib/metadata/ScanProfile/modules/HostScanItemFile.rb +51 -0
  259. data/lib/metadata/ScanProfile/modules/HostScanItemNteventlog.rb +84 -0
  260. data/lib/metadata/ScanProfile/modules/VmScanItemFile.rb +39 -0
  261. data/lib/metadata/ScanProfile/modules/VmScanItemNteventlog.rb +34 -0
  262. data/lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb +64 -0
  263. data/lib/metadata/VMMount/VMMount.rb +81 -0
  264. data/lib/metadata/VMMount/VMPlatformMount.rb +18 -0
  265. data/lib/metadata/VMMount/VMPlatformMountLinux.rb +75 -0
  266. data/lib/metadata/VMMount/VMPlatformMountWin.rb +13 -0
  267. data/lib/metadata/VmConfig/GetNativeCfg.rb +45 -0
  268. data/lib/metadata/VmConfig/VmConfig.rb +947 -0
  269. data/lib/metadata/VmConfig/cfgConfig.rb +45 -0
  270. data/lib/metadata/VmConfig/ovfConfig.rb +99 -0
  271. data/lib/metadata/VmConfig/test/GetVMwareCfgTest.rb +40 -0
  272. data/lib/metadata/VmConfig/vmcConfig.rb +116 -0
  273. data/lib/metadata/VmConfig/vmtxConfig.rb +4 -0
  274. data/lib/metadata/VmConfig/vmxConfig.rb +162 -0
  275. data/lib/metadata/VmConfig/xmlConfig.rb +79 -0
  276. data/lib/metadata/VmConfig/xmlMsHyperVConfig.rb +41 -0
  277. data/lib/metadata/linux/InitProcHash.rb +632 -0
  278. data/lib/metadata/linux/LinuxInitProcs.rb +142 -0
  279. data/lib/metadata/linux/LinuxOSInfo.rb +237 -0
  280. data/lib/metadata/linux/LinuxPackages.rb +209 -0
  281. data/lib/metadata/linux/LinuxSystemd.rb +130 -0
  282. data/lib/metadata/linux/LinuxUsers.rb +289 -0
  283. data/lib/metadata/linux/LinuxUtils.rb +197 -0
  284. data/lib/metadata/linux/MiqConaryPackages.rb +41 -0
  285. data/lib/metadata/linux/MiqRpmPackages.rb +160 -0
  286. data/lib/metadata/linux/test/Name +0 -0
  287. data/lib/metadata/linux/test/Packages +0 -0
  288. data/lib/metadata/linux/test/rpoTest.rb +5 -0
  289. data/lib/metadata/linux/test/tc_LinuxUtils.rb +4157 -0
  290. data/lib/metadata/util/event_log_filter.rb +61 -0
  291. data/lib/metadata/util/md5deep.rb +280 -0
  292. data/lib/metadata/util/win32/Win32Accounts.rb +764 -0
  293. data/lib/metadata/util/win32/Win32EventLog.rb +743 -0
  294. data/lib/metadata/util/win32/Win32Services.rb +86 -0
  295. data/lib/metadata/util/win32/Win32Software.rb +326 -0
  296. data/lib/metadata/util/win32/Win32System.rb +333 -0
  297. data/lib/metadata/util/win32/boot_info_win.rb +59 -0
  298. data/lib/metadata/util/win32/fleece_hives.rb +220 -0
  299. data/lib/metadata/util/win32/ms-registry.rb +650 -0
  300. data/lib/metadata/util/win32/peheader.rb +868 -0
  301. data/lib/metadata/util/win32/remote-registry.rb +142 -0
  302. data/lib/metadata/util/win32/system_path_win.rb +103 -0
  303. data/lib/metadata/util/win32/versioninfo.rb +17 -0
  304. data/manageiq-smartstate.gemspec +35 -0
  305. 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