forj 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +7 -0
  3. data/.gitreview +4 -0
  4. data/Gemfile +21 -19
  5. data/Gemfile.lock +71 -0
  6. data/bin/forj +126 -83
  7. data/forj.gemspec +64 -0
  8. data/{lib → forj}/defaults.yaml +23 -1
  9. data/lib/appinit.rb +5 -5
  10. data/lib/build_tmpl/build-env.py +293 -0
  11. data/lib/cloud_test.rb +121 -0
  12. data/lib/forj-settings.rb +52 -39
  13. data/lib/forj/ForjCli.rb +11 -10
  14. data/lib/forj/ForjCore.rb +8 -6
  15. data/lib/forj/process/ForjProcess.rb +345 -82
  16. data/lib/ssh.rb +81 -20
  17. metadata +110 -80
  18. data/lib/compute.rb +0 -36
  19. data/lib/connection.rb +0 -144
  20. data/lib/down.rb +0 -60
  21. data/lib/forj-account.rb +0 -294
  22. data/lib/forj-config.rb +0 -522
  23. data/lib/helpers.rb +0 -56
  24. data/lib/lib-forj/lib/core/core.rb +0 -1740
  25. data/lib/lib-forj/lib/core/definition.rb +0 -441
  26. data/lib/lib-forj/lib/core/definition_internal.rb +0 -306
  27. data/lib/lib-forj/lib/core_process/CloudProcess.rb +0 -334
  28. data/lib/lib-forj/lib/core_process/global_process.rb +0 -406
  29. data/lib/lib-forj/lib/core_process/network_process.rb +0 -603
  30. data/lib/lib-forj/lib/lib-forj.rb +0 -37
  31. data/lib/lib-forj/lib/providers/hpcloud/Hpcloud.rb +0 -419
  32. data/lib/lib-forj/lib/providers/hpcloud/compute.rb +0 -108
  33. data/lib/lib-forj/lib/providers/hpcloud/network.rb +0 -117
  34. data/lib/lib-forj/lib/providers/hpcloud/security_groups.rb +0 -67
  35. data/lib/lib-forj/lib/providers/templates/compute.rb +0 -42
  36. data/lib/lib-forj/lib/providers/templates/core.rb +0 -61
  37. data/lib/lib-forj/lib/providers/templates/network.rb +0 -33
  38. data/lib/log.rb +0 -162
  39. data/lib/network.rb +0 -365
  40. data/lib/repositories.rb +0 -222
  41. data/lib/security.rb +0 -207
  42. data/lib/ssh.sh +0 -185
  43. data/spec/connection_spec.rb +0 -52
  44. data/spec/forj-config_spec.rb +0 -237
  45. data/spec/repositories_spec.rb +0 -50
data/lib/connection.rb DELETED
@@ -1,144 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- require 'rubygems'
19
- require 'fog'
20
-
21
- #
22
- # Connection module
23
- #
24
-
25
- class SSLErrorMgt
26
-
27
- def initialize()
28
- @iRetry=0
29
- end
30
-
31
- def ErrorDetected(message,backtrace)
32
- if message.match('SSLv2/v3 read server hello A: unknown protocol')
33
- if @iRetry <5
34
- sleep(2)
35
- @iRetry+=1
36
- print "%s/5 try...\r" % @iRetry if $FORJ_LOGGER.level == 0
37
- return false
38
- else
39
- Logging.error('Too many retry. %s' % message)
40
- return true
41
- end
42
- else
43
- Logging.error("%s\n%s" % [message,backtrace.join("\n")])
44
- return true
45
- end
46
- end
47
-
48
- end
49
-
50
- class ForjConnection
51
-
52
- attr_accessor :oCompute
53
- attr_accessor :oNetwork
54
- attr_accessor :sAccountName
55
-
56
- def initialize(oConfig, bAutoConnect = true)
57
-
58
- Logging.fatal(1, 'Internal Error: Missing global $HPC_ACCOUNTS') if not $HPC_ACCOUNTS
59
-
60
- @oConfig = oConfig
61
- @sAccountName = @oConfig.get(:account_name)
62
- @provider='HP' # TODO: Support multiple provider. (Generic Provider object required)
63
- @sAccountName = @oConfig.get(:provider) if not @sAccountName
64
- @sAccountName = 'hpcloud' if not @sAccountName
65
-
66
- @credentials = get_credentials()
67
-
68
- # Trying to get Compute object
69
- compute_connect if bAutoConnect
70
-
71
- # Trying to get Network object
72
- network_connect if bAutoConnect
73
-
74
- end
75
-
76
- def compute_connect
77
-
78
- oSSLError=SSLErrorMgt.new # Retry object
79
-
80
- Logging.debug("compute: Connecting to '%s' - Project '%s'" % [@provider, @credentials['tenant_id']])
81
- begin
82
- @oCompute=Fog::Compute.new({
83
- :provider => @provider,
84
- :hp_access_key => @credentials['access_key'],
85
- :hp_secret_key => @credentials['secret_key'],
86
- :hp_auth_uri => @credentials['auth_uri'],
87
- :hp_tenant_id => @credentials['tenant_id'],
88
- :hp_avl_zone => @credentials['availability_zone'],
89
- :version => 'v2'
90
- })
91
- rescue => e
92
- if not oSSLError.ErrorDetected(e.message,e.backtrace)
93
- retry
94
- end
95
- Logging.fatal(1, 'Compute: Unable to connect.', e)
96
- end
97
- end
98
-
99
- def network_connect
100
- # Trying to get Network object
101
- oSSLError=SSLErrorMgt.new # Retry object
102
- Logging.debug("HP network: Connecting to '%s' - Project '%s'" % [@provider, @credentials['tenant_id']])
103
- begin
104
- @oNetwork=Fog::HP::Network.new({
105
- :hp_access_key => @credentials['access_key'],
106
- :hp_secret_key => @credentials['secret_key'],
107
- :hp_auth_uri => @credentials['auth_uri'],
108
- :hp_tenant_id => @credentials['tenant_id'],
109
- :hp_avl_zone => @credentials['availability_zone']
110
- })
111
- rescue => e
112
- if not oSSLError.ErrorDetected(e.message,e.backtrace)
113
- retry
114
- end
115
- Logging.fatal(1, 'Network: Unable to connect.', e)
116
- end
117
-
118
- end
119
-
120
- def get_credentials()
121
- # TODO: Should support forj credentials. not hpcloud credentials.
122
-
123
- creds = File.join($HPC_ACCOUNTS, @sAccountName)
124
- if not File.exists?(creds)
125
- Logging.fatal(1, "'%s' was not configured. Did you executed 'forj setup %s'? Please do it and retry." % [@sAccountName, @sAccountName])
126
- end
127
- @oConfig.oConfig.ExtraLoad(creds, :hpc_accounts, @sAccountName)
128
-
129
- template = @oConfig.oConfig.ExtraGet(:hpc_accounts, @sAccountName)
130
- credentials = {}
131
- begin
132
- credentials['access_key'] = template[:credentials][:account_id]
133
- credentials['secret_key'] = template[:credentials][:secret_key]
134
- credentials['auth_uri'] = template[:credentials][:auth_uri]
135
- credentials['tenant_id'] = template[:credentials][:tenant_id]
136
- credentials['availability_zone'] = template[:regions][:compute]
137
- rescue => e
138
- Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
139
- puts 'your credentials are not configured, delete the file %s and run forj setup again' % [creds]
140
- end
141
- credentials
142
- end
143
-
144
- end
data/lib/down.rb DELETED
@@ -1,60 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- require 'rubygems'
19
- require 'require_relative'
20
-
21
- require_relative 'network.rb'
22
- include Network
23
- require_relative 'security.rb'
24
- include SecurityGroup
25
- #require_relative 'log.rb'
26
- #include Logging
27
- require_relative 'ssh.rb'
28
- include Ssh
29
- require_relative 'compute.rb'
30
- include Compute
31
-
32
- #
33
- # Down module
34
- #
35
- module Down
36
- def down(oConfig, name)
37
- begin
38
-
39
- initial_msg = 'deleting forge "%s"' % [name]
40
- Logging.info(initial_msg)
41
-
42
- oFC=ForjConnection.new(oConfig)
43
-
44
- Compute.delete_forge(oFC, name)
45
-
46
- #~ router = Network.get_router(oFC, 'private-ext')
47
- #~ subnet = Network.get_subnet(oFC, name)
48
- #~ Network.delete_router_interface(subnet.id, router)
49
- #~
50
- #~ Network.delete_subnet(oFC, subnet.id)
51
- #~ network = Network.get_network(oFC, name)
52
- #~ Network.delete_network(oFC, network.name)
53
-
54
- rescue SystemExit, Interrupt
55
- Logging.error('process interrupted by user')
56
- rescue Exception => e
57
- Logging.error("%s\n%s" % [e.message, e.backtrace.join("\n")])
58
- end
59
- end
60
- end
data/lib/forj-account.rb DELETED
@@ -1,294 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: UTF-8
3
-
4
- # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
-
18
- require 'rubygems'
19
-
20
- class ForjAccounts
21
- # Class to query FORJ Accounts list.
22
- def initialize()
23
- end
24
-
25
- def dump()
26
- aAccounts=[]
27
- Dir.foreach($FORJ_ACCOUNTS_PATH) { |x| aAccounts << x if not x.match(/^\..?$/) }
28
- aAccounts
29
- end
30
- end
31
-
32
- # ForjAccount manage a list of key/value grouped by section.
33
- # The intent of ForjAccount is to attach some keys/values to
34
- # an account to help end users to switch between each of them.
35
- #
36
- # ForjAccount based on ForjConfig (see forj-config.rb)
37
- # ensure ForjConfig and ForjAccount defines following common functions
38
- # - set (key, value)
39
- # - get (key)
40
- #
41
- # This means that key HAVE to be unique across sections
42
- # By default, keys maps with the same key name in ForjConfig.
43
- # But we can redefine the ForjConfig mapping of any key on need.
44
- #
45
- # ForjConfig, loads Account meta structure from defaults.yaml, sections
46
- #
47
- # defaults.yaml structure is:
48
- # sections:
49
- # default: => defines key/values recognized by ForjAccount to be only managed by ForjConfig.
50
- # <key> :
51
- # :desc : <value> => defines the ForjConfig key description.
52
- # <section>: Define a section name. For each keys on this section, the account file will kept those data under this section.
53
- # <key>:
54
- # :desc: defines the key description.
55
- # :readonly: true if this key cannot be updated by ForjAccount.set
56
- # :account_exclusive: true if this key cannot be predefined on ForjConfig keys list
57
- # :default: <ForjConfig real key name> Used to map the ForjAccount key to a different ForjConfig key name.
58
-
59
- class ForjAccount
60
-
61
- attr_reader :sAccountName
62
- attr_reader :hAccountData
63
- attr_reader :oConfig
64
-
65
- # This object manage data located in oConfig[:hpc_accounts/AccountName]
66
-
67
- def initialize(oConfig)
68
- # Initialize object
69
- @oConfig = oConfig
70
-
71
- if @oConfig.get(:account_name)
72
- @sAccountName = @oConfig.get(:account_name)
73
- else
74
- @sAccountName = 'hpcloud'
75
- end
76
- @sAccountFile = File.join($FORJ_ACCOUNTS_PATH, @sAccountName)
77
-
78
- sProvider = 'hpcloud'
79
- sProvider = @oConfig.get(:provider) if @oConfig.get(:provider)
80
-
81
- @hAccountData = {}
82
- _set(:account, :name, @sAccountName) if exist?(:name) != 'hash'
83
- _set(:account, :provider, sProvider) if exist?(:provider) != 'hash'
84
-
85
- end
86
-
87
- # oForjAccount data get at several levels:
88
- # - get the data from runtime (runtimeSet/runtimeGet)
89
- # - otherwise, get data from account file under section described in defaults.yaml (:account_section_mapping), as soon as this mapping exists.
90
- # - otherwise, get the data from the local configuration file. Usually ~/.forj/config.yaml
91
- # - otherwise, get the data from defaults.yaml
92
- # otherwise, use the get default parameter as value. Default is nil.
93
- def get(key, default = nil)
94
- return nil if not key
95
-
96
- key = key.to_sym if key.class == String
97
-
98
- return @oConfig.runtimeGet(key) if @oConfig.runtimeExist?(key)
99
-
100
- section = ForjDefault.get_meta_section(key)
101
- default_key = key
102
-
103
- if not section
104
- Logging.debug("ForjAccount.get: No section found for key '%s'." % [key])
105
- else
106
- return rhGet(@hAccountData, section, key) if rhExist?(@hAccountData, section, key) == 2
107
-
108
- hMeta = @oConfig.getAppDefault(:sections)
109
- if rhExist?(hMeta, section, key, :default) == 3
110
- default_key = rhGet(hMeta, section, key, :default)
111
- Logging.debug("ForjAccount.get: Reading default key '%s' instead of '%s'" % [default_key, key])
112
- end
113
- return default if rhExist?(hMeta, section, key, :account_exclusive) == 3
114
- end
115
-
116
- @oConfig.get(default_key , default )
117
- end
118
-
119
- def [](key, default = nil)
120
- get(key, default)
121
- end
122
-
123
- def exist?(key)
124
- return nil if not key
125
-
126
- key = key.to_sym if key.class == String
127
- section = ForjDefault.get_meta_section(key)
128
- if not section
129
- Logging.debug("ForjAccount.exist?: No section found for key '%s'." % [key])
130
- return nil
131
- end
132
- return @sAccountName if rhExist?(@hAccountData, section, key) == 2
133
-
134
- hMeta = @oConfig.getAppDefault(:sections)
135
- if rhExist?(hMeta, section, key, :default) == 3
136
- default_key = rhGet(hMeta, section, key, :default)
137
- Logging.debug("ForjAccount.exist?: Reading default key '%s' instead of '%s'" % [default_key, key])
138
- else
139
- default_key = key
140
- end
141
- return nil if rhExist?(hMeta, section, key, :account_exclusive) == 3
142
-
143
- @oConfig.exist?(default_key)
144
-
145
- end
146
-
147
- # Return true if readonly. set won't be able to update this value.
148
- # Only _set (private function) is able.
149
- def readonly?(key)
150
- return nil if not key
151
-
152
- key = key.to_sym if key.class == String
153
- section = ForjDefault.get_meta_section(key)
154
-
155
- rhGet(@oConfig.getAppDefault(:sections, section), key, :readonly)
156
-
157
- end
158
-
159
- def meta_set(key, hMeta)
160
- key = key.to_sym if key.class == String
161
- section = ForjDefault.get_meta_section(key)
162
- hCurMeta = rhGet(@oConfig.getAppDefault(:sections, section), key)
163
- hMeta.each { | mykey, myvalue |
164
- rhSet(hCurMeta, myvalue, mykey)
165
- }
166
- end
167
-
168
- def meta_exist?(key)
169
- return nil if not key
170
-
171
- key = key.to_sym if key.class == String
172
- section = ForjDefault.get_meta_section(key)
173
- rhExist?(@oConfig.getAppDefault(:sections, section), key) == 1
174
- end
175
-
176
- def get_meta_section(key)
177
- key = key.to_sym if key.class == String
178
- rhGet(@account_section_mapping, key)
179
- end
180
-
181
- def meta_type?(key)
182
- return nil if not key
183
-
184
- section = ForjDefault.get_meta_section(key)
185
-
186
- return section if section == :default
187
- @sAccountName
188
- end
189
-
190
- # Loop on account metadata
191
- def metadata_each
192
- rhGet(ForjDefault.dump(), :sections).each { | section, hValue |
193
- next if section == :default
194
- hValue.each { | key, value |
195
- yield section, key, value
196
- }
197
- }
198
- end
199
-
200
- # Return true if exclusive
201
- def exclusive?(key)
202
- return nil if not key
203
-
204
- key = key.to_sym if key.class == String
205
- section = ForjDefault.get_meta_section(key)
206
-
207
- rhGet(@oConfig.getAppDefault(:sections, section), key, :account_exclusive)
208
- end
209
-
210
- # This function update a section/key=value if the account structure is defined.
211
- # If no section is defined, set it in runtime config.
212
- def set(key, value)
213
- return nil if not key
214
-
215
- key = key.to_sym if key.class == String
216
- section = ForjDefault.get_meta_section(key)
217
-
218
- return @oConfig.set(key, value) if not section
219
- return nil if readonly?(key)
220
- _set(section, key, value)
221
- end
222
-
223
- def []=(key, value)
224
- set(key, value)
225
- end
226
-
227
- def del(key)
228
- return nil if not key
229
-
230
- key = key.to_sym if key.class == String
231
- section = ForjDefault.get_meta_section(key)
232
- return nil if not section
233
- rhSet(@hAccountData, nil, section, key)
234
- end
235
-
236
- def getAccountData(section, key, default=nil)
237
- return rhGet(@hAccountData, section, key) if rhExist?(@hAccountData, section, key) == 2
238
- default
239
- end
240
-
241
- def ac_new(sAccountName)
242
- return nil if sAccountName.nil?
243
- @sAccountName = sAccountName
244
- @sAccountFile = File.join($FORJ_ACCOUNTS_PATH, @sAccountName)
245
-
246
- @hAccountData = {:account => {:name => sAccountName, :provider => @oConfig.get(:provider_name)}}
247
- end
248
-
249
- def ac_load(sAccountName = @sAccountName)
250
- # Load Account Information
251
-
252
- if sAccountName != @sAccountName
253
- ac_new(sAccountName)
254
- end
255
-
256
- if File.exists?(@sAccountFile)
257
- @hAccountData = @oConfig.ExtraLoad(@sAccountFile, :forj_accounts, @sAccountName)
258
- # Check if hAccountData are using symbol or needs to be updated.
259
- sProvider = @oConfig.get(:provider, 'hpcloud')
260
- rhSet(@hAccountData, @sAccountName, :account, :name) if rhExist?(@hAccountData, :account, :name) != 2
261
- rhSet(@hAccountData, sProvider, :account, :provider) if rhExist?(@hAccountData, :account, :provider) != 2
262
-
263
- if rhKeyToSymbol?(@hAccountData, 2)
264
- @hAccountData = rhKeyToSymbol(@hAccountData, 2)
265
- self.ac_save()
266
- end
267
- return @hAccountData
268
- end
269
- nil
270
- end
271
-
272
- def dump()
273
- { :forj_account => @hAccountData }
274
- end
275
-
276
- def ac_save()
277
- @oConfig.ExtraSet(:forj_accounts, @sAccountName, nil, @hAccountData)
278
- @oConfig.ExtraSave(@sAccountFile, :forj_accounts, @sAccountName)
279
-
280
- if not @oConfig.LocalDefaultExist?('account_name')
281
- @oConfig.LocalSet('account_name',@sAccountName)
282
- @oConfig.SaveConfig
283
- end
284
- end
285
-
286
- # private functions
287
- private
288
- def _set(section, key, value)
289
- return nil if not key or not section
290
-
291
- rhSet(@hAccountData, value, section, key)
292
- end
293
-
294
- end