oxford 0.9

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.
@@ -0,0 +1,10 @@
1
+ module Oxford
2
+ require 'active_ldap'
3
+ require 'yaml'
4
+ require File.join(File.dirname(__FILE__),"oxford/facts.rb")
5
+ require File.join(File.dirname(__FILE__),"oxford/ldap.rb")
6
+ require File.join(File.dirname(__FILE__),"oxford/host.rb")
7
+ require File.join(File.dirname(__FILE__),"oxford/processor.rb")
8
+ require File.join(File.dirname(__FILE__),"oxford/network.rb")
9
+ require File.join(File.dirname(__FILE__),"oxford/runner.rb")
10
+ end
@@ -0,0 +1,66 @@
1
+ module Oxford
2
+ class Facts
3
+ require 'facter'
4
+ attr_reader :all
5
+
6
+ def method_missing(m, *args, &block)
7
+ if @all.has_key?(m.to_s)
8
+ @all[m.to_s]
9
+ else
10
+ raise NoMethodError
11
+ end
12
+ end
13
+
14
+ def initialize
15
+ @all = Facter.to_hash
16
+ end
17
+
18
+ def networks
19
+ networks = Hash.new
20
+ @all['interfaces'].split(',').each do |interface|
21
+ networks[interface] = {
22
+ 'interface' => interface,
23
+ 'ipaddress' => @all["ipaddress_#{interface}"],
24
+ 'macaddress' => @all["macaddress_#{interface}"],
25
+ 'network' => @all["network_#{interface}"],
26
+ 'netmask' => @all["netmask_#{interface}"]
27
+ }
28
+ end
29
+ networks
30
+ end
31
+
32
+ def processors
33
+ case @all['operatingsystem']
34
+ when 'CentOS', 'RedHat'
35
+ Facts::Linux.processors(@all)
36
+ when 'Darwin'
37
+ Facts::OSX.processors(@all)
38
+ end
39
+ end
40
+
41
+ class Linux
42
+ def self.processors(facts)
43
+ processors = Hash.new
44
+ facts.each do |key, value|
45
+ if key =~ /^processor\d{1,100}/
46
+ processors[key] = {
47
+ 'processorId' => key.gsub(/^processor/, ''),
48
+ 'processorInfo' => value
49
+ }
50
+ end
51
+ end
52
+ processors
53
+ end
54
+ end
55
+
56
+ class OSX
57
+ def self.processors(facts)
58
+ {'processor0' =>
59
+ { 'processorId' => "0",
60
+ 'processorInfo' => "#{facts['sp_cpu_type']} #{facts['sp_current_processor_speed']}"
61
+ }
62
+ }
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,53 @@
1
+ module Oxford
2
+ class Host < ActiveLdap::Base
3
+ ldap_mapping :dn_attribute => 'cn', :prefix => 'ou=Hosts',
4
+ :classes => ['top', 'device', 'facterHost']
5
+ #belongs_to :groups, :class_name => 'WebsagesLDAP::Group', :many => 'memberUid'
6
+ #
7
+ def self.find(host)
8
+ begin
9
+ super(host)
10
+ rescue ActiveLdap::EntryNotFound
11
+ return []
12
+ end
13
+ end
14
+
15
+ def networks(name='*')
16
+ Network.all(:prefix => "cn=#{self.commonName},ou=Hosts", :filter => "(cn=#{name})")
17
+ end
18
+
19
+ def processors(search = {})
20
+ Processor.all(:prefix => "cn=#{self.commonName},ou=Hosts")
21
+ end
22
+
23
+ def add_network(name, value)
24
+ begin
25
+ a = Network.find(name, :prefix => "cn=#{self.commonName},ou=Hosts")
26
+ rescue
27
+ a = Network.new(name)
28
+ a.base = "cn=#{self.commonName},ou=Hosts"
29
+ end
30
+ value.each { |fact, value| a.__send__("fact#{fact}=", value.to_s) }
31
+ raise StandardError unless a.valid?
32
+ a.save
33
+ end
34
+
35
+ def add_processor(name, value)
36
+ begin
37
+ a = Processor.find(name, :prefix => "cn=#{self.commonName},ou=Hosts")
38
+ rescue
39
+ a = Processor.new(name)
40
+ a.base = "cn=#{self.commonName},ou=Hosts"
41
+ end
42
+ value.each { |fact, value| a.__send__("fact#{fact}=", value.to_s) }
43
+ raise StandardError unless a.valid?
44
+ a.save
45
+ end
46
+
47
+ def update!
48
+ time = Time.now.to_i
49
+ self.factLastUpdated = time.to_s
50
+ self.save
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,33 @@
1
+ module Oxford
2
+ class LDAPAdapter
3
+ def initialize
4
+ load_config
5
+ setup_connection
6
+ end
7
+
8
+ def load_config
9
+ config = YAML.load_file(Oxford::Runner.config)
10
+ config['ldap'].each { |key, value| instance_variable_set "@#{key}", value }
11
+ end
12
+
13
+ def setup_connection
14
+ ActiveLdap::Base.setup_connection(
15
+ :host => @host,
16
+ :port => @port,
17
+ :base => @base,
18
+ :method => @method,
19
+ :bind_dn => @user,
20
+ :password => @pass
21
+ )
22
+ end
23
+
24
+ def connected?
25
+ begin
26
+ ActiveLdap::Base.search(:base => @base, :filter => '(cn=admin)', :scope => :sub)
27
+ return true
28
+ rescue => e
29
+ return false
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ module Oxford
2
+ class Network < ActiveLdap::Base
3
+ ldap_mapping :dn_attribute => 'cn', :prefix => "",
4
+ :classes => ['top', 'device', 'facterNetwork']
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Oxford
2
+ class Processor < ActiveLdap::Base
3
+ ldap_mapping :dn_attribute => 'cn', :prefix => "",
4
+ :classes => ['top', 'device', 'facterProcessor']
5
+ end
6
+ end
@@ -0,0 +1,41 @@
1
+ module Oxford
2
+ class Runner
3
+ class << self; attr_accessor :config,:debug end
4
+ @config = File.join(File.dirname(__FILE__), '../../config/database.yaml')
5
+ @debug = false
6
+
7
+ def self.run!
8
+ Oxford::LDAPAdapter.new
9
+
10
+ # should run the fact retrievers
11
+ @facts = Oxford::Facts.new
12
+ @host = Oxford::Host.find(@facts.hostname)
13
+ if @host.is_a?(Array)
14
+ @host = Oxford::Host.new(@facts.hostname)
15
+ end
16
+ @host.save
17
+
18
+ # Set facts provided by Facter.
19
+ @facts.all.each do |fact, value|
20
+ f = fact.gsub(/_/, '')
21
+ if @host.respond_to?("fact#{f}")
22
+ @host.__send__("fact#{f}=", value.to_s)
23
+ else
24
+ puts "fact #{f} not being recorded as there is no corresponding entry in the data store" if @debug
25
+ end
26
+ end
27
+
28
+ # Set Processor Info
29
+ @facts.processors.each do |fact, value|
30
+ @host.add_processor(fact, value)
31
+ end
32
+
33
+ # Set Network Info
34
+ @facts.networks.each do |interface, value|
35
+ @host.add_network(interface, value)
36
+ end
37
+
38
+ @host.update!
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ #require "facter-ldap/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "oxford"
7
+ s.version = '0.9'
8
+ s.authors = ["James Fryman", "Aziz Shamim"]
9
+ s.email = ["james@frymanet.com","azizshamim@gmail.com"]
10
+ s.summary = %q{}
11
+ s.description = %q{}
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+
18
+ # specify any dependencies here; for example:
19
+ s.add_dependency "facter", ">= 1.5.8"
20
+ s.add_dependency "activeldap", ">= 3.1.0"
21
+ s.add_development_dependency "ruby-ldap", ">= 0.9.11"
22
+ s.add_development_dependency "rspec", '~> 2.6.0'
23
+ s.add_development_dependency "rake", '>= 0.8.7'
24
+ # need to check versions
25
+ end
@@ -0,0 +1,36 @@
1
+ describe Oxford::Facts do
2
+ before(:all) do
3
+ @f = Oxford::Facts.new
4
+ end
5
+
6
+ it 'should retrieve local facts from PuppetLabs facter' do
7
+ @f.all.should be_a(Hash)
8
+ end
9
+
10
+ context "network" do
11
+ it 'should retrieve network facts in a parsed format' do
12
+ @f.networks.should be_a(Hash)
13
+ @f.networks.should_not be_empty
14
+ end
15
+
16
+ it 'should retrieve system specific network facts' do
17
+ case @f.kernel
18
+ when 'Darwin'
19
+ @f.networks.should include('en0')
20
+ when 'Linux'
21
+ @f.networks.should include('eth0')
22
+ end
23
+ end
24
+ end
25
+
26
+ context "processor" do
27
+ it 'should return processor facts in a parsed format' do
28
+ @f.processors.should be_a(Hash)
29
+ @f.processors.should_not be_empty
30
+ end
31
+
32
+ it 'should retrieve system specific processor facts' do
33
+ @f.processors.should include('processor0')
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,158 @@
1
+ -
2
+ dn:
3
+ - cn=<%= hostname %>,ou=Hosts,dc=test,dc=com
4
+ cn:
5
+ - <%= hostname %>
6
+ objectClass:
7
+ - top
8
+ - device
9
+ - facterHost
10
+ factProcessorCount:
11
+ - '1'
12
+ factRubySiteDir:
13
+ - '/opt/ruby/lib/ruby/site_ruby/1.8'
14
+ factId:
15
+ - root
16
+ factSwapSize:
17
+ - 1.03 GB
18
+ factArchitecture:
19
+ - i386
20
+ factSshDsaKey:
21
+ - AAAAB3NzaC1kc3MAAACBALTYvtVT480vuAMPxy6Y5T+jriZ3bvB6rPRgVwltMsI8GCcbDJ3C8QbMfQlSoSEPtJVL5kkL4RtFN/KUf8qYr8/e3fDHQ3eUvU2qWhbcU88x2vKM8rup7zIdxcNLGYCv/UJoi+zP9mOTLQwgZAClINr0gW1tmccuclclkA3bpNErAAAAFQCncrjQqIBHYbuQMEe5qy48794N5QAAAIBOPzK4VRnSBMMtvJm0qmd4b/l9Ua5feqFMFVXp9dSuI1z4Gl1JLDD5wmtDoVWQaMAgEN0mQTFXOlerVzKsSs7W8QNJZHUfogUukYY8pzQAn8Oa0GJyRRbQBvCFCyDubS79qw8KnEpZLm31BTMo4+OzqcLPydIDZM5egYHKpTSpqwAAAIEAnf+5NVAYz41OoikhgtpYyAbE3yc38pXgkw4vyW4bpMolJ+KQ8MU1P9mQoD+8zSPWr0gPefpHOoxw/hSTNU9fM6O4CAl4Y/p9HIF/86D6cTzuikhbW0dSmbEWTxs0gCbxcz3vo+KzDUBdlVwsO1uGHycsEOQknu2bECO/CM40C/4=
22
+ factIsVirtual:
23
+ - 'false'
24
+ factHardwareModel:
25
+ - i686
26
+ factKernelRelease:
27
+ - 2.6.18-238.el5
28
+ factKernel:
29
+ - Linux
30
+ factUniqueId:
31
+ - 007f0100
32
+ factLsbRelease:
33
+ - ":core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch"
34
+ factUptimeDays:
35
+ - '0'
36
+ factSelinux:
37
+ - 'true'
38
+ factLsbDistCodename:
39
+ - Final
40
+ factHostname:
41
+ - <%= hostname %>
42
+ factUptimeSeconds:
43
+ - '37636'
44
+ factFqdn:
45
+ - <%= hostname %>.test.com
46
+ factTimeZone:
47
+ - CDT
48
+ factHardwareisa:
49
+ - i686
50
+ factSelinuxConfigPolicy:
51
+ - targeted
52
+ factLastUpdated:
53
+ - '1317236700'
54
+ factSwapFree:
55
+ - 1.03 GB
56
+ factPhysicalProcessorCount:
57
+ - '0'
58
+ factKernelMajVersion:
59
+ - '2.6'
60
+ factSelinuxEnforced:
61
+ - 'false'
62
+ factOperatingSystemRelease:
63
+ - '5.6'
64
+ factDomain:
65
+ - test.com
66
+ factSelinuxConfigMode:
67
+ - permissive
68
+ factMemoryFree:
69
+ - 282.85 MB
70
+ factUptimeHours:
71
+ - '10'
72
+ factLsbMajDistRelease:
73
+ - '5'
74
+ factPath:
75
+ - /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/ruby/bin/:/usr/local/rvm/bin:/root/bin
76
+ factKernelVersion:
77
+ - 2.6.18
78
+ factPuppetVersion:
79
+ - 2.6.8
80
+ factOperatingSystem:
81
+ - CentOS
82
+ factSelinuxPolicyVersion:
83
+ - '21'
84
+ factMemorySize:
85
+ - 375.85 MB
86
+ factSelinuxMode:
87
+ - targeted
88
+ factSshRsaKey:
89
+ - AAAAB3NzaC1yc2EAAAABIwAAAQEArIQv2wN+QYh+UmMMDPQANIlve3hkq+ZGZM00mLw1A7FQnJEt286XaVDfwC8kK2vOmKh2/YTA0FdRpOSM65AmjjHef/wygKGQj5K4GMhs64VlzC+Hxu4BYBMGrxIzJuB54+yrukZDVJ/eC8Q/IlNAsx/3okeWiEtuOpflrAfJtah4HNB5n/8Do0++IiN76EOi5+qnxogBmsGKr0HLB9JARUwMjRyyur4sXE4rYRAOeANXFlsH86gkeEMizyBautjKE0m3JrN5BOPuhFxuZdKQsRqbeQXv13n8CJtw0YTz+u1MFGsWCJQID+IsLbc362NMISIG5DHS0gw92BwQIJ3Wlw==
90
+ factLsbDistId:
91
+ - CentOS
92
+ factPs:
93
+ - 'ps -ef'
94
+ factFacterVersion:
95
+ - 1.5.9
96
+ factMacAddress:
97
+ - 08:00:27:40:9A:F7
98
+ factVirtual:
99
+ - physical
100
+ factLsbDistRelease:
101
+ - '5.6'
102
+ factLsbDistDescription:
103
+ - CentOS release 5.6 (Final)
104
+ factUptime:
105
+ - 10:27 hours
106
+ factRubyVersion:
107
+ - 1.8.7
108
+ factSelinuxCurrentMode:
109
+ - permissive
110
+ -
111
+ dn:
112
+ - cn=processor0,cn=<%= hostname %>,ou=Hosts,dc=test,dc=com
113
+ cn:
114
+ - processor0
115
+ objectClass:
116
+ - top
117
+ - device
118
+ - facterProcessor
119
+ factProcessorInfo:
120
+ - Intel(R) Core(TM) i5-2415M CPU @ 2.30GHz
121
+ factProcessorId:
122
+ - '0'
123
+ -
124
+ dn:
125
+ - cn=lo,cn=<%= hostname %>,ou=Hosts,dc=test,dc=com
126
+ cn:
127
+ - lo
128
+ objectClass:
129
+ - top
130
+ - device
131
+ - facterNetwork
132
+ factNetwork:
133
+ - 127.0.0.0
134
+ factIpAddress:
135
+ - 127.0.0.1
136
+ factInterface:
137
+ - lo
138
+ factNetmask:
139
+ - 255.0.0.0
140
+ -
141
+ dn:
142
+ - cn=eth0,cn=<%= hostname %>,ou=Hosts,dc=test,dc=com
143
+ cn:
144
+ - eth0
145
+ objectClass:
146
+ - top
147
+ - device
148
+ - facterNetwork
149
+ factNetwork:
150
+ - 10.0.2.0
151
+ factIpAddress:
152
+ - 10.0.2.15
153
+ factInterface:
154
+ - eth0
155
+ factMacAddress:
156
+ - 08:00:27:40:9A:F7
157
+ factNetmask:
158
+ - 255.255.255.0