lorj 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +39 -579
- data/Rakefile +7 -0
- data/example/students_1/student_v1.md +115 -0
- data/example/students_1/students.rb +8 -2
- data/example/students_2/process/students.rb +5 -5
- data/example/students_2/student_v2.md +90 -0
- data/example/students_2/students.rb +6 -6
- data/example/students_3/controller/yaml_students.rb +23 -73
- data/example/students_3/controller/yaml_students_code.rb +106 -0
- data/example/students_3/controller/yaml_students_def.rb +69 -0
- data/example/students_3/process/students.rb +23 -157
- data/example/students_3/student_v3.md +283 -0
- data/example/students_3/students.rb +26 -83
- data/example/students_4/controller/yaml_students.rb +51 -0
- data/example/students_4/controller/yaml_students_code.rb +109 -0
- data/example/students_4/controller/yaml_students_def.rb +72 -0
- data/example/students_4/process/students/code/students.rb +103 -0
- data/example/students_4/process/students/definition/students.rb +60 -0
- data/example/students_4/process/students.rb +29 -0
- data/example/students_4/student_v4.md +191 -0
- data/example/students_4/students.rb +65 -0
- data/example/students_5/controller/yaml_students.rb +106 -0
- data/example/{students_3 → students_5}/controller/yaml_students_controller.rb +5 -3
- data/example/students_5/process/students.rb +182 -0
- data/example/students_5/student_v5.md +382 -0
- data/example/students_5/students.rb +119 -0
- data/example/yaml_students/students.rb +1 -1
- data/example/yaml_students/yaml_students.rb +102 -23
- data/lib/concept.md +3 -3
- data/lib/core/core.rb +15 -15
- data/lib/core/core_controller.rb +49 -24
- data/lib/core/core_internal.rb +2 -2
- data/lib/core/core_model.rb +13 -7
- data/lib/core/core_object_data.rb +18 -18
- data/lib/core/core_object_params.rb +75 -34
- data/lib/core/core_process.rb +104 -59
- data/lib/core/core_process_setup.rb +11 -11
- data/lib/core/core_setup_ask.rb +24 -14
- data/lib/core/core_setup_encrypt.rb +17 -15
- data/lib/core/core_setup_init.rb +19 -15
- data/lib/core/core_setup_list.rb +12 -12
- data/lib/core/definition.rb +20 -20
- data/lib/core/definition_internal.rb +20 -10
- data/lib/core/lorj_basecontroller.rb +8 -8
- data/lib/core/lorj_basedefinition.rb +47 -126
- data/lib/core/lorj_baseprocess.rb +81 -57
- data/lib/core/lorj_data.rb +28 -27
- data/lib/core/lorj_keypath.rb +1 -1
- data/lib/core_process/cloud/process/flavor.rb +3 -2
- data/lib/core_process/cloud/process/keypairs.rb +5 -4
- data/lib/core_process/cloud/process/network.rb +4 -3
- data/lib/core_process/cloud/process/public_ip.rb +3 -2
- data/lib/core_process/cloud/process/rules.rb +7 -6
- data/lib/core_process/cloud/process/security_groups.rb +1 -1
- data/lib/core_process/cloud/process/server.rb +1 -1
- data/lib/core_process/cloud/process/server_log.rb +1 -1
- data/lib/core_process/cloud/process/subnetwork.rb +4 -1
- data/lib/core_process/cloud_process.rb +1 -1
- data/lib/logging.rb +41 -48
- data/lib/lorj/version.rb +1 -1
- data/lib/lorj.rb +7 -0
- data/lib/lorj_account.rb +3 -3
- data/lib/lorj_config.rb +1 -1
- data/lib/lorj_defaults.rb +222 -26
- data/lib/overview.md +120 -0
- data/lib/prc.rb +97 -24
- data/lib/prc_core_config.rb +134 -52
- data/lib/providers/hpcloud/compute.rb +3 -3
- data/lib/providers/hpcloud/hpcloud.rb +14 -14
- data/lib/providers/hpcloud/network.rb +4 -4
- data/lib/providers/hpcloud/security_groups.rb +1 -1
- data/lib/providers/mock/mock.rb +3 -3
- data/lib/providers/openstack/openstack.rb +12 -12
- data/lib/providers/templates/compute.rb +6 -6
- data/lib/rh.rb +7 -5
- data/spec/04_prc_core_config_spec.rb +52 -0
- data/spec/11_lorj_config_spec.rb +1 -1
- metadata +21 -3
data/lib/overview.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
As described by the [concept](concept_md.html), lorj is a combination of 4 blocks:
|
2
|
+
|
3
|
+
* The main of your application
|
4
|
+
* a Config system
|
5
|
+
* a Generic process
|
6
|
+
* a controller
|
7
|
+
|
8
|
+
Those blocks communicate through lorj Core, except the config system which can be
|
9
|
+
accessible from anywhere.
|
10
|
+
|
11
|
+
|
12
|
+
# Lorj configuration
|
13
|
+
To run your application with lorj, you will certainly need to configure lorj
|
14
|
+
()Lorj::Core), like the application name, the application path, log file name, etc...
|
15
|
+
|
16
|
+
For details about the lorj configuration, please read documentation on PrcLib.
|
17
|
+
|
18
|
+
|
19
|
+
# Config system
|
20
|
+
About the config system, lorj provides 2 differents predefined configuration classes.
|
21
|
+
|
22
|
+
* Lorj::Config - Basic config systems. Data are retrieved in **application defaults**, then **local config**, then **runtime**.
|
23
|
+
* Lorj::Account - Based on Lorj::Config, it introduces an **account** file, between **local config** and **runtime**.
|
24
|
+
|
25
|
+
Those 2 classes are based on a generic PRC::BaseConfig(or SectionConfig), and PRC::CoreConfig.
|
26
|
+
PRC::CoreConfig introduce a way to get data from different source, organized by layers.
|
27
|
+
It automates the notion of, 'if not there here, go to the next one, until default'
|
28
|
+
A config layer, can be a instant memory data, created on demand, or any kind of
|
29
|
+
local yaml file, loaded at startup or runtime.
|
30
|
+
|
31
|
+
For details, see PRC::CoreConfig
|
32
|
+
|
33
|
+
Lorj has implemented some classes, predefining:
|
34
|
+
For Lorj::Config : 3 layers
|
35
|
+
* Application defaults (defaults.yaml). The file is loaded thanks to Lorj PrcLib configuration
|
36
|
+
This layer is used to predefine lorj data model, to setup the account file.
|
37
|
+
* local data. Refer to a user local application config file.
|
38
|
+
* runtime. A lorj process can get/set any data on needs.
|
39
|
+
|
40
|
+
Details available from Lorj::Config
|
41
|
+
|
42
|
+
For Lorj::Account: 4 layers
|
43
|
+
* Application defaults (defaults.yaml). The file is loaded thanks to Lorj PrcLib configuration
|
44
|
+
This layer is used to predefine lorj data model, to setup the account file.
|
45
|
+
* local data. Refer to a user local application config file.
|
46
|
+
* account. Depending on needs, lorj can setup an account file to preload some data
|
47
|
+
to help the process or the dedicated controller to do the work.
|
48
|
+
Ex: with a cloud process, a cloud controller will need some credentials. lorj setup
|
49
|
+
will be able to ask those information to the user, save them to the account file
|
50
|
+
and Lorj::Account will be able to load them for process execution.
|
51
|
+
* runtime. A lorj process can get/set any data on needs.
|
52
|
+
|
53
|
+
Details available from Lorj::Account, and BaseDefinition.setup
|
54
|
+
|
55
|
+
|
56
|
+
# Generic process
|
57
|
+
|
58
|
+
The generic Process is your application process.
|
59
|
+
|
60
|
+
To simplify the vision, imagine a human as an application
|
61
|
+
Then the application process is the brain.
|
62
|
+
|
63
|
+
But to keep the power of lorj, a process must respect some rules:
|
64
|
+
* A process defines a data model which is known only by it self.
|
65
|
+
* A process should never have to deal with a controller data model.
|
66
|
+
lorj provides a mapping feature to map process data with controller data.
|
67
|
+
* A process should never deal with how a controller manipulate data.
|
68
|
+
A controller can have his own independant process
|
69
|
+
Ex: If your process deals with booting a server, the process do not take care on
|
70
|
+
how to ensure the network is already configured to access internet.
|
71
|
+
|
72
|
+
For details, see Lorj::BaseProcess
|
73
|
+
|
74
|
+
|
75
|
+
# Controller
|
76
|
+
|
77
|
+
A controller enhance a generic Process with how to really execute what the
|
78
|
+
process define to do.
|
79
|
+
|
80
|
+
In the simple human application vision, a controller is the human body.
|
81
|
+
It gives you the way to walk, for example.
|
82
|
+
|
83
|
+
You can consider that the 'brain' process can be enhanced in 2 differents areas:
|
84
|
+
* Do and execute a task:
|
85
|
+
This is like, human muscles
|
86
|
+
* how to do a controller task that the brain do not care of.
|
87
|
+
This is like how to automate several muscles to execute a simple task 'walk'
|
88
|
+
|
89
|
+
For details, see Lorj::BaseController
|
90
|
+
|
91
|
+
|
92
|
+
# enhanced logger system
|
93
|
+
|
94
|
+
There is nothing clever here. Globally, you should be able to redefine the lorj
|
95
|
+
logging system by any thing, if you redefine PrcLib logging messages.
|
96
|
+
This said, Lorj has implemented a logging system based on logger. It helps to
|
97
|
+
save any debug info to a rotated log file system, even if the data is not printed out
|
98
|
+
to the default output.
|
99
|
+
|
100
|
+
This helps in debugging the lorj application.
|
101
|
+
|
102
|
+
|
103
|
+
# Implementation examples
|
104
|
+
|
105
|
+
##Students examples:
|
106
|
+
The main lorj README has a learn by examples documentation. This could help to start.
|
107
|
+
|
108
|
+
## Forj cli
|
109
|
+
forj cli is the first implementation of lorj.
|
110
|
+
|
111
|
+
Forj cli is a command line interface to start a DevOps solution in the cloud.
|
112
|
+
As forj has been developped with cloud agnostics in mind, the cli has implemented
|
113
|
+
a Cloud process to start the first box called 'Maestro'. And lorj help forj cli
|
114
|
+
to boot maestro on any kind of cloud, as soon as a controller exists.
|
115
|
+
|
116
|
+
It ensures that everything is configured on the cloud provider to boot up a box
|
117
|
+
with all features needed, like network connected to internet, image available,
|
118
|
+
NAT preconfigured, with port open, etc...
|
119
|
+
|
120
|
+
See [forj cli gem](https://rubygems.org/gems/forj)
|
data/lib/prc.rb
CHANGED
@@ -15,26 +15,96 @@
|
|
15
15
|
require 'fileutils'
|
16
16
|
require 'logger'
|
17
17
|
|
18
|
-
#
|
18
|
+
#
|
19
|
+
# PrcLib module
|
20
|
+
#
|
21
|
+
# This module helps to configure the lorj library.
|
22
|
+
# It implements also a Logging class based on logger.
|
23
|
+
#
|
24
|
+
# For details about this class capabilities, see PrcLib::Logging
|
25
|
+
#
|
19
26
|
# List of possible library settings:
|
20
|
-
# PrcLib.log
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# PrcLib.
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
27
|
+
# - PrcLib.log
|
28
|
+
#
|
29
|
+
# PrcLib::Logging object. Used internally by PrcLib logging system.
|
30
|
+
#
|
31
|
+
# This object is automatically created as soon as a message is printed out
|
32
|
+
# - PrcLib.core_level
|
33
|
+
#
|
34
|
+
# Initialize lorj debug level. from 0 to 5.
|
35
|
+
#
|
36
|
+
# ex:
|
37
|
+
#
|
38
|
+
# PrcLib.core_level = 4
|
39
|
+
# - PrcLib.pdata_path
|
40
|
+
#
|
41
|
+
# Define the private data local directory. Usually used
|
42
|
+
# for any private keys, passwords, etc...
|
43
|
+
#
|
44
|
+
# By default: ~/.config/<app_name>
|
45
|
+
#
|
46
|
+
# ex:
|
47
|
+
#
|
48
|
+
# PrcLib.pdata_path = File.join('~', '.private_myapp')
|
49
|
+
# - PrcLib.data_path
|
50
|
+
#
|
51
|
+
# Define the data local directory.
|
52
|
+
#
|
53
|
+
# By default: ~/.<app_name>
|
54
|
+
#
|
55
|
+
# ex:
|
56
|
+
#
|
57
|
+
# PrcLib.data_path = File.join('/etc', 'myapp')
|
58
|
+
#
|
59
|
+
# - PrcLib.app_name
|
60
|
+
#
|
61
|
+
# Define the application name. By default 'lorj'.
|
62
|
+
# By default, this setting configure PrcLib.data_path and PrcLib.pdata_path
|
63
|
+
# automatically, except if you set it before.
|
64
|
+
#
|
65
|
+
# ex:
|
66
|
+
#
|
67
|
+
# PrcLib.app_name = 'myapp'
|
68
|
+
# - PrcLib.app_defaults
|
69
|
+
#
|
70
|
+
# Used by Lorj::Config to identify application defaults and your application
|
71
|
+
# data model data.
|
72
|
+
#
|
73
|
+
# By default nil.
|
74
|
+
# Ex:
|
75
|
+
#
|
76
|
+
# puts PrcLib.app_defaults[:data] # To get value of the predefined :data key.
|
77
|
+
# - PrcLib.log_file
|
78
|
+
#
|
79
|
+
# Define the log file name used.
|
80
|
+
#
|
81
|
+
# By default, defined as ~/.<app_name>/<app_name>.log
|
82
|
+
# - PrcLib.level
|
83
|
+
# logger level used. It can be updated at runtime.
|
84
|
+
#
|
85
|
+
# Ex:
|
86
|
+
#
|
87
|
+
# PrcLib.level = Logger::FATAL
|
88
|
+
# - PrcLib.model
|
89
|
+
#
|
90
|
+
# Model loaded.
|
91
|
+
#
|
92
|
+
# - PrcLib.log_file
|
93
|
+
#
|
94
|
+
# Initialize a log file name instead of default one.
|
95
|
+
#
|
96
|
+
# Ex:
|
97
|
+
#
|
98
|
+
# PrcLib.log_file = "mylog.file.log"
|
99
|
+
#
|
100
|
+
# - PrcLib.controller_path
|
101
|
+
#
|
102
|
+
# Provides the default controller path.
|
103
|
+
#
|
104
|
+
# - PrcLib.process_path
|
105
|
+
#
|
106
|
+
# Provides the default process path.
|
107
|
+
#
|
38
108
|
module PrcLib
|
39
109
|
# Check if dir exists and is fully accessible (rwx)
|
40
110
|
def self.dir_exists?(path)
|
@@ -71,8 +141,7 @@ module PrcLib
|
|
71
141
|
# Define module data for lorj library configuration
|
72
142
|
class << self
|
73
143
|
attr_accessor :log, :core_level
|
74
|
-
attr_reader :pdata_path, :data_path, :app_defaults, :log_file, :level
|
75
|
-
:model
|
144
|
+
attr_reader :pdata_path, :data_path, :app_defaults, :log_file, :level
|
76
145
|
end
|
77
146
|
|
78
147
|
module_function
|
@@ -83,7 +152,7 @@ module PrcLib
|
|
83
152
|
end
|
84
153
|
|
85
154
|
def app_name
|
86
|
-
|
155
|
+
self.app_name = 'Lorj' unless @app_name
|
87
156
|
@app_name
|
88
157
|
end
|
89
158
|
|
@@ -109,10 +178,14 @@ module PrcLib
|
|
109
178
|
PrcLib.ensure_dir_exists(@data_path)
|
110
179
|
end
|
111
180
|
|
112
|
-
# TODO: Low. Be able to support multiple model.
|
113
181
|
def app_name=(v)
|
114
182
|
@app_name = v unless @app_name
|
115
|
-
|
183
|
+
end
|
184
|
+
|
185
|
+
# TODO: Low. Be able to support multiple model.
|
186
|
+
def model
|
187
|
+
@model = Lorj::Model.new if @model.nil?
|
188
|
+
@model
|
116
189
|
end
|
117
190
|
|
118
191
|
# TODO: Support for several defaults, depending on controllers loaded.
|
data/lib/prc_core_config.rb
CHANGED
@@ -212,15 +212,16 @@ module PRC
|
|
212
212
|
|
213
213
|
def layers
|
214
214
|
result = []
|
215
|
-
@config_layers.each { |
|
215
|
+
@config_layers.each { |layer| result << layer[:name] }
|
216
216
|
result
|
217
217
|
end
|
218
218
|
|
219
219
|
def to_s
|
220
220
|
data = "Configs list ordered:\n"
|
221
|
-
@config_layers.each do |
|
221
|
+
@config_layers.each do |layer|
|
222
222
|
data += format("---- Config : %s ----\noptions: ", layer[:name])
|
223
223
|
|
224
|
+
data += 'predefined, ' if layer[:init].is_a?(TrueClass)
|
224
225
|
if layer[:set]
|
225
226
|
data += 'data RW '
|
226
227
|
else
|
@@ -333,7 +334,7 @@ module PRC
|
|
333
334
|
|
334
335
|
return nil if keys.length == 0 || keys[0].nil? || config_layers[0].nil?
|
335
336
|
|
336
|
-
config_layers.each_index do |
|
337
|
+
config_layers.each_index do |index|
|
337
338
|
config = @config_layers[index][:config]
|
338
339
|
|
339
340
|
data_options = options.clone
|
@@ -381,7 +382,7 @@ module PRC
|
|
381
382
|
|
382
383
|
def _do_where?(config_layers, keys, options, data_opts)
|
383
384
|
layer_indexes = []
|
384
|
-
config_layers.each_index do |
|
385
|
+
config_layers.each_index do |index|
|
385
386
|
config = config_layers[index][:config]
|
386
387
|
|
387
388
|
data_options = options.clone
|
@@ -421,7 +422,7 @@ module PRC
|
|
421
422
|
|
422
423
|
return nil if keys.length == 0 || keys[0].nil? || config_layers[0].nil?
|
423
424
|
|
424
|
-
config_layers.each_index do |
|
425
|
+
config_layers.each_index do |layer_index|
|
425
426
|
layer = config_layers[layer_index]
|
426
427
|
|
427
428
|
data_options = options.clone
|
@@ -650,12 +651,88 @@ module PRC
|
|
650
651
|
initialize_layers(config_layers)
|
651
652
|
end
|
652
653
|
|
654
|
+
# This function add a config layer at runtime.
|
655
|
+
# The new layer added at runtime, can be removed at runtime
|
656
|
+
# with layer_remove
|
657
|
+
# The name MUST be different than other existing config layer names
|
658
|
+
#
|
659
|
+
# *Args*
|
660
|
+
# - +options+ : Hash data
|
661
|
+
# - :name : Required. Name of the layer to add
|
662
|
+
# - :index : Config position to use. 0 is the default. 0 is the first
|
663
|
+
# Config layer use by get.
|
664
|
+
# - :config : A Config instance of class type PRC::BaseConfig
|
665
|
+
# - :set : Boolean. True if is authorized to set a variable.
|
666
|
+
# - :load : Boolean. True if is authorized to load from a file.
|
667
|
+
# - :save : Boolean. True if is authorized to save to a file.
|
668
|
+
# - :file_set : Boolean. True if is authorized to change the file name.
|
669
|
+
#
|
670
|
+
# *returns*
|
671
|
+
# - true if layer is added.
|
672
|
+
# OR
|
673
|
+
# - nil : if layer name already exist
|
674
|
+
def layer_add(options)
|
675
|
+
layer = CoreConfig.define_layer(options)
|
676
|
+
|
677
|
+
layer[:init] = false # Runtime layer
|
678
|
+
|
679
|
+
index = 0
|
680
|
+
index = options[:index] if options[:index].is_a?(Fixnum)
|
681
|
+
names = []
|
682
|
+
@config_layers.each { |alayer| names << alayer[:name] }
|
683
|
+
|
684
|
+
return nil if names.include?(layer[:name])
|
685
|
+
@config_layers.insert(index, layer)
|
686
|
+
true
|
687
|
+
end
|
688
|
+
|
689
|
+
# Function to remove a runtime layer.
|
690
|
+
# You cannot remove a predefined layer, created during CoreConfig
|
691
|
+
# instanciation.
|
692
|
+
# *Args*
|
693
|
+
# - +options+ : Hash data
|
694
|
+
# - +:name+ : Name of the layer to remove.
|
695
|
+
# - +:index+: Index of the layer to remove.
|
696
|
+
#
|
697
|
+
# At least, :name or :index is required.
|
698
|
+
# If both; :name and :index are set, :name is used.
|
699
|
+
# *return*
|
700
|
+
# - true if layer name is removed.
|
701
|
+
# OR
|
702
|
+
# - nil : if not found or invalid.
|
703
|
+
def layer_remove(options)
|
704
|
+
index = layer_index(options[:name])
|
705
|
+
index = options[:index] if index.nil?
|
706
|
+
|
707
|
+
return nil if index.nil?
|
708
|
+
|
709
|
+
layer = @config_layers[index]
|
710
|
+
|
711
|
+
return nil if layer.nil? || layer[:init]
|
712
|
+
|
713
|
+
@config_layers.delete_at(index)
|
714
|
+
true
|
715
|
+
end
|
716
|
+
|
717
|
+
# Function to define layer options.
|
718
|
+
# By default, :set is true and :config is attached to a new PRC::BaseConfig
|
719
|
+
# instance.
|
720
|
+
#
|
721
|
+
# Supported options:
|
722
|
+
# - :config : optional. See `Defining Config layer instance` for details
|
723
|
+
# - :name : required. String. Name of the config layer.
|
724
|
+
# Warning! unique name on layers is no tested.
|
725
|
+
# - :set : boolean. True if authorized. Default is True.
|
726
|
+
# - :load : boolean. True if authorized. Default is False.
|
727
|
+
# - :save : boolean. True if authorized. Default is False.
|
728
|
+
# - :file_set : boolean. True if authorized to update a filename.
|
729
|
+
# Default is False.
|
653
730
|
def self.define_layer(options = {})
|
654
731
|
attributes = [:name, :config, :set, :load, :save, :file_set]
|
655
732
|
|
656
733
|
layer = {}
|
657
734
|
|
658
|
-
attributes.each do |
|
735
|
+
attributes.each do |attribute|
|
659
736
|
if options.key?(attribute)
|
660
737
|
layer[attribute] = options[attribute]
|
661
738
|
else
|
@@ -674,6 +751,48 @@ module PRC
|
|
674
751
|
layer
|
675
752
|
end
|
676
753
|
|
754
|
+
# layer_indexes function
|
755
|
+
#
|
756
|
+
# * *Args*
|
757
|
+
# - +:name+ : layer to identify.
|
758
|
+
#
|
759
|
+
# * *Returns*
|
760
|
+
# first index found or nil.
|
761
|
+
#
|
762
|
+
def layer_indexes(names)
|
763
|
+
names = [names] if names.is_a?(String)
|
764
|
+
return nil unless names.is_a?(Array)
|
765
|
+
|
766
|
+
layers = []
|
767
|
+
|
768
|
+
names.each do |name|
|
769
|
+
index = layer_index(name)
|
770
|
+
layers << index unless index.nil?
|
771
|
+
end
|
772
|
+
return layers if layers.length > 0
|
773
|
+
nil
|
774
|
+
end
|
775
|
+
|
776
|
+
# layer_index function
|
777
|
+
#
|
778
|
+
# * *Args*
|
779
|
+
# - +:name+ : layer to identify.
|
780
|
+
#
|
781
|
+
# * *Returns*
|
782
|
+
# first index found or nil.
|
783
|
+
#
|
784
|
+
def layer_index(name)
|
785
|
+
return nil unless name.is_a?(String)
|
786
|
+
return nil if @config_layers.nil?
|
787
|
+
|
788
|
+
@config_layers.each_index do |index|
|
789
|
+
return index if @config_layers[index][:name] == name
|
790
|
+
end
|
791
|
+
nil
|
792
|
+
end
|
793
|
+
|
794
|
+
private
|
795
|
+
|
677
796
|
# Function to initialize Config layers.
|
678
797
|
#
|
679
798
|
# *Args*
|
@@ -705,7 +824,7 @@ module PRC
|
|
705
824
|
def initialize_layers(config_layers = nil)
|
706
825
|
@config_layers = []
|
707
826
|
|
708
|
-
config_layers.each do |
|
827
|
+
config_layers.each do |layer|
|
709
828
|
next unless layer.is_a?(Hash) && layer.key?(:config) &&
|
710
829
|
layer[:config].is_a?(BaseConfig)
|
711
830
|
next unless layer[:name].is_a?(String)
|
@@ -714,55 +833,18 @@ module PRC
|
|
714
833
|
@config_layers.reverse!
|
715
834
|
end
|
716
835
|
|
836
|
+
# Function to initialize a predefined layer
|
837
|
+
# Used internally by initialize_layers.
|
717
838
|
def initialize_layer(layer)
|
718
839
|
newlayer = { :config => layer[:config], :name => layer[:name] }
|
719
840
|
newlayer[:set] = layer[:set].boolean? ? layer[:set] : true
|
720
841
|
newlayer[:load] = layer[:load].boolean? ? layer[:load] : false
|
721
842
|
newlayer[:save] = layer[:save].boolean? ? layer[:save] : false
|
722
843
|
newlayer[:file_set] = layer[:file_set].boolean? ? layer[:file_set] : false
|
844
|
+
newlayer[:init] = true
|
723
845
|
newlayer
|
724
846
|
end
|
725
847
|
|
726
|
-
# layer_indexes function
|
727
|
-
#
|
728
|
-
# * *Args*
|
729
|
-
# - +:name+ : layer to identify.
|
730
|
-
#
|
731
|
-
# * *Returns*
|
732
|
-
# first index found or nil.
|
733
|
-
#
|
734
|
-
def _layer_indexes(names)
|
735
|
-
names = [names] if names.is_a?(String)
|
736
|
-
return nil unless names.is_a?(Array)
|
737
|
-
|
738
|
-
layers = []
|
739
|
-
|
740
|
-
names.each do | name |
|
741
|
-
index = layer_index(name)
|
742
|
-
layers << index unless index.nil?
|
743
|
-
end
|
744
|
-
return layers if layers.length > 0
|
745
|
-
nil
|
746
|
-
end
|
747
|
-
|
748
|
-
# layer_index function
|
749
|
-
#
|
750
|
-
# * *Args*
|
751
|
-
# - +:name+ : layer to identify.
|
752
|
-
#
|
753
|
-
# * *Returns*
|
754
|
-
# first index found or nil.
|
755
|
-
#
|
756
|
-
def layer_index(name)
|
757
|
-
return nil unless name.is_a?(String)
|
758
|
-
return nil if @config_layers.nil?
|
759
|
-
|
760
|
-
@config_layers.each_index do | index |
|
761
|
-
return index if @config_layers[index][:name] == name
|
762
|
-
end
|
763
|
-
nil
|
764
|
-
end
|
765
|
-
|
766
848
|
# Check and returns values of options required and optionnal.
|
767
849
|
#
|
768
850
|
# * *Args*
|
@@ -781,12 +863,12 @@ module PRC
|
|
781
863
|
|
782
864
|
result = [[], []]
|
783
865
|
|
784
|
-
required.each do |
|
866
|
+
required.each do |key|
|
785
867
|
return nil unless options.key?(key)
|
786
868
|
result[0] << options[key]
|
787
869
|
end
|
788
870
|
|
789
|
-
optionnal.each { |
|
871
|
+
optionnal.each { |key| result[1] << options[key] }
|
790
872
|
|
791
873
|
result
|
792
874
|
end
|
@@ -837,7 +919,7 @@ module PRC
|
|
837
919
|
|
838
920
|
# Setting indexes from names or indexes.
|
839
921
|
def _set_indexes(result)
|
840
|
-
names_indexes =
|
922
|
+
names_indexes = layer_indexes(result[1][1])
|
841
923
|
# replaced indexes by names indexes if exists.
|
842
924
|
result[1][0] = names_indexes if names_indexes
|
843
925
|
result[1].delete_at(1)
|
@@ -846,7 +928,7 @@ module PRC
|
|
846
928
|
def _set_data_opts(result)
|
847
929
|
data_opts = []
|
848
930
|
|
849
|
-
result[0][0].each_index do |
|
931
|
+
result[0][0].each_index do |layer_index|
|
850
932
|
data_options = result[1][0][layer_index] if result[1][0].is_a?(Array)
|
851
933
|
data_options = {} unless data_options.is_a?(Hash)
|
852
934
|
data_opts << data_options
|
@@ -863,7 +945,7 @@ module PRC
|
|
863
945
|
config_layers = @config_layers
|
864
946
|
else
|
865
947
|
config_layers = []
|
866
|
-
result[1][0].each do |
|
948
|
+
result[1][0].each do |index|
|
867
949
|
config_layers << @config_layers[index] if index.is_a?(Fixnum)
|
868
950
|
end
|
869
951
|
config_layers = @config_layers if config_layers.length == 0
|
@@ -54,9 +54,9 @@ module HPCompute
|
|
54
54
|
|
55
55
|
result = []
|
56
56
|
addresses = oComputeConnect.addresses.all
|
57
|
-
addresses.each do |
|
57
|
+
addresses.each do |oElem|
|
58
58
|
is_found = true
|
59
|
-
sQuery.each do |
|
59
|
+
sQuery.each do |key, value|
|
60
60
|
if !oElem.attributes.key?(key) || oElem.attributes[key] != value
|
61
61
|
is_found = false
|
62
62
|
break
|
@@ -76,7 +76,7 @@ module HPCompute
|
|
76
76
|
addresses = oComputeConnect.addresses.all
|
77
77
|
address = nil
|
78
78
|
# Search for an available IP
|
79
|
-
addresses.each do |
|
79
|
+
addresses.each do |oElem|
|
80
80
|
if oElem.fixed_ip.nil?
|
81
81
|
address = oElem
|
82
82
|
break
|
@@ -74,12 +74,12 @@ class Hpcloud
|
|
74
74
|
obj_needs :data, :addr_map, :mapping => :remote_ip_prefix
|
75
75
|
obj_needs :data, :sg_id, :mapping => :security_group_id
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
77
|
+
def_attr_mapping :dir, :direction
|
78
|
+
def_attr_mapping :proto, :protocol
|
79
|
+
def_attr_mapping :port_min, :port_range_min
|
80
|
+
def_attr_mapping :port_max, :port_range_max
|
81
|
+
def_attr_mapping :addr_map, :remote_ip_prefix
|
82
|
+
def_attr_mapping :sg_id, :security_group_id
|
83
83
|
|
84
84
|
define_obj :keypairs
|
85
85
|
|
@@ -95,11 +95,11 @@ class Hpcloud
|
|
95
95
|
obj_needs :data, :external_gateway_id, :mapping => [:external_gateway_info,
|
96
96
|
'network_id']
|
97
97
|
|
98
|
-
|
98
|
+
def_attr_mapping :gateway_network_id, [:external_gateway_info, 'network_id']
|
99
99
|
|
100
100
|
# ************************************ SERVER Object
|
101
101
|
define_obj :server
|
102
|
-
|
102
|
+
def_attr_mapping :status, :state
|
103
103
|
attr_value_mapping :create, 'BUILD'
|
104
104
|
attr_value_mapping :boot, :boot
|
105
105
|
attr_value_mapping :active, 'ACTIVE'
|
@@ -108,12 +108,12 @@ class Hpcloud
|
|
108
108
|
define_obj :server_log
|
109
109
|
|
110
110
|
# Excon::Response object type
|
111
|
-
|
111
|
+
def_attr_mapping :output, 'output'
|
112
112
|
|
113
113
|
# ************************************* Public IP Object
|
114
114
|
define_obj :public_ip
|
115
|
-
|
116
|
-
|
115
|
+
def_attr_mapping :server_id, :instance_id
|
116
|
+
def_attr_mapping :public_ip, :ip
|
117
117
|
|
118
118
|
# defines setup Cloud data (:account => true for setup)
|
119
119
|
define_data(:account_id,
|
@@ -368,7 +368,7 @@ class HpcloudController # rubocop: disable Metrics/ClassLength
|
|
368
368
|
def query_each(oFogObject)
|
369
369
|
case oFogObject.class.to_s
|
370
370
|
when 'Fog::HP::Network::Networks'
|
371
|
-
oFogObject.each { |
|
371
|
+
oFogObject.each { |value| yield(value) }
|
372
372
|
else
|
373
373
|
controller_error "'%s' is not a valid list for 'each'",
|
374
374
|
oFogObject.class
|
@@ -439,7 +439,7 @@ class HpcloudController # rubocop: disable Metrics/ClassLength
|
|
439
439
|
# not know why...
|
440
440
|
search_services = services.rh_get(:service_catalog)
|
441
441
|
service = nil
|
442
|
-
service_to_find.each do |
|
442
|
+
service_to_find.each do |sServiceElem|
|
443
443
|
if search_services.key?(sServiceElem)
|
444
444
|
service = sServiceElem
|
445
445
|
break
|
@@ -450,7 +450,7 @@ class HpcloudController # rubocop: disable Metrics/ClassLength
|
|
450
450
|
service_to_find if service.nil?
|
451
451
|
result = services.rh_get(:service_catalog, service).keys
|
452
452
|
result.delete('name')
|
453
|
-
result.each_index do |
|
453
|
+
result.each_index do |iIndex|
|
454
454
|
result[iIndex] = result[iIndex].to_s if result[iIndex].is_a?(Symbol)
|
455
455
|
end
|
456
456
|
return result
|
@@ -36,10 +36,10 @@ module HPNetwork
|
|
36
36
|
|
37
37
|
def self.create_subnetwork(oNetworkConnect, oNetwork, name)
|
38
38
|
oNetworkConnect.subnets.create(
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
:network_id => oNetwork.id,
|
40
|
+
:name => name,
|
41
|
+
:cidr => get_next_subnet(oNetworkConnect),
|
42
|
+
:ip_version => '4'
|
43
43
|
)
|
44
44
|
end
|
45
45
|
|