kanrisuru 0.12.1 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +5 -5
- data/kanrisuru.gemspec +7 -3
- data/lib/kanrisuru/command.rb +15 -1
- data/lib/kanrisuru/core/apt/commands/autoclean.rb +13 -0
- data/lib/kanrisuru/core/apt/commands/autoremove.rb +15 -0
- data/lib/kanrisuru/core/apt/commands/clean.rb +13 -0
- data/lib/kanrisuru/core/apt/commands/full_upgrade.rb +14 -0
- data/lib/kanrisuru/core/apt/commands/install.rb +22 -0
- data/lib/kanrisuru/core/apt/commands/list.rb +21 -0
- data/lib/kanrisuru/core/apt/commands/purge.rb +18 -0
- data/lib/kanrisuru/core/apt/commands/remove.rb +18 -0
- data/lib/kanrisuru/core/apt/commands/search.rb +18 -0
- data/lib/kanrisuru/core/apt/commands/show.rb +21 -0
- data/lib/kanrisuru/core/apt/commands/update.rb +14 -0
- data/lib/kanrisuru/core/apt/commands/upgrade.rb +14 -0
- data/lib/kanrisuru/core/apt/commands.rb +14 -0
- data/lib/kanrisuru/core/apt/parser.rb +6 -0
- data/lib/kanrisuru/core/apt/parsers/base.rb +51 -0
- data/lib/kanrisuru/core/apt/parsers/list.rb +28 -0
- data/lib/kanrisuru/core/apt/parsers/search.rb +32 -0
- data/lib/kanrisuru/core/apt/parsers/show.rb +90 -0
- data/lib/kanrisuru/core/apt/types.rb +36 -0
- data/lib/kanrisuru/core/apt.rb +4 -284
- data/lib/kanrisuru/core/archive/commands/tar.rb +126 -0
- data/lib/kanrisuru/core/archive/commands.rb +3 -0
- data/lib/kanrisuru/core/archive/types.rb +9 -0
- data/lib/kanrisuru/core/archive.rb +3 -121
- data/lib/kanrisuru/core/disk/commands/blkid.rb +35 -0
- data/lib/kanrisuru/core/disk/commands/df.rb +26 -0
- data/lib/kanrisuru/core/disk/commands/du.rb +24 -0
- data/lib/kanrisuru/core/disk/commands/lsblk.rb +49 -0
- data/lib/kanrisuru/core/disk/commands.rb +6 -0
- data/lib/kanrisuru/core/disk/constants.rb +9 -0
- data/lib/kanrisuru/core/disk/parser.rb +7 -0
- data/lib/kanrisuru/core/disk/parsers/blkid.rb +72 -0
- data/lib/kanrisuru/core/disk/parsers/df.rb +33 -0
- data/lib/kanrisuru/core/disk/parsers/du.rb +25 -0
- data/lib/kanrisuru/core/disk/parsers/lsblk.rb +96 -0
- data/lib/kanrisuru/core/disk/parsers/lsblk_version.rb +21 -0
- data/lib/kanrisuru/core/disk/types.rb +21 -0
- data/lib/kanrisuru/core/disk.rb +6 -290
- data/lib/kanrisuru/core/dmi/commands/dmi.rb +42 -0
- data/lib/kanrisuru/core/dmi/commands.rb +3 -0
- data/lib/kanrisuru/core/dmi/parser.rb +3 -0
- data/lib/kanrisuru/core/dmi/parsers/dmi.rb +149 -0
- data/lib/kanrisuru/core/dmi/types.rb +361 -0
- data/lib/kanrisuru/core/dmi.rb +4 -522
- data/lib/kanrisuru/core/file/commands/chmod.rb +29 -0
- data/lib/kanrisuru/core/file/commands/chown.rb +35 -0
- data/lib/kanrisuru/core/file/commands/copy.rb +54 -0
- data/lib/kanrisuru/core/file/commands/link.rb +25 -0
- data/lib/kanrisuru/core/file/commands/mkdir.rb +42 -0
- data/lib/kanrisuru/core/file/commands/move.rb +48 -0
- data/lib/kanrisuru/core/file/commands/rm.rb +41 -0
- data/lib/kanrisuru/core/file/commands/symlink.rb +46 -0
- data/lib/kanrisuru/core/file/commands/touch.rb +34 -0
- data/lib/kanrisuru/core/file/commands/unlink.rb +13 -0
- data/lib/kanrisuru/core/file/commands/wc.rb +16 -0
- data/lib/kanrisuru/core/file/commands.rb +29 -0
- data/lib/kanrisuru/core/file/parser.rb +3 -0
- data/lib/kanrisuru/core/file/parsers/wc.rb +16 -0
- data/lib/kanrisuru/core/file/types.rb +9 -0
- data/lib/kanrisuru/core/file.rb +4 -312
- data/lib/kanrisuru/core/find/commands/find.rb +97 -0
- data/lib/kanrisuru/core/find/commands.rb +3 -0
- data/lib/kanrisuru/core/find/constants.rb +9 -0
- data/lib/kanrisuru/core/find/parser.rb +3 -0
- data/lib/kanrisuru/core/find/parsers/find.rb +18 -0
- data/lib/kanrisuru/core/find/types.rb +9 -0
- data/lib/kanrisuru/core/find.rb +5 -97
- data/lib/kanrisuru/core/group/commands/create_group.rb +21 -0
- data/lib/kanrisuru/core/group/commands/delete_group.rb +16 -0
- data/lib/kanrisuru/core/group/commands/get_gid.rb +17 -0
- data/lib/kanrisuru/core/group/commands/get_group.rb +29 -0
- data/lib/kanrisuru/core/group/commands/is_group.rb +14 -0
- data/lib/kanrisuru/core/group/commands/update_group.rb +23 -0
- data/lib/kanrisuru/core/group/commands.rb +8 -0
- data/lib/kanrisuru/core/group/parser.rb +4 -0
- data/lib/kanrisuru/core/group/parsers/gid.rb +15 -0
- data/lib/kanrisuru/core/group/parsers/group.rb +15 -0
- data/lib/kanrisuru/core/group/types.rb +10 -0
- data/lib/kanrisuru/core/group.rb +4 -81
- data/lib/kanrisuru/core/ip/commands/address.rb +86 -0
- data/lib/kanrisuru/core/ip/commands/address_label.rb +54 -0
- data/lib/kanrisuru/core/ip/commands/link.rb +116 -0
- data/lib/kanrisuru/core/ip/commands/link_set_opts.rb +61 -0
- data/lib/kanrisuru/core/ip/commands/link_type_opts.rb +313 -0
- data/lib/kanrisuru/core/ip/commands/maddress.rb +42 -0
- data/lib/kanrisuru/core/ip/commands/neighbour.rb +72 -0
- data/lib/kanrisuru/core/ip/commands/route.rb +152 -0
- data/lib/kanrisuru/core/ip/commands/rule.rb +57 -0
- data/lib/kanrisuru/core/ip/commands.rb +26 -0
- data/lib/kanrisuru/core/ip/constants.rb +25 -0
- data/lib/kanrisuru/core/ip/parser.rb +11 -0
- data/lib/kanrisuru/core/ip/parsers/address.rb +104 -0
- data/lib/kanrisuru/core/ip/parsers/address_label.rb +27 -0
- data/lib/kanrisuru/core/ip/parsers/base.rb +166 -0
- data/lib/kanrisuru/core/ip/parsers/link.rb +86 -0
- data/lib/kanrisuru/core/ip/parsers/maddress.rb +85 -0
- data/lib/kanrisuru/core/ip/parsers/neighbour.rb +89 -0
- data/lib/kanrisuru/core/ip/parsers/route.rb +76 -0
- data/lib/kanrisuru/core/ip/parsers/rule.rb +60 -0
- data/lib/kanrisuru/core/ip/parsers/version.rb +15 -0
- data/lib/kanrisuru/core/ip/types.rb +46 -0
- data/lib/kanrisuru/core/ip.rb +15 -1002
- data/lib/kanrisuru/core/mount/commands/mount.rb +65 -0
- data/lib/kanrisuru/core/mount/commands/umount.rb +35 -0
- data/lib/kanrisuru/core/mount/commands.rb +49 -0
- data/lib/kanrisuru/core/mount.rb +2 -125
- data/lib/kanrisuru/core/path/commands/ls.rb +26 -0
- data/lib/kanrisuru/core/path/commands/pwd.rb +16 -0
- data/lib/kanrisuru/core/path/commands/readlink.rb +22 -0
- data/lib/kanrisuru/core/path/commands/realpath.rb +18 -0
- data/lib/kanrisuru/core/path/commands/which.rb +19 -0
- data/lib/kanrisuru/core/path/commands/whoami.rb +16 -0
- data/lib/kanrisuru/core/path/commands.rb +8 -0
- data/lib/kanrisuru/core/path/parser.rb +4 -0
- data/lib/kanrisuru/core/path/parsers/ls.rb +53 -0
- data/lib/kanrisuru/core/path/parsers/which.rb +18 -0
- data/lib/kanrisuru/core/path/types.rb +12 -0
- data/lib/kanrisuru/core/path.rb +4 -121
- data/lib/kanrisuru/core/socket/commands/ss.rb +44 -0
- data/lib/kanrisuru/core/socket/commands.rb +3 -0
- data/lib/kanrisuru/core/socket/constants.rb +29 -0
- data/lib/kanrisuru/core/socket/parser.rb +3 -0
- data/lib/kanrisuru/core/socket/parsers/ss.rb +109 -0
- data/lib/kanrisuru/core/socket/types.rb +18 -0
- data/lib/kanrisuru/core/socket.rb +5 -164
- data/lib/kanrisuru/core/stat/commands/stat.rb +62 -0
- data/lib/kanrisuru/core/stat/commands.rb +3 -0
- data/lib/kanrisuru/core/stat/parser.rb +3 -0
- data/lib/kanrisuru/core/stat/parsers/stat.rb +34 -0
- data/lib/kanrisuru/core/stat/types.rb +14 -0
- data/lib/kanrisuru/core/stat.rb +4 -81
- data/lib/kanrisuru/core/stream/commands/cat.rb +25 -0
- data/lib/kanrisuru/core/stream/commands/echo.rb +20 -0
- data/lib/kanrisuru/core/stream/commands/head.rb +18 -0
- data/lib/kanrisuru/core/stream/commands/read_file_chunk.rb +21 -0
- data/lib/kanrisuru/core/stream/commands/sed.rb +23 -0
- data/lib/kanrisuru/core/stream/commands/tail.rb +18 -0
- data/lib/kanrisuru/core/stream/commands.rb +27 -0
- data/lib/kanrisuru/core/stream/parser.rb +4 -0
- data/lib/kanrisuru/core/stream/parsers/echo.rb +17 -0
- data/lib/kanrisuru/core/stream/parsers/sed.rb +17 -0
- data/lib/kanrisuru/core/stream.rb +3 -104
- data/lib/kanrisuru/core/system/commands/cpu_info.rb +32 -0
- data/lib/kanrisuru/core/system/commands/free.rb +25 -0
- data/lib/kanrisuru/core/system/commands/kernel_statistics.rb +21 -0
- data/lib/kanrisuru/core/system/commands/kill.rb +22 -0
- data/lib/kanrisuru/core/system/commands/last.rb +31 -0
- data/lib/kanrisuru/core/system/commands/load_average.rb +16 -0
- data/lib/kanrisuru/core/system/commands/load_env.rb +16 -0
- data/lib/kanrisuru/core/system/commands/lscpu.rb +17 -0
- data/lib/kanrisuru/core/system/commands/lsof.rb +16 -0
- data/lib/kanrisuru/core/system/commands/poweroff.rb +42 -0
- data/lib/kanrisuru/core/system/commands/ps.rb +35 -0
- data/lib/kanrisuru/core/system/commands/reboot.rb +42 -0
- data/lib/kanrisuru/core/system/commands/uptime.rb +18 -0
- data/lib/kanrisuru/core/system/commands/w.rb +24 -0
- data/lib/kanrisuru/core/system/commands.rb +34 -0
- data/lib/kanrisuru/core/system/parser.rb +11 -0
- data/lib/kanrisuru/core/system/parsers/kernel_statistics.rb +56 -0
- data/lib/kanrisuru/core/system/parsers/last.rb +64 -0
- data/lib/kanrisuru/core/system/parsers/load_average.rb +15 -0
- data/lib/kanrisuru/core/system/parsers/load_env.rb +24 -0
- data/lib/kanrisuru/core/system/parsers/lscpu.rb +90 -0
- data/lib/kanrisuru/core/system/parsers/lsof.rb +62 -0
- data/lib/kanrisuru/core/system/parsers/ps.rb +71 -0
- data/lib/kanrisuru/core/system/parsers/uptime.rb +38 -0
- data/lib/kanrisuru/core/system/parsers/w.rb +30 -0
- data/lib/kanrisuru/core/system/types.rb +108 -0
- data/lib/kanrisuru/core/system.rb +4 -687
- data/lib/kanrisuru/core/transfer/commands/download.rb +26 -0
- data/lib/kanrisuru/core/transfer/commands/upload.rb +23 -0
- data/lib/kanrisuru/core/transfer/commands/wget.rb +168 -0
- data/lib/kanrisuru/core/transfer/commands.rb +5 -0
- data/lib/kanrisuru/core/transfer/constants.rb +10 -0
- data/lib/kanrisuru/core/transfer.rb +3 -199
- data/lib/kanrisuru/core/user/commands/create_user.rb +49 -0
- data/lib/kanrisuru/core/user/commands/delete_user.rb +20 -0
- data/lib/kanrisuru/core/user/commands/get_uid.rb +15 -0
- data/lib/kanrisuru/core/user/commands/get_user.rb +48 -0
- data/lib/kanrisuru/core/user/commands/is_user.rb +14 -0
- data/lib/kanrisuru/core/user/commands/update_user.rb +54 -0
- data/lib/kanrisuru/core/user/commands.rb +8 -0
- data/lib/kanrisuru/core/user/parser.rb +4 -0
- data/lib/kanrisuru/core/user/parsers/getent.rb +17 -0
- data/lib/kanrisuru/core/user/parsers/groups.rb +17 -0
- data/lib/kanrisuru/core/user/types.rb +11 -0
- data/lib/kanrisuru/core/user.rb +4 -182
- data/lib/kanrisuru/core/yum/commands/autoremove.rb +14 -0
- data/lib/kanrisuru/core/yum/commands/clean.rb +23 -0
- data/lib/kanrisuru/core/yum/commands/erase.rb +20 -0
- data/lib/kanrisuru/core/yum/commands/info.rb +21 -0
- data/lib/kanrisuru/core/yum/commands/install.rb +18 -0
- data/lib/kanrisuru/core/yum/commands/list.rb +30 -0
- data/lib/kanrisuru/core/yum/commands/localinstall.rb +22 -0
- data/lib/kanrisuru/core/yum/commands/remove.rb +20 -0
- data/lib/kanrisuru/core/yum/commands/repolist.rb +20 -0
- data/lib/kanrisuru/core/yum/commands/search.rb +21 -0
- data/lib/kanrisuru/core/yum/commands/update.rb +14 -0
- data/lib/kanrisuru/core/yum/commands/upgrade.rb +14 -0
- data/lib/kanrisuru/core/yum/commands.rb +39 -0
- data/lib/kanrisuru/core/yum/parser.rb +7 -0
- data/lib/kanrisuru/core/yum/parsers/base.rb +31 -0
- data/lib/kanrisuru/core/yum/parsers/info.rb +69 -0
- data/lib/kanrisuru/core/yum/parsers/list.rb +24 -0
- data/lib/kanrisuru/core/yum/parsers/repolist.rb +60 -0
- data/lib/kanrisuru/core/yum/parsers/search.rb +30 -0
- data/lib/kanrisuru/core/yum/types.rb +41 -0
- data/lib/kanrisuru/core/yum.rb +4 -347
- data/lib/kanrisuru/core/zypper/commands/add_lock.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/add_repo.rb +38 -0
- data/lib/kanrisuru/core/zypper/commands/add_service.rb +26 -0
- data/lib/kanrisuru/core/zypper/commands/clean_cache.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/clean_locks.rb +17 -0
- data/lib/kanrisuru/core/zypper/commands/dist_upgrade.rb +25 -0
- data/lib/kanrisuru/core/zypper/commands/info.rb +25 -0
- data/lib/kanrisuru/core/zypper/commands/install.rb +39 -0
- data/lib/kanrisuru/core/zypper/commands/install_new_recommends.rb +23 -0
- data/lib/kanrisuru/core/zypper/commands/list_locks.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/list_patches.rb +34 -0
- data/lib/kanrisuru/core/zypper/commands/list_repos.rb +21 -0
- data/lib/kanrisuru/core/zypper/commands/list_services.rb +21 -0
- data/lib/kanrisuru/core/zypper/commands/list_updates.rb +30 -0
- data/lib/kanrisuru/core/zypper/commands/modify_repo.rb +48 -0
- data/lib/kanrisuru/core/zypper/commands/modify_service.rb +40 -0
- data/lib/kanrisuru/core/zypper/commands/patch.rb +40 -0
- data/lib/kanrisuru/core/zypper/commands/patch_check.rb +29 -0
- data/lib/kanrisuru/core/zypper/commands/purge_kernels.rb +18 -0
- data/lib/kanrisuru/core/zypper/commands/refresh_repos.rb +24 -0
- data/lib/kanrisuru/core/zypper/commands/refresh_services.rb +21 -0
- data/lib/kanrisuru/core/zypper/commands/remove.rb +26 -0
- data/lib/kanrisuru/core/zypper/commands/remove_lock.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/remove_repo.rb +32 -0
- data/lib/kanrisuru/core/zypper/commands/remove_service.rb +21 -0
- data/lib/kanrisuru/core/zypper/commands/rename_repo.rb +20 -0
- data/lib/kanrisuru/core/zypper/commands/search.rb +52 -0
- data/lib/kanrisuru/core/zypper/commands/source_install.rb +22 -0
- data/lib/kanrisuru/core/zypper/commands/update.rb +27 -0
- data/lib/kanrisuru/core/zypper/commands/verify.rb +23 -0
- data/lib/kanrisuru/core/zypper/commands.rb +109 -0
- data/lib/kanrisuru/core/zypper/constants.rb +19 -0
- data/lib/kanrisuru/core/zypper/parser.rb +11 -0
- data/lib/kanrisuru/core/zypper/parsers/base.rb +18 -0
- data/lib/kanrisuru/core/zypper/parsers/info.rb +77 -0
- data/lib/kanrisuru/core/zypper/parsers/list_locks.rb +36 -0
- data/lib/kanrisuru/core/zypper/parsers/list_patches.rb +40 -0
- data/lib/kanrisuru/core/zypper/parsers/list_repos.rb +37 -0
- data/lib/kanrisuru/core/zypper/parsers/list_services.rb +36 -0
- data/lib/kanrisuru/core/zypper/parsers/list_updates.rb +32 -0
- data/lib/kanrisuru/core/zypper/parsers/patch_check.rb +34 -0
- data/lib/kanrisuru/core/zypper/parsers/search.rb +37 -0
- data/lib/kanrisuru/core/zypper/types.rb +88 -0
- data/lib/kanrisuru/core/zypper.rb +5 -998
- data/lib/kanrisuru/result.rb +15 -0
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/archive_spec.rb +1 -1
- data/spec/functional/core/disk_spec.rb +77 -0
- data/spec/functional/core/dmi_spec.rb +78 -0
- data/spec/functional/core/file_spec.rb +284 -0
- data/spec/functional/core/group_spec.rb +62 -0
- data/spec/functional/core/ip/ip_address_label_spec.rb +81 -0
- data/spec/functional/core/ip/ip_address_spec.rb +95 -0
- data/spec/functional/core/ip/ip_link_spec.rb +814 -0
- data/spec/functional/core/ip/ip_maddress_spec.rb +78 -0
- data/spec/functional/core/ip/ip_neighbour_spec.rb +119 -0
- data/spec/functional/core/ip/ip_route_spec.rb +174 -0
- data/spec/functional/core/ip/ip_rule_spec.rb +75 -0
- data/spec/functional/core/ip/ip_spec.rb +27 -0
- data/spec/functional/core/system_spec.rb +135 -0
- data/spec/functional/core/user_spec.rb +97 -0
- data/spec/functional/result_spec.rb +197 -0
- data/spec/{hosts.json → helper/hosts.json} +0 -0
- data/spec/helper/simplecov.rb +21 -0
- data/spec/helper/stub_network.rb +6 -2
- data/spec/helper/test_hosts.rb +1 -1
- data/spec/integration/core/apt/debian_spec.rb +9 -0
- data/spec/integration/core/apt/ubuntu_spec.rb +9 -0
- data/spec/integration/core/archive/centos_spec.rb +9 -0
- data/spec/integration/core/archive/debian_spec.rb +9 -0
- data/spec/integration/core/archive/fedora_spec.rb +9 -0
- data/spec/integration/core/archive/opensuse_spec.rb +9 -0
- data/spec/integration/core/archive/rhel_spec.rb +9 -0
- data/spec/integration/core/archive/sles_spec.rb +9 -0
- data/spec/integration/core/archive/ubuntu_spec.rb +9 -0
- data/spec/integration/core/disk/centos_spec.rb +9 -0
- data/spec/integration/core/disk/debian_spec.rb +9 -0
- data/spec/integration/core/disk/fedora_spec.rb +9 -0
- data/spec/integration/core/disk/opensuse_spec.rb +9 -0
- data/spec/integration/core/disk/rhel_spec.rb +9 -0
- data/spec/integration/core/disk/sles_spec.rb +9 -0
- data/spec/integration/core/disk/ubuntu_spec.rb +9 -0
- data/spec/integration/core/dmi/centos_spec.rb +9 -0
- data/spec/integration/core/dmi/debian_spec.rb +9 -0
- data/spec/integration/core/dmi/fedora_spec.rb +9 -0
- data/spec/integration/core/dmi/opensuse_spec.rb +9 -0
- data/spec/integration/core/dmi/rhel_spec.rb +9 -0
- data/spec/integration/core/dmi/sles_spec.rb +9 -0
- data/spec/integration/core/dmi/ubuntu_spec.rb +9 -0
- data/spec/integration/core/file/centos_spec.rb +9 -0
- data/spec/integration/core/file/debian_spec.rb +9 -0
- data/spec/integration/core/file/fedora_spec.rb +9 -0
- data/spec/integration/core/file/opensuse_spec.rb +9 -0
- data/spec/integration/core/file/rhel_spec.rb +9 -0
- data/spec/integration/core/file/sles_spec.rb +9 -0
- data/spec/integration/core/file/ubuntu_spec.rb +9 -0
- data/spec/integration/core/find/centos_spec.rb +9 -0
- data/spec/integration/core/find/debian_spec.rb +9 -0
- data/spec/integration/core/find/fedora_spec.rb +9 -0
- data/spec/integration/core/find/opensuse_spec.rb +9 -0
- data/spec/integration/core/find/rhel_spec.rb +9 -0
- data/spec/integration/core/find/sles_spec.rb +9 -0
- data/spec/integration/core/find/ubuntu_spec.rb +9 -0
- data/spec/integration/core/group/centos_spec.rb +9 -0
- data/spec/integration/core/group/debian_spec.rb +9 -0
- data/spec/integration/core/group/fedora_spec.rb +9 -0
- data/spec/integration/core/group/opensuse_spec.rb +9 -0
- data/spec/integration/core/group/rhel_spec.rb +9 -0
- data/spec/integration/core/group/sles_spec.rb +9 -0
- data/spec/integration/core/group/ubuntu_spec.rb +9 -0
- data/spec/integration/core/ip/centos_spec.rb +9 -0
- data/spec/integration/core/ip/debian_spec.rb +9 -0
- data/spec/integration/core/ip/fedora_spec.rb +9 -0
- data/spec/integration/core/ip/opensuse_spec.rb +9 -0
- data/spec/integration/core/ip/rhel_spec.rb +9 -0
- data/spec/integration/core/ip/sles_spec.rb +9 -0
- data/spec/integration/core/ip/ubuntu_spec.rb +9 -0
- data/spec/integration/core/path/centos_spec.rb +9 -0
- data/spec/integration/core/path/debian_spec.rb +9 -0
- data/spec/integration/core/path/fedora_spec.rb +9 -0
- data/spec/integration/core/path/opensuse_spec.rb +9 -0
- data/spec/integration/core/path/rhel_spec.rb +9 -0
- data/spec/integration/core/path/sles_spec.rb +9 -0
- data/spec/integration/core/path/ubuntu_spec.rb +9 -0
- data/spec/integration/core/socket/centos_spec.rb +9 -0
- data/spec/integration/core/socket/debian_spec.rb +9 -0
- data/spec/integration/core/socket/fedora_spec.rb +9 -0
- data/spec/integration/core/socket/opensuse_spec.rb +9 -0
- data/spec/integration/core/socket/rhel_spec.rb +9 -0
- data/spec/integration/core/socket/sles_spec.rb +9 -0
- data/spec/integration/core/socket/ubuntu_spec.rb +9 -0
- data/spec/integration/core/stat/centos_spec.rb +9 -0
- data/spec/integration/core/stat/debian_spec.rb +9 -0
- data/spec/integration/core/stat/fedora_spec.rb +9 -0
- data/spec/integration/core/stat/opensuse_spec.rb +9 -0
- data/spec/integration/core/stat/rhel_spec.rb +9 -0
- data/spec/integration/core/stat/sles_spec.rb +9 -0
- data/spec/integration/core/stat/ubuntu_spec.rb +9 -0
- data/spec/integration/core/stream/centos_spec.rb +9 -0
- data/spec/integration/core/stream/debian_spec.rb +9 -0
- data/spec/integration/core/stream/fedora_spec.rb +9 -0
- data/spec/integration/core/stream/opensuse_spec.rb +9 -0
- data/spec/integration/core/stream/rhel_spec.rb +9 -0
- data/spec/integration/core/stream/sles_spec.rb +9 -0
- data/spec/integration/core/stream/ubuntu_spec.rb +9 -0
- data/spec/integration/core/system/centos_spec.rb +9 -0
- data/spec/integration/core/system/debian_spec.rb +9 -0
- data/spec/integration/core/system/fedora_spec.rb +9 -0
- data/spec/integration/core/system/opensuse_spec.rb +9 -0
- data/spec/integration/core/system/rhel_spec.rb +9 -0
- data/spec/integration/core/system/sles_spec.rb +9 -0
- data/spec/integration/core/system/ubuntu_spec.rb +9 -0
- data/spec/integration/core/transfer/centos_spec.rb +9 -0
- data/spec/integration/core/transfer/debian_spec.rb +9 -0
- data/spec/integration/core/transfer/fedora_spec.rb +9 -0
- data/spec/integration/core/transfer/opensuse_spec.rb +9 -0
- data/spec/integration/core/transfer/rhel_spec.rb +9 -0
- data/spec/integration/core/transfer/sles_spec.rb +9 -0
- data/spec/integration/core/transfer/ubuntu_spec.rb +9 -0
- data/spec/integration/core/user/centos_spec.rb +9 -0
- data/spec/integration/core/user/debian_spec.rb +9 -0
- data/spec/integration/core/user/fedora_spec.rb +9 -0
- data/spec/integration/core/user/opensuse_spec.rb +9 -0
- data/spec/integration/core/user/rhel_spec.rb +9 -0
- data/spec/integration/core/user/sles_spec.rb +9 -0
- data/spec/integration/core/user/ubuntu_spec.rb +9 -0
- data/spec/integration/core/yum/centos_spec.rb +9 -0
- data/spec/integration/core/yum/fedora_spec.rb +9 -0
- data/spec/integration/core/yum/rhel_spec.rb +9 -0
- data/spec/integration/core/zypper/opensuse_spec.rb +9 -0
- data/spec/integration/core/zypper/sles_spec.rb +9 -0
- data/spec/integration/remote/cluster/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/cpu/centos_spec.rb +9 -0
- data/spec/integration/remote/cpu/debian_spec.rb +9 -0
- data/spec/integration/remote/cpu/fedora_spec.rb +9 -0
- data/spec/integration/remote/cpu/opensuse_spec.rb +9 -0
- data/spec/integration/remote/cpu/rhel_spec.rb +9 -0
- data/spec/integration/remote/cpu/sles_spec.rb +9 -0
- data/spec/integration/remote/cpu/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/env/centos_spec.rb +9 -0
- data/spec/integration/remote/env/debian_spec.rb +9 -0
- data/spec/integration/remote/env/fedora_spec.rb +9 -0
- data/spec/integration/remote/env/opensuse_spec.rb +9 -0
- data/spec/integration/remote/env/rhel_spec.rb +9 -0
- data/spec/integration/remote/env/sles_spec.rb +9 -0
- data/spec/integration/remote/env/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/fstab/centos_spec.rb +9 -0
- data/spec/integration/remote/fstab/debian_spec.rb +9 -0
- data/spec/integration/remote/fstab/fedora_spec.rb +9 -0
- data/spec/integration/remote/fstab/opensuse_spec.rb +9 -0
- data/spec/integration/remote/fstab/rhel_spec.rb +9 -0
- data/spec/integration/remote/fstab/sles_spec.rb +9 -0
- data/spec/integration/remote/fstab/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/host/centos_spec.rb +9 -0
- data/spec/integration/remote/host/debian_spec.rb +9 -0
- data/spec/integration/remote/host/fedora_spec.rb +9 -0
- data/spec/integration/remote/host/opensuse_spec.rb +9 -0
- data/spec/integration/remote/host/rhel_spec.rb +9 -0
- data/spec/integration/remote/host/sles_spec.rb +9 -0
- data/spec/integration/remote/host/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/memory/centos_spec.rb +9 -0
- data/spec/integration/remote/memory/debian_spec.rb +9 -0
- data/spec/integration/remote/memory/fedora_spec.rb +9 -0
- data/spec/integration/remote/memory/opensuse_spec.rb +9 -0
- data/spec/integration/remote/memory/rhel_spec.rb +9 -0
- data/spec/integration/remote/memory/sles_spec.rb +9 -0
- data/spec/integration/remote/memory/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/os/centos_spec.rb +9 -0
- data/spec/integration/remote/os/debian_spec.rb +9 -0
- data/spec/integration/remote/os/fedora_spec.rb +9 -0
- data/spec/integration/remote/os/opensuse_spec.rb +9 -0
- data/spec/integration/remote/os/rhel_spec.rb +9 -0
- data/spec/integration/remote/os/sles_spec.rb +9 -0
- data/spec/integration/remote/os/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/remote_file/centos_spec.rb +9 -0
- data/spec/integration/remote/remote_file/debian_spec.rb +9 -0
- data/spec/integration/remote/remote_file/fedora_spec.rb +9 -0
- data/spec/integration/remote/remote_file/opensuse_spec.rb +9 -0
- data/spec/integration/remote/remote_file/rhel_spec.rb +9 -0
- data/spec/integration/remote/remote_file/sles_spec.rb +9 -0
- data/spec/integration/remote/remote_file/ubuntu_spec.rb +9 -0
- data/spec/spec_helper.rb +2 -11
- data/spec/support/shared_examples/integration/core/apt.rb +117 -0
- data/spec/support/shared_examples/integration/core/archive.rb +221 -0
- data/spec/support/shared_examples/integration/core/disk.rb +91 -0
- data/spec/support/shared_examples/integration/core/dmi.rb +34 -0
- data/spec/support/shared_examples/integration/core/file.rb +357 -0
- data/spec/support/shared_examples/integration/core/find.rb +50 -0
- data/spec/support/shared_examples/integration/core/group.rb +62 -0
- data/spec/support/shared_examples/integration/core/ip.rb +68 -0
- data/spec/support/shared_examples/integration/core/path.rb +90 -0
- data/spec/support/shared_examples/integration/core/socket.rb +27 -0
- data/spec/support/shared_examples/integration/core/stat.rb +95 -0
- data/spec/support/shared_examples/integration/core/stream.rb +112 -0
- data/spec/support/shared_examples/integration/core/system.rb +155 -0
- data/spec/support/shared_examples/integration/core/transfer.rb +101 -0
- data/spec/support/shared_examples/integration/core/user.rb +72 -0
- data/spec/support/shared_examples/integration/core/yum.rb +115 -0
- data/spec/support/shared_examples/integration/core/zypper.rb +196 -0
- data/spec/{integration/remote/cluster_spec.rb → support/shared_examples/integration/remote/cluster.rb} +2 -2
- data/spec/support/shared_examples/integration/remote/cpu.rb +38 -0
- data/spec/support/shared_examples/integration/remote/env_spec.rb +33 -0
- data/spec/support/shared_examples/integration/remote/fstab.rb +89 -0
- data/spec/support/shared_examples/integration/remote/host.rb +65 -0
- data/spec/support/shared_examples/integration/remote/memory.rb +27 -0
- data/spec/support/shared_examples/integration/remote/os.rb +60 -0
- data/spec/support/shared_examples/integration/remote/remote_file.rb +172 -0
- data/spec/unit/command_spec.rb +2 -0
- data/spec/unit/core/ip_spec.rb +12 -0
- data/spec/unit/util_spec.rb +16 -0
- metadata +436 -31
- data/spec/integration/core/apt_spec.rb +0 -119
- data/spec/integration/core/archive_spec.rb +0 -223
- data/spec/integration/core/disk_spec.rb +0 -93
- data/spec/integration/core/dmi_spec.rb +0 -36
- data/spec/integration/core/file_spec.rb +0 -359
- data/spec/integration/core/find_spec.rb +0 -52
- data/spec/integration/core/group_spec.rb +0 -64
- data/spec/integration/core/ip_spec.rb +0 -70
- data/spec/integration/core/path_spec.rb +0 -92
- data/spec/integration/core/socket_spec.rb +0 -29
- data/spec/integration/core/stat_spec.rb +0 -97
- data/spec/integration/core/stream_spec.rb +0 -114
- data/spec/integration/core/system_spec.rb +0 -142
- data/spec/integration/core/transfer_spec.rb +0 -103
- data/spec/integration/core/user_spec.rb +0 -74
- data/spec/integration/core/yum_spec.rb +0 -117
- data/spec/integration/core/zypper_spec.rb +0 -198
- data/spec/integration/remote/cpu_spec.rb +0 -40
- data/spec/integration/remote/env_spec.rb +0 -35
- data/spec/integration/remote/fstab_spec.rb +0 -91
- data/spec/integration/remote/host_spec.rb +0 -67
- data/spec/integration/remote/memory_spec.rb +0 -29
- data/spec/integration/remote/os_spec.rb +0 -62
- data/spec/integration/remote/remote_file_spec.rb +0 -174
- data/spec/zz_reboot_spec.rb +0 -46
@@ -3,6 +3,10 @@
|
|
3
3
|
require 'date'
|
4
4
|
require 'ipaddr'
|
5
5
|
|
6
|
+
require_relative 'system/types'
|
7
|
+
require_relative 'system/parser'
|
8
|
+
require_relative 'system/commands'
|
9
|
+
|
6
10
|
module Kanrisuru
|
7
11
|
module Core
|
8
12
|
module System
|
@@ -15,702 +19,15 @@ module Kanrisuru
|
|
15
19
|
os_define :linux, :free
|
16
20
|
os_define :linux, :ps
|
17
21
|
os_define :linux, :kill
|
18
|
-
|
19
22
|
os_define :linux, :kernel_statistics
|
20
23
|
os_define :linux, :kstat
|
21
|
-
|
22
24
|
os_define :linux, :lsof
|
23
25
|
os_define :linux, :last
|
24
|
-
|
25
26
|
os_define :linux, :uptime
|
26
|
-
|
27
27
|
os_define :linux, :w
|
28
28
|
os_define :linux, :who
|
29
|
-
|
30
29
|
os_define :linux, :reboot
|
31
30
|
os_define :linux, :poweroff
|
32
|
-
|
33
|
-
CPUArchitectureVulnerability = Struct.new(
|
34
|
-
:name,
|
35
|
-
:data
|
36
|
-
)
|
37
|
-
|
38
|
-
CPUArchitecture = Struct.new(
|
39
|
-
:architecture,
|
40
|
-
:cores,
|
41
|
-
:byte_order,
|
42
|
-
:address_sizes,
|
43
|
-
:operation_modes,
|
44
|
-
:online_cpus,
|
45
|
-
:threads_per_core,
|
46
|
-
:cores_per_socket,
|
47
|
-
:sockets,
|
48
|
-
:numa_mode,
|
49
|
-
:vendor_id,
|
50
|
-
:cpu_family,
|
51
|
-
:model,
|
52
|
-
:model_name,
|
53
|
-
:stepping,
|
54
|
-
:cpu_mhz,
|
55
|
-
:cpu_max_mhz,
|
56
|
-
:cpu_min_mhz,
|
57
|
-
:bogo_mips,
|
58
|
-
:virtualization,
|
59
|
-
:hypervisor_vendor,
|
60
|
-
:virtualization_type,
|
61
|
-
:l1d_cache,
|
62
|
-
:l1i_cache,
|
63
|
-
:l2_cache,
|
64
|
-
:l3_cache,
|
65
|
-
:numa_nodes,
|
66
|
-
:vulnerabilities,
|
67
|
-
:flags
|
68
|
-
)
|
69
|
-
|
70
|
-
KernelStatisticCpu = Struct.new(
|
71
|
-
:user,
|
72
|
-
:nice,
|
73
|
-
:system,
|
74
|
-
:idle,
|
75
|
-
:iowait,
|
76
|
-
:irq,
|
77
|
-
:softirq,
|
78
|
-
:steal,
|
79
|
-
:guest,
|
80
|
-
:guest_nice
|
81
|
-
)
|
82
|
-
|
83
|
-
KernelStatistic = Struct.new(
|
84
|
-
:cpu_total,
|
85
|
-
:cpus,
|
86
|
-
:interrupt_total,
|
87
|
-
:interrupts,
|
88
|
-
:ctxt,
|
89
|
-
:btime,
|
90
|
-
:processes,
|
91
|
-
:procs_running,
|
92
|
-
:procs_blocked,
|
93
|
-
:softirq_total,
|
94
|
-
:softirqs
|
95
|
-
)
|
96
|
-
|
97
|
-
ProcessInfo = Struct.new(
|
98
|
-
:uid, :user, :gid, :group, :ppid, :pid,
|
99
|
-
:cpu_usage, :memory_usage, :stat, :priority,
|
100
|
-
:flags, :policy_abbr, :policy, :cpu_time, :command
|
101
|
-
)
|
102
|
-
|
103
|
-
Uptime = Struct.new(
|
104
|
-
:boot_time, :uptime, :seconds, :minutes, :hours, :days
|
105
|
-
)
|
106
|
-
|
107
|
-
UserLoggedIn = Struct.new(:user, :tty, :ip, :login, :idle, :jcpu, :pcpu, :command)
|
108
|
-
|
109
|
-
OpenFile = Struct.new(
|
110
|
-
:command,
|
111
|
-
:pid,
|
112
|
-
:uid,
|
113
|
-
:file_descriptor,
|
114
|
-
:type,
|
115
|
-
:device,
|
116
|
-
:fsize,
|
117
|
-
:inode,
|
118
|
-
:name
|
119
|
-
)
|
120
|
-
|
121
|
-
SessionDetail = Struct.new(
|
122
|
-
:tty,
|
123
|
-
:login_at,
|
124
|
-
:logout_at,
|
125
|
-
:ip_address,
|
126
|
-
:success
|
127
|
-
)
|
128
|
-
|
129
|
-
LoginUser = Struct.new(
|
130
|
-
:user,
|
131
|
-
:sessions
|
132
|
-
)
|
133
|
-
|
134
|
-
def load_env
|
135
|
-
command = Kanrisuru::Command.new('env')
|
136
|
-
execute_shell(command)
|
137
|
-
|
138
|
-
Kanrisuru::Result.new(command) do |cmd|
|
139
|
-
string = cmd.to_s
|
140
|
-
hash = {}
|
141
|
-
|
142
|
-
rows = string.split("\n")
|
143
|
-
rows.each do |row|
|
144
|
-
key, value = row.split('=', 2)
|
145
|
-
hash[key] = value
|
146
|
-
end
|
147
|
-
|
148
|
-
hash
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def lscpu
|
153
|
-
command = Kanrisuru::Command.new('lscpu')
|
154
|
-
|
155
|
-
execute_shell(command)
|
156
|
-
|
157
|
-
Kanrisuru::Result.new(command) do |cmd|
|
158
|
-
lines = cmd.to_a
|
159
|
-
|
160
|
-
result = CPUArchitecture.new
|
161
|
-
result.vulnerabilities = []
|
162
|
-
result.numa_nodes = []
|
163
|
-
|
164
|
-
lines.each do |line|
|
165
|
-
values = line.split(': ', 2)
|
166
|
-
|
167
|
-
field = values[0].strip
|
168
|
-
data = values[1].strip
|
169
|
-
|
170
|
-
case field
|
171
|
-
when 'Architecture'
|
172
|
-
result.architecture = data
|
173
|
-
when 'CPU op-mode(s)'
|
174
|
-
result.operation_modes = data.split(', ')
|
175
|
-
when 'Byte Order'
|
176
|
-
result.byte_order = data
|
177
|
-
when 'Address sizes'
|
178
|
-
result.address_sizes = data.split(', ')
|
179
|
-
when 'CPU(s)'
|
180
|
-
result.cores = data.to_i
|
181
|
-
when 'On-line CPU(s) list'
|
182
|
-
result.online_cpus = data.to_i
|
183
|
-
when 'Thread(s) per core'
|
184
|
-
result.threads_per_core = data.to_i
|
185
|
-
when 'Core(s) per socket'
|
186
|
-
result.cores_per_socket = data.to_i
|
187
|
-
when 'Socket(s)'
|
188
|
-
result.sockets = data.to_i
|
189
|
-
when 'NUMA node(s)'
|
190
|
-
result.numa_nodes = data.to_i
|
191
|
-
when 'Vendor ID'
|
192
|
-
result.vendor_id = data
|
193
|
-
when 'CPU family'
|
194
|
-
result.cpu_family = data.to_i
|
195
|
-
when 'Model'
|
196
|
-
result.model = data.to_i
|
197
|
-
when 'Model name'
|
198
|
-
result.model_name = data
|
199
|
-
when 'Stepping'
|
200
|
-
result.stepping = data.to_i
|
201
|
-
when 'CPU MHz'
|
202
|
-
result.cpu_mhz = data.to_f
|
203
|
-
when 'CPU max MHz'
|
204
|
-
result.cpu_max_mhz = data.to_f
|
205
|
-
when 'CPU min MHz'
|
206
|
-
result.cpu_min_mhz = data.to_f
|
207
|
-
when 'CPUBogoMIPS'
|
208
|
-
result.bogo_mips = data.to_f
|
209
|
-
when 'Virtualization'
|
210
|
-
result.virtualization = data
|
211
|
-
when 'Hypervisor vendor'
|
212
|
-
result.hypervisor_vendor = data
|
213
|
-
when 'Virtualization type'
|
214
|
-
result.virtualization_type = data
|
215
|
-
when 'L1d cache'
|
216
|
-
result.l1d_cache = data
|
217
|
-
when 'L1i cache'
|
218
|
-
result.l1i_cache = data
|
219
|
-
when 'L2 cache'
|
220
|
-
result.l2_cache = data
|
221
|
-
when 'L3 cache'
|
222
|
-
result.l3_cache = data
|
223
|
-
when /^Numa node/
|
224
|
-
result.numa_nodes << data.split(',')
|
225
|
-
when /^Vulnerability/
|
226
|
-
name = field.split('Vulnerability ')[1]
|
227
|
-
result.vulnerabilities << CPUArchitectureVulnerability.new(name, data)
|
228
|
-
when 'Flags'
|
229
|
-
result.flags = data.split
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
result
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
def cpu_info(spec)
|
238
|
-
Kanrisuru.logger.info do
|
239
|
-
'DEPRECATION WARNING: cpu_info will be removed in the upcoming major release. Use lscpu instead.'
|
240
|
-
end
|
241
|
-
|
242
|
-
name =
|
243
|
-
case spec
|
244
|
-
when 'sockets'
|
245
|
-
'^Socket'
|
246
|
-
when 'cores_per_socket'
|
247
|
-
'^Core'
|
248
|
-
when 'threads'
|
249
|
-
'^Thread'
|
250
|
-
when 'cores'
|
251
|
-
'^CPU('
|
252
|
-
else
|
253
|
-
return
|
254
|
-
end
|
255
|
-
|
256
|
-
command = Kanrisuru::Command.new("lscpu | grep -i '#{name}' | awk '{print $NF}'")
|
257
|
-
execute(command)
|
258
|
-
|
259
|
-
Kanrisuru::Result.new(command, &:to_i)
|
260
|
-
end
|
261
|
-
|
262
|
-
def load_average
|
263
|
-
command = Kanrisuru::Command.new("cat /proc/loadavg | awk '{print $1,$2,$3}'")
|
264
|
-
execute(command)
|
265
|
-
|
266
|
-
Kanrisuru::Result.new(command) do |cmd|
|
267
|
-
cmd.to_s.split.map(&:to_f)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
def free(type)
|
272
|
-
conversions = {
|
273
|
-
total: 'MemTotal',
|
274
|
-
free: 'MemFree',
|
275
|
-
swap: 'SwapTotal',
|
276
|
-
swap_free: 'SwapFree'
|
277
|
-
}
|
278
|
-
|
279
|
-
option = conversions[type.to_sym]
|
280
|
-
raise ArgumentError, 'Invalid mem type' unless option
|
281
|
-
|
282
|
-
command = Kanrisuru::Command.new("cat /proc/meminfo | grep -i '^#{option}' | awk '{print $2}'")
|
283
|
-
execute(command)
|
284
|
-
|
285
|
-
## In kB
|
286
|
-
Kanrisuru::Result.new(command, &:to_i)
|
287
|
-
end
|
288
|
-
|
289
|
-
def last(opts = {})
|
290
|
-
command =
|
291
|
-
if opts[:failed_attempts]
|
292
|
-
Kanrisuru::Command.new('lastb')
|
293
|
-
else
|
294
|
-
Kanrisuru::Command.new('last')
|
295
|
-
end
|
296
|
-
|
297
|
-
command.append_flag('-i')
|
298
|
-
command.append_flag('-F')
|
299
|
-
command.append_arg('-f', opts[:file])
|
300
|
-
|
301
|
-
## Some systems only use 1 space between user and TTY field
|
302
|
-
## Add an additional space in output formatting for simple parsing
|
303
|
-
## logic.
|
304
|
-
command | "sed 's/ / /'"
|
305
|
-
|
306
|
-
execute_shell(command)
|
307
|
-
|
308
|
-
Kanrisuru::Result.new(command) do |cmd|
|
309
|
-
lines = cmd.to_a
|
310
|
-
|
311
|
-
mapping = {}
|
312
|
-
|
313
|
-
lines.each do |line|
|
314
|
-
next if Kanrisuru::Util.blank?(line)
|
315
|
-
next if line.include?('wtmp') || line.include?('btmp')
|
316
|
-
|
317
|
-
line = line.gsub(' still logged in', '- still logged in') if line.include?('still logged in')
|
318
|
-
|
319
|
-
values = line.split(/\s{2,}/, 4)
|
320
|
-
user = values[0]
|
321
|
-
tty = values[1]
|
322
|
-
ip = IPAddr.new(values[2])
|
323
|
-
|
324
|
-
date_range = values[3]
|
325
|
-
login, logout = date_range.split(' - ')
|
326
|
-
|
327
|
-
login = parse_last_date(login) if login
|
328
|
-
|
329
|
-
logout = parse_last_date(logout) if logout
|
330
|
-
|
331
|
-
detail = SessionDetail.new
|
332
|
-
detail.tty = tty
|
333
|
-
detail.ip_address = ip
|
334
|
-
detail.login_at = login
|
335
|
-
detail.logout_at = logout
|
336
|
-
|
337
|
-
detail.success = !Kanrisuru::Util.present?(opts[:failed_attemps])
|
338
|
-
|
339
|
-
mapping[user] = LoginUser.new(user, []) unless mapping.key?(user)
|
340
|
-
|
341
|
-
mapping[user].sessions << detail
|
342
|
-
end
|
343
|
-
|
344
|
-
mapping.values
|
345
|
-
end
|
346
|
-
end
|
347
|
-
|
348
|
-
def ps(opts = {})
|
349
|
-
group = opts[:group]
|
350
|
-
user = opts[:user]
|
351
|
-
pid = opts[:pid]
|
352
|
-
ppid = opts[:ppid]
|
353
|
-
# tree = opts[:tree]
|
354
|
-
|
355
|
-
command = Kanrisuru::Command.new('ps ww')
|
356
|
-
|
357
|
-
if !user.nil? || !group.nil? || !pid.nil? || !ppid.nil?
|
358
|
-
command.append_arg('--user', user.instance_of?(Array) ? user.join(',') : user)
|
359
|
-
command.append_arg('--group', group.instance_of?(Array) ? group.join(',') : group)
|
360
|
-
command.append_arg('--pid', pid.instance_of?(Array) ? pid.join(',') : pid)
|
361
|
-
command.append_arg('--ppid', ppid.instance_of?(Array) ? ppid.join(',') : ppid)
|
362
|
-
else
|
363
|
-
command.append_flag('ax')
|
364
|
-
end
|
365
|
-
|
366
|
-
command.append_arg('-o', 'uid,user,gid,group,ppid,pid,pcpu,pmem,stat,pri,flags,policy,time,cmd')
|
367
|
-
command.append_flag('--no-headers')
|
368
|
-
|
369
|
-
execute(command)
|
370
|
-
|
371
|
-
## Have found issues with regular newline parsing from command
|
372
|
-
## most likely a buffer overflow from SSH buffer.
|
373
|
-
## Join string then split by newline.
|
374
|
-
Kanrisuru::Result.new(command) do |cmd|
|
375
|
-
result_string = cmd.raw_result.join
|
376
|
-
rows = result_string.split("\n")
|
377
|
-
|
378
|
-
build_process_list(rows)
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
def kill(signal, pids)
|
383
|
-
raise ArgumentError, 'Invalid signal' unless Kanrisuru::Util::Signal.valid?(signal)
|
384
|
-
|
385
|
-
## Use named signals for readabilitiy
|
386
|
-
signal = Kanrisuru::Util::Signal[signal] if signal.instance_of?(Integer)
|
387
|
-
|
388
|
-
command = Kanrisuru::Command.new('kill')
|
389
|
-
command << "-#{signal}"
|
390
|
-
command << (pids.instance_of?(Array) ? pids.join(' ') : pids)
|
391
|
-
|
392
|
-
execute_shell(command)
|
393
|
-
|
394
|
-
Kanrisuru::Result.new(command)
|
395
|
-
end
|
396
|
-
|
397
|
-
def lsof(_opts = {})
|
398
|
-
command = Kanrisuru::Command.new('lsof -F pcuftDsin')
|
399
|
-
|
400
|
-
execute_shell(command)
|
401
|
-
Kanrisuru::Result.new(command) do |cmd|
|
402
|
-
lines = cmd.to_a
|
403
|
-
|
404
|
-
current_row = nil
|
405
|
-
current_pid = nil
|
406
|
-
current_user = nil
|
407
|
-
current_command = nil
|
408
|
-
|
409
|
-
rows = []
|
410
|
-
|
411
|
-
lines.each do |line|
|
412
|
-
case line
|
413
|
-
when /^p/
|
414
|
-
current_pid = parse_lsof(line, 'p').to_i
|
415
|
-
when /^c/
|
416
|
-
current_command = parse_lsof(line, 'c')
|
417
|
-
when /^u/
|
418
|
-
current_user = parse_lsof(line, 'u').to_i
|
419
|
-
when /^f/
|
420
|
-
rows << current_row if current_row
|
421
|
-
|
422
|
-
current_row = OpenFile.new
|
423
|
-
current_row.pid = current_pid
|
424
|
-
current_row.command = current_command
|
425
|
-
current_row.uid = current_user
|
426
|
-
|
427
|
-
current_row.file_descriptor = parse_lsof(line, 'f')
|
428
|
-
when /^t/
|
429
|
-
current_row.type = parse_lsof(line, 't')
|
430
|
-
when /^D/
|
431
|
-
current_row.device = parse_lsof(line, 'D')
|
432
|
-
when /^s/
|
433
|
-
current_row.fsize = parse_lsof(line, 's').to_i
|
434
|
-
when /^i/
|
435
|
-
current_row.inode = parse_lsof(line, 'i').to_i
|
436
|
-
when /^n/
|
437
|
-
current_row.name = parse_lsof(line, 'n')
|
438
|
-
end
|
439
|
-
end
|
440
|
-
|
441
|
-
rows << current_row if current_row
|
442
|
-
|
443
|
-
rows
|
444
|
-
end
|
445
|
-
end
|
446
|
-
|
447
|
-
def kstat
|
448
|
-
kernel_statistics
|
449
|
-
end
|
450
|
-
|
451
|
-
def kernel_statistics
|
452
|
-
command = Kanrisuru::Command.new('cat /proc/stat')
|
453
|
-
|
454
|
-
execute_shell(command)
|
455
|
-
|
456
|
-
Kanrisuru::Result.new(command) do |cmd|
|
457
|
-
lines = cmd.to_a
|
458
|
-
|
459
|
-
result = KernelStatistic.new
|
460
|
-
result.cpus = []
|
461
|
-
|
462
|
-
lines.each do |line|
|
463
|
-
values = line.split
|
464
|
-
field = values[0]
|
465
|
-
values = values[1..-1].map(&:to_i)
|
466
|
-
|
467
|
-
case field
|
468
|
-
when /^cpu/
|
469
|
-
cpu_stat = KernelStatisticCpu.new
|
470
|
-
cpu_stat.user = values[0]
|
471
|
-
cpu_stat.nice = values[1]
|
472
|
-
cpu_stat.system = values[2]
|
473
|
-
cpu_stat.idle = values[3]
|
474
|
-
cpu_stat.iowait = values[4]
|
475
|
-
cpu_stat.irq = values[5]
|
476
|
-
cpu_stat.softirq = values[6]
|
477
|
-
cpu_stat.steal = values[7]
|
478
|
-
cpu_stat.guest = values[8]
|
479
|
-
cpu_stat.guest_nice = values[9]
|
480
|
-
|
481
|
-
case field
|
482
|
-
when /^cpu$/
|
483
|
-
result.cpu_total = cpu_stat
|
484
|
-
when /^cpu\d+/
|
485
|
-
result.cpus << cpu_stat
|
486
|
-
end
|
487
|
-
when 'intr'
|
488
|
-
result.interrupt_total = values[0]
|
489
|
-
result.interrupts = values[1..-1]
|
490
|
-
when 'softirq'
|
491
|
-
result.softirq_total = values[0]
|
492
|
-
result.softirqs = values[1..-1]
|
493
|
-
else
|
494
|
-
result[field] = values[0]
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
result
|
499
|
-
end
|
500
|
-
end
|
501
|
-
|
502
|
-
def uptime
|
503
|
-
## Ported from https://github.com/djberg96/sys-uptime
|
504
|
-
command = Kanrisuru::Command.new('cat /proc/uptime')
|
505
|
-
|
506
|
-
execute_shell(command)
|
507
|
-
|
508
|
-
Kanrisuru::Result.new(command) do |cmd|
|
509
|
-
seconds = cmd.to_s.split[0].to_i
|
510
|
-
minutes = seconds / 60
|
511
|
-
hours = seconds / 3600
|
512
|
-
days = seconds / 86_400
|
513
|
-
|
514
|
-
seconds_dur = seconds
|
515
|
-
days_dur = seconds_dur / 86_400
|
516
|
-
seconds_dur -= days_dur * 86_400
|
517
|
-
hours_dur = seconds_dur / 3600
|
518
|
-
seconds_dur -= hours_dur * 3600
|
519
|
-
minutes_dur = seconds_dur / 60
|
520
|
-
seconds_dur -= minutes_dur * 60
|
521
|
-
uptime_s = "#{days_dur}:#{hours_dur}:#{minutes_dur}:#{seconds_dur}"
|
522
|
-
|
523
|
-
boot_time = Time.now - seconds
|
524
|
-
|
525
|
-
Uptime.new(
|
526
|
-
boot_time,
|
527
|
-
uptime_s,
|
528
|
-
seconds,
|
529
|
-
minutes,
|
530
|
-
hours,
|
531
|
-
days
|
532
|
-
)
|
533
|
-
end
|
534
|
-
end
|
535
|
-
|
536
|
-
def w(opts = {})
|
537
|
-
users = opts[:users]
|
538
|
-
command = Kanrisuru::Command.new('w -hi')
|
539
|
-
|
540
|
-
command << users if Kanrisuru::Util.present?(users)
|
541
|
-
|
542
|
-
execute(command)
|
543
|
-
|
544
|
-
Kanrisuru::Result.new(command) do |cmd|
|
545
|
-
result_string = cmd.raw_result.join
|
546
|
-
rows = result_string.split("\n")
|
547
|
-
|
548
|
-
rows.map do |row|
|
549
|
-
values = *row.split(/\s+/, 8)
|
550
|
-
UserLoggedIn.new(
|
551
|
-
values[0],
|
552
|
-
values[1],
|
553
|
-
IPAddr.new(values[2]),
|
554
|
-
values[3],
|
555
|
-
values[4],
|
556
|
-
values[5].to_f,
|
557
|
-
values[6].to_f,
|
558
|
-
values[7]
|
559
|
-
)
|
560
|
-
end
|
561
|
-
end
|
562
|
-
end
|
563
|
-
|
564
|
-
def who(opts = {})
|
565
|
-
w(opts)
|
566
|
-
end
|
567
|
-
|
568
|
-
def reboot(opts = {})
|
569
|
-
time = opts[:time]
|
570
|
-
cancel = opts[:cancel]
|
571
|
-
message = opts[:message]
|
572
|
-
no_wall = opts[:no_wall]
|
573
|
-
|
574
|
-
command = Kanrisuru::Command.new('shutdown')
|
575
|
-
|
576
|
-
if Kanrisuru::Util.present?(cancel)
|
577
|
-
command.append_flag('-c')
|
578
|
-
command << message if message
|
579
|
-
else
|
580
|
-
command.append_flag('-r')
|
581
|
-
|
582
|
-
time = format_shutdown_time(time) if Kanrisuru::Util.present?(time)
|
583
|
-
|
584
|
-
if Kanrisuru::Util.present?(no_wall)
|
585
|
-
command.append_flag('--no-wall')
|
586
|
-
else
|
587
|
-
command << time if time
|
588
|
-
command << message if message
|
589
|
-
end
|
590
|
-
end
|
591
|
-
|
592
|
-
begin
|
593
|
-
execute_shell(command)
|
594
|
-
Kanrisuru::Result.new(command)
|
595
|
-
rescue IOError
|
596
|
-
## When rebooting 'now', ssh io stream closes
|
597
|
-
## Set exit status to 0
|
598
|
-
command.handle_status(0)
|
599
|
-
Kanrisuru::Result.new(command)
|
600
|
-
end
|
601
|
-
end
|
602
|
-
|
603
|
-
def poweroff(opts = {})
|
604
|
-
time = opts[:time]
|
605
|
-
cancel = opts[:cancel]
|
606
|
-
message = opts[:message]
|
607
|
-
no_wall = opts[:no_wall]
|
608
|
-
|
609
|
-
command = Kanrisuru::Command.new('shutdown')
|
610
|
-
|
611
|
-
if Kanrisuru::Util.present?(cancel)
|
612
|
-
command.append_flag('-c')
|
613
|
-
command << message if message
|
614
|
-
else
|
615
|
-
time = format_shutdown_time(time) if Kanrisuru::Util.present?(time)
|
616
|
-
|
617
|
-
if Kanrisuru::Util.present?(no_wall)
|
618
|
-
command.append_flag('--no-wall')
|
619
|
-
else
|
620
|
-
command << time if time
|
621
|
-
command << message if message
|
622
|
-
end
|
623
|
-
end
|
624
|
-
|
625
|
-
begin
|
626
|
-
execute_shell(command)
|
627
|
-
|
628
|
-
Kanrisuru::Result.new(command)
|
629
|
-
rescue IOError
|
630
|
-
## When powering off 'now', ssh io stream closes
|
631
|
-
## Set exit status to 0
|
632
|
-
command.handle_status(0)
|
633
|
-
|
634
|
-
Kanrisuru::Result.new(command)
|
635
|
-
end
|
636
|
-
end
|
637
|
-
|
638
|
-
private
|
639
|
-
|
640
|
-
def parse_lsof(line, char)
|
641
|
-
line.split(char, 2)[1]
|
642
|
-
end
|
643
|
-
|
644
|
-
def parse_last_date(string)
|
645
|
-
tokens = string.split
|
646
|
-
|
647
|
-
return if tokens.length < 4
|
648
|
-
|
649
|
-
month_abbr = tokens[1]
|
650
|
-
day = tokens[2]
|
651
|
-
timestamp = tokens[3]
|
652
|
-
year = tokens[4]
|
653
|
-
|
654
|
-
DateTime.parse("#{day} #{month_abbr} #{year} #{timestamp}")
|
655
|
-
end
|
656
|
-
|
657
|
-
def parse_policy_abbr(value)
|
658
|
-
case value
|
659
|
-
when '-'
|
660
|
-
'not reported'
|
661
|
-
when 'TS'
|
662
|
-
'SCHED_OTHER'
|
663
|
-
when 'FF'
|
664
|
-
'SCHED_FIFO'
|
665
|
-
when 'RR'
|
666
|
-
'SCHED_RR'
|
667
|
-
when 'B'
|
668
|
-
'SCHED_BATCH'
|
669
|
-
when 'ISO'
|
670
|
-
'SCHED_ISO'
|
671
|
-
when 'IDL'
|
672
|
-
'SCHED_IDLE'
|
673
|
-
when 'DLN'
|
674
|
-
'SCHED_DEADLINE'
|
675
|
-
else
|
676
|
-
'unknown value'
|
677
|
-
end
|
678
|
-
end
|
679
|
-
|
680
|
-
def build_process_list(rows)
|
681
|
-
rows.map do |row|
|
682
|
-
values = *row.split(/\s+/, 15)
|
683
|
-
values.shift if values[0] == ''
|
684
|
-
|
685
|
-
ProcessInfo.new(
|
686
|
-
values[0].to_i,
|
687
|
-
values[1],
|
688
|
-
values[2].to_i,
|
689
|
-
values[3],
|
690
|
-
values[4].to_i,
|
691
|
-
values[5].to_i,
|
692
|
-
values[6].to_f,
|
693
|
-
values[7].to_f,
|
694
|
-
values[8],
|
695
|
-
values[9].to_i,
|
696
|
-
values[10].to_i,
|
697
|
-
values[11],
|
698
|
-
parse_policy_abbr(values[11]),
|
699
|
-
values[12],
|
700
|
-
values[13]
|
701
|
-
)
|
702
|
-
end
|
703
|
-
end
|
704
|
-
|
705
|
-
def format_shutdown_time(time)
|
706
|
-
if time.instance_of?(Integer) || !/^[0-9]+$/.match(time).nil?
|
707
|
-
"+#{time}"
|
708
|
-
elsif !/^[0-9]{0,2}:[0-9]{0,2}$/.match(time).nil? || time == 'now'
|
709
|
-
time
|
710
|
-
else
|
711
|
-
raise ArgumentError, 'Invalid time format'
|
712
|
-
end
|
713
|
-
end
|
714
31
|
end
|
715
32
|
end
|
716
33
|
end
|