chapp 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chapp/app.rb +4 -3
- data/lib/chapp/app/node_app.rb +5 -4
- data/lib/chapp/app_config.rb +69 -68
- data/lib/chapp/database.rb +17 -17
- data/lib/chapp/provisioner/ec2_provisioner.rb +24 -18
- data/lib/chapp/wiring.rb +22 -21
- data/lib/chef/knife/app_instance_create.rb +31 -33
- data/lib/chef/knife/app_show.rb +33 -27
- metadata +34 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df5a3ee559314be541400ce3f160eb2249a3eb33
|
4
|
+
data.tar.gz: c30c0a7a36926f19790ae97662f8f1994b436c7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ffa4a00648cd946eae3a84c5261e29fb794af24dee1f6cd98bf883c17ac8972f61d5c4afb728beab8979982c93d6307b503e9d311c82b9a15ab30500e9be6d7
|
7
|
+
data.tar.gz: 85952443b0773e367700db08ef5eb1c6e8f4c113b22f7ea3b8fb122384e23b0d71472002f73c94c3f05a788b5edf7aebd15661c6457c04c90a790f009aad1651
|
data/lib/chapp/app.rb
CHANGED
@@ -6,8 +6,9 @@ module Chapp
|
|
6
6
|
|
7
7
|
attr_reader :id, :attributes, :instances
|
8
8
|
|
9
|
-
def initialize id, attributes, instances, db
|
9
|
+
def initialize id, id_hash, attributes, instances, db
|
10
10
|
@id = id
|
11
|
+
@id_hash = id_hash
|
11
12
|
@db = db
|
12
13
|
@attributes = attributes
|
13
14
|
@instances = instances
|
@@ -17,7 +18,7 @@ module Chapp
|
|
17
18
|
|
18
19
|
def config
|
19
20
|
unless @config
|
20
|
-
@config = @db.app_config @
|
21
|
+
@config = @db.app_config @id_hash
|
21
22
|
end
|
22
23
|
|
23
24
|
@config
|
@@ -27,7 +28,7 @@ module Chapp
|
|
27
28
|
unless @connected_apps
|
28
29
|
@connected_apps = Array.new
|
29
30
|
|
30
|
-
@db.connected_app_ids(
|
31
|
+
@db.connected_app_ids(id_hash).each do |app_id|
|
31
32
|
@connected_apps << @db.app(app_id)
|
32
33
|
end
|
33
34
|
end
|
data/lib/chapp/app/node_app.rb
CHANGED
@@ -3,10 +3,11 @@ require 'chapp'
|
|
3
3
|
module Chapp
|
4
4
|
class NodeApp < Chapp::App
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
@id = id
|
6
|
+
def initialize app_config, db, attributes, node_name, fqdn
|
7
|
+
@id = app_config.id
|
8
|
+
@id_hash = app_config.id_hash
|
8
9
|
@db = db
|
9
|
-
@config =
|
10
|
+
@config = app_config
|
10
11
|
@fqdn = fqdn
|
11
12
|
@node_name = node_name
|
12
13
|
@attributes = attributes
|
@@ -17,7 +18,7 @@ module Chapp
|
|
17
18
|
|
18
19
|
def instances
|
19
20
|
unless @instances
|
20
|
-
app = @db.app
|
21
|
+
app = @db.app @id_hash
|
21
22
|
app_instances = app.instances
|
22
23
|
@instances = []
|
23
24
|
|
data/lib/chapp/app_config.rb
CHANGED
@@ -3,68 +3,66 @@ require 'chef/node/attribute'
|
|
3
3
|
|
4
4
|
module Chapp
|
5
5
|
class AppConfig
|
6
|
-
|
6
|
+
|
7
7
|
# TODO: Define allowed characters (.)
|
8
|
-
|
8
|
+
|
9
9
|
DEFAULT_RECIPE = "default"
|
10
|
-
|
10
|
+
|
11
11
|
attr_reader :used_apps
|
12
12
|
attr_reader :dependencies
|
13
|
-
|
13
|
+
|
14
14
|
def self.from_file app_file
|
15
15
|
appString = IO.read app_file
|
16
|
-
|
16
|
+
|
17
17
|
app = AppConfig.new
|
18
18
|
app.instance_eval appString
|
19
|
-
|
19
|
+
|
20
20
|
app
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def self.from_hash app_hash
|
24
24
|
app = AppConfig.new
|
25
|
-
|
26
|
-
app.
|
25
|
+
|
26
|
+
app.name_space app_hash["name_space"]
|
27
27
|
app.name app_hash["name"]
|
28
|
-
|
28
|
+
|
29
29
|
app.pre_run_list app_hash["pre_run_list"]
|
30
30
|
app.post_run_list app_hash["post_run_list"]
|
31
|
-
|
31
|
+
|
32
32
|
app.run_list app_hash["run_list"]
|
33
|
-
|
33
|
+
|
34
34
|
app_hash["dependencies"].each do |cookbook, version_constraint|
|
35
35
|
app.depends cookbook, version_constraint
|
36
36
|
end
|
37
|
-
|
38
|
-
app_hash["used_apps"].each do |
|
39
|
-
|
40
|
-
app.uses type, app_id
|
41
|
-
end
|
37
|
+
|
38
|
+
app_hash["used_apps"].each do |app_id|
|
39
|
+
app.uses app_id
|
42
40
|
end
|
43
|
-
|
41
|
+
|
44
42
|
app.cloud app_hash["cloud"]
|
45
|
-
|
43
|
+
|
46
44
|
app.node Chef::Node::Attribute.new({}, app_hash["node"], {}, {}).default
|
47
45
|
app.environment app_hash["environment"]
|
48
|
-
|
46
|
+
|
49
47
|
if app_hash.include? "type"
|
50
48
|
app.type app_hash["type"]
|
51
49
|
end
|
52
|
-
|
50
|
+
|
53
51
|
if app_hash.include? "recipe"
|
54
52
|
app.recipe app_hash["recipe"]
|
55
53
|
end
|
56
|
-
|
54
|
+
|
57
55
|
if app_hash.include? "cookbook"
|
58
56
|
app.cookbook app_hash["cookbook"]
|
59
57
|
end
|
60
|
-
|
58
|
+
|
61
59
|
app
|
62
60
|
end
|
63
|
-
|
61
|
+
|
64
62
|
def initialize
|
65
|
-
@
|
63
|
+
@name_space = Hash.new
|
66
64
|
@name = nil
|
67
|
-
@used_apps =
|
65
|
+
@used_apps = Array.new
|
68
66
|
@cloud = Hash.new
|
69
67
|
@dependencies = Hash.new
|
70
68
|
@pre_run_list = Array.new
|
@@ -76,52 +74,55 @@ module Chapp
|
|
76
74
|
@recipe = nil
|
77
75
|
@cookbook = nil
|
78
76
|
end
|
79
|
-
|
80
|
-
def
|
81
|
-
set_or_return :
|
77
|
+
|
78
|
+
def name_space name_space=nil
|
79
|
+
set_or_return :name_space, name_space
|
82
80
|
end
|
83
|
-
|
81
|
+
|
84
82
|
def name name=nil
|
85
83
|
set_or_return :name, name
|
86
84
|
end
|
87
|
-
|
85
|
+
|
88
86
|
def id
|
89
|
-
|
87
|
+
hash = name_space.clone
|
88
|
+
hash["name"] = name
|
89
|
+
hash.sort_by{|k,v| k.to_s}.map{|k,v| "#{k}_#{v}"}.join("_")
|
90
|
+
end
|
91
|
+
|
92
|
+
def id_hash
|
93
|
+
hash = name_space.clone
|
94
|
+
hash["name"] = name
|
95
|
+
hash
|
90
96
|
end
|
91
|
-
|
97
|
+
|
92
98
|
def role_name
|
93
99
|
"chapp_#{id}"
|
94
100
|
end
|
95
|
-
|
101
|
+
|
96
102
|
def environment_name
|
97
103
|
"chapp_#{id}"
|
98
104
|
end
|
99
|
-
|
100
|
-
def uses
|
101
|
-
|
102
|
-
unless @used_apps.has_key? type
|
103
|
-
@used_apps[type] = Array.new
|
104
|
-
end
|
105
|
-
|
106
|
-
@used_apps[type].push app
|
105
|
+
|
106
|
+
def uses app_id
|
107
|
+
@used_apps << app_id
|
107
108
|
end
|
108
|
-
|
109
|
+
|
109
110
|
def cookbook cookbook=nil
|
110
111
|
set_or_return_with_default :cookbook, @name, cookbook
|
111
112
|
end
|
112
|
-
|
113
|
+
|
113
114
|
def recipe recipe=nil
|
114
115
|
set_or_return_with_default :recipe, DEFAULT_RECIPE, recipe
|
115
116
|
end
|
116
|
-
|
117
|
+
|
117
118
|
def type type=nil
|
118
119
|
set_or_return_with_default :type, cookbook, type
|
119
120
|
end
|
120
|
-
|
121
|
+
|
121
122
|
def depends cookbook, version_constraint
|
122
123
|
@dependencies.store cookbook, version_constraint
|
123
124
|
end
|
124
|
-
|
125
|
+
|
125
126
|
def pre_run_list *recipes
|
126
127
|
if recipes.length > 0
|
127
128
|
@pre_run_list = recipes
|
@@ -129,7 +130,7 @@ module Chapp
|
|
129
130
|
@pre_run_list
|
130
131
|
end
|
131
132
|
end
|
132
|
-
|
133
|
+
|
133
134
|
def post_run_list *recipes
|
134
135
|
if recipes.length > 0
|
135
136
|
@post_run_list = recipes
|
@@ -137,57 +138,57 @@ module Chapp
|
|
137
138
|
@post_run_list
|
138
139
|
end
|
139
140
|
end
|
140
|
-
|
141
|
+
|
141
142
|
def node node=nil
|
142
143
|
set_or_return :node, node
|
143
144
|
end
|
144
|
-
|
145
|
+
|
145
146
|
def cloud cloud=nil
|
146
147
|
set_or_return :cloud, cloud
|
147
148
|
end
|
148
|
-
|
149
|
+
|
149
150
|
def run_list run_list=nil
|
150
151
|
set_or_return :run_list, run_list
|
151
152
|
end
|
152
|
-
|
153
|
+
|
153
154
|
def environment environment=nil
|
154
155
|
set_or_return :environment, environment
|
155
156
|
end
|
156
|
-
|
157
|
+
|
157
158
|
def to_hash
|
158
159
|
hash = Hash.new
|
159
|
-
|
160
|
-
hash.store "
|
160
|
+
|
161
|
+
hash.store "name_space", name_space
|
161
162
|
hash.store "name", name
|
162
163
|
hash.store "used_apps", used_apps
|
163
|
-
|
164
|
+
|
164
165
|
hash.store "cloud", cloud
|
165
|
-
|
166
|
+
|
166
167
|
hash.store "pre_run_list", pre_run_list
|
167
168
|
hash.store "post_run_list", post_run_list
|
168
|
-
|
169
|
+
|
169
170
|
hash.store "dependencies", dependencies
|
170
|
-
|
171
|
+
|
171
172
|
hash.store "node", node.to_hash
|
172
173
|
hash.store "environment", environment
|
173
|
-
|
174
|
+
|
174
175
|
if @type
|
175
176
|
hash.store "type", type
|
176
177
|
end
|
177
|
-
|
178
|
+
|
178
179
|
if @recipe
|
179
180
|
hash.store "recipe", recipe
|
180
181
|
end
|
181
|
-
|
182
|
+
|
182
183
|
if @cookbook
|
183
184
|
hash.store "cookbook", cookbook
|
184
185
|
end
|
185
|
-
|
186
|
+
|
186
187
|
hash
|
187
188
|
end
|
188
|
-
|
189
|
+
|
189
190
|
private
|
190
|
-
|
191
|
+
|
191
192
|
def set_or_return(symbol, arg)
|
192
193
|
iv_symbol = "@#{symbol.to_s}".to_sym
|
193
194
|
if arg.nil?
|
@@ -196,7 +197,7 @@ module Chapp
|
|
196
197
|
self.instance_variable_set(iv_symbol, arg)
|
197
198
|
end
|
198
199
|
end
|
199
|
-
|
200
|
+
|
200
201
|
def set_or_return_with_default(symbol, default_val, arg)
|
201
202
|
iv_symbol = "@#{symbol.to_s}".to_sym
|
202
203
|
if arg.nil?
|
@@ -210,6 +211,6 @@ module Chapp
|
|
210
211
|
self.instance_variable_set(iv_symbol, arg)
|
211
212
|
end
|
212
213
|
end
|
213
|
-
|
214
|
+
|
214
215
|
end
|
215
|
-
end
|
216
|
+
end
|
data/lib/chapp/database.rb
CHANGED
@@ -18,17 +18,19 @@ module Chapp
|
|
18
18
|
def app_config app_id
|
19
19
|
|
20
20
|
unless app_exists? app_id
|
21
|
-
raise AppNotExistsException.new, "App
|
21
|
+
raise AppNotExistsException.new, "App #{app_id_hash} does not exist"
|
22
22
|
end
|
23
23
|
|
24
|
-
AppConfig.from_hash apps_config_databag_item(app_id).raw_data["app"]
|
24
|
+
AppConfig.from_hash apps_config_databag_item(hash_to_app_id(app_id)).raw_data["app"]
|
25
|
+
|
25
26
|
end
|
26
27
|
|
27
28
|
def app_exists? app_id
|
28
|
-
apps_config_databag.has_key? app_id
|
29
|
+
apps_config_databag.has_key? hash_to_app_id(app_id)
|
29
30
|
end
|
30
31
|
|
31
32
|
def connected_app_ids app_id
|
33
|
+
# TODO: Does not work
|
32
34
|
app_ids = Array.new
|
33
35
|
|
34
36
|
query = Chef::Search::Query.new
|
@@ -49,6 +51,7 @@ module Chapp
|
|
49
51
|
|
50
52
|
attributes = app_config.node
|
51
53
|
attributes["chapp"]["app_id"] = app_config.id
|
54
|
+
attributes["chapp"]["app_hash_id"] = app_config.id_hash
|
52
55
|
|
53
56
|
# Build/Save role
|
54
57
|
role = Chef::Role.new
|
@@ -84,20 +87,23 @@ module Chapp
|
|
84
87
|
|
85
88
|
end
|
86
89
|
|
87
|
-
def delete_app
|
90
|
+
def delete_app app_id_hash
|
88
91
|
# TODO (not necessary for now)
|
89
92
|
# Delete role/environment, app config databag item, app attribute databag item, app instances
|
90
93
|
end
|
91
94
|
|
92
95
|
def app app_id
|
96
|
+
|
97
|
+
id = hash_to_app_id(app_id)
|
98
|
+
|
93
99
|
app_instances = []
|
94
100
|
app_attributes = {}
|
95
101
|
latest_time = 0
|
96
102
|
|
97
103
|
query = Chef::Search::Query.new
|
98
104
|
# TODO Figure out how to get role name more appropriately
|
99
|
-
query.search(:node, "role:chapp_#{
|
100
|
-
app_instances.push Chapp::AppInstance.new(
|
105
|
+
query.search(:node, "role:chapp_#{id}") do |node|
|
106
|
+
app_instances.push Chapp::AppInstance.new(id, node.name, node["fqdn"])
|
101
107
|
|
102
108
|
if node.has_key?("ohai_time") && node.has_key?("chapp") && node["chapp"].has_key?("app_attributes") && node["ohai_time"] > latest_time
|
103
109
|
latest_time = node["ohai_time"]
|
@@ -105,7 +111,7 @@ module Chapp
|
|
105
111
|
end
|
106
112
|
end
|
107
113
|
|
108
|
-
Chapp::App.new app_id, app_attributes, app_instances, self
|
114
|
+
Chapp::App.new id, app_id, app_attributes, app_instances, self
|
109
115
|
end
|
110
116
|
|
111
117
|
def write_app_instance app_instance
|
@@ -116,21 +122,15 @@ module Chapp
|
|
116
122
|
# TODO: Delete node/client (not necessary for now)
|
117
123
|
end
|
118
124
|
|
119
|
-
def app_attributes app_id
|
120
|
-
databag = app_attributes_databag
|
121
|
-
|
122
|
-
unless databag.has_key? app_id
|
123
|
-
raise AppAttributesNotExistsException.new, "Attributes for app [#{app_id}] do not exist"
|
124
|
-
end
|
125
|
-
|
126
|
-
app_attributes_databag_item(app_id).raw_data["app_attributes"]
|
127
|
-
end
|
128
|
-
|
129
125
|
class AppAttributesNotExistsException < StandardError; end
|
130
126
|
class AppNotExistsException < StandardError; end
|
131
127
|
|
132
128
|
private
|
133
129
|
|
130
|
+
def hash_to_app_id app_id_hash
|
131
|
+
app_id_hash.sort.map{|k,v| "#{k}_#{v}"}.join("_")
|
132
|
+
end
|
133
|
+
|
134
134
|
def apps_config_databag
|
135
135
|
get_or_create_databag APPS_CONFIG_DATA_BAG_NAME
|
136
136
|
end
|
@@ -1,67 +1,73 @@
|
|
1
1
|
require 'chapp'
|
2
|
-
require 'aws'
|
2
|
+
require 'aws-sdk'
|
3
|
+
require 'chef_metal/transport/ssh'
|
3
4
|
|
4
5
|
module Chapp
|
5
6
|
class EC2Provisioner < Chapp::Provisioner
|
6
|
-
|
7
|
+
|
7
8
|
# Knife config
|
8
9
|
ACCESS_KEY = "ec2_access_key_id"
|
9
10
|
SECRET_KEY = "ec2_secret_access_key"
|
10
11
|
KEY_PAIR = "ec2_key_pair"
|
11
|
-
|
12
|
+
|
12
13
|
# App config
|
13
14
|
IMAGE_ID = "image_id"
|
14
15
|
INSTANCE_TYPE = "instance_type"
|
15
|
-
|
16
|
+
|
16
17
|
def build_server app_config, properties
|
17
|
-
|
18
|
+
|
18
19
|
errors = []
|
19
|
-
|
20
|
+
|
20
21
|
access_key = Chef::Config[ACCESS_KEY]
|
21
22
|
secret_key = Chef::Config[SECRET_KEY]
|
22
23
|
key_pair = Chef::Config[KEY_PAIR]
|
23
|
-
|
24
|
+
|
24
25
|
if access_key.nil?
|
25
26
|
errors << "#{ACCESS_KEY} must be specified in your knife config"
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
if secret_key.nil?
|
29
30
|
errors << "#{SECRET_KEY} must be specified in your knife config"
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
if key_pair.nil?
|
33
34
|
errors << "#{KEY_PAIR} must be specified in your knife config"
|
34
35
|
end
|
35
|
-
|
36
|
+
|
36
37
|
unless app_config.cloud.has_key? IMAGE_ID
|
37
38
|
errors << "#{IMAGE_ID} must be specified in your app's cloud config"
|
38
39
|
end
|
39
|
-
|
40
|
+
|
40
41
|
unless app_config.cloud.has_key? INSTANCE_TYPE
|
41
42
|
errors << "#{INSTANCE_TYPE} must be specified in your app's cloud config"
|
42
43
|
end
|
43
|
-
|
44
|
+
|
44
45
|
image_id = app_config.cloud[IMAGE_ID]
|
45
46
|
instance_type = app_config.cloud[INSTANCE_TYPE]
|
46
|
-
|
47
|
+
|
47
48
|
ec2 = AWS::EC2.new(:access_key_id => access_key, :secret_access_key => secret_key)
|
48
|
-
|
49
|
+
|
49
50
|
instance = ec2.instances.create(
|
50
51
|
:image_id => image_id,
|
51
52
|
:instance_type => instance_type,
|
52
53
|
:key_pair => ec2.key_pairs[key_pair]
|
53
54
|
)
|
54
|
-
|
55
|
+
|
55
56
|
puts "Waiting for new instance with id #{instance.id} to become available..."
|
56
57
|
sleep 1 while instance.status == :pending
|
57
|
-
|
58
|
+
|
58
59
|
puts "#{instance.dns_name} is ready"
|
60
|
+
puts "Waiting for host to finish booting ..."
|
59
61
|
|
60
62
|
# TODO: Wait for SSH to become available
|
61
|
-
|
63
|
+
ssh = ChefMetal::Transport::SSH.new instance.dns_name, "root", {:keys => [Chef::Config[:knife][:identity_file]]}, {}, {}
|
64
|
+
|
65
|
+
while !ssh.available?
|
66
|
+
sleep 5
|
67
|
+
end
|
62
68
|
|
63
69
|
instance.dns_name
|
64
70
|
end
|
65
|
-
|
71
|
+
|
66
72
|
end
|
67
73
|
end
|
data/lib/chapp/wiring.rb
CHANGED
@@ -2,30 +2,31 @@ require 'chapp'
|
|
2
2
|
require 'chapp/app/node_app'
|
3
3
|
|
4
4
|
module Chapp
|
5
|
-
|
5
|
+
|
6
6
|
class Wiring
|
7
|
-
|
7
|
+
|
8
8
|
attr_reader :node
|
9
|
-
|
9
|
+
|
10
10
|
def initialize app_config, db, node
|
11
11
|
@used_apps = Hash.new
|
12
|
-
|
12
|
+
|
13
13
|
@db = db
|
14
14
|
@node = node
|
15
|
-
@app = Chapp::NodeApp.new app_config
|
16
|
-
|
17
|
-
|
18
|
-
app_config.used_apps.each do |
|
15
|
+
@app = Chapp::NodeApp.new app_config, db, node.default["chapp"]["app_attributes"],
|
16
|
+
Chef::Config[:node_name], node["fqdn"]
|
17
|
+
|
18
|
+
app_config.used_apps.each do |app_id|
|
19
|
+
used_app = @db.app app_id
|
20
|
+
type = used_app.config.type
|
21
|
+
|
19
22
|
unless @used_apps.has_key? type
|
20
23
|
@used_apps[type] = Array.new
|
21
24
|
end
|
22
|
-
|
23
|
-
|
24
|
-
@used_apps[type] << app_id
|
25
|
-
end
|
25
|
+
|
26
|
+
@used_apps[type] << used_app
|
26
27
|
end
|
27
28
|
end
|
28
|
-
|
29
|
+
|
29
30
|
def app type=nil
|
30
31
|
if type.nil?
|
31
32
|
@app
|
@@ -33,23 +34,23 @@ module Chapp
|
|
33
34
|
unless @used_apps.has_key? type
|
34
35
|
raise "App does not use app of type [#{type}]"
|
35
36
|
end
|
36
|
-
|
37
|
+
|
37
38
|
if @used_apps[type].size > 1
|
38
39
|
raise "App uses many apps of [#{type}]"
|
39
40
|
end
|
40
|
-
|
41
|
-
@
|
41
|
+
|
42
|
+
@used_apps[type].first
|
42
43
|
end
|
43
44
|
end
|
44
|
-
|
45
|
+
|
45
46
|
def apps type
|
46
47
|
unless @used_apps.has_key? type
|
47
48
|
raise "App does not use app of type [#{type}]"
|
48
49
|
end
|
49
|
-
|
50
|
-
@
|
50
|
+
|
51
|
+
@used_apps[type]
|
51
52
|
end
|
52
|
-
|
53
|
+
|
53
54
|
end
|
54
|
-
|
55
|
+
|
55
56
|
end
|
@@ -6,88 +6,86 @@ require 'chapp'
|
|
6
6
|
class Chef
|
7
7
|
class Knife
|
8
8
|
class AppInstanceCreate < Chef::Knife::Bootstrap
|
9
|
-
|
9
|
+
|
10
10
|
banner "knife app instance create app_id [properties] (options)"
|
11
11
|
category "app instance"
|
12
|
-
|
12
|
+
|
13
13
|
def initialize arguments
|
14
14
|
bootstrap = Chef::Knife::Bootstrap.new
|
15
|
-
|
15
|
+
|
16
16
|
bootstrap.options.each do |name, args|
|
17
17
|
AppInstanceCreate.option name, args
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
Chef::Knife::Bootstrap.load_deps
|
21
|
-
|
21
|
+
|
22
22
|
super arguments
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# This method will be executed when you run this knife command.
|
26
26
|
def run
|
27
|
-
|
27
|
+
|
28
28
|
# Get Arguments
|
29
29
|
if @name_args.size < 1
|
30
30
|
ui.info("Please specify an app_id")
|
31
31
|
show_usage
|
32
32
|
exit 1
|
33
33
|
end
|
34
|
-
|
35
|
-
app_id =
|
34
|
+
|
35
|
+
app_id = {}
|
36
|
+
@name_args[0].split(" ").each do |id_arg|
|
37
|
+
key_value = id_arg.split("=")
|
38
|
+
app_id[key_value.first] = key_value.last
|
39
|
+
end
|
40
|
+
|
36
41
|
properties = parse_properties @name_args[1, @name_args.size]
|
37
|
-
|
42
|
+
|
38
43
|
db = Chapp.database
|
39
44
|
provisioner = Chapp.provisioner
|
40
|
-
|
45
|
+
|
41
46
|
app_config = db.app_config app_id
|
42
|
-
|
47
|
+
|
43
48
|
# Provision the server and retrieve the host name
|
44
49
|
host = provisioner.build_server app_config, properties
|
45
|
-
|
50
|
+
|
46
51
|
properties.each do |key, value|
|
47
52
|
@config[key.to_sym] = value
|
48
53
|
end
|
49
|
-
|
54
|
+
|
50
55
|
# Tells bootstrap what environment to use
|
51
56
|
Chef::Config[:environment] = app_config.environment_name
|
52
|
-
|
57
|
+
|
53
58
|
# Tells bootstrap what run_list to use
|
54
59
|
@config[:run_list] = "role[#{app_config.role_name}]"
|
55
|
-
|
60
|
+
|
56
61
|
# Tells bootstrap what node name to use
|
57
62
|
@config[:chef_node_name] = host
|
58
|
-
|
63
|
+
|
59
64
|
# Tells bootstrap what ip/fqdn to use
|
60
65
|
@name_args = host
|
61
|
-
|
66
|
+
|
62
67
|
# Runs bootstrap
|
63
68
|
super
|
64
|
-
|
65
|
-
# We have to save the node here since bootstrap wont actually assign the run_list
|
66
|
-
node = Node.new
|
67
|
-
node.name host
|
68
|
-
node.run_list = Chef::RunList.new "role[#{app_config.role_name}]"
|
69
|
-
node.chef_environment = app_config.environment_name
|
70
|
-
node.save
|
71
69
|
end
|
72
|
-
|
70
|
+
|
73
71
|
private
|
74
|
-
|
72
|
+
|
75
73
|
def parse_properties properties
|
76
74
|
hash = Hash.new
|
77
|
-
|
75
|
+
|
78
76
|
properties.each do |property|
|
79
77
|
key_value = property.split "="
|
80
|
-
|
78
|
+
|
81
79
|
unless key_value.size == 2
|
82
80
|
raise "Property #{property} is missing ="
|
83
81
|
end
|
84
|
-
|
82
|
+
|
85
83
|
hash[key_value.first] = key_value[1]
|
86
84
|
end
|
87
|
-
|
85
|
+
|
88
86
|
hash
|
89
87
|
end
|
90
|
-
|
88
|
+
|
91
89
|
end
|
92
90
|
end
|
93
|
-
end
|
91
|
+
end
|
data/lib/chef/knife/app_show.rb
CHANGED
@@ -4,73 +4,79 @@ require 'chapp'
|
|
4
4
|
class Chef
|
5
5
|
class Knife
|
6
6
|
class AppShow < Chef::Knife
|
7
|
-
|
7
|
+
|
8
8
|
banner "knife app show app_id (options)"
|
9
9
|
category "app"
|
10
|
-
|
10
|
+
|
11
11
|
# This method will be executed when you run this knife command.
|
12
12
|
def run
|
13
|
-
|
13
|
+
|
14
14
|
# Get Arguments
|
15
15
|
if @name_args.size != 1
|
16
16
|
ui.info("Please specify an app_id")
|
17
17
|
show_usage
|
18
18
|
exit 1
|
19
19
|
end
|
20
|
-
|
21
|
-
app_id =
|
22
|
-
|
20
|
+
|
21
|
+
app_id = {}
|
22
|
+
@name_args[0].split(" ").each do |id_arg|
|
23
|
+
key_value = id_arg.split("=")
|
24
|
+
app_id[key_value.first] = key_value.last
|
25
|
+
end
|
26
|
+
|
23
27
|
app = Chapp.database.app app_id
|
24
|
-
|
28
|
+
|
25
29
|
app_config = app.config
|
26
|
-
|
30
|
+
|
27
31
|
puts "App :"
|
28
32
|
puts " id : #{app_config.id}"
|
29
|
-
|
33
|
+
|
34
|
+
puts " name_space :"
|
35
|
+
print_hash app_config.name_space
|
36
|
+
|
30
37
|
puts " name : #{app_config.name}"
|
31
38
|
puts " type : #{app_config.type}"
|
32
39
|
puts " cookbook : #{app_config.cookbook}"
|
33
40
|
puts " recipe : #{app_config.recipe}"
|
34
|
-
|
35
|
-
|
41
|
+
|
42
|
+
puts " cloud :"
|
43
|
+
print_hash app_config.cloud
|
44
|
+
|
36
45
|
puts " used_apps :"
|
37
|
-
app_config.used_apps.each do |
|
38
|
-
|
39
|
-
used_app_ids.each do |used_app_id|
|
40
|
-
puts " #{used_app_id}"
|
41
|
-
end
|
46
|
+
app_config.used_apps.each do |used_app|
|
47
|
+
print_hash used_app
|
42
48
|
end
|
43
|
-
|
49
|
+
|
44
50
|
puts " node :"
|
45
51
|
print_hash app_config.node
|
46
|
-
|
52
|
+
|
47
53
|
puts " dependencies :"
|
48
54
|
app_config.dependencies.each do |cookbook, version_constraint|
|
49
55
|
puts " #{cookbook} #{version_constraint}"
|
50
56
|
end
|
51
|
-
|
57
|
+
|
52
58
|
puts " pre_run_list :"
|
53
59
|
app_config.pre_run_list.each do |run_list_item|
|
54
60
|
puts " #{run_list_item}"
|
55
61
|
end
|
56
|
-
|
62
|
+
|
57
63
|
puts " post_run_list :"
|
58
64
|
app_config.post_run_list.each do |run_list_item|
|
59
65
|
puts " #{run_list_item}"
|
60
66
|
end
|
61
|
-
|
67
|
+
|
62
68
|
puts ""
|
63
|
-
|
69
|
+
|
64
70
|
puts "App Attributes :"
|
65
71
|
print_hash app.attributes, 2
|
66
|
-
|
72
|
+
|
67
73
|
puts "App Instances :"
|
68
74
|
app.instances.each do |app_instance|
|
69
75
|
puts " #{app_instance.fqdn}"
|
70
76
|
end
|
71
|
-
|
77
|
+
|
72
78
|
end
|
73
|
-
|
79
|
+
|
74
80
|
def print_hash hash, spacing=4
|
75
81
|
hash.each do |key, value|
|
76
82
|
if !value.is_a? Hash
|
@@ -81,7 +87,7 @@ class Chef
|
|
81
87
|
end
|
82
88
|
end
|
83
89
|
end
|
84
|
-
|
90
|
+
|
85
91
|
end
|
86
92
|
end
|
87
|
-
end
|
93
|
+
end
|
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.
|
4
|
+
version: 0.4.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-07-
|
11
|
+
date: 2014-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
@@ -25,19 +25,47 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '11.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: aws
|
28
|
+
name: aws-sdk
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '1.47'
|
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
|
-
version: '
|
40
|
+
version: '1.47'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: chef-metal
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.13'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.13'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cheffish
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.6.2
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rake
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,9 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
122
|
version: '0'
|
95
123
|
requirements: []
|
96
124
|
rubyforge_project: nowarning
|
97
|
-
rubygems_version: 2.0.
|
125
|
+
rubygems_version: 2.0.14
|
98
126
|
signing_key:
|
99
127
|
specification_version: 4
|
100
128
|
summary: A Chef knife plugin for creating Chef Apps
|
101
129
|
test_files: []
|
102
|
-
has_rdoc:
|