hosties 1.0.0 → 1.1.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hosties.rb +1 -0
- data/lib/hosties/{Definitions.rb → definitions.rb} +4 -0
- data/lib/hosties/easydata.rb +40 -0
- data/lib/hosties/{Reification.rb → reification.rb} +17 -16
- data/spec/easydata_spec.rb +38 -0
- data/spec/hosties_spec.rb +7 -7
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b67e9ef6e1d2d98eaf6c3e5dc570e2b478e12708
|
4
|
+
data.tar.gz: d3fa2796ecfee0d21f0091c6ca6d1518961d281f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3b2df43b6b47519ad39ef1c339c60b94e0ad27f2d1b7941c4686e7cbaed8166735aa03ac4fa1c8b9a3fae126a41935e041030a669f6ab1c1410eb3d0d5ee326
|
7
|
+
data.tar.gz: 86b140c14683a0b37cf754158920181856cd4fb0bc85f560806e37166b13246a0da667a2db1c965a0c1bb44574a601163ab7d8c2ae3cec5aea9bce4e11879e51
|
data/lib/hosties.rb
CHANGED
@@ -37,6 +37,8 @@ class HasAttributes
|
|
37
37
|
end
|
38
38
|
|
39
39
|
alias_method :have_attribute, :have_attributes
|
40
|
+
alias_method :has_attribute, :have_attribute
|
41
|
+
alias_method :has_attributes, :have_attributes
|
40
42
|
|
41
43
|
# Helpful method to define constraints
|
42
44
|
def where(name)
|
@@ -71,6 +73,8 @@ class HostRequirement < HasAttributes
|
|
71
73
|
end
|
72
74
|
|
73
75
|
alias_method :have_service, :have_services
|
76
|
+
alias_method :has_service, :have_service
|
77
|
+
alias_method :has_services, :have_services
|
74
78
|
|
75
79
|
def finished
|
76
80
|
Hosties::HostDefinitions[@type] = self
|
@@ -0,0 +1,40 @@
|
|
1
|
+
###############################################################
|
2
|
+
# Provide a more convenient data structure to work with once #
|
3
|
+
# environment declarations have been read. #
|
4
|
+
###############################################################
|
5
|
+
class DataWrapper
|
6
|
+
def metaclass
|
7
|
+
class << self
|
8
|
+
self
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Hosties
|
14
|
+
module EasyData
|
15
|
+
def self.fromHost(hash)
|
16
|
+
result = DataWrapper.new
|
17
|
+
hash.each do |k, v|
|
18
|
+
result.metaclass.send(:define_method, k) do v end
|
19
|
+
end
|
20
|
+
result
|
21
|
+
end
|
22
|
+
def self.fromEnv(hash)
|
23
|
+
result = DataWrapper.new
|
24
|
+
hash.each do |k, v|
|
25
|
+
result.metaclass.send(:define_method, k) do v end
|
26
|
+
end
|
27
|
+
# Add a hosts_by_type method
|
28
|
+
result.metaclass.send(:define_method, :hosts_by_type) do |type|
|
29
|
+
self.hosts.find_all do |host|
|
30
|
+
host.type == type
|
31
|
+
end
|
32
|
+
end
|
33
|
+
# Add an each_host method
|
34
|
+
result.metaclass.send(:define_method, :each_host) do |&block|
|
35
|
+
yield self.hosts
|
36
|
+
end
|
37
|
+
result
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -64,8 +64,8 @@ class HostBuilder < UsesAttributes
|
|
64
64
|
@definition.services.each do |svc|
|
65
65
|
raise ArgumentError, "Missing service #{svc}" if @service_ports[svc].nil?
|
66
66
|
end
|
67
|
-
# TODO:
|
68
|
-
super.merge({ :hostname => @hostname }).merge(@service_ports)
|
67
|
+
# TODO: Declare these reserved names
|
68
|
+
super.merge({ :hostname => @hostname, :type => @type }).merge(@service_ports)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
@@ -75,7 +75,7 @@ class EnvironmentBuilder < UsesAttributes
|
|
75
75
|
if Hosties::EnvironmentDefinitions[type].nil? then
|
76
76
|
raise ArgumentError, "Unrecognized environment type"
|
77
77
|
end
|
78
|
-
@hosts =
|
78
|
+
@hosts = []
|
79
79
|
@type = type
|
80
80
|
@definition = Hosties::EnvironmentDefinitions[@type]
|
81
81
|
super(@definition) # Creates attribute code
|
@@ -86,8 +86,7 @@ class EnvironmentBuilder < UsesAttributes
|
|
86
86
|
begin
|
87
87
|
builder = HostBuilder.new(host_type, hostname)
|
88
88
|
builder.instance_eval(&block)
|
89
|
-
|
90
|
-
@hosts[host_type] << builder.finish
|
89
|
+
@hosts << Hosties::EasyData.fromHost(builder.finish)
|
91
90
|
rescue ArgumentError => ex
|
92
91
|
#puts "Problem declaring host: #{ex}"
|
93
92
|
raise ex
|
@@ -99,19 +98,11 @@ class EnvironmentBuilder < UsesAttributes
|
|
99
98
|
def finish
|
100
99
|
# Verify all of the required hosts were set
|
101
100
|
@definition.hosts.each do |host_type|
|
102
|
-
|
103
|
-
|
104
|
-
retval = super.merge({ :hosts => @hosts })
|
105
|
-
Hosties::Environments[@type] << retval
|
106
|
-
# Add ourselves into the grouped listing if necessary
|
107
|
-
attr = @definition.grouping
|
108
|
-
unless attr.nil? then # TODO: This is really ugly
|
109
|
-
if Hosties::GroupedEnvironments[@type].nil? then
|
110
|
-
Hosties::GroupedEnvironments[@type] = Hash.new{|h,k| h[k] = []}
|
101
|
+
unless @hosts.detect { |host| host.type == host_type } then
|
102
|
+
raise ArgumentError, "Missing #{host_type} host"
|
111
103
|
end
|
112
|
-
Hosties::GroupedEnvironments[@type][retval[attr]] << retval
|
113
104
|
end
|
114
|
-
|
105
|
+
super.merge({ :hosts => @hosts })
|
115
106
|
end
|
116
107
|
end
|
117
108
|
|
@@ -120,6 +111,16 @@ def environment_for(type, &block)
|
|
120
111
|
builder = EnvironmentBuilder.new(type)
|
121
112
|
builder.instance_eval(&block)
|
122
113
|
data = builder.finish
|
114
|
+
nice_version = Hosties::EasyData.fromEnv(data)
|
115
|
+
Hosties::Environments[type] << nice_version
|
116
|
+
definition = Hosties::EnvironmentDefinitions[type]
|
117
|
+
# Add into the grouped listing if necessary
|
118
|
+
unless definition.grouping.nil? then
|
119
|
+
if Hosties::GroupedEnvironments[type].nil? then
|
120
|
+
Hosties::GroupedEnvironments[type] = Hash.new{|h,k| h[k] = []}
|
121
|
+
end
|
122
|
+
Hosties::GroupedEnvironments[type][data[definition.grouping]] << nice_version
|
123
|
+
end
|
123
124
|
rescue ArgumentError => ex
|
124
125
|
puts "Problem declaring environment: #{ex}"
|
125
126
|
raise ex
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hosties::EasyData do
|
4
|
+
it 'should turn host declarations into something awesome' do
|
5
|
+
host_type :easydata_one do
|
6
|
+
have_service :http
|
7
|
+
have_attribute :attr_one
|
8
|
+
end
|
9
|
+
builder = HostBuilder.new(:easydata_one, "localhost")
|
10
|
+
builder.http 80
|
11
|
+
builder.attr_one "One!"
|
12
|
+
result = Hosties::EasyData.fromHost(builder.finish)
|
13
|
+
expect(result.http).to eq(80)
|
14
|
+
expect(result.attr_one).to eq("One!")
|
15
|
+
expect(result.hostname).to eq("localhost")
|
16
|
+
expect(result.type).to eq(:easydata_one)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should turn environment declarations into something awesome too' do
|
20
|
+
host_type :easydata_two do end
|
21
|
+
host_type :easydata_three do end
|
22
|
+
environment_type :easydata_one do
|
23
|
+
need :easydata_two, :easydata_three
|
24
|
+
have_attribute :environment
|
25
|
+
where(:environment).can_be :dev, :testing
|
26
|
+
end
|
27
|
+
builder = EnvironmentBuilder.new :easydata_one
|
28
|
+
builder.easydata_two "0.0.0.0" do end
|
29
|
+
builder.easydata_three "1.1.1.1" do end
|
30
|
+
builder.environment :dev
|
31
|
+
result = Hosties::EasyData.fromEnv(builder.finish)
|
32
|
+
expect(result.environment).to eq(:dev)
|
33
|
+
type_two_hosts = result.hosts_by_type(:easydata_two)
|
34
|
+
expect(type_two_hosts.size).to eq(1)
|
35
|
+
host = type_two_hosts.first
|
36
|
+
expect(host.hostname).to eq("0.0.0.0")
|
37
|
+
end
|
38
|
+
end
|
data/spec/hosties_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Hosties do
|
|
5
5
|
host_type :special_host do
|
6
6
|
end
|
7
7
|
instance = HostBuilder.new(:special_host, "0.0.0.0")
|
8
|
-
expect(instance.finish).to eq({ :hostname => "0.0.0.0"})
|
8
|
+
expect(instance.finish).to eq({ :hostname => "0.0.0.0", :type => :special_host})
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'catches missing services' do
|
@@ -81,12 +81,12 @@ describe Hosties do
|
|
81
81
|
end
|
82
82
|
expect(Hosties::Environments[:typical_product].nil?).to eq(false)
|
83
83
|
data = Hosties::Environments[:typical_product].first
|
84
|
-
expect(data
|
85
|
-
expect(data
|
86
|
-
expect(data
|
87
|
-
service_host = data
|
88
|
-
expect(service_host
|
89
|
-
expect(service_host
|
84
|
+
expect(data.environment).to eq(:qa)
|
85
|
+
expect(data.hosts_by_type(:monitoring).size).to eq(2) # Two monitoring hosts
|
86
|
+
expect(data.hosts_by_type(:service_host).size).to eq(1)
|
87
|
+
service_host = data.hosts_by_type(:service_host).first
|
88
|
+
expect(service_host.service_port).to eq(1234)
|
89
|
+
expect(service_host.uuid).to eq("81E3C1D4-C040-4D59-A56F-4273384D576B")
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'can group environments by attribute' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hosties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.1.0.alpha
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ron Dahlgren
|
@@ -32,10 +32,12 @@ executables: []
|
|
32
32
|
extensions: []
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
|
-
- lib/hosties/
|
36
|
-
- lib/hosties/
|
35
|
+
- lib/hosties/definitions.rb
|
36
|
+
- lib/hosties/easydata.rb
|
37
|
+
- lib/hosties/reification.rb
|
37
38
|
- lib/hosties.rb
|
38
39
|
- spec/definitions_spec.rb
|
40
|
+
- spec/easydata_spec.rb
|
39
41
|
- spec/hosties_spec.rb
|
40
42
|
- spec/reification_spec.rb
|
41
43
|
- spec/spec_helper.rb
|
@@ -54,9 +56,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
56
|
version: '0'
|
55
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
58
|
requirements:
|
57
|
-
- - '
|
59
|
+
- - '>'
|
58
60
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
61
|
+
version: 1.3.1
|
60
62
|
requirements: []
|
61
63
|
rubyforge_project:
|
62
64
|
rubygems_version: 2.0.3
|
@@ -65,6 +67,7 @@ specification_version: 4
|
|
65
67
|
summary: Easy environment description
|
66
68
|
test_files:
|
67
69
|
- spec/definitions_spec.rb
|
70
|
+
- spec/easydata_spec.rb
|
68
71
|
- spec/hosties_spec.rb
|
69
72
|
- spec/reification_spec.rb
|
70
73
|
- spec/spec_helper.rb
|