foreman_discovery 1.2.0 → 1.3.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- N2MwZjcwMGYzYWVmM2IzMTkxNmVlNDg2MGVmMjcxYjZjYTA2MzQzMQ==
5
- data.tar.gz: !binary |-
6
- Mzc5NWQ4ZmIyY2ViOWFjNjg1YTViODBhNjI4NTk1YmVkOTdmOGRlMw==
2
+ SHA1:
3
+ metadata.gz: 24eedabca60396493d62ff3dfa144f4da8481034
4
+ data.tar.gz: 066958ace4619f3a24f5570c4f976b9b2219eb46
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- OGM3NTNlNDgxMmRmOGJkYjc5Yjg5N2EyYzgwNWU3MzkxNzMxNmUxMTU4YjVj
10
- NDA2Y2RmMzE2ZDdmY2NhZDE5ZDYzNGYxNjg2MDE1YjNmMGRhNjRiMThiZDVk
11
- MDFhNjBkNzExYTdmMDg3OWI1OGI4MjRiNWFmY2NlNWMwMWJkY2Q=
12
- data.tar.gz: !binary |-
13
- NDA5N2EzMjNmNDk0MTE5MTFiYzA3NTM2YmNjNjViZmRhNzUzZDUyNGVjNGFj
14
- ZWIyMDlhYjc3OWIxZGZjZjdmNGIwMWRjYzIyNDQxNzZlZTAxY2M2OTI3NjEz
15
- YjU4MTI4NzM2OTVlN2Q4OWNmZWI1YTQ0ODFiYThhNmRlZTk2YmM=
6
+ metadata.gz: 9da2be93c9e85e4d5783d29e81388c7ed656d768d7f643d8227eda0cf5a8cf43ffa4d7b8dbbfd9e45dd8288a690fc53bd50398a0681125056519c06648bc006b
7
+ data.tar.gz: 0eb4329f85cc0a246e07152bee098f0ca10d8b59d232e3555bd52aa678a7ff448947969c228f9127d01e25260bfb1aaf35c70c4a787392ea8198b335a48b8a31
data/README.md CHANGED
@@ -18,7 +18,8 @@ RPM users can install the "ruby193-rubygem-foreman_discovery" or
18
18
  | Foreman Version | Plugin Version | oVirt Image Version |
19
19
  | --------------- | --------------:| -------------------:|
20
20
  | <= 1.2 | 1.0.2 | N/A |
21
- | >= 1.3 | 1.1.0 | 0.1.0 |
21
+ | = 1.3 | 1.1.0 | 0.1.0 |
22
+ | >= 1.4 | 1.2.0 | 0.3.0-1 |
22
23
 
23
24
  ## Latest code
24
25
 
@@ -26,6 +27,12 @@ You can get the develop branch of the plugin by specifying your Gemfile in this
26
27
 
27
28
  gem 'foreman_discovery', :git => "https://github.com/theforeman/foreman_discovery.git"
28
29
 
30
+ ## Reporting bugs
31
+
32
+ We use [RedMine
33
+ instance](http://projects.theforeman.org/projects/discovery/issues) instead of
34
+ github.com issues.
35
+
29
36
  # Building or downloading an image
30
37
 
31
38
  There are two options at the moment:
@@ -121,6 +121,10 @@ class DiscoversController < ::ApplicationController
121
121
 
122
122
  private
123
123
 
124
+ def resource_base
125
+ @resource_base ||= ::Host::Discovered.authorized(current_permission, ::Host::Discovered)
126
+ end
127
+
124
128
  def load_vars_for_ajax
125
129
  return unless @host
126
130
 
@@ -142,10 +146,29 @@ class DiscoversController < ::ApplicationController
142
146
  @host.overwrite = "true" if @host.errors.any? and @host.errors.are_all_conflicts?
143
147
  end
144
148
 
149
+ def controller_permission
150
+ 'discovered_hosts'
151
+ end
152
+
153
+ def action_permission
154
+ case params[:action]
155
+ when 'refresh_facts'
156
+ :view
157
+ when 'new', 'create'
158
+ :provision
159
+ when 'update_multiple_location', 'select_multiple_organization', 'update_multiple_organization', 'select_multiple_location'
160
+ :edit
161
+ when 'submit_multiple_destroy', 'multiple_destroy'
162
+ :destroy
163
+ else
164
+ super
165
+ end
166
+ end
167
+
145
168
  def find_by_name
146
169
  params[:id].downcase! if params[:id].present?
147
- @host = ::Host::Discovered.find_by_id(params[:id])
148
- @host ||= ::Host::Discovered.find_by_name(params[:id])
170
+ @host = resource_base.find_by_id(params[:id])
171
+ @host ||= resource_base.find_by_name(params[:id])
149
172
  return false unless @host
150
173
  end
151
174
 
@@ -162,6 +185,7 @@ class DiscoversController < ::ApplicationController
162
185
  redirect_to(discovers_path) and return false
163
186
  end
164
187
 
188
+ return @hosts
165
189
  rescue => e
166
190
  error _("Something went wrong while selecting hosts - %s") % e
167
191
  redirect_to discovers_path
@@ -20,15 +20,15 @@ module DiscoversHelper
20
20
  end
21
21
 
22
22
  def multiple_discovers_actions_select
23
- actions = [[_('Delete hosts'), multiple_destroy_discovers_path, 'trash']]
24
- actions << [_('Assign Organization'), select_multiple_organization_discovers_path, 'tags'] if SETTINGS[:organizations_enabled]
25
- actions << [_('Assign Location'), select_multiple_location_discovers_path, 'map-marker'] if SETTINGS[:locations_enabled]
23
+ actions = [[_('Delete hosts'), multiple_destroy_discovers_path]]
24
+ actions << [_('Assign Organization'), select_multiple_organization_discovers_path] if SETTINGS[:organizations_enabled]
25
+ actions << [_('Assign Location'), select_multiple_location_discovers_path] if SETTINGS[:locations_enabled]
26
26
 
27
- content_tag :span, :id => 'submit_multiple' do
28
- select_action_button( _("Select action"), actions.map do |action|
29
- link_to(icon_text(action[2], action[0]) , action[1], :class=>'btn', :title => _("%s - The following hosts are about to be changed") % action[0])
30
- end.flatten)
31
- end
27
+ select_action_button( _("Select Action"), {:id => 'submit_multiple'},
28
+ actions.map do |action|
29
+ link_to(action[0] , action[1], :'data-dialog-title' => _("%s - The following hosts are about to be changed") % action[0])
30
+ end.flatten
31
+ )
32
32
 
33
33
  end
34
34
 
@@ -21,11 +21,11 @@ class Host::Discovered < ::Host::Base
21
21
  # this seems like a rails bug, TODO: figure out whats really wrong here
22
22
  scope :list, lambda { where(:type => "Host::Discovered").includes(:model, :location, :organization) }
23
23
 
24
- def self.importHostAndFacts facts
25
- raise(::Foreman::Exception.new("Invalid Facts, must be a Hash")) unless facts.is_a?(Hash)
24
+ def self.import_host_and_facts facts
25
+ raise(::Foreman::Exception.new(N_("Invalid facts, must be a Hash"))) unless facts.is_a?(Hash)
26
26
  fact_name = Setting[:discovery_fact] || 'macaddress'
27
27
  hostname = facts[fact_name].try(:downcase).try(:gsub,/:/,'')
28
- raise(::Foreman::Exception.new("Invalid facts: hash does not contain the required fact '#{fact_name}'")) unless hostname
28
+ raise(::Foreman::Exception.new(N_("Invalid facts: hash does not contain the required fact '%s'"), fact_name)) unless hostname
29
29
 
30
30
  # filter facts
31
31
  facts.reject!{|k,v| k =~ /kernel|operatingsystem|osfamily|ruby|path|time|swap|free|filesystem/i }
@@ -51,11 +51,11 @@ class Host::Discovered < ::Host::Base
51
51
  end
52
52
 
53
53
  h.save(:validate => false) if h.new_record?
54
- state = h.importFacts(facts)
54
+ state = h.import_facts(facts)
55
55
  return h, state
56
56
  end
57
57
 
58
- def importFacts facts
58
+ def import_facts facts
59
59
  # Discovered Hosts won't report in via puppet, so we can use that field to
60
60
  # record the last time it sent facts...
61
61
  self.last_report = Time.now
@@ -66,7 +66,7 @@ class Host::Discovered < ::Host::Base
66
66
  super + [:ip]
67
67
  end
68
68
 
69
- def populateFieldsFromFacts facts = self.facts_hash
69
+ def populate_fields_from_facts facts = self.facts_hash
70
70
  importer = super
71
71
  self.subnet = Subnet.subnet_for(importer.ip)
72
72
  self.save
@@ -81,7 +81,7 @@ class Host::Discovered < ::Host::Base
81
81
  raise _("Could not get facts from proxy: %s") % e
82
82
  end
83
83
 
84
- return self.class.importHostAndFacts facts
84
+ return self.class.import_host_and_facts facts
85
85
  end
86
86
 
87
87
  def self.model_name
@@ -4,15 +4,15 @@
4
4
  <tr>
5
5
  <th class="ca"><%= check_box_tag "check_all", "", false, { :onclick => "toggleCheck()", :'check-title' => _("Select all items in this page"), :'uncheck-title'=> _("items selected. Uncheck to Clear") } %></th>
6
6
  <th class=''><%= sort :name, :as => _('Name') %></th>
7
- <th class="hidden-tablet hidden-phone"><%= sort :model, :as => _('Model') %></th>
7
+ <th class="hidden-tablet hidden-xs"><%= sort :model, :as => _('Model') %></th>
8
8
  <% if SETTINGS[:locations_enabled] -%>
9
- <th class="hidden-tablet hidden-phone"><%= sort :location, :as => _('Location') %></th>
9
+ <th class="hidden-tablet hidden-xs"><%= sort :location, :as => _('Location') %></th>
10
10
  <% end -%>
11
11
  <% if SETTINGS[:organizations_enabled] -%>
12
- <th class="hidden-tablet hidden-phone"><%= sort :organization, :as => _('Organization') %></th>
12
+ <th class="hidden-tablet hidden-xs"><%= sort :organization, :as => _('Organization') %></th>
13
13
  <% end -%>
14
- <th class="hidden-tablet hidden-phone"><%= sort :subnet, :as => _("Subnet") %></th>
15
- <th class="hidden-tablet hidden-phone"><%= sort :last_report, :as => _("Last facts upload") %></th>
14
+ <th class="hidden-tablet hidden-xs"><%= sort :subnet, :as => _("Subnet") %></th>
15
+ <th class="hidden-tablet hidden-xs"><%= sort :last_report, :as => _("Last facts upload") %></th>
16
16
  <th></th>
17
17
  </tr>
18
18
  <% @hosts.each do |host| -%>
@@ -21,15 +21,15 @@
21
21
  <%= check_box_tag "host_ids[]", nil, false, :id => "host_ids_#{host.id}", :disabled => !authorized?, :class => 'host_select_boxes', :onclick => 'hostChecked(this)' -%>
22
22
  </td>
23
23
  <td><%= link_to("#{host}", discover_path(host) ) %> </td>
24
- <td class="hidden-tablet hidden-phone"><%= model_name host %></td>
24
+ <td class="hidden-tablet hidden-xs"><%= model_name host %></td>
25
25
  <% if SETTINGS[:locations_enabled] -%>
26
- <td class="hidden-tablet hidden-phone"><%= host.location.try(:name) %></td>
26
+ <td class="hidden-tablet hidden-xs"><%= host.location.try(:name) %></td>
27
27
  <% end -%>
28
28
  <% if SETTINGS[:organizations_enabled] -%>
29
- <td class="hidden-tablet hidden-phone"><%= host.organization.try(:name) %></td>
29
+ <td class="hidden-tablet hidden-xs"><%= host.organization.try(:name) %></td>
30
30
  <% end -%>
31
- <td class="hidden-tablet hidden-phone"><%= host.subnet %></td>
32
- <td class="hidden-tablet hidden-phone"><%= disc_report_column(host) %></td>
31
+ <td class="hidden-tablet hidden-xs"><%= host.subnet %></td>
32
+ <td class="hidden-tablet hidden-xs"><%= disc_report_column(host) %></td>
33
33
  <td>
34
34
  <%= action_buttons(
35
35
  link_to(_("Provision"), hash_for_edit_discover_path(:id => host)),
@@ -40,17 +40,23 @@
40
40
  <% end -%>
41
41
  </table>
42
42
 
43
- <div id="confirmation-modal" class="modal hide fade">
44
- <div class="modal-header">
45
- <a href="#" class="close" data-dismiss="modal">×</a>
46
- <h3><%= _('Please Confirm') %></h3>
47
- </div>
48
- <div class="modal-body"></div>
49
- <div class="modal-footer">
50
- <a href="#" class="btn btn-primary"><%= _('Submit') %></a>
51
- <a href="#" class="btn secondary"><%= _('Cancel') %></a>
52
- </div>
53
- </div>
43
+ <div id="confirmation-modal" class="modal fade">
44
+ <div class="modal-dialog">
45
+ <div class="modal-content">
46
+ <div class="modal-header">
47
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
48
+ <h4 class="modal-title"><%= _('Please Confirm') %></h4>
49
+ </div>
50
+ <div class="modal-body">
51
+
52
+ </div>
53
+ <div class="modal-footer">
54
+ <button type="button" class="btn btn-default" data-dismiss="modal"><%= _('Cancel') %></button>
55
+ <button type="button" class="btn btn-primary"><%= _('Submit') %></button>
56
+ </div>
57
+ </div><!-- /.modal-content -->
58
+ </div><!-- /.modal-dialog -->
59
+ </div><!-- /.modal -->
54
60
 
55
61
  <%= page_entries_info @hosts %>
56
62
  <%= will_paginate @hosts %>
@@ -1,5 +1,5 @@
1
1
  <div class="row">
2
- <div class="span8">
2
+ <div class="col-md-8">
3
3
 
4
4
  <table class="table table-bordered table-striped">
5
5
  <thead>
@@ -1,6 +1,6 @@
1
1
  <%= render 'selected_hosts', :hosts => @hosts %>
2
2
 
3
- <%= form_tag submit_multiple_destroy_hosts_path(:host_ids => params[:host_ids]), :onsubmit => "resetSelection()" do -%>
3
+ <%= form_tag submit_multiple_destroy_discovers_path(:host_ids => params[:host_ids]), :onsubmit => "resetSelection()" do -%>
4
4
  <span class="label label-warning"><%= _('Warning') -%></span>
5
5
  <%= _('This might take a while, as all hosts, facts and reports will be destroyed as well') %>
6
6
  <% end %>
@@ -1,7 +1,7 @@
1
1
  <%= render 'selected_hosts', :hosts => @hosts %>
2
2
  <div class="row">
3
- <div class="span8">
4
- <%= form_for :location, :url => update_multiple_location_hosts_path(:host_ids => params[:host_ids]) do |f| %>
3
+ <div class="col-md-8">
4
+ <%= form_for :location, :url => update_multiple_location_discovers_path(:host_ids => params[:host_ids]) do |f| %>
5
5
  <%= f.select :id, Location.all.map{|e| [e.name, e.id]},{:include_blank => _("Select location")},
6
6
  :onchange => "toggle_multiple_ok_button(this)" %>
7
7
  <%= f.hidden_field :optimistic_import, :value => "yes" %>
@@ -1,7 +1,7 @@
1
1
  <%= render 'selected_hosts', :hosts => @hosts %>
2
2
  <div class="row">
3
- <div class="span8">
4
- <%= form_for :organization, :url => update_multiple_organization_hosts_path(:host_ids => params[:host_ids]) do |f| %>
3
+ <div class="col-md-8">
4
+ <%= form_for :organization, :url => update_multiple_organization_discovers_path(:host_ids => params[:host_ids]) do |f| %>
5
5
  <%= f.select :id, Organization.all.map{|e| [e.name, e.id]},{:include_blank => _("Select organization")},
6
6
  :onchange => "toggle_multiple_ok_button(this)" %>
7
7
  <%= f.hidden_field :optimistic_import, :value => "yes" %>
data/extra/build_iso.sh CHANGED
@@ -88,7 +88,7 @@ fi
88
88
 
89
89
  # Build the init script
90
90
  echo "" >> opt/bootlocal.sh
91
- echo "sleep 20" >> opt/bootlocal.sh # network can be slow to come up, and we're not in a rush
91
+ echo "/opt/wait_for_network.sh" >> opt/bootlocal.sh # network can be slow to come up
92
92
  echo "/opt/foreman_startup.rb" >> opt/bootlocal.sh
93
93
  echo "/opt/discovery_init.sh" >> opt/bootlocal.sh
94
94
 
@@ -96,9 +96,19 @@ echo "/opt/discovery_init.sh" >> opt/bootlocal.sh
96
96
  cp $SCRIPT_DIR/foreman_startup.rb opt/foreman_startup.rb
97
97
  chmod 755 opt/foreman_startup.rb
98
98
 
99
+ # Copy the script that wait for network before trying to use it
100
+ cp $SCRIPT_DIR/wait_for_network.sh opt/wait_for_network.sh
101
+ chmod 755 opt/wait_for_network.sh
102
+
99
103
  # Get the gems
100
104
  mkdir opt/gems && cd opt/gems
101
- for n in $GEMS ; do gem fetch $n ; done
105
+ gem fetch facter
106
+ gem fetch json_pure
107
+ gem fetch rack
108
+ gem fetch rack-protection
109
+ # Explicit version for tilt or it brakes sinatra (actual tilt version >= 2.0.0) :
110
+ gem fetch --version 1.3.4 tilt
111
+ gem fetch sinatra
102
112
 
103
113
  # Build the fallback script
104
114
  echo "#!/bin/sh" >> ../discovery_init.sh
@@ -0,0 +1,55 @@
1
+ # vim: sw=2:ts=2:et:ft=ruby
2
+
3
+ box = {:name => 'f19', :libvirt => 'fm-fedora19', :image_name => /Fedora.*19/, :pty => true}
4
+
5
+ if ENV['box']
6
+ box = {:name => ENV['box'], :libvirt => ENV['box'], :image_name => ENV['box'], :os_user => ENV['box']}
7
+ end
8
+
9
+ Vagrant.configure("2") do |config|
10
+ config.vm.define box[:name], primary: box[:default] do |machine|
11
+ machine.vm.box = box[:name]
12
+ machine.vm.hostname = "foreman-#{box[:name]}.bulder.theforeman.org"
13
+ machine.vm.provision :shell, :path => 'build_image.sh', :args => [
14
+ ENV['base_image_url'],
15
+ ENV['buildnumber'],
16
+ ENV['proxy_repo'],
17
+ ENV['repoowner'],
18
+ ENV['branch'],
19
+ ]
20
+
21
+ machine.vm.provider :libvirt do |p, override|
22
+ override.vm.box = "#{box[:libvirt]}"
23
+ override.vm.box_url = "http://m0dlx.com/files/foreman/boxes/#{box[:libvirt].sub(/^fm-/, '')}.box"
24
+ p.memory = 1024
25
+ end
26
+
27
+ machine.vm.provider :rackspace do |p, override|
28
+ override.vm.box = 'dummy'
29
+ p.server_name = machine.vm.hostname
30
+ p.flavor = /1GB/
31
+ p.image = box[:image_name]
32
+ override.ssh.pty = true if box[:pty]
33
+ end
34
+
35
+ # ~/.vagrant.d/Vagrantfile will need
36
+ # config.ssh.private_key_path = "~/.ssh/id_rsa" # private key for keypair below
37
+
38
+ config.vm.provider :openstack do |p, override|
39
+ override.vm.box = 'dummy'
40
+ p.server_name = machine.vm.hostname
41
+ p.flavor = /m1.tiny/
42
+ p.image = box[:image_name] # Might as well use consistent image names
43
+ p.ssh_username = box[:os_user] # login for the VM
44
+
45
+ # ~/.vagrant.d/Vagrantfile will need
46
+ # p.username = "admin" # e.g. "#{ENV['OS_USERNAME']}"
47
+ # p.api_key = "secret" # e.g. "#{ENV['OS_PASSWORD']}"
48
+ # p.endpoint = "http://openstack:5000/v2.0/tokens" # e.g. "#{ENV['OS_AUTH_URL']}/tokens"
49
+ # p.keypair_name = "my_key" # as stored in Nova
50
+
51
+ # You may need
52
+ # p.floating_ip = '172.20.10.160' # Must be hardcoded, cannot ask Openstack for an IP
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,96 @@
1
+ #!/bin/bash
2
+ # vim: sw=2:ts=2:et
3
+ set -x
4
+
5
+ base_image_url=${1}
6
+ buildnumber=${2}
7
+ proxy_repo=${3}
8
+ repoowner=${4}
9
+ branch=${5}
10
+
11
+ echo Building $repoowner/$branch from $base_image_url and $proxy_repo
12
+
13
+ cat > ./fedora.repo <<'EOF'
14
+ [fedora-edit-node]
15
+ name=Fedora $releasever - $basearch
16
+ #baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
17
+ baseurl=http://mirror.rackspace.com/fedora/releases/$releasever/Everything/$basearch/os/
18
+ #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch
19
+ failovermethod=priority
20
+ retries=200
21
+ enabled=1
22
+ gpgcheck=1
23
+ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
24
+
25
+ [updates-edit-node]
26
+ name=Fedora $releasever - $basearch - Updates
27
+ #baseurl=http://download.fedoraproject.org/pub/fedora/linux/updates/$releasever/$basearch/
28
+ baseurl=http://mirror.rackspace.com/fedora/updates/$releasever/$basearch/
29
+ #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=updates-released-f$releasever&arch=$basearch
30
+ failovermethod=priority
31
+ retries=200
32
+ enabled=1
33
+ gpgcheck=1
34
+ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch
35
+ EOF
36
+
37
+ cat > ./foreman.repo <<EOF2
38
+ [foreman]
39
+ name=Foreman nightly
40
+ baseurl=$proxy_repo
41
+ enabled=1
42
+ gpgcheck=0
43
+ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-foreman
44
+ EOF2
45
+
46
+ cat fedora.repo foreman.repo > edit-node.repo
47
+
48
+ export OVIRT_NODE_BASE=$PWD
49
+ export OVIRT_CACHE_DIR=~/ovirt-cache
50
+ export OVIRT_LOCAL_REPO=file://${OVIRT_CACHE_DIR}/ovirt
51
+ mkdir -p $OVIRT_CACHE_DIR
52
+
53
+ # give the VM some time to finish booting and network configuration
54
+ sleep 40
55
+
56
+ yum -y install livecd-tools appliance-tools-minimizer fedora-packager \
57
+ python-devel rpm-build createrepo selinux-policy-doc checkpolicy \
58
+ selinux-policy-devel autoconf automake python-mock python-lockfile git wget
59
+ git clone http://gerrit.ovirt.org/p/ovirt-node.git
60
+ git clone http://gerrit.ovirt.org/p/ovirt-node-iso.git
61
+ git clone https://github.com/$repoowner/foreman_discovery.git -b $branch
62
+
63
+ BASE_IMAGE=$(basename $base_image_url)
64
+ VERSION=$(grep AC_INIT foreman_discovery/extra/ovirt-node-plugin-foreman/configure.ac | grep -oE '[0-9].[0-9].[0-9]')-$buildnumber
65
+
66
+ wget -q -nc -c "$base_image_url"
67
+
68
+ function build() {
69
+ RPMSDIR=$(rpm --eval '%{_rpmdir}')
70
+ rm -f $RPMSDIR/noarch/*rpm
71
+ pushd foreman_discovery/extra/ovirt-node-plugin-foreman
72
+ git pull
73
+ make distclean
74
+ if [[ "$1" == "debug" ]]; then
75
+ ./autogen.sh --enable-debug && make rpms
76
+ else
77
+ ./autogen.sh && make rpms
78
+ fi
79
+ popd
80
+ cat edit-node.repo
81
+ ovirt-node/tools/edit-node --repo edit-node.repo --nogpgcheck \
82
+ --install $RPMSDIR/noarch/ovirt-node-plugin-foreman-0*.rpm \
83
+ $BASE_IMAGE
84
+ echo edit-node returned: $?
85
+ mv -f ovirt-node-iso-*.foreman.*.iso foreman.iso
86
+ rm -rf tftpboot
87
+ livecd-iso-to-pxeboot foreman.iso
88
+ mv -f tftpboot/vmlinuz0 discovery-$1-$VERSION-vmlinuz
89
+ mv -f tftpboot/initrd0.img discovery-$1-$VERSION-initrd.img
90
+ mv -f foreman.iso foreman-discovery-$1-$VERSION.iso
91
+ }
92
+
93
+ build prod
94
+ build debug
95
+
96
+
@@ -17,7 +17,7 @@
17
17
  # MA 02110-1301, USA. A copy of the GNU General Public License is
18
18
  # also available at http://www.gnu.org/copyleft/gpl.html.
19
19
 
20
- AC_INIT([ovirt-node-plugin-foreman], [0.3.0], [foreman-dev@googlegroups.com])
20
+ AC_INIT([ovirt-node-plugin-foreman], [0.3.1], [foreman-dev@googlegroups.com])
21
21
  AM_INIT_AUTOMAKE([-Wall -Werror foreign -Wno-portability tar-pax])
22
22
  AC_SUBST([ENGINENAME], ['Foreman Discovery'])
23
23
  PKG_PROG_PKG_CONFIG
@@ -29,6 +29,8 @@ require 'fileutils'
29
29
  require 'net/http'
30
30
  require 'net/https'
31
31
  require 'uri'
32
+ require 'socket'
33
+ require 'resolv'
32
34
 
33
35
  # For comparison
34
36
  require 'rubygems'
@@ -74,73 +76,89 @@ def error msg
74
76
  $stderr.puts "#{time_prefix} #{msg}"
75
77
  end
76
78
 
77
- def cmdline
78
- return File.open("/proc/cmdline", 'r') { |f| f.read }
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
79
87
  end
80
88
 
81
89
  def discover_server
82
90
  debug "Parsing kernel line: #{cmdline}"
83
- server = (discover_by_pxe or discover_by_dns)
84
- unless server =~ /^http/
85
- server = "http://#{server}"
86
- end
87
- server
91
+ discover_by_url or discover_by_ip or
92
+ discover_by_server or discover_by_dns_srv
88
93
  end
89
94
 
90
- def discover_by_pxe
91
- begin
92
- server_ip = cmdline.split.map { |x| $1 if x.match(/foreman.ip=(.*)/)}.compact
93
- if server_ip.size == 1
94
- result = server_ip.join
95
- println "Discovered by PXE: #{result}"
96
- return result
97
- else
98
- return false
99
- end
100
- rescue
101
- return false
102
- end
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
103
111
  end
104
112
 
105
- def discover_by_dns
106
- begin
107
- server_name = cmdline.split.map { |x| $1 if x.match(/foreman.server=(.*)/)}.compact
108
- server_name = server_name.size == 1 ? server_name.join : 'foreman'
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
109
120
 
110
- require 'socket'
111
- result = TCPSocket.gethostbyname(server_name)[3..-1].first || false
112
- println "Discovered by DNS: #{result}"
113
- return result
114
- rescue
115
- return false
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'
116
131
  end
132
+ uri = "#{scheme}://#{hostname}:#{result.port}"
133
+ println "Discovered by SRV: #{uri}"
134
+ URI.parse(uri)
135
+ rescue
136
+ return nil
117
137
  end
118
138
 
119
139
  def upload
120
140
  ip = Facter.value('ipaddress')
121
- server = discover_server
122
- println "Triggering import of facts from Foreman (#{server}, ip=#{ip})"
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})"
123
144
  data = ip.nil? ? {} : {'ip' => ip}
124
- begin
125
- uri = URI.parse(server)
126
- http = Net::HTTP.new(uri.host, uri.port)
127
- if uri.scheme == 'https' then
128
- http.use_ssl = true
129
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
130
- end
131
- req = Net::HTTP::Post.new("/discovers")
132
- req.set_form_data(data)
133
- response = http.request(req)
134
- debug "Response from Foreman #{response.code}: #{response.body}"
135
- if response.code == "200"
136
- return true
137
- else
138
- return false
139
- end
140
- rescue Exception => e
141
- error "Could not send facts to Foreman: #{e}"
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
142
157
  return false
143
158
  end
159
+ rescue => e
160
+ error "Could not send facts to Foreman: #{e}"
161
+ return false
144
162
  end
145
163
 
146
164
  def write_cache(data)
@@ -172,15 +190,15 @@ end
172
190
  println "Some interesting facts about this system:"
173
191
  facts = Facter.to_hash.select {|k,v| k =~ /address|hardware|manufacturer|productname|memorytotal/}
174
192
  facts.keys.sort.each {|k| println " #{k}: #{facts[k]}"}
175
- println "\nLogs from discovery services now follows:"
193
+ println "Logs from discovery services now follows:"
176
194
 
177
195
  # loop, but only upload on changes
178
196
  while true do
179
- sleep DEBUG ? 30 : 60
180
197
  uninteresting_facts=/kernel|operatingsystem|osfamily|ruby|path|time|swap|free|filesystem|version|selinux/i
181
198
  facts = Facter.to_hash.reject! {|k,v| k =~ uninteresting_facts }
182
199
  unless YAML.load(read_cache) == facts
183
200
  debug "Fact cache invalid, reloading to foreman"
184
201
  write_cache(YAML.dump(facts)) if upload
202
+ sleep DEBUG ? 30 : 60
185
203
  end
186
204
  end
@@ -0,0 +1,23 @@
1
+ #!/bin/sh
2
+ n=1
3
+
4
+ for x in `cat /proc/cmdline`
5
+ do
6
+ case $x in
7
+ foreman.ip=*)
8
+ server="${x//foreman.ip=}"
9
+ ;;
10
+ foreman.server=*)
11
+ server="${x//foreman.server=}"
12
+ ;;
13
+ esac
14
+ done
15
+
16
+ echo "Testing ping to $server to see if network is up..."
17
+
18
+ until ping -w 1 -c 1 "$server" &>/dev/null ;do
19
+ sleep 1
20
+ n=$(( n+1 ))
21
+ [ $n -eq 180 ] && break
22
+ done
23
+
@@ -26,17 +26,17 @@ module ForemanDiscovery
26
26
 
27
27
  initializer 'foreman_discovery.register_plugin', :after=> :finisher_hook do |app|
28
28
  Foreman::Plugin.register :foreman_discovery do
29
- requires_foreman '>= 1.4'
29
+ requires_foreman '> 1.4'
30
30
 
31
31
  # Add permissions
32
32
  security_block :discovery do
33
- permission :view_discovered_hosts, {:discovers => [:index, :show, :auto_complete_search, :refresh_facts] }
34
- permission :provision_discovered_hosts, {:discovers => [:new, :create] }
33
+ permission :view_discovered_hosts, {:discovers => [:index, :show, :auto_complete_search, :refresh_facts] }, :resource_type => 'Host'
34
+ permission :provision_discovered_hosts, {:discovers => [:new, :create] }, :resource_type => 'Host'
35
35
  permission :edit_discovered_hosts, {:discovers => [:edit, :update, :update_multiple_location,
36
36
  :select_multiple_organization,
37
37
  :update_multiple_organization,
38
- :select_multiple_location] }
39
- permission :destroy_discovered_hosts, {:discovers => [:destroy, :submit_multiple_destroy, :multiple_destroy] }
38
+ :select_multiple_location] }, :resource_type => 'Host'
39
+ permission :destroy_discovered_hosts, {:discovers => [:destroy, :submit_multiple_destroy, :multiple_destroy] }, :resource_type => 'Host'
40
40
 
41
41
  end
42
42
 
@@ -1,3 +1,3 @@
1
1
  module ForemanDiscovery
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0.rc1"
3
3
  end
@@ -7,7 +7,7 @@ msgid ""
7
7
  msgstr ""
8
8
  "Project-Id-Version: version 0.0.1\n"
9
9
  "Report-Msgid-Bugs-To: \n"
10
- "POT-Creation-Date: 2014-01-24 13:57+0100\n"
10
+ "POT-Creation-Date: 2014-04-08 15:59+0200\n"
11
11
  "PO-Revision-Date: 2013-03-01 15:45-0500\n"
12
12
  "Last-Translator: \n"
13
13
  "Language-Team: Foreman Team <foreman-dev@googlegroups.com>\n"
@@ -83,6 +83,12 @@ msgstr ""
83
83
  msgid "Imported Host::Discovered"
84
84
  msgstr ""
85
85
 
86
+ msgid "Invalid facts, must be a Hash"
87
+ msgstr ""
88
+
89
+ msgid "Invalid facts: hash does not contain the required fact '%s'"
90
+ msgstr ""
91
+
86
92
  msgid "Last facts upload"
87
93
  msgstr ""
88
94
 
@@ -116,7 +122,7 @@ msgstr ""
116
122
  msgid "Refresh facts"
117
123
  msgstr ""
118
124
 
119
- msgid "Select action"
125
+ msgid "Select Action"
120
126
  msgstr ""
121
127
 
122
128
  msgid "Select all items in this page"
metadata CHANGED
@@ -1,58 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_discovery
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sutcliffe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2014-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: open4
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ftools
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: deface
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: ! 'MaaS Discovery Plugin engine for Foreman '
55
+ description: 'MaaS Discovery Plugin engine for Foreman '
56
56
  email: gsutclif@redhat.com
57
57
  executables: []
58
58
  extensions: []
@@ -60,67 +60,66 @@ extra_rdoc_files:
60
60
  - LICENSE
61
61
  - README.md
62
62
  files:
63
- - LICENSE
64
- - README.md
65
- - Rakefile
66
- - app/controllers/discovers_controller.rb
63
+ - app/overrides/add_dashboard_table.rb
67
64
  - app/helpers/discovers_helper.rb
68
65
  - app/models/host/discovered.rb
69
66
  - app/models/host/managed_extensions.rb
70
67
  - app/models/setting/discovered.rb
71
- - app/overrides/add_dashboard_table.rb
72
- - app/views/discovers/_discovers_list.html.erb
73
- - app/views/discovers/_selected_hosts.html.erb
68
+ - app/controllers/discovers_controller.rb
74
69
  - app/views/discovers/index.html.erb
75
- - app/views/discovers/multiple_destroy.html.erb
70
+ - app/views/discovers/_selected_hosts.html.erb
71
+ - app/views/discovers/show.html.erb
76
72
  - app/views/discovers/select_multiple_location.html.erb
73
+ - app/views/discovers/_discovers_list.html.erb
74
+ - app/views/discovers/multiple_destroy.html.erb
77
75
  - app/views/discovers/select_multiple_organization.html.erb
78
- - app/views/discovers/show.html.erb
79
- - config/initializers/discovery_setup.rb
80
- - config/routes.rb
81
- - extra/build_iso.sh
82
- - extra/discover_host
83
- - extra/discovery_init.sh.example
84
- - extra/disk_facts.rb
85
- - extra/foreman_startup.rb
86
- - extra/ovirt-node-plugin-foreman/COPYING
87
- - extra/ovirt-node-plugin-foreman/Makefile.am
88
76
  - extra/ovirt-node-plugin-foreman/README.md
89
- - extra/ovirt-node-plugin-foreman/autogen.sh
90
- - extra/ovirt-node-plugin-foreman/conf/Makefile.am
91
- - extra/ovirt-node-plugin-foreman/conf/foreman-plugin.firewall.in
92
- - extra/ovirt-node-plugin-foreman/conf/foreman-plugin.logs
93
- - extra/ovirt-node-plugin-foreman/configure.ac
94
77
  - extra/ovirt-node-plugin-foreman/ovirt-node-plugin-foreman.spec.in
95
- - extra/ovirt-node-plugin-foreman/recipe/Makefile.am
96
78
  - extra/ovirt-node-plugin-foreman/recipe/foreman-plugin-iso.ks
97
79
  - extra/ovirt-node-plugin-foreman/recipe/foreman-plugin-minimizer.ks
98
- - extra/ovirt-node-plugin-foreman/src/Makefile.am
80
+ - extra/ovirt-node-plugin-foreman/recipe/Makefile.am
81
+ - extra/ovirt-node-plugin-foreman/conf/foreman-plugin.firewall.in
82
+ - extra/ovirt-node-plugin-foreman/conf/Makefile.am
83
+ - extra/ovirt-node-plugin-foreman/conf/foreman-plugin.logs
84
+ - extra/ovirt-node-plugin-foreman/src/find-missing-libs
85
+ - extra/ovirt-node-plugin-foreman/src/discovery-version-fact.rb.in
99
86
  - extra/ovirt-node-plugin-foreman/src/discover-host.rb.in
100
87
  - extra/ovirt-node-plugin-foreman/src/discover-host.service
101
- - extra/ovirt-node-plugin-foreman/src/discovery-version-fact.rb.in
102
- - extra/ovirt-node-plugin-foreman/src/find-missing-libs
88
+ - extra/ovirt-node-plugin-foreman/src/Makefile.am
89
+ - extra/ovirt-node-plugin-foreman/configure.ac
90
+ - extra/ovirt-node-plugin-foreman/Makefile.am
91
+ - extra/ovirt-node-plugin-foreman/COPYING
92
+ - extra/ovirt-node-plugin-foreman/autogen.sh
93
+ - extra/build_iso.sh
94
+ - extra/discover_host
95
+ - extra/wait_for_network.sh
96
+ - extra/ovirt-node-build/build_image.sh
97
+ - extra/ovirt-node-build/Vagrantfile
98
+ - extra/discovery_init.sh.example
99
+ - extra/foreman_startup.rb
100
+ - extra/disk_facts.rb
101
+ - config/initializers/discovery_setup.rb
102
+ - config/routes.rb
103
103
  - lib/discovery.rake
104
- - lib/foreman_discovery.rb
105
104
  - lib/foreman_discovery/engine.rb
106
- - lib/foreman_discovery/facts.rb
107
105
  - lib/foreman_discovery/version.rb
108
- - locale/Makefile
109
- - locale/discovery.pot
110
- - locale/en_GB/LC_MESSAGES/discovery.mo
106
+ - lib/foreman_discovery/facts.rb
107
+ - lib/foreman_discovery.rb
108
+ - locale/sv_SE/discovery.po
109
+ - locale/fr/discovery.po
111
110
  - locale/en_GB/discovery.po
112
- - locale/es/LC_MESSAGES/discovery.mo
111
+ - locale/foreman_discovery.pot
113
112
  - locale/es/discovery.po
114
- - locale/fr/LC_MESSAGES/discovery.mo
115
- - locale/fr/discovery.po
116
- - locale/sv_SE/LC_MESSAGES/discovery.mo
117
- - locale/sv_SE/discovery.po
118
- - test/functional/discovers_controller_test.rb
113
+ - locale/Makefile
114
+ - LICENSE
115
+ - Rakefile
116
+ - README.md
119
117
  - test/test_helper.rb
120
- - test/test_plugin_helper.rb
121
118
  - test/unit/facts.json
122
119
  - test/unit/host_discovered_test.rb
123
120
  - test/unit/setting_discovered_test.rb
121
+ - test/functional/discovers_controller_test.rb
122
+ - test/test_plugin_helper.rb
124
123
  homepage: http://github.com/theforeman/foreman_discovery
125
124
  licenses:
126
125
  - GPL-3
@@ -131,24 +130,25 @@ require_paths:
131
130
  - lib
132
131
  required_ruby_version: !ruby/object:Gem::Requirement
133
132
  requirements:
134
- - - ! '>='
133
+ - - '>='
135
134
  - !ruby/object:Gem::Version
136
135
  version: '0'
137
136
  required_rubygems_version: !ruby/object:Gem::Requirement
138
137
  requirements:
139
- - - ! '>='
138
+ - - '>'
140
139
  - !ruby/object:Gem::Version
141
- version: '0'
140
+ version: 1.3.1
142
141
  requirements: []
143
142
  rubyforge_project:
144
- rubygems_version: 2.2.1
143
+ rubygems_version: 2.0.3
145
144
  signing_key:
146
145
  specification_version: 4
147
146
  summary: MaaS Discovery Plugin for Foreman
148
147
  test_files:
149
- - test/functional/discovers_controller_test.rb
148
+ - test/test_helper.rb
150
149
  - test/unit/facts.json
151
- - test/unit/setting_discovered_test.rb
152
150
  - test/unit/host_discovered_test.rb
151
+ - test/unit/setting_discovered_test.rb
152
+ - test/functional/discovers_controller_test.rb
153
153
  - test/test_plugin_helper.rb
154
- - test/test_helper.rb
154
+ has_rdoc:
Binary file
Binary file
Binary file
Binary file