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,130 @@
|
|
1
|
+
require 'util/miq-xml'
|
2
|
+
|
3
|
+
# iniparse needed to handle duplicate options (inifile will overwrite)
|
4
|
+
require 'iniparse'
|
5
|
+
|
6
|
+
module MiqLinux
|
7
|
+
class Systemd
|
8
|
+
SYSTEM_DIRS = ['/etc/systemd/system', '/usr/lib/systemd/system']
|
9
|
+
USER_DIRS = ['/etc/systemd/user', '/usr/lib/systemd/user']
|
10
|
+
ALL_DIRS = SYSTEM_DIRS + USER_DIRS
|
11
|
+
|
12
|
+
def self.detected?(fs)
|
13
|
+
ALL_DIRS.any? { |dir| fs.fileExists?(dir) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(fs)
|
17
|
+
@fs = fs
|
18
|
+
parse_systemd
|
19
|
+
end
|
20
|
+
|
21
|
+
def toXml(doc)
|
22
|
+
@services.each do |service|
|
23
|
+
doc.add_element("service", service_xml(service))
|
24
|
+
# service_targets_xml(service).each { |tx| node.add_element("target", tx) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def parse_systemd
|
31
|
+
@services = files('.service').collect { |sf| parse_service(sf) }.compact
|
32
|
+
@targets = files('.target').collect { |tf| parse_target(tf) }.compact
|
33
|
+
end
|
34
|
+
|
35
|
+
def files(unit_extension)
|
36
|
+
existing_dirs.flat_map do |dir|
|
37
|
+
dir_files = []
|
38
|
+
@fs.dirForeach(dir) do |unit|
|
39
|
+
dir_files << File.join(dir, unit) if @fs.fileExtname(unit) == unit_extension
|
40
|
+
end
|
41
|
+
dir_files
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def existing_dirs
|
46
|
+
ALL_DIRS.select { |dir| @fs.fileExists?(dir) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def ini(file)
|
50
|
+
fdata = nil
|
51
|
+
@fs.fileOpen(file) { |fo| fdata = fo.read }
|
52
|
+
IniParse.parse(fdata)
|
53
|
+
end
|
54
|
+
|
55
|
+
def parse_service(file)
|
56
|
+
debug "Parsing service unit: #{file}"
|
57
|
+
|
58
|
+
unit = @fs.fileBasename(file)
|
59
|
+
name = unit.gsub(".service", "")
|
60
|
+
inif = ini(file)
|
61
|
+
desc = parse_description(inif)
|
62
|
+
wanted_by = parse_wanted(inif)
|
63
|
+
required_by = parse_required(inif)
|
64
|
+
|
65
|
+
{:unit => unit,
|
66
|
+
:name => name,
|
67
|
+
:path => file,
|
68
|
+
:description => desc,
|
69
|
+
:wanted_by => wanted_by,
|
70
|
+
:required_by => required_by}
|
71
|
+
|
72
|
+
rescue
|
73
|
+
warn "Error parsing: #{file}"
|
74
|
+
nil # make sure no intermediate result is returned!
|
75
|
+
end
|
76
|
+
|
77
|
+
def parse_description(inif)
|
78
|
+
return nil unless inif.has_section?('Unit') && inif['Unit'].has_option?('Description')
|
79
|
+
inif['Unit']['Description']
|
80
|
+
end
|
81
|
+
|
82
|
+
def parse_wanted(inif)
|
83
|
+
return [] unless inif.has_section?('Install') && inif['Install'].has_option?('WantedBy')
|
84
|
+
[inif['Install']['WantedBy']].flatten.collect(&:split).flatten
|
85
|
+
end
|
86
|
+
|
87
|
+
def parse_required(inif)
|
88
|
+
return [] unless inif.has_section?('Install') && inif['Install'].has_option?('RequiredBy')
|
89
|
+
[inif['Install']['RequiredBy']].flatten.collect(&:split).flatten
|
90
|
+
end
|
91
|
+
|
92
|
+
def parse_target(file)
|
93
|
+
debug "Parsing target unit: #{file}"
|
94
|
+
|
95
|
+
unit = @fs.fileBasename(file)
|
96
|
+
name = unit.gsub(".target", "")
|
97
|
+
inif = ini(file)
|
98
|
+
desc = parse_description(inif)
|
99
|
+
|
100
|
+
{:unit => unit,
|
101
|
+
:name => name,
|
102
|
+
:path => file,
|
103
|
+
:description => desc}
|
104
|
+
rescue
|
105
|
+
warn "Error parsing: #{file}"
|
106
|
+
nil # make sure no intermediate result is returned!
|
107
|
+
end
|
108
|
+
|
109
|
+
def service_xml(service)
|
110
|
+
{"name" => service[:name],
|
111
|
+
"image_path" => service[:path],
|
112
|
+
"description" => service[:description],
|
113
|
+
"typename" => "linux_systemd"}
|
114
|
+
end
|
115
|
+
|
116
|
+
def service_targets_xml(service)
|
117
|
+
(service[:required_by] + service[:wanted_by]).collect do |tgt|
|
118
|
+
{"value" => tgt.gsub(".target", "")}
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def debug(msg)
|
123
|
+
$log.debug msg if $log
|
124
|
+
end
|
125
|
+
|
126
|
+
def warn(msg)
|
127
|
+
$log.warn msg if $log
|
128
|
+
end
|
129
|
+
end # class Systemd
|
130
|
+
end # module MiqLinux
|
@@ -0,0 +1,289 @@
|
|
1
|
+
require 'binary_struct'
|
2
|
+
require 'util/miq-hash_struct'
|
3
|
+
require 'util/miq-xml'
|
4
|
+
|
5
|
+
module MiqLinux
|
6
|
+
class Users
|
7
|
+
attr_reader :userHash, :groups
|
8
|
+
|
9
|
+
def initialize(fs)
|
10
|
+
@userHash = {}
|
11
|
+
@usersByGid = Hash.new { |h, k| h[k] = [] }
|
12
|
+
@groups = []
|
13
|
+
|
14
|
+
wtmp = FileWTMP.new(fs)
|
15
|
+
|
16
|
+
fname = "/etc/passwd"
|
17
|
+
if fs.fileExists?(fname)
|
18
|
+
pfes = nil
|
19
|
+
fs.fileOpen(fname) { |fo| pfes = fo.read }
|
20
|
+
unless pfes.nil?
|
21
|
+
pfes.each_line do |pfe|
|
22
|
+
next if pfe =~ /^#/
|
23
|
+
fields = pfe.chop.split(':')
|
24
|
+
u = MiqHashStruct.new
|
25
|
+
u.name = fields[0]
|
26
|
+
u.uid = fields[2]
|
27
|
+
u.gid = fields[3]
|
28
|
+
u.gecos = fields[4]
|
29
|
+
u.dir = fields[5]
|
30
|
+
u.shell = fields[6] || "NONE"
|
31
|
+
u.last_logon = wtmp.last_logon(u.name) unless wtmp.nil?
|
32
|
+
u.groups = []
|
33
|
+
@userHash[u.name] = u
|
34
|
+
@usersByGid[u.gid] << u
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
fname = "/etc/group"
|
40
|
+
if fs.fileExists?(fname)
|
41
|
+
pfes = nil
|
42
|
+
fs.fileOpen(fname) { |fo| pfes = fo.read }
|
43
|
+
unless pfes.nil?
|
44
|
+
pfes.each_line do |pfe|
|
45
|
+
next if pfe =~ /^#/
|
46
|
+
fields = pfe.chop.split(':')
|
47
|
+
g = MiqHashStruct.new
|
48
|
+
g.name = fields[0]
|
49
|
+
g.gid = fields[2]
|
50
|
+
g.ulist = fields[3].split(',') if fields[3]
|
51
|
+
g.ulist = [] unless g.ulist
|
52
|
+
@usersByGid[g.gid].each { |u| g.ulist << u.name }
|
53
|
+
g.ulist.uniq!
|
54
|
+
g.ulist.each { |un| @userHash[un].groups << g.name if @userHash[un] }
|
55
|
+
@groups << g
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
@userHash.each_value { |u| u.groups.uniq! }
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_s
|
63
|
+
str = ''
|
64
|
+
|
65
|
+
@userHash.each_value do |u|
|
66
|
+
str += "Login: " + u.name
|
67
|
+
str += "\n\tUid: " + u.uid.to_s
|
68
|
+
str += "\n\tGid: " + u.gid.to_s
|
69
|
+
str += "\n\tHome: " + u.dir
|
70
|
+
str += "\n\tShell: " + u.shell
|
71
|
+
str += "\n\tGECOS: " + u.gecos
|
72
|
+
str += "\n\tGroups: "
|
73
|
+
u.groups.each { |gn| str += "\n\t\t#{gn}" }
|
74
|
+
str += "\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
@groups.each do |g|
|
78
|
+
str += "Group Name: " + g.name
|
79
|
+
str += "\n\tGid: " + g.gid
|
80
|
+
str += "\n\tUsers:"
|
81
|
+
g.ulist.each { |un| str += "\n\t\t#{un}" }
|
82
|
+
str += "\n"
|
83
|
+
end
|
84
|
+
(str)
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_xml(doc = nil)
|
88
|
+
doc = MiqXml.createDoc(nil) unless doc
|
89
|
+
usersToXml(doc)
|
90
|
+
groupsToXml(doc)
|
91
|
+
doc
|
92
|
+
end
|
93
|
+
|
94
|
+
def usersToXml(doc = nil)
|
95
|
+
doc = MiqXml.createDoc(nil) unless doc
|
96
|
+
|
97
|
+
users = doc.add_element('users')
|
98
|
+
@userHash.each_value do |u|
|
99
|
+
user = users.add_element('user', {'name' => u.name, 'userid' => u.uid, 'homedir' => u.dir})
|
100
|
+
user.add_attribute('comment', u.gecos) unless u.gecos.blank?
|
101
|
+
user.add_attribute('last_logon', u.last_logon) unless u.last_logon.nil? || u.last_logon.blank?
|
102
|
+
|
103
|
+
u.groups.each do |gn|
|
104
|
+
user.add_element('member_of_group', {'name' => gn})
|
105
|
+
end
|
106
|
+
end
|
107
|
+
doc
|
108
|
+
end
|
109
|
+
|
110
|
+
def groupsToXml(doc = nil)
|
111
|
+
doc = MiqXml.createDoc(nil) unless doc
|
112
|
+
|
113
|
+
groups = doc.add_element('groups')
|
114
|
+
@groups.each do |g|
|
115
|
+
group = groups.add_element('group', {'name' => g.name, 'groupid' => g.gid})
|
116
|
+
|
117
|
+
g.ulist.each do |un|
|
118
|
+
group.add_element('member_users', {'name' => un})
|
119
|
+
end
|
120
|
+
end
|
121
|
+
doc
|
122
|
+
end
|
123
|
+
end # class Users
|
124
|
+
|
125
|
+
class FileWTMP
|
126
|
+
# From http://www.hcidata.info/wtmp.htm
|
127
|
+
#
|
128
|
+
# The wtmp log file is usually found in /var/log/wtmp and contains the following information:
|
129
|
+
#
|
130
|
+
# * Activity code (e.g. login, logout, boot)
|
131
|
+
# * PID
|
132
|
+
# * Date and time of last login
|
133
|
+
# * Terminal line name
|
134
|
+
# * Host user came from
|
135
|
+
#
|
136
|
+
# The following one line PERL program will format and print /var/log/wtmp but it may need modification to work on your site.
|
137
|
+
#
|
138
|
+
# perl -we '@type=("Empty","Run Lvl","Boot","New Time","Old Time","Init","Login","Normal","Term","Account");$recs = ""; while (<>) {$recs .= $_};foreach (split(/(.{384})/s,$recs)) {next if length($_) == 0;my ($type,$pid,$line,$inittab,$user,$host,$t1,$t2,$t3,$t4,$t5) = $_ =~/(.{4})(.{4})(.{32})(.{4})(.{32})(.{256})(.{4})(.{4})(.{4})(.{4})(.{4})/s;if (defined $line && $line =~ /\w/) {$line =~ s/\x00+//g;$host =~ s/\x00+//g;$user =~ s/\x00+//g;printf("%s %-8s %-12s %10s %-45s \n",scalar(gmtime(unpack("I4",$t3))),$type[unpack("I4",$type)],$user,$line,$host)}}print"\n"' < /var/log/wtmp
|
139
|
+
#
|
140
|
+
# The items that may need modification in order to format and print your lastlog file are:
|
141
|
+
#
|
142
|
+
# * 384 - this should be changed to the length of each record on /var/log/wtmp.
|
143
|
+
# * 32 - this should be changed to the value of UT_LINESIZE (probably 32) in /usr/include/bits/utmp.h
|
144
|
+
# * 32 - this should be changed to the value of UT_NAMESIZE](probably 32) in /usr/include/bits/utmp.h
|
145
|
+
# * 256 - this should be changed to the value of UT_HOSTSIZE (probably 256) in /usr/include/bits/utmp.h
|
146
|
+
# * /var/log/wtmp - this should be the name of the lastlog file on your system - probably /var/log/wtmp
|
147
|
+
#
|
148
|
+
|
149
|
+
WTMP_RECORD = BinaryStruct.new([
|
150
|
+
'V', 'type', # type of login
|
151
|
+
'V', 'pid', # PID of login process
|
152
|
+
'a32', 'line', # device name of tty - "/dev/"
|
153
|
+
'V', 'inittab', # init id or abbrev. ttyname
|
154
|
+
'a32', 'user', # user name
|
155
|
+
'a256', 'host', # hostname for remote login
|
156
|
+
'v', 'e_termination', # process termination status
|
157
|
+
'v', 'e_exit', # process exit status
|
158
|
+
'V', 'session', # Session ID, used for windowing
|
159
|
+
'V', 'seconds', # Time, in seconds
|
160
|
+
'V', 'useconds', # microseconds
|
161
|
+
'V4', 'addr_v6', # * Internet address of remote host; IPv4 address uses just ut_addr_v6[0] */
|
162
|
+
'a20', 'extra'
|
163
|
+
])
|
164
|
+
WTMP_RECORD_LEN = WTMP_RECORD.size
|
165
|
+
|
166
|
+
# WTMP Account Types
|
167
|
+
WTMP_TYPE_UT_UNKNOWN = 0
|
168
|
+
WTMP_TYPE_RUN_LVL = 1
|
169
|
+
WTMP_TYPE_BOOT_TIME = 2
|
170
|
+
WTMP_TYPE_NEW_TIME = 3
|
171
|
+
WTMP_TYPE_OLD_TIME = 4
|
172
|
+
WTMP_TYPE_INIT_PROCESS = 5
|
173
|
+
WTMP_TYPE_LOGIN_PROCESS = 6
|
174
|
+
WTMP_TYPE_USER_PROCESS = 7
|
175
|
+
WTMP_TYPE_DEAD_PROCESS = 8
|
176
|
+
WTMP_TYPE_ACCOUNTING = 9
|
177
|
+
|
178
|
+
WTMP_TYPES = {
|
179
|
+
WTMP_TYPE_UT_UNKNOWN => "Unknown",
|
180
|
+
WTMP_TYPE_RUN_LVL => "Run Level",
|
181
|
+
WTMP_TYPE_BOOT_TIME => "Boot Time",
|
182
|
+
WTMP_TYPE_NEW_TIME => "New Time",
|
183
|
+
WTMP_TYPE_OLD_TIME => "Old Time",
|
184
|
+
WTMP_TYPE_INIT_PROCESS => "Init Process",
|
185
|
+
WTMP_TYPE_LOGIN_PROCESS => "Login Process",
|
186
|
+
WTMP_TYPE_USER_PROCESS => "User Process",
|
187
|
+
WTMP_TYPE_DEAD_PROCESS => "Dead Process",
|
188
|
+
WTMP_TYPE_ACCOUNTING => "Accounting"
|
189
|
+
}
|
190
|
+
|
191
|
+
def initialize(fs, path = "/var/log/wtmp")
|
192
|
+
@contents = nil
|
193
|
+
@records = nil
|
194
|
+
begin
|
195
|
+
fs.fileOpen(path, "rb") { |fo| @contents = fo.read }
|
196
|
+
rescue
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def last_logon(username)
|
201
|
+
return nil if @contents.nil?
|
202
|
+
last = nil
|
203
|
+
|
204
|
+
begin
|
205
|
+
last = records[username]
|
206
|
+
last = Time.at(last).getutc unless last.nil?
|
207
|
+
rescue => err
|
208
|
+
$log.error("Error processing WTMP file because <#{err.message}>") if $log
|
209
|
+
end
|
210
|
+
last
|
211
|
+
end
|
212
|
+
|
213
|
+
def dump(rec)
|
214
|
+
puts "WTMP Record:"
|
215
|
+
# puts "WTMP Record: #{rec.inspect}"
|
216
|
+
puts "\ttype: #{WTMP_TYPES[rec["type"]]}"
|
217
|
+
puts "\tuser: #{rec["user"]}"
|
218
|
+
puts "\thost: #{rec["host"]}"
|
219
|
+
puts "\tline: #{rec["line"]}"
|
220
|
+
puts "\tpid: #{rec["pid"]}"
|
221
|
+
puts "\ttime: #{Time.at(rec["seconds"])}"
|
222
|
+
end
|
223
|
+
|
224
|
+
def records
|
225
|
+
return @records unless @records.nil?
|
226
|
+
@records = {}
|
227
|
+
recnum = 0
|
228
|
+
nrecs = @contents.length / WTMP_RECORD_LEN
|
229
|
+
# TODO(lsmola) limiting log file size and logging warning when it's over it?
|
230
|
+
# Cause this can potentily go through milions of records
|
231
|
+
while recnum < nrecs
|
232
|
+
offset = recnum * WTMP_RECORD_LEN
|
233
|
+
recnum += 1
|
234
|
+
buf = @contents[offset, WTMP_RECORD_LEN]
|
235
|
+
break unless buf.length == WTMP_RECORD_LEN
|
236
|
+
rec = WTMP_RECORD.decode(buf)
|
237
|
+
['host', 'user', 'line'].each { |k| rec[k].strip! if rec[k] }
|
238
|
+
next if rec["user"].blank?
|
239
|
+
next unless rec["type"] == WTMP_TYPE_USER_PROCESS
|
240
|
+
|
241
|
+
current = rec["seconds"]
|
242
|
+
user = rec["user"]
|
243
|
+
# Get the latest logon timestamp for each user
|
244
|
+
@records[user] = current if @records[user].blank? || current > @records[user]
|
245
|
+
end
|
246
|
+
@records
|
247
|
+
end
|
248
|
+
end # class FileWTMP
|
249
|
+
end # module MiqLinux
|
250
|
+
|
251
|
+
if __FILE__ == $0
|
252
|
+
require 'log4r'
|
253
|
+
require 'MiqVm/MiqVm'
|
254
|
+
|
255
|
+
vmDir = File.join(ENV.fetch("HOME", '.'), 'VMs')
|
256
|
+
puts "vmDir = #{vmDir}"
|
257
|
+
|
258
|
+
class ConsoleFormatter < Log4r::Formatter
|
259
|
+
def format(event)
|
260
|
+
(event.data.kind_of?(String) ? event.data : event.data.inspect)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
toplog = Log4r::Logger.new 'toplog'
|
265
|
+
Log4r::StderrOutputter.new('err_console', :level => Log4r::ERROR, :formatter => ConsoleFormatter)
|
266
|
+
toplog.add 'err_console'
|
267
|
+
$log = toplog if $log.nil?
|
268
|
+
|
269
|
+
#
|
270
|
+
# *** Test start
|
271
|
+
#
|
272
|
+
|
273
|
+
vmCfg = File.join(vmDir, "Red Hat Linux.vmwarevm/Red Hat Linux.vmx")
|
274
|
+
# vmCfg = File.join(vmDir, "MIQ Server Appliance - Ubuntu MD - small/MIQ Server Appliance - Ubuntu.vmx")
|
275
|
+
# vmCfg = File.join(vmDir, "winxpDev.vmwarevm/winxpDev.vmx")
|
276
|
+
vmCfg = "/Volumes/OB VMs/vms/Ubuntu Subversion/Ubuntu.vmx"
|
277
|
+
puts "VM config file: #{vmCfg}"
|
278
|
+
|
279
|
+
vm = MiqVm.new(vmCfg)
|
280
|
+
raise "No OSs detected" if vm.rootTrees.length == 0
|
281
|
+
rt = vm.rootTrees[0]
|
282
|
+
u = MiqLinux::Users.new(rt)
|
283
|
+
puts "**** USERS:"
|
284
|
+
u.usersToXml.write($stdout, 4)
|
285
|
+
puts
|
286
|
+
puts "**** GROUPS:"
|
287
|
+
u.groupsToXml.write($stdout, 4)
|
288
|
+
puts
|
289
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
module MiqLinux
|
2
|
+
class Utils
|
3
|
+
def self.parse_ls_l_fulltime(lines)
|
4
|
+
ret = []
|
5
|
+
return ret if lines.nil? || lines.empty?
|
6
|
+
|
7
|
+
lines.each do |line|
|
8
|
+
line = line.chomp
|
9
|
+
parts = line.split(' ')
|
10
|
+
next unless parts.length >= 9
|
11
|
+
|
12
|
+
perms, ftype = permissions_to_octal(parts[0])
|
13
|
+
|
14
|
+
ret << {
|
15
|
+
:ftype => ftype,
|
16
|
+
:permissions => perms,
|
17
|
+
:hard_links => perms[1],
|
18
|
+
:owner => parts[2],
|
19
|
+
:group => parts[3],
|
20
|
+
:size => parts[4],
|
21
|
+
:mtime => Time.parse(parts[5..7].join(' ')).utc,
|
22
|
+
:name => parts[8..-1].join(' '),
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
ret
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.permissions_to_octal(perms)
|
30
|
+
if perms.length == 9
|
31
|
+
ftype = nil
|
32
|
+
elsif perms.length == 10
|
33
|
+
ftype = perms[0, 1]
|
34
|
+
perms = perms[1..-1]
|
35
|
+
elsif perms.length == 11
|
36
|
+
# TODO: when se-linux is present, the format is like this '-rw-rw-r--.', . means an SELinux ACL. (+ means a
|
37
|
+
# general ACL.). I need to figure out where to store this fact, ignoring it for now
|
38
|
+
ftype = perms[0, 1]
|
39
|
+
perms = perms[1..-2]
|
40
|
+
else
|
41
|
+
raise "Invalid perms length"
|
42
|
+
end
|
43
|
+
|
44
|
+
unless ftype.nil?
|
45
|
+
ftype = case ftype
|
46
|
+
when 'd' then 'dir'
|
47
|
+
when 'l' then 'link'
|
48
|
+
else 'file'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
octal = [0, 0, 0, 0]
|
53
|
+
perms.split(//).each_with_index do |c, i|
|
54
|
+
# puts [c, i, i % 3, 2 - (i % 3), 2 ** (2 - (i % 3)), i / 3, 2 - (i / 3), 2 ** (2 - (i / 3))].inspect
|
55
|
+
octal[i / 3 + 1] += 2**(2 - (i % 3)) unless %w(- S T).include?(c)
|
56
|
+
# puts octal.inspect
|
57
|
+
octal[0] += 2**(2 - (i / 3)) if %w(s t S T).include?(c)
|
58
|
+
# puts octal.inspect
|
59
|
+
end
|
60
|
+
octal = octal.join
|
61
|
+
|
62
|
+
return octal, ftype
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.octal_to_permissions(octal, ftype = nil)
|
66
|
+
perms = ""
|
67
|
+
|
68
|
+
unless ftype.nil?
|
69
|
+
ftype = ftype[0, 1]
|
70
|
+
ftype = '-' if ftype == 'f'
|
71
|
+
perms << ftype
|
72
|
+
end
|
73
|
+
|
74
|
+
octal = octal.to_i(8) if octal.kind_of?(String)
|
75
|
+
|
76
|
+
perms << (octal & 00400 != 0 ? 'r' : '-')
|
77
|
+
perms << (octal & 00200 != 0 ? 'w' : '-')
|
78
|
+
perms << (octal & 04000 != 0 ? (octal & 00100 != 0 ? 's' : 'S') : octal & 00100 != 0 ? 'x' : '-')
|
79
|
+
perms << (octal & 00040 != 0 ? 'r' : '-')
|
80
|
+
perms << (octal & 00020 != 0 ? 'w' : '-')
|
81
|
+
perms << (octal & 02000 != 0 ? (octal & 00010 != 0 ? 's' : 'S') : octal & 00010 != 0 ? 'x' : '-')
|
82
|
+
perms << (octal & 00004 != 0 ? 'r' : '-')
|
83
|
+
perms << (octal & 00002 != 0 ? 'w' : '-')
|
84
|
+
perms << (octal & 01000 != 0 ? (octal & 00001 != 0 ? 't' : 'T') : octal & 00001 != 0 ? 'x' : '-')
|
85
|
+
|
86
|
+
perms
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.parse_chkconfig_list(lines)
|
90
|
+
ret = []
|
91
|
+
return ret if lines.nil? || lines.empty?
|
92
|
+
|
93
|
+
lines.each_line do |line|
|
94
|
+
line = line.chomp
|
95
|
+
parts = line.split(' ')
|
96
|
+
next unless parts.length >= 8
|
97
|
+
|
98
|
+
enable_level = []
|
99
|
+
disable_level = []
|
100
|
+
|
101
|
+
parts[1..-1].each do |part|
|
102
|
+
level, state = part.split(':')
|
103
|
+
case state
|
104
|
+
when 'on' then enable_level << level
|
105
|
+
when 'off' then disable_level << level
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
nh = {:name => parts[0]}
|
110
|
+
nh[:enable_run_level] = enable_level.empty? ? nil : enable_level.sort
|
111
|
+
nh[:disable_run_level] = disable_level.empty? ? nil : disable_level.sort
|
112
|
+
|
113
|
+
ret << nh
|
114
|
+
end
|
115
|
+
|
116
|
+
ret
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.parse_systemctl_list(lines)
|
120
|
+
return [] if lines.nil? || lines.empty?
|
121
|
+
|
122
|
+
lines.each_line.map do |line|
|
123
|
+
line = line.chomp
|
124
|
+
parts = line.split(' ')
|
125
|
+
next if (/^.*?\.service$/ =~ parts[0]).nil?
|
126
|
+
|
127
|
+
name, = parts[0].split('.')
|
128
|
+
|
129
|
+
# TODO(lsmola) investigate adding systemd targets, which are used instead of runlevels. Drawback, it's not
|
130
|
+
# returned by any command, so we would have to parse the dir structure of /etc/systemd/system/
|
131
|
+
# There is already MiqLinux::Systemd.new(@systemFs) called from class MIQExtract, we should leverage that
|
132
|
+
{:name => name,
|
133
|
+
:systemd_load => parts[1],
|
134
|
+
:systemd_active => parts[2],
|
135
|
+
:systemd_sub => parts[3],
|
136
|
+
:typename => 'linux_systemd',
|
137
|
+
:description => parts[4..-1].join(" "),
|
138
|
+
:enable_run_level => nil,
|
139
|
+
:disable_run_level => nil,
|
140
|
+
:running => parts[3] == 'running'}
|
141
|
+
end.compact
|
142
|
+
end
|
143
|
+
|
144
|
+
def self.collect_interface(interfaces, interface)
|
145
|
+
mac_addr = interface[:mac_address]
|
146
|
+
return if mac_addr.blank?
|
147
|
+
|
148
|
+
existing_interface = interfaces[mac_addr]
|
149
|
+
if existing_interface.blank?
|
150
|
+
interfaces[mac_addr] = interface
|
151
|
+
else
|
152
|
+
interface[:name] += "," + existing_interface[:name]
|
153
|
+
existing_interface.merge!(interface)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.parse_network_interface_list(lines)
|
158
|
+
return [] if lines.blank?
|
159
|
+
|
160
|
+
interfaces = {}
|
161
|
+
interface = {}
|
162
|
+
lines.each_line do |line|
|
163
|
+
if /^\d+\:\s([\w-]+)\:.*?mtu\s(\d+).*?$/ =~ line
|
164
|
+
collect_interface(interfaces, interface) unless interface.blank?
|
165
|
+
interface = {:name => $1}
|
166
|
+
elsif /^.*?link.*?((\w\w\:)+\w\w).*?$/ =~ line
|
167
|
+
interface[:mac_address] = $1
|
168
|
+
elsif /^.*?inet\s((\d+\.)+\d+).*?$/ =~ line
|
169
|
+
interface[:fixed_ip] = $1
|
170
|
+
elsif /^.*?inet6\s((\w*\:+)+\w+).*?$/ =~ line
|
171
|
+
interface[:fixed_ipv6] = $1
|
172
|
+
end
|
173
|
+
end
|
174
|
+
collect_interface(interfaces, interface)
|
175
|
+
|
176
|
+
interfaces.values
|
177
|
+
end
|
178
|
+
|
179
|
+
def self.parse_openstack_status(lines)
|
180
|
+
lines.to_s.split("\n").reject{|t| t.include? "="}.group_by{|t| t.gsub(/openstack\-([a-z]+).*/i, '\1')}.map do |title, services|
|
181
|
+
{
|
182
|
+
'name' => title.capitalize,
|
183
|
+
'services' => services.map do |service_line|
|
184
|
+
# split service line by :, ( and ) and strip white space from results
|
185
|
+
service_line.split(/[:\(\)]/).map(&:strip)
|
186
|
+
end.map do |service|
|
187
|
+
{
|
188
|
+
'name' => service.first,
|
189
|
+
'active' => service[1] == 'active',
|
190
|
+
'enabled' => !(service[2] =~ /disabled/)
|
191
|
+
}
|
192
|
+
end
|
193
|
+
}
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'binary_struct'
|
2
|
+
require 'util/miq-hash_struct'
|
3
|
+
require 'db/MiqSqlite/MiqSqlite3'
|
4
|
+
|
5
|
+
class MiqConaryPackages
|
6
|
+
def initialize(fs, dbFile)
|
7
|
+
@pkgDb = MiqSqlite3DB::MiqSqlite3.new(dbFile, fs)
|
8
|
+
|
9
|
+
tVersions = @pkgDb.getTable("Versions")
|
10
|
+
tInstances = @pkgDb.getTable("Instances")
|
11
|
+
|
12
|
+
@versions = {}
|
13
|
+
tVersions.each_row do |row|
|
14
|
+
id = row['versionId']
|
15
|
+
@versions[id] = row['version']
|
16
|
+
end
|
17
|
+
|
18
|
+
@troves = {}
|
19
|
+
tInstances.each_row do |row|
|
20
|
+
troveName = row['troveName']
|
21
|
+
versionId = row['versionId']
|
22
|
+
@troves[troveName] = versionId if @versions.key?(versionId) && !troveName.include?(":") && row['isPresent']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def each
|
27
|
+
@troves.keys.sort.each do |t|
|
28
|
+
versionId = @troves[t]
|
29
|
+
pkg = MiqHashStruct.new
|
30
|
+
pkg.name = t
|
31
|
+
pkg.version = @versions[versionId]
|
32
|
+
pkg.installed = true
|
33
|
+
|
34
|
+
yield pkg
|
35
|
+
end
|
36
|
+
end # def each
|
37
|
+
|
38
|
+
def close
|
39
|
+
@pkgDb.close
|
40
|
+
end
|
41
|
+
end # class MiqConaryPackages
|