foreman_default_hostgroup 0.1.0 → 1.0.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82a6b0143d9889fb4302f38b6a92850aa724a367
4
- data.tar.gz: 7e74dba1ddcd2cdbdadb07c624ac6e9556d0397c
3
+ metadata.gz: 80eeeefe5330eb909cbff3b1945df18fd64b5270
4
+ data.tar.gz: a31c296a3e787879056a7f167f6ae4e31a9ce999
5
5
  SHA512:
6
- metadata.gz: 91f93da69dae782a3b52ee958eed4abb554780d9801b3f06f9b515f7bcb1e17e42817245de14f87ee060a0ab9b2df650cc5d258bc75ff896ef5e9a38efd3ae97
7
- data.tar.gz: 36b6e5428a3557e24efd87ab551d9cf38446418842a385ccd2da8f350e1e38a335064a365c3e8009defd7b335b5e7ceeb2cbf931a61fcd379b1ef462dd1134c1
6
+ metadata.gz: df1e1a9fbf5adefc691245525c284125a3e7f19f29043189e5a0c402dd9468ad860326feee0fb0195fd32d14a809e2abd67f98dac397017f29256df0a873b1f5
7
+ data.tar.gz: 3d03a685af3174d5ba437330fee1172539b2cdd4961aa4e67bc7dcefadfb4b6228ea7d3e7e9df6595b7b24be17ab3c4d6e8575ca4904d7d5ea6e33a0f4ad3824
data/README.md CHANGED
@@ -5,11 +5,15 @@ a Hostgroup set.
5
5
 
6
6
  ## Installation
7
7
 
8
- Usual Rails Engine installation - add to your Gemfile:
8
+ See [How_to_Install_a_Plugin](http://projects.theforeman.org/projects/foreman/wiki/How_to_Install_a_Plugin)
9
+ for how to install Foreman plugins
9
10
 
10
- gem 'foreman_default_hostgroup', :git => 'https://github.com/GregSutcliffe/foreman_default_hostgroup'
11
+ ## Compatibility
11
12
 
12
- then run `bundle update` and restart Foreman
13
+ | Foreman Version | Plugin Version |
14
+ | --------------- | --------------:|
15
+ | <= 1.2 | 0.1.0 |
16
+ | >= 1.3 | 1.0.0 |
13
17
 
14
18
  ## Usage
15
19
 
@@ -17,8 +21,8 @@ Go to `Settings -> DefaultHostgroup` and enter the name of the default
17
21
  hostgroup. Leaving this blank disables the plugin. Nested Hostgroups should be
18
22
  specified with the full label, e.g. `Base/Level1/Level2`
19
23
 
20
- Once set, any upload to `/fact_values/create` for a Host with no Hostgroup set
21
- will cause the Hostgroup to be set to the value in the Settings. THis happens
24
+ Once set, any fact upload to `/api/hosts/facts` for a Host with no Hostgroup set
25
+ will cause the Hostgroup to be set to the value in the Settings. This happens
22
26
  *before* the ENC data is downloaded, meaning it applies for a Host's very first
23
27
  run.
24
28
 
@@ -28,7 +32,6 @@ reports (i.e new Hosts only).
28
32
  ## TODO
29
33
 
30
34
  * Tests
31
- * Rewrite this in a less hacky way
32
35
 
33
36
  ## Contributing
34
37
 
@@ -10,36 +10,17 @@ module DefaultHostgroupManagedHostPatch
10
10
  end
11
11
 
12
12
  module ClassMethods
13
- def importHostAndFacts_with_apply_hostgroup yaml
14
- orig_result = importHostAndFacts_without_apply_hostgroup(yaml)
13
+ def importHostAndFacts_with_apply_hostgroup hostname, facts, certname = nil
14
+ host, result = importHostAndFacts_without_apply_hostgroup(hostname, facts, certname)
15
15
  Rails.logger.debug "DefaultHostgroup: performing Hostgroup check"
16
- # The aliased method just returns true/false so we have to reparse the yaml
17
- # to find the host
18
- unless Setting[:default_hostgroup] == ''
19
- facts = YAML::load yaml
20
- case facts
21
- when Puppet::Node::Facts
22
- certname = facts.name
23
- name = facts.values["fqdn"].downcase
24
- when Hash
25
- certname = facts["clientcert"] || facts["certname"]
26
- name = facts["fqdn"].downcase
27
- end
28
- h=nil
29
- if name == certname or certname.nil?
30
- h = Host.find_by_name name
31
- else
32
- h = Host.find_by_certname certname
33
- h ||= Host.find_by_name name
34
- end
35
- # Now we can update it
36
- if h.hostgroup.nil? and h.reports.empty?
37
- h.hostgroup = Hostgroup.find_by_label(Setting[:default_hostgroup])
38
- h.save
39
- Rails.logger.debug "DefaultHostgroup: added #{h.name} to #{h.hostgroup.label}"
40
- end
16
+ # host.new_record? will only test for the early return in the core method, a real host
17
+ # will have already been saved at least once.
18
+ if host.present? && !host.new_record? && host.hostgroup.nil? && host.reports.empty?
19
+ host.hostgroup = Hostgroup.find_by_label(Setting[:default_hostgroup])
20
+ host.save(:validate => false)
21
+ Rails.logger.debug "DefaultHostgroup: added #{host.name} to #{host.hostgroup.label}"
41
22
  end
42
- orig_result
23
+ return host, result
43
24
  end
44
25
  end
45
26
  end
@@ -1,4 +1,3 @@
1
- require 'deface'
2
1
  require 'default_hostgroup_managed_host_patch'
3
2
 
4
3
  module ForemanDefaultHostgroup
@@ -1,3 +1,3 @@
1
1
  module ForemanDefaultHostgroup
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_default_hostgroup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Sutcliffe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-03 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: deface
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
11
+ date: 2013-10-04 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: Adds the option to specify a default hostgroup for new hosts created
28
14
  from facts/reports
29
15
  email: gsutclif@redhat.com