foreman_discovery 1.3.0.rc3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +176 -33
- data/app/models/host/discovered.rb +6 -0
- data/lib/foreman_discovery/version.rb +1 -1
- metadata +4 -21
- data/extra/ovirt-node-plugin-foreman/COPYING +0 -340
- data/extra/ovirt-node-plugin-foreman/Makefile.am +0 -60
- data/extra/ovirt-node-plugin-foreman/README.md +0 -217
- data/extra/ovirt-node-plugin-foreman/autogen.sh +0 -66
- data/extra/ovirt-node-plugin-foreman/conf/Makefile.am +0 -29
- data/extra/ovirt-node-plugin-foreman/conf/foreman-plugin.firewall.in +0 -4
- data/extra/ovirt-node-plugin-foreman/conf/foreman-plugin.logs +0 -2
- data/extra/ovirt-node-plugin-foreman/configure.ac +0 -62
- data/extra/ovirt-node-plugin-foreman/ovirt-node-plugin-foreman.spec.in +0 -145
- data/extra/ovirt-node-plugin-foreman/recipe/Makefile.am +0 -33
- data/extra/ovirt-node-plugin-foreman/recipe/foreman-plugin-iso.ks +0 -5
- data/extra/ovirt-node-plugin-foreman/recipe/foreman-plugin-minimizer.ks +0 -160
- data/extra/ovirt-node-plugin-foreman/src/Makefile.am +0 -32
- data/extra/ovirt-node-plugin-foreman/src/discover-host.rb.in +0 -204
- data/extra/ovirt-node-plugin-foreman/src/discover-host.service +0 -14
- data/extra/ovirt-node-plugin-foreman/src/discovery-version-fact.rb.in +0 -25
- data/extra/ovirt-node-plugin-foreman/src/find-missing-libs +0 -35
@@ -1,145 +0,0 @@
|
|
1
|
-
# vim: ts=4:sw=4:et
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013 Red Hat, Inc.
|
4
|
-
#
|
5
|
-
# This program is free software; you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation; version 2 of the License.
|
8
|
-
#
|
9
|
-
# This program is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
-
# GNU General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU General Public License
|
15
|
-
# along with this program; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
17
|
-
# MA 02110-1301, USA. A copy of the GNU General Public License is
|
18
|
-
# also available at http://www.gnu.org/copyleft/gpl.html.
|
19
|
-
|
20
|
-
Summary: A plugin for Foreman Discovery nodes
|
21
|
-
Name: ovirt-node-plugin-foreman
|
22
|
-
Version: @VERSION@
|
23
|
-
Release: 1%{?BUILD_NUMBER}%{?extra_release}%{?dist}
|
24
|
-
Source0: %{name}-%{version}.tar.gz
|
25
|
-
License: GPLv2+
|
26
|
-
Group: Applications/System
|
27
|
-
|
28
|
-
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
|
29
|
-
URL: http://www.ovirt.org/
|
30
|
-
Requires: ovirt-node >= 3.0.0
|
31
|
-
Requires: facter
|
32
|
-
Requires: foreman-proxy
|
33
|
-
Requires: sudo
|
34
|
-
%if "@PLUGIN_DEBUG@" == "1"
|
35
|
-
Requires: openssh-server
|
36
|
-
Requires: vim-minimal
|
37
|
-
Requires: file telnet lsof
|
38
|
-
%endif
|
39
|
-
|
40
|
-
BuildArch: noarch
|
41
|
-
|
42
|
-
BuildRequires: systemd
|
43
|
-
|
44
|
-
%define app_root %{_datadir}/%{name}
|
45
|
-
%define recipe_root %{_datadir}/ovirt-node-recipe
|
46
|
-
|
47
|
-
%description
|
48
|
-
Provides Foreman Proxy and Discovery component for automatic registration
|
49
|
-
of nodes in Foreman and provisioning.
|
50
|
-
|
51
|
-
%package recipe
|
52
|
-
Summary: Kickstarts for building Node isos including %{name}
|
53
|
-
Group: Applications/System
|
54
|
-
Requires: ovirt-node-recipe >= 2.6.0
|
55
|
-
|
56
|
-
%description recipe
|
57
|
-
Provides kickstart files for generating an oVirt Node ISO image containing
|
58
|
-
%{name}.
|
59
|
-
|
60
|
-
%prep
|
61
|
-
%setup -q
|
62
|
-
|
63
|
-
|
64
|
-
%build
|
65
|
-
%if "@PLUGIN_DEBUG@" == "1"
|
66
|
-
%configure --enable-debug
|
67
|
-
%else
|
68
|
-
%configure
|
69
|
-
%endif
|
70
|
-
|
71
|
-
%install
|
72
|
-
%{__rm} -rf %{buildroot}
|
73
|
-
make install DESTDIR=%{buildroot}
|
74
|
-
|
75
|
-
%post
|
76
|
-
# Modify login issue
|
77
|
-
sed -i 's/oVirt Node Hypervisor/Foreman Discovery/' /etc/issue
|
78
|
-
|
79
|
-
# Reserve tty1 only for logs
|
80
|
-
rm -f /etc/systemd/system/getty.target.wants/getty@tty1.service
|
81
|
-
|
82
|
-
# In development mode set password and enable ssh daemon (with root access)
|
83
|
-
%if "@PLUGIN_DEBUG@" == "1"
|
84
|
-
echo "root:development" | chpasswd
|
85
|
-
sed -i 's/^.*PasswordAuthentication.*$/PasswordAuthentication yes/' /etc/ssh/sshd_config
|
86
|
-
sed -i 's/^.*PermitRootLogin.*$/PermitRootLogin yes/' /etc/ssh/sshd_config
|
87
|
-
%endif
|
88
|
-
|
89
|
-
# Configure foreman-proxy
|
90
|
-
%if "@PLUGIN_DEBUG@" == "1"
|
91
|
-
LOGLEVEL="DEBUG"
|
92
|
-
%else
|
93
|
-
LOGLEVEL="ERROR"
|
94
|
-
%endif
|
95
|
-
sed -i 's|.*:log_file:.*|:log_file: /dev/stdout|' /etc/foreman-proxy/settings.yml
|
96
|
-
sed -i "s/.*:log_level:.*/:log_level: $LOGLEVEL/" /etc/foreman-proxy/settings.yml
|
97
|
-
sed -i 's/.*:bmc:.*/:bmc: true/' /etc/foreman-proxy/settings.yml
|
98
|
-
sed -i 's/.*:bmc_default_provider:.*/:bmc_default_provider: shell/' /etc/foreman-proxy/settings.yml
|
99
|
-
|
100
|
-
# Connect smart-proxy standard output to tty1
|
101
|
-
sed '/^ExecStart/aStandardOutput=tty' -i /usr/lib/systemd/system/foreman-proxy.service
|
102
|
-
sed '/^ExecStart/aTTYPath=/dev/tty1' -i /usr/lib/systemd/system/foreman-proxy.service
|
103
|
-
|
104
|
-
# Enable Foreman Proxy service
|
105
|
-
systemctl enable foreman-proxy.service
|
106
|
-
|
107
|
-
# Enable Discover Host service (must be executed as the last - idle - service)
|
108
|
-
systemctl enable discover-host.service
|
109
|
-
|
110
|
-
# Force NetworkManager to wait for IP address
|
111
|
-
systemctl enable NetworkManager-wait-online.service
|
112
|
-
|
113
|
-
# Add foreman-proxy user to sudo and disable interactive tty for reboot
|
114
|
-
sed -i -e 's/^Defaults.*requiretty/Defaults !requiretty/g' /etc/sudoers
|
115
|
-
echo "foreman-proxy ALL=NOPASSWD: /sbin/shutdown" >> /etc/sudoers
|
116
|
-
|
117
|
-
# Limit maximum use of systemd journal (it is kept in memory for stateless)
|
118
|
-
sed -i -e 's/^.*SystemMaxUse.*$/SystemMaxUse=20M/g' /etc/systemd/journald.conf
|
119
|
-
|
120
|
-
# When using ntpdate during start, do not pause when time servers not available
|
121
|
-
[ -f /etc/sysconfig/ntpdate ] && sed -i -e 's/^.*RETRIES.*$/RETRIES=0/g' /etc/sysconfig/ntpdate
|
122
|
-
|
123
|
-
# Set extra directory for facter
|
124
|
-
sed -i '/\[Service\]/a Environment="FACTERLIB=/usr/share/ovirt-node-plugin-foreman"' /usr/lib/systemd/system/foreman-proxy.service
|
125
|
-
|
126
|
-
%preun
|
127
|
-
|
128
|
-
%files recipe
|
129
|
-
%{recipe_root}
|
130
|
-
|
131
|
-
%files
|
132
|
-
%{_bindir}/discover-host.rb
|
133
|
-
%{_bindir}/find-missing-libs
|
134
|
-
%{_datadir}/%{name}/discovery-version-fact.rb
|
135
|
-
%{_unitdir}/discover-host.service
|
136
|
-
%{_sysconfdir}/ovirt-plugins.d
|
137
|
-
|
138
|
-
%changelog
|
139
|
-
* Thu Dec 19 2013 Lukas Zapletal <lzap+rpm@redhat.com> 0.2.0-1
|
140
|
-
- Logging on tty1
|
141
|
-
- Changes to /etc/issue
|
142
|
-
- Faster start
|
143
|
-
|
144
|
-
* Wed Oct 30 2013 Lukas Zapletal <lzap+rpm@redhat.com> 0.1.0-1
|
145
|
-
- Initial version
|
@@ -1,33 +0,0 @@
|
|
1
|
-
# vim: ts=8:sw=8:noet
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013 Red Hat, Inc.
|
4
|
-
#
|
5
|
-
# This program is free software; you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation; version 2 of the License.
|
8
|
-
#
|
9
|
-
# This program is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
-
# GNU General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU General Public License
|
15
|
-
# along with this program; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
17
|
-
# MA 02110-1301, USA. A copy of the GNU General Public License is
|
18
|
-
# also available at http://www.gnu.org/copyleft/gpl.html.
|
19
|
-
|
20
|
-
EXTRA_DIST = *.ks
|
21
|
-
|
22
|
-
OVIRT_NODE_RECIPEdir = $(datadir)/ovirt-node-recipe
|
23
|
-
pluginsdir = $(sysconfdir)/ovirt-plugins.d
|
24
|
-
|
25
|
-
OVIRT_NODE_RECIPE_DATA = \
|
26
|
-
foreman-plugin-minimizer.ks \
|
27
|
-
foreman-plugin-iso.ks
|
28
|
-
|
29
|
-
dist_plugins_DATA = \
|
30
|
-
foreman-plugin-minimizer.ks
|
31
|
-
|
32
|
-
install-data-hook:
|
33
|
-
mv $(DESTDIR)/$(pluginsdir)/foreman-plugin-minimizer.ks $(DESTDIR)/$(pluginsdir)/foreman-plugin.minimize
|
@@ -1,160 +0,0 @@
|
|
1
|
-
# Minimize script optimized for Foreman Discovery plugin (Fedora 19)
|
2
|
-
#
|
3
|
-
# Use this to find interesting packages in the image:
|
4
|
-
#
|
5
|
-
# rpm -qa --queryformat '%{SIZE} %{NAME}\n' | sort -n -r | head -n100
|
6
|
-
#
|
7
|
-
# Use this tool (part of this plugin) to check for missing libs:
|
8
|
-
#
|
9
|
-
# find-missing-libs
|
10
|
-
#
|
11
|
-
|
12
|
-
# ovirt-node and deps
|
13
|
-
droprpm ovirt-node
|
14
|
-
droprpm collectd
|
15
|
-
droprpm collectd-*
|
16
|
-
|
17
|
-
# virtualization
|
18
|
-
droprpm qemu
|
19
|
-
droprpm qemu-*
|
20
|
-
droprpm ipxe-roms-qemu
|
21
|
-
droprpm xen-licenses
|
22
|
-
droprpm vhostmd
|
23
|
-
droprpm libvirt
|
24
|
-
droprpm libvirt-*
|
25
|
-
|
26
|
-
# python
|
27
|
-
droprpm python
|
28
|
-
droprpm python-*
|
29
|
-
droprpm *-python
|
30
|
-
droprpm pyliblzma
|
31
|
-
droprpm pyxattr
|
32
|
-
droprpm pygpgme
|
33
|
-
droprpm pygobject*
|
34
|
-
|
35
|
-
# selinux (need to provide selinux=0 kernel argument)
|
36
|
-
droprpm selinux-policy-targeted
|
37
|
-
droprpm policycoreutils
|
38
|
-
|
39
|
-
# x window
|
40
|
-
droprpm cairo
|
41
|
-
droprpm cairo-gobject
|
42
|
-
droprpm colord-libs
|
43
|
-
droprpm gdk-pixbuf2
|
44
|
-
droprpm gsettings-desktop-schemas
|
45
|
-
droprpm gtk3
|
46
|
-
droprpm hicolor-icon-theme
|
47
|
-
droprpm libsndfile
|
48
|
-
droprpm libvorbis
|
49
|
-
droprpm libX*
|
50
|
-
droprpm libxcb
|
51
|
-
droprpm mesa-*
|
52
|
-
droprpm pango
|
53
|
-
droprpm pulseaudio-libs
|
54
|
-
droprpm SDL
|
55
|
-
droprpm vte3
|
56
|
-
|
57
|
-
# various
|
58
|
-
droprpm acpid
|
59
|
-
droprpm aic94xx-firmware
|
60
|
-
droprpm alsa-lib
|
61
|
-
droprpm anyterm
|
62
|
-
droprpm avahi
|
63
|
-
droprpm bc
|
64
|
-
droprpm bfa-firmware
|
65
|
-
droprpm bridge-utils
|
66
|
-
droprpm btrfs-progs
|
67
|
-
droprpm ceph-libs
|
68
|
-
droprpm cracklib-dicts
|
69
|
-
droprpm device-mapper-multipath
|
70
|
-
droprpm dmraid
|
71
|
-
droprpm dosfstools
|
72
|
-
droprpm dracut-fips
|
73
|
-
droprpm dracut-network
|
74
|
-
droprpm e2fsprogs
|
75
|
-
droprpm efibootmgr
|
76
|
-
droprpm fcoe-utils
|
77
|
-
droprpm gdb
|
78
|
-
droprpm glusterfs
|
79
|
-
droprpm glusterfs-*
|
80
|
-
droprpm hwdata
|
81
|
-
droprpm irqbalance
|
82
|
-
droprpm iscsi-initiator-utils
|
83
|
-
droprpm jfsutils
|
84
|
-
droprpm kbd-misc
|
85
|
-
droprpm kexec-tools
|
86
|
-
droprpm kpartx
|
87
|
-
droprpm less
|
88
|
-
droprpm libguestfs
|
89
|
-
droprpm libguestfs-*
|
90
|
-
droprpm libicu
|
91
|
-
droprpm libmlx4
|
92
|
-
droprpm mcelog
|
93
|
-
droprpm net-snmp-libs
|
94
|
-
droprpm ntfs-3g
|
95
|
-
droprpm ntfsprogs
|
96
|
-
droprpm numactl
|
97
|
-
droprpm openssh-clients
|
98
|
-
droprpm parted
|
99
|
-
droprpm patch
|
100
|
-
droprpm pciutils
|
101
|
-
droprpm plymouth
|
102
|
-
droprpm plymouth-*
|
103
|
-
droprpm poppler-data
|
104
|
-
droprpm psmisc
|
105
|
-
droprpm PyPAM
|
106
|
-
droprpm reiserfs-utils
|
107
|
-
droprpm rsync
|
108
|
-
droprpm rsyslog
|
109
|
-
droprpm setools-console
|
110
|
-
droprpm sos
|
111
|
-
droprpm spice-server
|
112
|
-
droprpm squashfs-tools
|
113
|
-
droprpm strace
|
114
|
-
droprpm sysfsutils
|
115
|
-
droprpm sysstat
|
116
|
-
droprpm systemtap-runtime
|
117
|
-
droprpm tcpdump
|
118
|
-
droprpm tuned
|
119
|
-
droprpm tzdata
|
120
|
-
droprpm urw-fonts
|
121
|
-
droprpm usbutils
|
122
|
-
droprpm vconfig
|
123
|
-
droprpm xen-libs
|
124
|
-
droprpm xfsprogs
|
125
|
-
droprpm zfs-fuse
|
126
|
-
|
127
|
-
# various files/directories
|
128
|
-
drop /usr/share/gems/cache
|
129
|
-
drop /usr/share/qemu
|
130
|
-
drop /usr/share/mime
|
131
|
-
drop /usr/share/groff
|
132
|
-
drop /usr/share/locale
|
133
|
-
|
134
|
-
# The following packages are REQUIRED
|
135
|
-
#
|
136
|
-
# ruby
|
137
|
-
# facter
|
138
|
-
# sudo
|
139
|
-
# ipmitool
|
140
|
-
|
141
|
-
# The following packages are required to boot
|
142
|
-
#
|
143
|
-
# ncurses-libs
|
144
|
-
# NetworkManager-glib
|
145
|
-
# grubby
|
146
|
-
# libselinux
|
147
|
-
# lua
|
148
|
-
# sqlite
|
149
|
-
# openldap
|
150
|
-
# mozjs17
|
151
|
-
|
152
|
-
# The following packages SHOULD not be dropped
|
153
|
-
# (used in development mode)
|
154
|
-
#
|
155
|
-
# file
|
156
|
-
# vim-minimal
|
157
|
-
# openssh-server
|
158
|
-
# lsof
|
159
|
-
|
160
|
-
# EOF
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# vim: ts=8:sw=8:noet
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013 Red Hat, Inc.
|
4
|
-
#
|
5
|
-
# This program is free software; you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU General Public License as published by
|
7
|
-
# the Free Software Foundation; version 2 of the License.
|
8
|
-
#
|
9
|
-
# This program is distributed in the hope that it will be useful,
|
10
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
-
# GNU General Public License for more details.
|
13
|
-
#
|
14
|
-
# You should have received a copy of the GNU General Public License
|
15
|
-
# along with this program; if not, write to the Free Software
|
16
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
17
|
-
# MA 02110-1301, USA. A copy of the GNU General Public License is
|
18
|
-
# also available at http://www.gnu.org/copyleft/gpl.html.
|
19
|
-
|
20
|
-
dist_bin_SCRIPTS = \
|
21
|
-
discover-host.rb \
|
22
|
-
find-missing-libs
|
23
|
-
|
24
|
-
if HAVE_SYSTEMD
|
25
|
-
dist_systemdsystemunit_DATA = discover-host.service
|
26
|
-
endif
|
27
|
-
|
28
|
-
dist_pkgdata_DATA = discovery-version-fact.rb
|
29
|
-
|
30
|
-
CLEANFILES = \
|
31
|
-
discover-host.rb \
|
32
|
-
discovery-version-fact.rb
|
@@ -1,204 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# vim: ts=2:sw=2:et
|
4
|
-
#
|
5
|
-
# Copyright (C) 2012-2013 Red Hat, Inc.
|
6
|
-
#
|
7
|
-
# This program is free software; you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation; version 2 of the License.
|
10
|
-
#
|
11
|
-
# This program is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with this program; if not, write to the Free Software
|
18
|
-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19
|
-
# MA 02110-1301, USA. A copy of the GNU General Public License is
|
20
|
-
# also available at http://www.gnu.org/copyleft/gpl.html.
|
21
|
-
|
22
|
-
PACKAGE_NAME = '@PACKAGE_NAME@'
|
23
|
-
PACKAGE_VERSION = '@PACKAGE_VERSION@'
|
24
|
-
ENGINE_NAME = '@ENGINENAME@'
|
25
|
-
DEBUG = ('@PLUGIN_DEBUG@'.to_i == 1) rescue false
|
26
|
-
PROXY_CACHE = '/tmp/proxy_cache'
|
27
|
-
|
28
|
-
require 'fileutils'
|
29
|
-
require 'net/http'
|
30
|
-
require 'net/https'
|
31
|
-
require 'uri'
|
32
|
-
require 'socket'
|
33
|
-
require 'resolv'
|
34
|
-
|
35
|
-
# For comparison
|
36
|
-
require 'rubygems'
|
37
|
-
require 'facter'
|
38
|
-
require 'yaml'
|
39
|
-
|
40
|
-
BANNER = <<'EOS'
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
_____
|
45
|
-
| ___|__ _ __ ___ _ __ ___ __ _ _ __
|
46
|
-
| |_ / _ \| '__/ _ \ '_ ` _ \ / _` | '_ \
|
47
|
-
| _| (_) | | | __/ | | | | | (_| | | | |
|
48
|
-
|_|__\___/|_| \___|_| |_| |_|\__,_|_| |_|
|
49
|
-
| _ \(_)___ ___ _____ _____ _ __ _ _
|
50
|
-
| | | | / __|/ __/ _ \ \ / / _ \ '__| | | |
|
51
|
-
| |_| | \__ \ (_| (_) \ V / __/ | | |_| |
|
52
|
-
|____/|_|___/\___\___/ \_/ \___|_| \__, |
|
53
|
-
|___/
|
54
|
-
|
55
|
-
|
56
|
-
EOS
|
57
|
-
|
58
|
-
$start_time = Time.now
|
59
|
-
def time_prefix
|
60
|
-
Time.at(Time.now - $start_time).strftime("[%_4s]")
|
61
|
-
rescue
|
62
|
-
"[ ? ]"
|
63
|
-
end
|
64
|
-
|
65
|
-
def println msg
|
66
|
-
puts "#{time_prefix} #{msg}\n"
|
67
|
-
end
|
68
|
-
|
69
|
-
def debug msg
|
70
|
-
if DEBUG
|
71
|
-
println msg
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def error msg
|
76
|
-
$stderr.puts "#{time_prefix} #{msg}"
|
77
|
-
end
|
78
|
-
|
79
|
-
def cmdline option=nil, default=nil
|
80
|
-
line = File.open("/proc/cmdline", 'r') { |f| f.read }
|
81
|
-
if option
|
82
|
-
result = line.split.map { |x| $1 if x.match(/^#{option}=(.*)/)}.compact
|
83
|
-
result.size == 1 ? result.first : default
|
84
|
-
else
|
85
|
-
line
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def discover_server
|
90
|
-
debug "Parsing kernel line: #{cmdline}"
|
91
|
-
discover_by_url or discover_by_ip or
|
92
|
-
discover_by_server or discover_by_dns_srv
|
93
|
-
end
|
94
|
-
|
95
|
-
# kept for backward compatibility
|
96
|
-
def discover_by_ip
|
97
|
-
ip = cmdline 'foreman.ip'
|
98
|
-
println "Discovered by PXE: #{ip}" if ip
|
99
|
-
URI.parse("http://#{ip}")
|
100
|
-
rescue
|
101
|
-
return nil
|
102
|
-
end
|
103
|
-
|
104
|
-
# kept for backward compatibility
|
105
|
-
def discover_by_server
|
106
|
-
server = cmdline 'foreman.server'
|
107
|
-
println "Discovered by SERVER: #{server}" if server
|
108
|
-
URI.parse("http://#{server}")
|
109
|
-
rescue
|
110
|
-
return nil
|
111
|
-
end
|
112
|
-
|
113
|
-
def discover_by_url
|
114
|
-
url = cmdline 'foreman.url'
|
115
|
-
println "Discovered by URL: #{url}" if url
|
116
|
-
URI.parse(url)
|
117
|
-
rescue
|
118
|
-
return nil
|
119
|
-
end
|
120
|
-
|
121
|
-
# SRV discovery will work only if DHCP returns valid search domain
|
122
|
-
def discover_by_dns_srv
|
123
|
-
resolver = Resolv::DNS.new
|
124
|
-
type = Resolv::DNS::Resource::IN::SRV
|
125
|
-
result = resolver.getresources("_x-foreman._tcp", type).first
|
126
|
-
hostname = result.target.to_s
|
127
|
-
if result.port == 443
|
128
|
-
scheme = 'https'
|
129
|
-
else
|
130
|
-
scheme = 'http'
|
131
|
-
end
|
132
|
-
uri = "#{scheme}://#{hostname}:#{result.port}"
|
133
|
-
println "Discovered by SRV: #{uri}"
|
134
|
-
URI.parse(uri)
|
135
|
-
rescue
|
136
|
-
return nil
|
137
|
-
end
|
138
|
-
|
139
|
-
def upload
|
140
|
-
ip = Facter.value('ipaddress')
|
141
|
-
uri = discover_server
|
142
|
-
error "Could not determine Foreman instance, add kernel command option" unless uri
|
143
|
-
println "Triggering import of facts from Foreman (#{uri}, ip=#{ip})"
|
144
|
-
data = ip.nil? ? {} : {'ip' => ip}
|
145
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
146
|
-
if uri.scheme == 'https' then
|
147
|
-
http.use_ssl = true
|
148
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
149
|
-
end
|
150
|
-
req = Net::HTTP::Post.new("/discovers")
|
151
|
-
req.set_form_data(data)
|
152
|
-
response = http.request(req)
|
153
|
-
debug "Response from Foreman #{response.code}: #{response.body}"
|
154
|
-
if response.code == "200"
|
155
|
-
return true
|
156
|
-
else
|
157
|
-
return false
|
158
|
-
end
|
159
|
-
rescue => e
|
160
|
-
error "Could not send facts to Foreman: #{e}"
|
161
|
-
return false
|
162
|
-
end
|
163
|
-
|
164
|
-
def write_cache(data)
|
165
|
-
File.open(PROXY_CACHE, 'w') {|f| f.write(data) }
|
166
|
-
end
|
167
|
-
|
168
|
-
def read_cache
|
169
|
-
File.read(PROXY_CACHE)
|
170
|
-
rescue => e
|
171
|
-
"empty cache"
|
172
|
-
end
|
173
|
-
|
174
|
-
# Main
|
175
|
-
|
176
|
-
$stdout.reopen("/dev/tty1", "w")
|
177
|
-
$stderr.reopen("/dev/tty1", "w")
|
178
|
-
|
179
|
-
# Script was (re)started - delete old data
|
180
|
-
File.unlink(PROXY_CACHE) if File.exists?(PROXY_CACHE)
|
181
|
-
|
182
|
-
puts "\e[H\e[2J"
|
183
|
-
println BANNER
|
184
|
-
TAG = DEBUG ? 'D' : 'P'
|
185
|
-
println "This is Foreman Discovery #{PACKAGE_VERSION} (#{TAG}), tty1 is reserved for logs. "
|
186
|
-
if DEBUG
|
187
|
-
println "The image was build with debug support, you can switch over to tty2+ "
|
188
|
-
println "and login as root/development."
|
189
|
-
end
|
190
|
-
println "Some interesting facts about this system:"
|
191
|
-
facts = Facter.to_hash.select {|k,v| k =~ /address|hardware|manufacturer|productname|memorytotal/}
|
192
|
-
facts.keys.sort.each {|k| println " #{k}: #{facts[k]}"}
|
193
|
-
println "Logs from discovery services now follows:"
|
194
|
-
|
195
|
-
# loop, but only upload on changes
|
196
|
-
while true do
|
197
|
-
uninteresting_facts=/kernel|operatingsystem|osfamily|ruby|path|time|swap|free|filesystem|version|selinux/i
|
198
|
-
facts = Facter.to_hash.reject! {|k,v| k =~ uninteresting_facts }
|
199
|
-
unless YAML.load(read_cache) == facts
|
200
|
-
debug "Fact cache invalid, reloading to foreman"
|
201
|
-
write_cache(YAML.dump(facts)) if upload
|
202
|
-
sleep DEBUG ? 30 : 60
|
203
|
-
end
|
204
|
-
end
|