chapp 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 231652d4a0cae298d0e709fbb14f61bccd2adc9d
4
- data.tar.gz: c6d90b4a20d780bb50e601a98a5227f71b224fc2
3
+ metadata.gz: a51ed604ba69b97122ede6837feabd660040fdaf
4
+ data.tar.gz: 10a9df7ee7b29d9329dc1ca0e1c87bc34934f5bc
5
5
  SHA512:
6
- metadata.gz: e0348558a2205618b5403a867b825358b06911819903ee13f2aed7048a301b576a02cbdd0a309148b69fe17852a723e6b4e2cefaa1d87282a7b26ec7c75bbef1
7
- data.tar.gz: 9ee83c73e05352bd6102400204a7205eaa5ce734c54cb5ca6e01758f02fd8783ca40c70c87a04f85b8b591694cc4fc48f5044da1f558ffdc49c5b85f673cf20e
6
+ metadata.gz: 4e0d79f04a2f028b409a16c4d49f1662102bf038d4b3424960735b8e01b01dccde14fe9643d1b906d406b52b0f809b4772bb0b36ee5e977006f1d7190fb094cc
7
+ data.tar.gz: 43503eda5bf4c0d2ed83804225e01cd9c33c61d313a8a9dc8b12a35a8b5721b336d1d522218a5dd988d46226df1d788c8b294dd8935155aee758a3cab3eef408
data/lib/chapp.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require 'chapp/app'
2
2
  require 'chapp/app_instance'
3
+ require 'chapp/app_config'
3
4
  require 'chapp/wiring'
4
5
  require 'chapp/database'
6
+ require 'chapp/provisioner'
7
+ require 'chapp/provisioner/property_provisioner'
5
8
 
6
9
  module Chapp
7
10
 
@@ -9,4 +12,9 @@ module Chapp
9
12
  Chapp::Database.new
10
13
  end
11
14
 
15
+ def self.provisioner
16
+ # TODO: Make configurable
17
+ Chapp::PropertyProvisioner.new
18
+ end
19
+
12
20
  end
data/lib/chapp/app.rb CHANGED
@@ -3,188 +3,54 @@ require 'chef/node/attribute'
3
3
 
4
4
  module Chapp
5
5
  class App
6
-
7
- # TODO: Define allowed characters (.)
8
6
 
9
- DEFAULT_RECIPE = "default"
10
-
11
- attr_reader :used_apps
12
- attr_reader :dependencies
13
-
14
- def self.from_file app_file
15
- appString = IO.read app_file
16
-
17
- app = App.new
18
- app.instance_eval appString
19
-
20
- app
21
- end
22
-
23
- def self.from_hash app_hash
24
- app = App.new
25
-
26
- app.group app_hash["group"]
27
- app.name app_hash["name"]
28
-
29
- app.pre_run_list app_hash["pre_run_list"]
30
- app.post_run_list app_hash["post_run_list"]
31
-
32
- app.run_list app_hash["run_list"]
33
-
34
- app_hash["dependencies"].each do |cookbook, version_constraint|
35
- app.depends cookbook, version_constraint
36
- end
37
-
38
- app_hash["used_apps"].each do |app_name|
39
- app.uses app_name
40
- end
41
-
42
- app.node Chef::Node::Attribute.new({}, app_hash["node"], {}, {}).default
43
- app.environment app_hash["environment"]
44
-
45
- if app_hash.include? "type"
46
- app.type app_hash["type"]
47
- end
48
-
49
- if app_hash.include? "recipe"
50
- app.recipe app_hash["recipe"]
51
- end
52
-
53
- if app_hash.include? "cookbook"
54
- app.cookbook app_hash["cookbook"]
55
- end
56
-
57
- app
58
- end
59
-
60
- def initialize
61
- @group = nil
62
- @name = nil
63
- @used_apps = Array.new
64
- @dependencies = Hash.new
65
- @pre_run_list = Array.new
66
- @post_run_list = Array.new
67
- @environment = nil
68
- @node = Chef::Node::Attribute.new({}, {}, {}, {}).default
69
- @run_list = nil
70
- @type = nil
71
- @recipe = nil
72
- @cookbook = nil
73
- end
74
-
75
- def group group=nil
76
- set_or_return :group, group
77
- end
78
-
79
- def name name=nil
80
- set_or_return :name, name
7
+ def initialize id, db, config=nil, attributes=nil
8
+ @id = id
9
+ @db = db
10
+ @config = config
11
+ @attributes = attributes
12
+ @instances = nil
13
+ @connected_apps = nil
81
14
  end
82
15
 
83
16
  def id
84
- "#{group}_#{name}"
85
- end
86
-
87
- def uses app=nil
88
- @used_apps.push app
89
- end
90
-
91
- def cookbook cookbook=nil
92
- set_or_return_with_default :cookbook, @name, cookbook
93
- end
94
-
95
- def recipe recipe=nil
96
- set_or_return_with_default :recipe, DEFAULT_RECIPE, recipe
97
- end
98
-
99
- def type type=nil
100
- set_or_return_with_default :type, cookbook, type
101
- end
102
-
103
- def depends cookbook, version_constraint
104
- @dependencies.store cookbook, version_constraint
17
+ @id
105
18
  end
106
19
 
107
- def pre_run_list *recipes
108
- if recipes.length > 0
109
- @pre_run_list = recipes
110
- else
111
- @pre_run_list
20
+ def config
21
+ unless @config
22
+ @config = @db.app_config @id
112
23
  end
24
+
25
+ @config
113
26
  end
114
27
 
115
- def post_run_list *recipes
116
- if recipes.length > 0
117
- @post_run_list = recipes
118
- else
119
- @post_run_list
120
- end
121
- end
122
-
123
- def node node=nil
124
- set_or_return :node, node
125
- end
126
-
127
- def run_list run_list=nil
128
- set_or_return :run_list, run_list
129
- end
130
-
131
- def environment environment=nil
132
- set_or_return :environment, environment
133
- end
134
-
135
- def to_hash
136
- hash = Hash.new
137
-
138
- hash.store "group", group
139
- hash.store "name", name
140
- hash.store "used_apps", used_apps
141
-
142
- hash.store "pre_run_list", pre_run_list
143
- hash.store "post_run_list", post_run_list
144
-
145
- hash.store "dependencies", dependencies
146
-
147
- hash.store "node", node.to_hash
148
- hash.store "environment", environment
149
-
150
- if @type
151
- hash.store "type", type
28
+ def instances
29
+ unless @instances
30
+ @instances = @db.app_instances @id
152
31
  end
153
32
 
154
- if @recipe
155
- hash.store "recipe", recipe
156
- end
157
-
158
- if @cookbook
159
- hash.store "cookbook", cookbook
160
- end
161
-
162
- hash
33
+ @instances
163
34
  end
164
35
 
165
- private
166
-
167
- def set_or_return(symbol, arg)
168
- iv_symbol = "@#{symbol.to_s}".to_sym
169
- if arg == nil
170
- self.instance_variable_get(iv_symbol)
171
- else
172
- self.instance_variable_set(iv_symbol, arg)
36
+ def attributes
37
+ unless @attributes
38
+ @attributes = @db.app_attributes @id
173
39
  end
40
+
41
+ @attributes
174
42
  end
175
43
 
176
- def set_or_return_with_default(symbol, default_val, arg)
177
- iv_symbol = "@#{symbol.to_s}".to_sym
178
- if arg == nil
179
- val = self.instance_variable_get(iv_symbol)
180
- if val
181
- val
182
- else
183
- default_val
44
+ def connected_apps
45
+ unless @connected_apps
46
+ @connected_apps = Array.new
47
+
48
+ @db.connected_app_ids(@id).each do |app_id|
49
+ @connected_apps << App.new(app_id, @db)
184
50
  end
185
- else
186
- self.instance_variable_set(iv_symbol, arg)
187
51
  end
52
+
53
+ @connected_apps
188
54
  end
189
55
 
190
56
  end
@@ -0,0 +1,206 @@
1
+ require 'chapp'
2
+ require 'chef/node/attribute'
3
+
4
+ module Chapp
5
+ class AppConfig
6
+
7
+ # TODO: Define allowed characters (.)
8
+
9
+ DEFAULT_RECIPE = "default"
10
+
11
+ attr_reader :used_apps
12
+ attr_reader :dependencies
13
+
14
+ def self.from_file app_file
15
+ appString = IO.read app_file
16
+
17
+ app = AppConfig.new
18
+ app.instance_eval appString
19
+
20
+ app
21
+ end
22
+
23
+ def self.from_hash app_hash
24
+ app = AppConfig.new
25
+
26
+ app.group app_hash["group"]
27
+ app.name app_hash["name"]
28
+
29
+ app.pre_run_list app_hash["pre_run_list"]
30
+ app.post_run_list app_hash["post_run_list"]
31
+
32
+ app.run_list app_hash["run_list"]
33
+
34
+ app_hash["dependencies"].each do |cookbook, version_constraint|
35
+ app.depends cookbook, version_constraint
36
+ end
37
+
38
+ app_hash["used_apps"].each do |type, app_ids|
39
+ app_ids.each do |app_id|
40
+ app.uses type, app_id
41
+ end
42
+ end
43
+
44
+ app.node Chef::Node::Attribute.new({}, app_hash["node"], {}, {}).default
45
+ app.environment app_hash["environment"]
46
+
47
+ if app_hash.include? "type"
48
+ app.type app_hash["type"]
49
+ end
50
+
51
+ if app_hash.include? "recipe"
52
+ app.recipe app_hash["recipe"]
53
+ end
54
+
55
+ if app_hash.include? "cookbook"
56
+ app.cookbook app_hash["cookbook"]
57
+ end
58
+
59
+ app
60
+ end
61
+
62
+ def initialize
63
+ @group = nil
64
+ @name = nil
65
+ @used_apps = Hash.new
66
+ @dependencies = Hash.new
67
+ @pre_run_list = Array.new
68
+ @post_run_list = Array.new
69
+ @environment = nil
70
+ @node = Chef::Node::Attribute.new({}, {}, {}, {}).default
71
+ @run_list = nil
72
+ @type = nil
73
+ @recipe = nil
74
+ @cookbook = nil
75
+ end
76
+
77
+ def group group=nil
78
+ set_or_return :group, group
79
+ end
80
+
81
+ def name name=nil
82
+ set_or_return :name, name
83
+ end
84
+
85
+ def id
86
+ "#{group}_#{name}"
87
+ end
88
+
89
+ def role_name
90
+ "chapp_#{id}"
91
+ end
92
+
93
+ def environment_name
94
+ "chapp_#{id}"
95
+ end
96
+
97
+ def uses type, app
98
+
99
+ unless @used_apps.has_key? type
100
+ @used_apps[type] = Array.new
101
+ end
102
+
103
+ @used_apps[type].push app
104
+ end
105
+
106
+ def cookbook cookbook=nil
107
+ set_or_return_with_default :cookbook, @name, cookbook
108
+ end
109
+
110
+ def recipe recipe=nil
111
+ set_or_return_with_default :recipe, DEFAULT_RECIPE, recipe
112
+ end
113
+
114
+ def type type=nil
115
+ set_or_return_with_default :type, cookbook, type
116
+ end
117
+
118
+ def depends cookbook, version_constraint
119
+ @dependencies.store cookbook, version_constraint
120
+ end
121
+
122
+ def pre_run_list *recipes
123
+ if recipes.length > 0
124
+ @pre_run_list = recipes
125
+ else
126
+ @pre_run_list
127
+ end
128
+ end
129
+
130
+ def post_run_list *recipes
131
+ if recipes.length > 0
132
+ @post_run_list = recipes
133
+ else
134
+ @post_run_list
135
+ end
136
+ end
137
+
138
+ def node node=nil
139
+ set_or_return :node, node
140
+ end
141
+
142
+ def run_list run_list=nil
143
+ set_or_return :run_list, run_list
144
+ end
145
+
146
+ def environment environment=nil
147
+ set_or_return :environment, environment
148
+ end
149
+
150
+ def to_hash
151
+ hash = Hash.new
152
+
153
+ hash.store "group", group
154
+ hash.store "name", name
155
+ hash.store "used_apps", used_apps
156
+
157
+ hash.store "pre_run_list", pre_run_list
158
+ hash.store "post_run_list", post_run_list
159
+
160
+ hash.store "dependencies", dependencies
161
+
162
+ hash.store "node", node.to_hash
163
+ hash.store "environment", environment
164
+
165
+ if @type
166
+ hash.store "type", type
167
+ end
168
+
169
+ if @recipe
170
+ hash.store "recipe", recipe
171
+ end
172
+
173
+ if @cookbook
174
+ hash.store "cookbook", cookbook
175
+ end
176
+
177
+ hash
178
+ end
179
+
180
+ private
181
+
182
+ def set_or_return(symbol, arg)
183
+ iv_symbol = "@#{symbol.to_s}".to_sym
184
+ if arg.nil?
185
+ self.instance_variable_get(iv_symbol)
186
+ else
187
+ self.instance_variable_set(iv_symbol, arg)
188
+ end
189
+ end
190
+
191
+ def set_or_return_with_default(symbol, default_val, arg)
192
+ iv_symbol = "@#{symbol.to_s}".to_sym
193
+ if arg.nil?
194
+ val = self.instance_variable_get(iv_symbol)
195
+ if val
196
+ val
197
+ else
198
+ default_val
199
+ end
200
+ else
201
+ self.instance_variable_set(iv_symbol, arg)
202
+ end
203
+ end
204
+
205
+ end
206
+ end
@@ -8,87 +8,85 @@ require 'chef/search/query'
8
8
  module Chapp
9
9
  class Database
10
10
 
11
- APPS_DATA_BAG_NAME = "chapp_apps"
11
+ APPS_CONFIG_DATA_BAG_NAME = "chapp_apps_config"
12
12
  APP_ATTRIBUTES_DATA_BAG_NAME = "chapp_app_attributes"
13
13
 
14
- PREFIX = "chapp"
15
-
16
14
  def app_ids
17
- apps_databag.keys
15
+ apps_config_databag.keys
18
16
  end
19
17
 
20
- def app app_id
18
+ def app_config app_id
21
19
 
22
20
  unless app_exists? app_id
23
- raise Chapp::DB::AppNotExistsException.new, "App [#{app_id}] does not exist"
21
+ raise AppNotExistsException.new, "App [#{app_id}] does not exist"
24
22
  end
25
23
 
26
- App.from_hash app_databag_item(app_id).raw_data["app"]
24
+ AppConfig.from_hash apps_config_databag_item(app_id).raw_data["app"]
27
25
  end
28
26
 
29
27
  def app_exists? app_id
30
- apps_databag.has_key? app_id
28
+ apps_config_databag.has_key? app_id
31
29
  end
32
30
 
33
31
  def connected_app_ids app_id
34
32
  app_ids = Array.new
35
33
 
36
34
  query = Chef::Search::Query.new
37
- query.search APPS_DATA_BAG_NAME, "used_apps:#{app_id}" do |databag_item|
38
- app = App.from_hash databag_item.raw_data["app"]
39
- app_ids.push app.id
35
+ query.search APPS_CONFIG_DATA_BAG_NAME, "used_apps:#{app_id}" do |databag_item|
36
+ app_config = AppConfig.from_hash databag_item.raw_data["app"]
37
+ app_ids.push app_config.id
40
38
  end
41
39
 
42
40
  app_ids
43
41
  end
44
42
 
45
- def write_app app
43
+ def write_app_config app_config
46
44
 
47
45
  # TODO Verify used_apps exist
48
46
  # TODO Verify cookbooks exist
49
47
 
50
- app_role_name = role_name app.id
48
+ app_role_name = app_config.role_name
51
49
 
52
- attributes = app.node
53
- attributes["chapp"]["app_id"] = app.id
50
+ attributes = app_config.node
51
+ attributes["chapp"]["app_id"] = app_config.id
54
52
 
55
53
  # Build/Save role
56
54
  role = Chef::Role.new
57
55
  role.name app_role_name
58
- role.description "Used to define the App [#{app.id}]"
56
+ role.description "Used to define the App [#{app_config.id}]"
59
57
  role.default_attributes attributes.to_hash
60
- role.run_list "recipe[chapp]", *app.pre_run_list, "recipe[#{app.cookbook}::#{app.recipe}]", *app.post_run_list, "recipe[chapp::publish_app_attributes]"
58
+ role.run_list "recipe[chapp]", *app_config.pre_run_list, "recipe[#{app_config.cookbook}::#{app_config.recipe}]", *app_config.post_run_list, "recipe[chapp::publish_app_attributes]"
61
59
  role.save
62
60
 
63
61
  # Set run_list of app to role
64
- app.run_list ["role[#{app_role_name}]"]
62
+ app_config.run_list ["role[#{app_role_name}]"]
65
63
 
66
- environment_name = "#{PREFIX}_env_#{app.id}"
64
+ environment_name = app_config.environment_name
67
65
 
68
66
  # Build/Save environment
69
67
  environment = Chef::Environment.new
70
- environment.name environment_name
71
- environment.description "Used to define the dependencies of App [#{app.id}]"
68
+ environment.name environment_name
69
+ environment.description "Used to define the dependencies of App [#{app_config.id}]"
72
70
 
73
- app.dependencies.each do |cookbook, version|
71
+ app_config.dependencies.each do |cookbook, version|
74
72
  environment.cookbook cookbook, version
75
73
  end
76
74
 
77
75
  environment.save
78
76
 
79
77
  # Set environment of app
80
- app.environment environment_name
78
+ app_config.environment environment_name
81
79
 
82
80
  # Update app databag item
83
- databag_item = app_databag_item app.id
84
- databag_item.raw_data["app"] = app.to_hash
81
+ databag_item = apps_config_databag_item app_config.id
82
+ databag_item.raw_data["app"] = app_config.to_hash
85
83
  databag_item.save
86
84
 
87
85
  end
88
86
 
89
87
  def delete_app app_name
90
88
  # TODO (not necessary for now)
91
- # Delete role/environment, app databag item, app attribute databag item, app instances
89
+ # Delete role/environment, app config databag item, app attribute databag item, app instances
92
90
  end
93
91
 
94
92
  def app_instances app_id
@@ -114,7 +112,7 @@ module Chapp
114
112
  databag = app_attributes_databag
115
113
 
116
114
  unless databag.has_key? app_id
117
- raise Chapp::DB::AppAttributesNotExistsException.new, "Attributes for app [#{app_id}] do not exist"
115
+ raise AppAttributesNotExistsException.new, "Attributes for app [#{app_id}] do not exist"
118
116
  end
119
117
 
120
118
  app_attributes_databag_item(app_id).raw_data["app_attributes"]
@@ -135,18 +133,17 @@ module Chapp
135
133
 
136
134
  end
137
135
 
138
- private
136
+ class AppAttributesNotExistsException < StandardError; end
137
+ class AppNotExistsException < StandardError; end
139
138
 
140
- def role_name app_id
141
- "#{PREFIX}_role_#{app_id}"
142
- end
139
+ private
143
140
 
144
- def apps_databag
145
- get_or_create_databag APPS_DATA_BAG_NAME
141
+ def apps_config_databag
142
+ get_or_create_databag APPS_CONFIG_DATA_BAG_NAME
146
143
  end
147
144
 
148
- def app_databag_item app_id
149
- load_or_build_databag_item apps_databag, APPS_DATA_BAG_NAME, app_id
145
+ def apps_config_databag_item app_id
146
+ load_or_build_databag_item apps_config_databag, APPS_CONFIG_DATA_BAG_NAME, app_id
150
147
  end
151
148
 
152
149
  def app_attributes_databag
@@ -0,0 +1,11 @@
1
+ require 'chapp'
2
+
3
+ module Chapp
4
+ class Provisioner
5
+
6
+ def build_server app_config, properties
7
+ raise "Unsupported operation"
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ require 'chapp'
2
+
3
+ module Chapp
4
+ class PropertyProvisioner < Chapp::Provisioner
5
+
6
+ HOST_KEY = "host"
7
+
8
+ def build_server app_config, properties
9
+
10
+ unless properties.has_key? HOST_KEY
11
+ raise "Unable to find #{HOST_KEY} in provided properties"
12
+ end
13
+
14
+ properties[HOST_KEY]
15
+ end
16
+
17
+ end
18
+ end
data/lib/chapp/wiring.rb CHANGED
@@ -7,79 +7,47 @@ module Chapp
7
7
  attr_reader :announcements
8
8
  attr_reader :node
9
9
 
10
- def initialize app, db, node
11
- @node = node
10
+ def initialize app_config, db, node
12
11
  @announcements = Hash.new
12
+ @used_apps = Hash.new
13
13
 
14
- @app = app
15
14
  @db = db
16
15
  @node = node
16
+ @app = App.new app_config.id, db, app_config, @announcements
17
17
 
18
- # Hash of used apps by type
19
- @used_apps = Hash.new
20
- @app.used_apps.each do |app_id|
21
- used_app = db.app app_id
22
-
23
- unless @used_apps.has_key? used_app.type
24
- @used_apps[used_app.type] = Array.new
18
+ app_config.used_apps.each do |type, app_ids|
19
+ unless @used_apps.has_key? type
20
+ @used_apps[type] = Array.new
25
21
  end
26
22
 
27
- @used_apps[used_app.type] << used_app
23
+ app_ids.each do |app_id|
24
+ @used_apps[type] << App.new(app_id, db)
25
+ end
28
26
  end
29
27
  end
30
28
 
31
- def app_id
32
- @app.id
33
- end
34
-
35
- def announce key, value
36
- @announcements[key] = value
37
- end
38
-
39
- def used_app_ids
40
- @app.used_apps
41
- end
42
-
43
- def used_app_attributes type
44
-
45
- app_attributes = Hash.new
46
-
47
- # TODO: Cache these values?
48
- @used_apps[type].each do |app|
49
- app_attributes[app.id] = @db.app_attributes app.id
29
+ def app type=nil
30
+ if type.nil?
31
+ @app
32
+ else
33
+ unless @used_apps.has_key? type
34
+ raise "App does not use app of type [#{type}]"
35
+ end
36
+
37
+ if @used_apps[type].size > 1
38
+ raise "App uses many apps of [#{type}]"
39
+ end
40
+
41
+ @used_apps[type].first
50
42
  end
51
-
52
- app_attributes
53
43
  end
54
44
 
55
- def used_app_instances type
56
- app_instances = Hash.new
57
-
58
- # TODO: Cache these values?
59
- @used_apps[type].each do |app|
60
- app_instances[app.id] = @db.app_instances app.id
45
+ def apps type
46
+ unless @used_apps.has_key? type
47
+ raise "App does not use app of type [#{type}]"
61
48
  end
62
49
 
63
- app_instances
64
- end
65
-
66
- def is_app_used? type
67
- @used_apps.has_key? type
68
- end
69
-
70
- def connected_app_ids
71
- # TODO: Cache these values?
72
- @db.connected_app_ids @app.id
73
- end
74
-
75
- def app_instances app_id
76
- # TODO: Cache these values?
77
- @db.app_instances app_id
78
- end
79
-
80
- def app_attributes app_id
81
- # TODO: Cache these values?
82
- @db.app_attributes app_id
50
+ @used_apps[type]
83
51
  end
84
52
 
85
53
  end
@@ -0,0 +1,92 @@
1
+ require 'chef/knife/bootstrap'
2
+ require 'chef/node'
3
+ require 'chef/run_list'
4
+ require 'chapp'
5
+
6
+ class Chef
7
+ class Knife
8
+ class AppInstanceCreate < Chef::Knife::Bootstrap
9
+
10
+ banner "knife app instance create app_id [properties] (options)"
11
+ category "app instance"
12
+
13
+ def initialize arguments
14
+ bootstrap = Chef::Knife::Bootstrap.new
15
+
16
+ bootstrap.options.each do |name, args|
17
+ AppInstanceCreate.option name, args
18
+ end
19
+
20
+ Chef::Knife::Bootstrap.load_deps
21
+
22
+ super arguments
23
+ end
24
+
25
+ # This method will be executed when you run this knife command.
26
+ def run
27
+
28
+ # Get Arguments
29
+ if @name_args.size < 1
30
+ ui.info("Please specify an app_id")
31
+ show_usage
32
+ exit 1
33
+ end
34
+
35
+ app_id = @name_args[0]
36
+ properties = parse_properties @name_args[1, @name_args.size]
37
+
38
+ db = Chapp.database
39
+ provisioner = Chapp.provisioner
40
+
41
+ app_config = db.app_config app_id
42
+
43
+ # TODO: May need something better than Time
44
+ node_name = "chapp_#{app_id}_#{Time.now.to_i}"
45
+
46
+ # Provision the server and retrieve the host name
47
+ host = provisioner.build_server app_config, properties
48
+
49
+ # Tells bootstrap what environment to use
50
+ Chef::Config[:environment] = app_config.environment_name
51
+
52
+ # Tells bootstrap what run_list to use
53
+ @config[:run_list] = "role[#{app_config.role_name}]"
54
+
55
+ # Tells bootstrap what node name to use
56
+ @config[:chef_node_name] = node_name
57
+
58
+ # Tells bootstrap what ip/fqdn to use
59
+ @name_args = host
60
+
61
+ # Runs bootstrap
62
+ super
63
+
64
+ # We have to save the node here since bootstrap wont actually assign the run_list
65
+ node = Node.new
66
+ node.name node_name
67
+ node.run_list = Chef::RunList.new "role[#{app_config.role_name}]"
68
+ node.chef_environment = app_config.environment_name
69
+ node.save
70
+ end
71
+
72
+ private
73
+
74
+ def parse_properties properties
75
+ hash = Hash.new
76
+
77
+ properties.each do |property|
78
+ key_value = property.split "="
79
+
80
+ unless key_value.size == 2
81
+ raise "Property #{property} is missing ="
82
+ end
83
+
84
+ hash[key_value.first] = key_value[1]
85
+ end
86
+
87
+ hash
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -22,44 +22,51 @@ class Chef
22
22
 
23
23
  db = Chapp.database
24
24
 
25
- app = db.app app_id
26
- attributes = db.app_attributes app_id
25
+ app_config = db.app_config app_id
27
26
 
28
27
  puts "App :"
29
- puts " id : #{app.id}"
30
- puts " group : #{app.group}"
31
- puts " name : #{app.name}"
32
- puts " type : #{app.type}"
33
- puts " cookbook : #{app.cookbook}"
34
- puts " recipe : #{app.recipe}"
28
+ puts " id : #{app_config.id}"
29
+ puts " group : #{app_config.group}"
30
+ puts " name : #{app_config.name}"
31
+ puts " type : #{app_config.type}"
32
+ puts " cookbook : #{app_config.cookbook}"
33
+ puts " recipe : #{app_config.recipe}"
35
34
 
36
35
  puts " used_apps :"
37
- app.used_apps.each do |used_app_id|
38
- puts " #{used_app_id}"
36
+ app_config.used_apps.each do |type, used_app_ids|
37
+ puts " #{type} :"
38
+ used_app_ids.each do |used_app_id|
39
+ puts " #{used_app_id}"
40
+ end
39
41
  end
40
42
 
41
43
  puts " node :"
42
- print_hash app.node
44
+ print_hash app_config.node
43
45
 
44
46
  puts " dependencies :"
45
- app.dependencies.each do |cookbook, version_constraint|
47
+ app_config.dependencies.each do |cookbook, version_constraint|
46
48
  puts " #{cookbook} #{version_constraint}"
47
49
  end
48
50
 
49
51
  puts " pre_run_list :"
50
- app.pre_run_list.each do |run_list_item|
52
+ app_config.pre_run_list.each do |run_list_item|
51
53
  puts " #{run_list_item}"
52
54
  end
53
55
 
54
56
  puts " post_run_list :"
55
- app.post_run_list.each do |run_list_item|
57
+ app_config.post_run_list.each do |run_list_item|
56
58
  puts " #{run_list_item}"
57
59
  end
58
60
 
59
61
  puts ""
60
62
 
61
63
  puts "App Attributes :"
62
- print_hash attributes, 2
64
+ begin
65
+ attributes = db.app_attributes app_id
66
+ print_hash attributes, 2
67
+ rescue Chapp::Database::AppAttributesNotExistsException => e
68
+ puts " NONE"
69
+ end
63
70
 
64
71
  puts "App Instances :"
65
72
  db.app_instances(app_id).each do |app_instance|
@@ -18,15 +18,15 @@ class Chef
18
18
  exit 1
19
19
  end
20
20
 
21
- app_file = @name_args[0]
21
+ app_config_file = @name_args[0]
22
22
 
23
- # Build app from file
24
- app = Chapp::App.from_file app_file
23
+ # Build app config from file
24
+ app_config = Chapp::AppConfig.from_file app_config_file
25
25
 
26
- # Write the app
27
- Chapp.database.write_app app
26
+ # Write the app config
27
+ Chapp.database.write_app_config app_config
28
28
 
29
- puts "Uploaded app [#{app.id}]"
29
+ puts "Uploaded app [#{app_config.id}]"
30
30
  end
31
31
 
32
32
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Baugher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
@@ -24,34 +24,6 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '11.0'
27
- - !ruby/object:Gem::Dependency
28
- name: uuid
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '2.3'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: '2.3'
41
- - !ruby/object:Gem::Dependency
42
- name: yajl-ruby
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: '1.1'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: '1.1'
55
27
  - !ruby/object:Gem::Dependency
56
28
  name: rake
57
29
  requirement: !ruby/object:Gem::Requirement
@@ -76,9 +48,13 @@ files:
76
48
  - Gemfile
77
49
  - lib/chapp.rb
78
50
  - lib/chapp/app.rb
51
+ - lib/chapp/app_config.rb
79
52
  - lib/chapp/app_instance.rb
80
53
  - lib/chapp/database.rb
54
+ - lib/chapp/provisioner.rb
55
+ - lib/chapp/provisioner/property_provisioner.rb
81
56
  - lib/chapp/wiring.rb
57
+ - lib/chef/knife/app_instance_create.rb
82
58
  - lib/chef/knife/app_list.rb
83
59
  - lib/chef/knife/app_show.rb
84
60
  - lib/chef/knife/app_upload.rb