forj 1.0.10 → 1.0.11

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.
@@ -23,7 +23,7 @@ module Forj
23
23
  def self.connect(account)
24
24
  a_processes = []
25
25
 
26
- provider = account[:provider]
26
+ provider = account['account#provider']
27
27
 
28
28
  # Defines how to manage Maestro and forges
29
29
  # Uses 'cloud' module process provided by 'lorj_cloud'
@@ -31,13 +31,7 @@ module Forj
31
31
  :controller_name => provider }
32
32
 
33
33
  # create a maestro box. Identify a forge instance, delete it,...
34
- a_processes << { :process_path => File.join(LIB_PATH, 'forj',
35
- 'ForjCore.rb') }
36
-
37
- # Defines how cli will control FORJ features
38
- # boot/down/ssh/...
39
- a_processes << { :process_path => File.join(LIB_PATH, 'forj',
40
- 'ForjCli.rb') }
34
+ a_processes << { :process_module => :forj_core }
41
35
 
42
36
  # Loading CloudCore embedding provider controller + its process.
43
37
  o_cloud = Lorj::Core.new(account, a_processes)
data/lib/destroy.rb CHANGED
@@ -26,14 +26,11 @@ module Forj
26
26
  def self.destroy(name, options)
27
27
  account = Lorj::Account.new(options[:config])
28
28
 
29
- # Setting account at runtime layer
30
- account[:account_name] = options[:account_name] if options[:account_name]
31
-
32
29
  # Loading account at account layer
33
- unless account.ac_load account[:account_name]
30
+ unless account.ac_load options[:account_name]
34
31
  PrcLib.fatal(1, "Invalid account '%s'. Use `forj show account` "\
35
32
  'to get the list of valid accounts.',
36
- account[:account_name])
33
+ options[:account_name])
37
34
  end
38
35
 
39
36
  o_cloud = Forj::CloudConnection.connect(account)
data/lib/forj-settings.rb CHANGED
@@ -14,6 +14,8 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ require 'cloud_connection.rb'
18
+
17
19
  module Forj
18
20
  # This module helps you to setup your forge's account
19
21
  module Settings
@@ -42,9 +44,9 @@ module Forj
42
44
  def self.account_show_all(account_name)
43
45
  config = Lorj::Account.new
44
46
 
45
- config[:account_name] = account_name
47
+ config.ac_load account_name
48
+ Forj::CloudConnection.connect(config)
46
49
 
47
- config.ac_load config[:account_name]
48
50
  puts format(
49
51
  "List of account settings for provider '%s': ",
50
52
  config.get(:provider)
@@ -56,7 +58,7 @@ module Forj
56
58
  )
57
59
 
58
60
  config.meta_each do |section, found_key, hValue|
59
- next if hValue.rh_get(:readonly)
61
+ next if hValue.rh_get(:readonly) || hValue.rh_get(:get) == false
60
62
  s_desc = hValue.rh_get(:desc)
61
63
  puts format('%-15s %-12s : %s', found_key, section, s_desc)
62
64
  end
@@ -79,7 +81,7 @@ module Forj
79
81
  'section name'
80
82
  )
81
83
  config.meta_each do |section, found_key, hValue|
82
- next if hValue.rh_get(:readonly)
84
+ next if hValue.rh_get(:readonly) || hValue.rh_get(:get) == fals
83
85
  s_desc = hValue.rh_get(:desc)
84
86
  puts format('%-15s %-12s : %s', found_key, section, s_desc)
85
87
  end
@@ -99,7 +101,10 @@ module Forj
99
101
  account_key, account_key, account_name)
100
102
  end
101
103
  end
104
+ end
102
105
 
106
+ # This module helps you to setup your forge's account
107
+ module Settings
103
108
  def self.format_old_key(account, old_value, key_to_set)
104
109
  s_bef = 'unset'
105
110
 
@@ -129,9 +134,8 @@ module Forj
129
134
 
130
135
  b_dirty = false
131
136
 
132
- config[:account_name] = account_name
133
-
134
- config.ac_load config[:account_name]
137
+ config.ac_load account_name
138
+ Forj::CloudConnection.connect(config)
135
139
 
136
140
  p.flatten!
137
141
  p.each do |key_val|
@@ -142,11 +146,8 @@ module Forj
142
146
 
143
147
  validate_account_set(config, account_name, key_to_set)
144
148
 
145
- full_key = format(
146
- '%s/%s',
147
- Lorj.data.first_section(key_to_set),
148
- key_to_set
149
- )
149
+ section, key_to_set = Lorj.data.first_section(key_to_set)
150
+ full_key = format('%s/%s', section, key_to_set)
150
151
 
151
152
  old_value = config.get(key_to_set)
152
153
  s_bef = format_old_key(config, old_value, key_to_set)
@@ -198,7 +199,10 @@ module Forj
198
199
 
199
200
  key
200
201
  end
202
+ end
201
203
 
204
+ # This module helps you to setup your forge's account
205
+ module Settings
202
206
  def self.config_set(*p)
203
207
  config = Lorj::Account.new
204
208
  b_dirty = false
@@ -260,16 +264,18 @@ module Forj
260
264
  end
261
265
 
262
266
  def self.get_account_values(account, account_name)
263
- Lorj.defaults.meta_each do |section, mykey, hValue|
264
- config_where = account.where?(mykey,
265
- :names => %w(account local default))
267
+ Lorj.data.meta_each do |section, mykey, hValue|
268
+ next if hValue.rh_get(:get) == false
269
+ config_where = account.where?(mykey, :section => section,
270
+ :names => account.layers -
271
+ %w(runtime))
266
272
 
267
273
  s_upd_msg = '+'
268
274
  s_upd_msg = ' ' if hValue.rh_get(:readonly)
269
275
 
270
276
  if config_where
271
277
  where_highlight = format_highlight(account_name,
272
- config_where[0], '%-7s')
278
+ config_where[0], '%-9s')
273
279
  default_key = nil
274
280
  if hValue.rh_exist?(:default) && config_where[0] != 'account'
275
281
  default_key = format(" (from default key '%s')",
@@ -277,10 +283,10 @@ module Forj
277
283
  end
278
284
  puts format("%s %-15s(%s) %-12s: '%s'%s",
279
285
  s_upd_msg, mykey, where_highlight, section,
280
- account.get(mykey), default_key)
286
+ account.get(mykey, nil, :section => section), default_key)
281
287
  else
282
288
  puts format(
283
- '%s %-15s( ) %-12s: unset',
289
+ '%s %-15s( ) %-12s: unset',
284
290
  s_upd_msg,
285
291
  mykey,
286
292
  section
@@ -290,10 +296,10 @@ module Forj
290
296
  end
291
297
 
292
298
  def self.account_get_all(oConfig, account_name)
293
- oConfig[:account_name] = account_name
294
-
299
+ # byebug
295
300
  PrcLib.fatal(1, "Unable to load account '%s'. Not found.",
296
- account_name) unless oConfig.ac_load oConfig[:account_name]
301
+ account_name) unless oConfig.ac_load account_name
302
+ Forj::CloudConnection.connect(oConfig)
297
303
 
298
304
  puts format(
299
305
  'legend: default = Application defaults, local = Local' \
@@ -322,23 +328,30 @@ module Forj
322
328
  account_name
323
329
  )
324
330
  end
331
+ end
325
332
 
333
+ # This module helps you to setup your forge's account
334
+ module Settings
326
335
  def self.config_get_all(oConfig)
327
336
  puts 'legend: default = Application defaults, local = Local default' \
328
337
  " config\n\n"
329
- puts format(
330
- "%s %-19s(%-7s) %-12s:\n-----------------------------------" \
331
- '-----', 'U',
332
- '''key', 'origin',
333
- 'section name'
334
- )
338
+ puts format("%s %-19s(%-7s) %-12s:\n"\
339
+ '----------------------------------------',
340
+ 'U', 'key', 'origin', 'section name')
341
+
342
+ a_processes = [{ :process_module => :cloud },
343
+ { :process_module => :forj_core }]
344
+
345
+ # Loading CloudCore embedding provider controller + its process.
346
+ Lorj::Core.new(oConfig, a_processes)
335
347
 
336
348
  oConfig.meta_each do |section, found_key, hValue|
349
+ next if hValue.rh_get(:get) == false
337
350
  s_upd_msg = '+'
338
351
  s_upd_msg = ' ' if hValue.rh_get(:readonly)
339
352
  found_key = hValue.rh_get(:default) if hValue.rh_exist?(:default)
340
353
 
341
- where = oConfig.where?(found_key)
354
+ where = oConfig.where?(found_key, :section => section)
342
355
  if where
343
356
  where = where[0]
344
357
  highlight = ''
@@ -351,7 +364,7 @@ module Forj
351
364
  where,
352
365
  ANSI.clear,
353
366
  section,
354
- oConfig.get(found_key)
367
+ oConfig.get(section.to_s + '#' + found_key.to_s)
355
368
  )
356
369
  else
357
370
  puts format(
@@ -367,10 +380,9 @@ module Forj
367
380
  end
368
381
 
369
382
  def self.account_get(oConfig, account_name, key)
370
- oConfig[:account_name] = account_name
371
-
372
383
  PrcLib.fatal(1, "Unable to load account '%s'. Not found.",
373
- account_name) unless oConfig.ac_load oConfig[:account_name]
384
+ account_name) unless oConfig.ac_load account_name
385
+ Forj::CloudConnection.connect(oConfig)
374
386
 
375
387
  if oConfig.where?(key)
376
388
  puts format(
data/lib/forj.rb ADDED
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'lorj'
18
+
19
+ Lorj.declare_process('forj_core', File.dirname(__FILE__))
@@ -0,0 +1,270 @@
1
+ # (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ # Following declares specific 'forj' process data.
16
+ # Those are combined with lorj_cloud data.
17
+ #
18
+ :setup:
19
+ :steps:
20
+ :provider_config:
21
+ :desc: "Provider configuration:"
22
+ :maestro_config:
23
+ :maestro_img_config:
24
+ :desc: "Maestro Cloud compute configuration:"
25
+ :add:
26
+ - :ssh_user
27
+ :gardener_config:
28
+ :desc: "Maestro gardener Cloud configuration:"
29
+ :explanation: |-
30
+ Maestro gardener is currently configured to access your cloud Compute service with fog openstack.
31
+ Fog openstack is compatible with hpcloud services
32
+
33
+ It requires the openstack project name, user and password.
34
+ :bp_config:
35
+ :desc: "Maestro and blueprint configuration:"
36
+ :maestro_access_config:
37
+ :desc: "Maestro server SSH access"
38
+ :add:
39
+ - :keypair_files
40
+ :dns_config:
41
+ :desc: "DNS Configuration for Maestro:"
42
+ :sections:
43
+ # This section define updatable data available from config.yaml. But will never be added in an account file.
44
+ # Used by forj set/get functions
45
+ :default:
46
+ :account_name:
47
+ :desc: "Default account name used by forj cli"
48
+ :provider_name:
49
+ :desc: "Default provider name while running forj setup. By default, hpcloud is selected."
50
+ # Defines account credentials data
51
+ :account:
52
+ :name:
53
+ :desc: "Name of the Forj cli account. use forj account rename <oldName> <NewName> to update it."
54
+ :readonly: true
55
+ :account_exclusive: true
56
+ :provider:
57
+ :desc: "Provider name attached to the forj cli account. To update it, use forj setup."
58
+ :readonly: true
59
+ :account_exclusive: true
60
+ :default: :provider_name
61
+
62
+ # Defines ssh keys credentials
63
+ :credentials:
64
+ :keypair_files:
65
+ :explanation: |-
66
+ A keypair is a combination of SSH public and private key files. Usually, generated in your '$HOME/.ssh/' directory.
67
+ The private key is used to identify yourself to access your box via ssh.
68
+ The public key is used to configure your server to authorize you to access the box with your private key.
69
+ This keypair files will be copied to '$HOME/.forj/keypairs/ under <keypair_name> files for 'forj' needs.
70
+
71
+ If the keypair doesn't exist locally, it will be created for you.
72
+ :desc: "Base keypair file name"
73
+ :default_value: "~/.ssh/<%= config[:keypair_name] %>-id_rsa"
74
+ :validate_function: :forj_check_keypairs_files
75
+ :account: true
76
+ :ask_step: :maestro_access_config
77
+ :after: :keypair_name
78
+ :pre_step_function: :forj_cloud_keypair_coherent?
79
+ :post_step_function: :forj_setup_keypairs_files
80
+ :keypair_path:
81
+ :desc: "Contains the full path to the :keypair_base."
82
+ :ask_step: :maestro_access_config
83
+ :default_value: "<%= Forj.keypairs_path %>"
84
+ :keypair_base:
85
+ :desc: "Contains the key file base name without .pem/.pub."
86
+ :ask_step: :maestro_access_config
87
+ :default_value: "<%= config[:keypair_name] %>"
88
+ :keypair_name:
89
+ :desc: "keypair name defined in your cloud to access your server. By default we named it 'forj'. If it doesn't exist, it will be created."
90
+ :required: true
91
+ :default_value: "forj"
92
+ :account: true
93
+ :ask_sort: 0
94
+ :ask_step: :maestro_access_config
95
+ :pre_step_function: :update_keypair_config
96
+ :post_step_function: :forj_check_cloud_keypair
97
+ :auth_uri:
98
+ :desc: "Generic service auth url"
99
+ :account_exclusive: true
100
+ :account: true
101
+ :required: true
102
+ :ask_sort: 0
103
+ :ask_step: :provider_config
104
+ :account_id:
105
+ :desc: "Generic Cloud Account name."
106
+ :account_exclusive: true
107
+ :account: true
108
+ :required: true
109
+ :ask_step: :provider_config
110
+ :account_key:
111
+ :desc: "Generic cloud account key"
112
+ :account_exclusive: true
113
+ :account: true
114
+ :required: true
115
+ :encrypted: true
116
+ :ask_step: :provider_config
117
+ :tenant:
118
+ :desc: "Openstack Tenant Name (Project name)"
119
+ :account_exclusive: true
120
+ :account: true
121
+ :required: true
122
+ :ask_step: :provider_config
123
+ :os_user:
124
+ :desc: "Openstack compute cloud User name"
125
+ :account_exclusive: true
126
+ :account: true
127
+ :required: true
128
+ :validate: !ruby/regexp /\w+/
129
+ :ask_step: :gardener_config
130
+ :default_value: "<%= (config[:provider] == 'openstack')?config['credentials#account_id']:nil %>"
131
+ :os_enckey:
132
+ :desc: "Openstack compute cloud password"
133
+ :account_exclusive: true
134
+ :encrypted: true
135
+ :account: true
136
+ :required: true
137
+ :ask_step: :gardener_config
138
+ :default_value: "<%= (config[:provider] == 'openstack')?config['credentials#account_key']:nil %>"
139
+
140
+ # Defines DNS services for maestro
141
+ :dns:
142
+ :domain_name:
143
+ :desc: "Domain name added to each hosts."
144
+ :account_exclusive: true
145
+ :account: true
146
+ :post_step_function: :forj_dns_settings
147
+ :ask_step: :dns_config
148
+ :dns_service:
149
+ :desc: "DNS service region name Maestro will use."
150
+ :account_exclusive: true
151
+ :account: true
152
+ :pre_step_function: :forj_dns_settings?
153
+ :ask_step: :dns_config
154
+ :dns_tenant_id:
155
+ :desc: "DNS Tenant ID Maestro will use"
156
+ :account_exclusive: true
157
+ :account: true
158
+ :pre_step_function: :forj_dns_settings?
159
+ :ask_step: :dns_config
160
+
161
+ :maestro:
162
+ :tenant_name:
163
+ :desc: "Tenant name required by fog/openstack on gardener"
164
+ :account: true
165
+ :validate: !ruby/regexp /^\w?[\w_:-]*$/
166
+ :ask_step: :gardener_config
167
+ :ask_sort: 0
168
+ :default_value: "<%= (config[:provider] == 'openstack')?config['credentials#tenant']:nil %>"
169
+ :network_name:
170
+ :desc: "Network name to attach to each forge boxes. By default we use 'forj'. If it doesn't exist, it will be created."
171
+ :default: network
172
+ :account: true
173
+ :required: true
174
+ :default_value: "forj"
175
+ :ask_step: :maestro_config
176
+ :security_group:
177
+ :desc: "Security group name to configure and attach to each forge boxes."
178
+ :account: true
179
+ :validate: !ruby/regexp /^\w?\w*$/
180
+ :default_value: "forj"
181
+ :ask_step: :maestro_config
182
+ :maestro_repo:
183
+ :desc: "To use a different Maestro repository already cloned."
184
+ :infra_repo:
185
+ :desc: "Defines your Infra directory to use while booting."
186
+ :box_name:
187
+ :desc: "forj cli use 'build.sh' to create Maestro. See box_name option on build.sh to get more information. By default 'maestro'"
188
+ :build_config:
189
+ :desc: "forj cli use 'build.sh' to create Maestro. See build_config option on build.sh to get more information. By default 'box'"
190
+ :bp_flavor:
191
+ :desc: "Blueprint nodes default flavor"
192
+ :explanation: |-
193
+ Blueprint usually defines the required flavor for their nodes. If not, it will use this flavor as default.
194
+ Usually, blueprint nodes are smaller than Maestro.
195
+ :account: true
196
+ :list_values:
197
+ :query_type: :query_call # Will execute a query on flavor, query_params is empty for all.
198
+ :object: :flavor
199
+ :value: :name
200
+ :validate: :list_strict
201
+ :ask_step: :maestro_config
202
+ :after: 'maestro#flavor_name'
203
+ :flavor_name:
204
+ :explanation: 'This flavor is for Maestro only.'
205
+ :desc: "Maestro Flavor name"
206
+ :default_value: 'medium'
207
+ :account: true
208
+ :list_values:
209
+ :query_type: :query_call # Will execute a query on flavor, query_params is empty for all.
210
+ :object: :flavor
211
+ :value: :name
212
+ :validate: :list_strict
213
+ :ask_step: :maestro_config
214
+ :image_name:
215
+ :desc: "Image name"
216
+ :explanation: |-
217
+ Ubuntu image used to create Maestro and all forge boxes. Originally, Maestro uses 'Ubuntu Precise 12.04.4 LTS Server 64-bit'.
218
+ You need to choose the appropriate image to make Maestro & boxes to boot normally.
219
+ :account: true
220
+ :ask_step: :maestro_img_config
221
+ :list_values:
222
+ :query_type: :query_call # Will execute a query on flavor, query_params is empty for all. No filter currently working.
223
+ :object: :image
224
+ :value: :name
225
+ :validate: :list_strict
226
+ :after: :bp_flavor
227
+ :ssh_user:
228
+ :desc: "User name for ssh connection of your selected image."
229
+ :explanation: |-
230
+ The image name you have selected has a unique SSH Account access.
231
+
232
+ Thanks to the name of the image, setup assume the account name to use.
233
+ If this name is incoherent with the image you choosed, please update it.
234
+
235
+ Checking image '<%= config['maestro#image_name'] %>'...
236
+ :account: true
237
+ :ask_step: :maestro_img_config
238
+ :ask_sort: 0
239
+ :after: :image_name
240
+ :list_values:
241
+ :query_type: :process_call # Will execute a process to query on image
242
+ :query_call: :setup_ssh_user # and return the list of images and a default value.
243
+ :object: :image # The process will get the image object
244
+ :query_params: # Transmitted as hParams
245
+ :image_name: "<%= config['maestro#image_name'] %>"
246
+ :ports:
247
+ :desc: "List of security group rules (1 port or range of ports) to open to the external network."
248
+ :branch:
249
+ :desc: "Branch to use to build your forge"
250
+ :bootstrap_dirs:
251
+ :desc: "Additional bootstrap directories (separated by space) to add in the bootstrap loop."
252
+ :bootstrap_extra_dir:
253
+ :desc: "Additional bootstrap directory to add in the bootstrap loop, before :bootstrap_dirs and after maestro default bootstrap directory."
254
+
255
+ # As forj_core is based on lorj_cloud, we have to disable Lorj_cloud data defaults.
256
+ :server:
257
+ :network_name:
258
+ :set: false
259
+ :security_group:
260
+ :set: false
261
+ :box_name:
262
+ :set: false
263
+ :flavor_name:
264
+ :set: false
265
+ :account: false
266
+ :image_name:
267
+ :account: false
268
+ :set: false
269
+ :ports:
270
+ :set: false