lorj 0.2.0 → 1.0.0

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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +46 -0
  4. data/Gemfile +15 -15
  5. data/README.md +22 -17
  6. data/Rakefile +12 -2
  7. data/bin/cloud_test.rb +13 -65
  8. data/example/students_1/process/students.rb +39 -0
  9. data/example/students_1/students.rb +22 -5
  10. data/example/students_2/process/students.rb +48 -0
  11. data/example/students_2/students.rb +39 -16
  12. data/example/students_3/controller/yaml_students.rb +50 -43
  13. data/example/students_3/controller/yaml_students_controller.rb +100 -87
  14. data/example/students_3/process/students.rb +161 -97
  15. data/example/students_3/students.rb +85 -56
  16. data/example/yaml_students/students.rb +40 -40
  17. data/example/yaml_students/yaml_students.rb +103 -90
  18. data/lib/core/core.rb +356 -696
  19. data/lib/core/core_controller.rb +227 -0
  20. data/lib/core/core_internal.rb +339 -0
  21. data/lib/core/core_model.rb +328 -0
  22. data/lib/core/core_object_data.rb +330 -0
  23. data/lib/core/core_object_params.rb +230 -0
  24. data/lib/core/core_process.rb +391 -0
  25. data/lib/core/core_process_setup.rb +353 -0
  26. data/lib/core/core_setup_ask.rb +241 -0
  27. data/lib/core/core_setup_encrypt.rb +146 -0
  28. data/lib/core/core_setup_init.rb +229 -0
  29. data/lib/core/core_setup_list.rb +160 -0
  30. data/lib/core/definition.rb +647 -469
  31. data/lib/core/definition_internal.rb +264 -308
  32. data/lib/core/lorj_basecontroller.rb +95 -0
  33. data/lib/core/lorj_basedefinition.rb +307 -0
  34. data/lib/core/lorj_baseprocess.rb +265 -0
  35. data/lib/core/lorj_data.rb +583 -0
  36. data/lib/core/lorj_keypath.rb +119 -0
  37. data/lib/core_process/cloud/process/common.rb +63 -0
  38. data/lib/core_process/cloud/process/connection.rb +93 -0
  39. data/lib/core_process/cloud/process/external_network.rb +94 -0
  40. data/lib/core_process/cloud/process/flavor.rb +99 -0
  41. data/lib/core_process/cloud/process/images.rb +87 -0
  42. data/lib/core_process/cloud/process/internet_network.rb +34 -0
  43. data/lib/core_process/cloud/process/internet_server.rb +30 -0
  44. data/lib/core_process/cloud/process/keypairs.rb +276 -0
  45. data/lib/core_process/cloud/process/network.rb +108 -0
  46. data/lib/core_process/cloud/process/public_ip.rb +100 -0
  47. data/lib/core_process/cloud/process/router.rb +260 -0
  48. data/lib/core_process/cloud/process/rules.rb +120 -0
  49. data/lib/core_process/cloud/process/security_groups.rb +121 -0
  50. data/lib/core_process/cloud/process/server.rb +127 -0
  51. data/lib/core_process/cloud/process/server_log.rb +35 -0
  52. data/lib/core_process/cloud/process/subnetwork.rb +108 -0
  53. data/lib/core_process/cloud_process.rb +30 -0
  54. data/lib/logging.rb +298 -0
  55. data/lib/lorj/version.rb +18 -1
  56. data/lib/lorj.rb +58 -18
  57. data/lib/lorj_account.rb +556 -0
  58. data/lib/lorj_config.rb +468 -0
  59. data/lib/lorj_defaults.rb +278 -0
  60. data/lib/prc.rb +136 -104
  61. data/lib/prc_base_config.rb +285 -0
  62. data/lib/prc_core_config.rb +878 -0
  63. data/lib/prc_section_config.rb +57 -0
  64. data/lib/providers/hpcloud/compute.rb +81 -93
  65. data/lib/providers/hpcloud/hpcloud.rb +462 -0
  66. data/lib/providers/hpcloud/network.rb +96 -98
  67. data/lib/providers/hpcloud/security_groups.rb +41 -40
  68. data/lib/providers/mock/mock.rb +144 -0
  69. data/lib/providers/openstack/openstack.rb +45 -0
  70. data/lib/providers/templates/compute.rb +21 -23
  71. data/lib/providers/templates/mycloud.rb +72 -0
  72. data/lib/providers/templates/network.rb +11 -12
  73. data/lib/rh.rb +339 -0
  74. data/lorj-spec/defaults.yaml +4 -0
  75. data/lorj.gemspec +6 -0
  76. data/spec/00_lorj_log_spec.rb +53 -0
  77. data/spec/01_hash_rh_spec.rb +243 -0
  78. data/spec/02_prc_base_config_spec.rb +216 -0
  79. data/spec/04_prc_core_config_spec.rb +83 -0
  80. data/spec/11_lorj_config_spec.rb +263 -0
  81. data/spec/12_lorj_account_spec.rb +181 -0
  82. metadata +76 -28
  83. data/Gemfile.lock +0 -37
  84. data/example/students_1/process/Students.rb +0 -20
  85. data/example/students_2/process/Students.rb +0 -27
  86. data/example/students_4/controller/yaml_students.rb +0 -82
  87. data/example/students_4/controller/yaml_students_controller.rb +0 -141
  88. data/example/students_4/process/students.rb +0 -112
  89. data/example/students_4/students.rb +0 -103
  90. data/lib/core/lorj-basecontroller.rb +0 -90
  91. data/lib/core/lorj-basedefinition.rb +0 -1139
  92. data/lib/core/lorj-baseprocess.rb +0 -236
  93. data/lib/core/lorj-data.rb +0 -567
  94. data/lib/core/lorj-keypath.rb +0 -115
  95. data/lib/core_process/CloudProcess.rb +0 -337
  96. data/lib/core_process/global_process.rb +0 -502
  97. data/lib/core_process/network_process.rb +0 -605
  98. data/lib/prc-account.rb +0 -339
  99. data/lib/prc-config.rb +0 -1030
  100. data/lib/prc-logging.rb +0 -261
  101. data/lib/providers/hpcloud/Hpcloud.rb +0 -426
  102. data/lib/providers/mock/Mock.rb +0 -141
  103. data/lib/providers/openstack/Openstack.rb +0 -47
  104. data/lib/providers/templates/core.rb +0 -61
  105. data/spec/forj-account_spec.rb +0 -75
  106. data/spec/forj-config_spec.rb +0 -196
data/lib/prc-logging.rb DELETED
@@ -1,261 +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
-
19
- # create a forj.log file in ~/.hpcloud/forj.log
20
-
21
- require 'rubygems'
22
- require 'logger'
23
- require 'ansi'
24
- require 'ansi/logger'
25
-
26
- #
27
- # PrcLib module
28
- #
29
- # PrcLib Implements a Logging class based on logger.
30
- #
31
- # For details about this class capabilities, see PrcLib::Logging
32
- #
33
- # # To use the Prc::Logging system, do the following:
34
- # require 'PrcLib'
35
- #
36
- # # To configure logging system:
37
- # PrcLib.app_name = 'config/app' # Define application data path as ~/.<app_name>. Ex: 'config/app' will use ~/.config/app
38
- # PrcLib.log_file = 'app.log' # Relative path to the log file name stored in the Application data path. Here, ~/.config/app/app.log
39
- # PrcLib.level = Logger::FATAL # Define printout debug level. Can be any Logger predefined value.
40
- #
41
- # # To log some information:
42
- # PrcLib.debug('My debug message')
43
- # PrcLib.info('My info message')
44
- # PrcLib.warning('my warning')
45
- # PrcLib.error('my error')
46
- # PrcLib.fatal(2, "Fatal error, with return code = 2)
47
- # PrcLib.message('Only printout message')
48
- #
49
- # # You can printout some instant message to the terminal, not logged.
50
- # # This is useful before any action that will take time to be executed.
51
- # # It is inform the end user that something is still running, which means
52
- # # the application is not frozen
53
- # PrcLib.state("Running a long task")
54
- # # The next message will replace the previous state message.
55
- # sleep(10)
56
- # PrcLib.info("The long task has been executed successfully.")
57
- #
58
- # # You can change the logger level with PrcLib.level
59
- # PrcLib.level = Logger::DEBUG
60
- #
61
- # # You can just print high level message (print without \n) if PrcLib.level is not DEBUG or INFO.
62
- # PrcLib.high_level_msg("Print a message, not logged, if level is not DEBUG or INFO")
63
- #
64
- # Enjoy!
65
- module PrcLib
66
-
67
- # Class used to create 2 logger object, in order to keep track of error in a log file and change log output to OUTPUT on needs (option flags).
68
- # The idea is that everytime, if you did not set the debug level mode, you can refer to the log file which is
69
- # already configured with Logger::DEBUG level.
70
- #
71
- # As well, sometimes, you do not want to keep track on messages that are just to keep informed the end user about activity.
72
- # So, this object implement 2 Logger objects.
73
- # * One for log file
74
- # * One for print out.
75
- #
76
- # Everytime you log a message with Logging, it is printed out if the level permits and stored everytime in the log file, never mind about Logger level set.
77
- # In several cases, messages are printed out, but not stored in the log file.
78
- #
79
- # See Logging functions for details.
80
- #
81
- class Logging
82
-
83
- attr_reader :level
84
-
85
- # Initialize Logging instance
86
- # The log file name is defined by PrcLib.log_file
87
- # The log path is defined by PrcLib.app_name and will be kept as ~/.<PrcLib.app_name>
88
- # The log level is defined by PrcLib.level. It will update only log print out.
89
- # Depending on levels, messages are prefixed by colored 'ERROR!!!', 'FATAL!!!', 'WARNING' or <LEVEL NAME>
90
- def initialize()
91
-
92
- if not PrcLib.app_name
93
- PrcLib.app_name = "Lorj"
94
- end
95
-
96
- if not PrcLib.data_path
97
- PrcLib.data_path = File.expand_path(File.join("~", ".%s" % PrcLib.app_name))
98
- end
99
-
100
- sLogFile = PrcLib.log_file
101
- sLogFile = File.join(PrcLib.data_path, "%s.log" % PrcLib.app_name) if PrcLib.log_file.nil?
102
-
103
- @oFileLogger = Logger.new(sLogFile, 'weekly')
104
- @oFileLogger.level = Logger::DEBUG
105
- @oFileLogger.formatter = proc do |severity, datetime, progname, msg|
106
- "#{progname} : #{datetime}: #{severity}: #{msg} \n"
107
- end
108
-
109
- @oOutLogger = Logger.new(STDOUT)
110
- @level = (PrcLib.level.nil? ? Logger::WARN : PrcLib.level)
111
- @oOutLogger.level = @level
112
- @oOutLogger.formatter = proc do |severity, datetime, progname, msg|
113
- case severity
114
- when 'ANY'
115
- str = "#{msg} \n"
116
- when "ERROR", "FATAL"
117
- str = ANSI.bold(ANSI.red("#{severity}!!!")) + ": #{msg} \n"
118
- when "WARN"
119
- str = ANSI.bold(ANSI.yellow("WARNING")) + ": #{msg} \n"
120
- else
121
- str = "#{severity}: #{msg} \n"
122
- end
123
- str
124
- end
125
- PrcLib.log_file = sLogFile
126
- end
127
-
128
- # Is Logging print out level is info?
129
- def info?
130
- return(@oOutLogger.info?)
131
- end
132
-
133
- # Is Logging print out level is debug?
134
- def debug?
135
- return(@oOutLogger.debug?)
136
- end
137
-
138
- # Is Logging print out level is error?
139
- def error?
140
- return(@oOutLogger.error?)
141
- end
142
-
143
- # Is Logging print out level is fatal?
144
- def fatal?
145
- return(@oOutLogger.fatal?)
146
- end
147
-
148
- # Log to STDOUT and Log file and INFO class message
149
- def info(message)
150
- @oOutLogger.info(message + ANSI.clear_line)
151
- @oFileLogger.info(message)
152
- end
153
-
154
- # Log to STDOUT and Log file and DEBUG class message
155
- def debug(message)
156
- @oOutLogger.debug(message + ANSI.clear_line)
157
- @oFileLogger.debug(message)
158
- end
159
-
160
- # Log to STDOUT and Log file and ERROR class message
161
- def error(message)
162
- @oOutLogger.error(message + ANSI.clear_line)
163
- @oFileLogger.error(message)
164
- end
165
-
166
- # Log to STDOUT and Log file and FATAL class message
167
- # fatal retrieve the caller list of functions and save it to the log file if the exception class is given.
168
- # The exception class should provide message and backtrace.
169
- def fatal(message, e)
170
- @oOutLogger.fatal(message + ANSI.clear_line)
171
- @oFileLogger.fatal("%s\n%s\n%s" % [message, e.message, e.backtrace.join("\n")]) if e
172
- @oFileLogger.fatal(message)
173
- end
174
-
175
- # Log to STDOUT and Log file and WARNING class message
176
- def warn(message)
177
- @oOutLogger.warn(message + ANSI.clear_line)
178
- @oFileLogger.warn(message)
179
- end
180
-
181
- # set STDOUT logger level
182
- def set_level(level)
183
- @level = level
184
- @oOutLogger.level = level
185
- end
186
-
187
- # Print out a message, not logged in the log file. This message is printed out systematically as not taking care of logger level.
188
- def unknown(message)
189
- @oOutLogger.unknown(message + ANSI.clear_line)
190
- end
191
-
192
- end
193
-
194
- module_function
195
-
196
- # Create a Logging object if missing and return it.
197
- # Used internally by other functions
198
- def log_object()
199
- if PrcLib.log.nil?
200
- PrcLib.log = PrcLib::Logging.new
201
- else
202
- PrcLib.log
203
- end
204
- end
205
-
206
- # Print out a message, not logged in the log file. This message is printed out systematically as not taking care of logger level.
207
- def message(message)
208
- log_object.unknown(message)
209
- end
210
-
211
- # Log to STDOUT and Log file and INFO class message
212
- def info(message)
213
- log_object.info(message)
214
- nil
215
- end
216
-
217
- # Log to STDOUT and Log file and DEBUG class message
218
- def debug(message)
219
- log_object.debug(message)
220
- nil
221
- end
222
-
223
- # Log to STDOUT and Log file and WARNING class message
224
- def warning(message)
225
- log_object.warn(message)
226
- nil
227
- end
228
-
229
- # Log to STDOUT and Log file and ERROR class message
230
- def error(message)
231
- log_object.error(message)
232
- nil
233
- end
234
-
235
- # Log to STDOUT and Log file and FATAL class message then exit the application with a return code.
236
- # fatal retrieve the caller list of functions and save it to the log file if the exception class is given.
237
- # The exception class should provide message and backtrace.
238
- def fatal(rc, message, e = nil)
239
- log_object.fatal(message, e)
240
- puts 'Issues found. Please fix it and retry. Process aborted.'
241
- exit rc
242
- end
243
-
244
- def set_level(level)
245
- log_object.set_level(level)
246
- nil
247
- end
248
-
249
- def state(message)
250
- print("%s ...%s\r" % [message, ANSI.clear_line]) if log_object.level <= Logger::INFO
251
- nil
252
- end
253
-
254
- # Not DEBUG and not INFO. Just printed to the output.
255
- def high_level_msg(message)
256
-
257
- print ("%s" % [message]) if log_object.level > 1
258
- nil
259
- end
260
-
261
- end
@@ -1,426 +0,0 @@
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
-
18
- # This class describes how to process some actions, and will do everything prior
19
- # this task to make it to work.
20
-
21
- require 'fog' # We use fog to access HPCloud
22
-
23
- $HPCLOUD_PATH = File.expand_path(File.dirname(__FILE__))
24
-
25
- require File.join($HPCLOUD_PATH, "compute.rb")
26
- require File.join($HPCLOUD_PATH, "network.rb")
27
- require File.join($HPCLOUD_PATH, "security_groups.rb")
28
-
29
- # Defines Meta HPCloud object
30
- class Hpcloud
31
-
32
- define_obj :services
33
- obj_needs :data, :account_id, :mapping => :hp_access_key
34
- obj_needs :data, :account_key, :mapping => :hp_secret_key
35
- obj_needs :data, :auth_uri, :mapping => :hp_auth_uri
36
- obj_needs :data, :tenant, :mapping => :hp_tenant_id
37
- obj_needs :data, ":excon_opts/:connect_timeout", :default_value => 30
38
- obj_needs :data, ":excon_opts/:read_timeout", :default_value => 240
39
- obj_needs :data, ":excon_opts/:write_timeout", :default_value => 240
40
-
41
- # Defines Object structure and function stored on the Hpcloud class object.
42
- # Compute Object
43
- define_obj :compute_connection
44
- # Defines Data used by compute.
45
-
46
- obj_needs :data, :account_id, :mapping => :hp_access_key
47
- obj_needs :data, :account_key, :mapping => :hp_secret_key
48
- obj_needs :data, :auth_uri, :mapping => :hp_auth_uri
49
- obj_needs :data, :tenant, :mapping => :hp_tenant_id
50
- obj_needs :data, :compute, :mapping => :hp_avl_zone
51
-
52
- define_obj :network_connection
53
- obj_needs :data, :account_id, :mapping => :hp_access_key
54
- obj_needs :data, :account_key, :mapping => :hp_secret_key
55
- obj_needs :data, :auth_uri, :mapping => :hp_auth_uri
56
- obj_needs :data, :tenant, :mapping => :hp_tenant_id
57
- obj_needs :data, :network, :mapping => :hp_avl_zone
58
-
59
- # Forj predefine following query mapping, used by ForjProcess
60
- # id => id, name => name
61
- # If we need to add another mapping, add
62
- # query_mapping :id => :MyID
63
- # If the query is not push through and Hash object, the Provider
64
- # will needs to create his own mapping function.
65
- define_obj :network
66
- query_mapping :external, :router_external
67
-
68
- define_obj :rule
69
- obj_needs :data, :dir, :mapping => :direction
70
- attr_value_mapping :IN, 'ingress'
71
- attr_value_mapping :OUT, 'egress'
72
-
73
- obj_needs :data, :proto, :mapping => :protocol
74
- obj_needs :data, :port_min, :mapping => :port_range_min
75
- obj_needs :data, :port_max, :mapping => :port_range_max
76
- obj_needs :data, :addr_map, :mapping => :remote_ip_prefix
77
- obj_needs :data, :sg_id, :mapping => :security_group_id
78
-
79
- get_attr_mapping :dir, :direction
80
- get_attr_mapping :proto, :protocol
81
- get_attr_mapping :port_min, :port_range_min
82
- get_attr_mapping :port_max, :port_range_max
83
- get_attr_mapping :addr_map, :remote_ip_prefix
84
- get_attr_mapping :sg_id, :security_group_id
85
-
86
- define_obj :keypairs
87
-
88
- undefine_attribute :id # Do not return any predefined ID
89
-
90
- # ************************************ Router Object
91
- define_obj :router
92
-
93
- obj_needs_optional
94
- obj_needs :data, :router_name, :mapping => :name
95
- # The FORJ gateway_network_id is extracted from Fog::HP::Network::Router[:external_gateway_info][:network_id]
96
- obj_needs :data, :external_gateway_id, :mapping => [:external_gateway_info, 'network_id' ]
97
-
98
- get_attr_mapping :gateway_network_id, [:external_gateway_info, 'network_id']
99
-
100
- # ************************************ SERVER Object
101
- define_obj :server
102
- get_attr_mapping :status, :state
103
- attr_value_mapping :create, "BUILD"
104
- attr_value_mapping :boot, :boot
105
- attr_value_mapping :active, "ACTIVE"
106
-
107
- # ************************************ SERVER log Object
108
- define_obj :server_log
109
-
110
- # Excon::Response object type
111
- get_attr_mapping :output, "output"
112
-
113
- # ************************************* Public IP Object
114
- define_obj :public_ip
115
- get_attr_mapping :server_id, :instance_id
116
- get_attr_mapping :public_ip, :ip
117
-
118
- # defines setup Cloud data (:account => true for setup)
119
- define_data(:account_id, {
120
- :account => true,
121
- :desc => 'HPCloud Access Key (From horizon, user drop down, manage keys)',
122
- :validate => /^[A-Z0-9]*$/
123
- })
124
- define_data(:account_key, {
125
- :account => true,
126
- :desc => 'HPCloud secret Key (From horizon, user drop down, manage keys)',
127
- :encrypted => false,
128
- :validate => /^.+/
129
- })
130
- define_data(:auth_uri, {
131
- :account => true,
132
- :desc => 'HPCloud Authentication service URL (default is HP Public cloud)',
133
- :validate => /^http(s)?:\/\/.*$/,
134
- :default_value => "https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/"
135
- })
136
- define_data(:tenant, {
137
- :account => true,
138
- :desc => 'HPCloud Tenant ID (from horizon, identity, projecs, Project ID)',
139
- :validate => /^[0-9]+$/
140
- })
141
-
142
- define_data(:compute, {
143
- :account => true,
144
- :desc => 'HPCloud Compute service zone (Ex: region-a.geo-1)',
145
- :depends_on => [:account_id, :account_key, :auth_uri,:tenant ],
146
- :list_values => {
147
- :query_type => :controller_call,
148
- :object => :services,
149
- :query_call => :get_services,
150
- :query_params => { :list_services => [:Compute, :compute] },
151
- :validate => :list_strict
152
- }
153
- })
154
-
155
- define_data(:network, {
156
- :account => true,
157
- :desc => 'HPCloud Network service zone (Ex: region-a.geo-1)',
158
- :depends_on => [:account_id, :account_key, :auth_uri,:tenant ],
159
- :list_values => {
160
- :query_type => :controller_call,
161
- :object => :services ,
162
- :query_call => :get_services,
163
- :query_params => { :list_services => [:Networking, :network] },
164
- :validate => :list_strict
165
- }
166
- })
167
-
168
- data_value_mapping 'xsmall', "standard.xsmall"
169
- data_value_mapping 'small', "standard.small"
170
- data_value_mapping 'medium', "standard.medium"
171
- data_value_mapping 'large', "standard.large"
172
- data_value_mapping 'xlarge', "standard.xlarge"
173
-
174
-
175
- end
176
-
177
- # Following class describe how FORJ should handle HP Cloud objects.
178
- # Except Cloud connection, all HPCloud objects management are described/called in HP* modules.
179
- class HpcloudController
180
-
181
- def connect(sObjectType, hParams)
182
- case sObjectType
183
- when :services
184
- Fog::HP.authenticate_v2(hParams[:hdata], hParams[:excon_opts])
185
- when :compute_connection
186
- Fog::Compute.new(hParams[:hdata].merge({:provider => :hp,:version => 'v2'}))
187
- when :network_connection
188
- Fog::HP::Network.new(hParams[:hdata])
189
- else
190
- Error "'%s' is not a valid object for 'connect'" % sObjectType
191
- end
192
- end
193
-
194
- def create(sObjectType, hParams)
195
- case sObjectType
196
- when :public_ip
197
- required?(hParams, :compute_connection)
198
- required?(hParams, :server)
199
- HPCompute.server_assign_address(hParams[:compute_connection], hParams[:server])
200
- when :server
201
- required?(hParams, :compute_connection)
202
- required?(hParams, :image)
203
- required?(hParams, :network)
204
- required?(hParams, :flavor)
205
- required?(hParams, :keypairs)
206
- required?(hParams, :security_groups)
207
- required?(hParams, :server_name)
208
- HPCompute.create_server(
209
- hParams[:compute_connection],
210
- hParams[:server_name], hParams[:security_groups],
211
- hParams[:image], hParams[:network],
212
- hParams[:flavor], hParams[:keypairs],
213
- hParams[:user_data], hParams[:meta_data]
214
- )
215
- when :image
216
- required?(hParams, :compute_connection)
217
- required?(hParams, :image_name)
218
- HPCompute.get_image(hParams[:compute_connection], hParams[:image_name])
219
- when :network
220
- required?(hParams, :network_connection)
221
- required?(hParams, :network_name)
222
- HPNetwork.create_network(hParams[:network_connection], hParams[:network_name])
223
- when :subnetwork
224
- required?(hParams, :network_connection)
225
- required?(hParams, :network)
226
- required?(hParams, :subnetwork_name)
227
- HPNetwork.create_subnetwork(hParams[:network_connection], hParams[:network], hParams[:subnetwork_name])
228
- when :security_groups
229
- required?(hParams, :network_connection)
230
- required?(hParams, :security_group)
231
- HPSecurityGroups.create_sg(hParams[:network_connection], hParams[:security_group], hParams[:sg_desc])
232
- when :keypairs
233
- required?(hParams, :compute_connection)
234
- required?(hParams, :keypair_name)
235
- required?(hParams, :public_key)
236
- HPKeyPairs.create_keypair(hParams[:compute_connection], hParams[:keypair_name], hParams[:public_key])
237
- when :router
238
- required?(hParams, :network_connection)
239
- required?(hParams, :router_name)
240
- #~ if hParams[:external_gateway_id]
241
- #~ hParams[:hdata][:external_gateway_info] = { 'network_id' => hParams[:external_gateway_id] }
242
- #~ end
243
- hParams[:hdata] = hParams[:hdata].merge(:admin_state_up => true) # Forcelly used admin_status_up to true.
244
-
245
- HPNetwork.create_router(hParams[:network_connection], hParams[:hdata])
246
- when :rule
247
- required?(hParams, :network_connection)
248
- required?(hParams, :security_groups)
249
- HPSecurityGroups.create_rule(hParams[:network_connection], hParams[:hdata])
250
- when :router_interface
251
- required?(hParams, :router)
252
- required?(hParams, :subnetwork)
253
- HPNetwork.add_interface(hParams[:router], hParams[:subnetwork])
254
- else
255
- Error "'%s' is not a valid object for 'create'" % sObjectType
256
- end
257
- end
258
-
259
- # This function return a collection which have to provide:
260
- # functions: [], length, each
261
- # Used by network process.
262
- def query(sObjectType, sQuery, hParams)
263
- case sObjectType
264
- when :public_ip
265
- required?(hParams, :compute_connection)
266
- required?(hParams, :server)
267
- HPCompute.query_server_assigned_addresses(hParams[:compute_connection], hParams[:server], sQuery)
268
- when :server
269
- required?(hParams, :compute_connection)
270
- HPCompute.query_server(hParams[:compute_connection], sQuery)
271
- when :image
272
- required?(hParams, :compute_connection)
273
- HPCompute.query_image(hParams[:compute_connection], sQuery)
274
- when :network
275
- required?(hParams, :network_connection)
276
- HPNetwork.query_network(hParams[:network_connection], sQuery)
277
- when :subnetwork
278
- required?(hParams, :network_connection)
279
- HPNetwork.query_subnetwork(hParams[:network_connection], sQuery)
280
- when :router
281
- required?(hParams, :network_connection)
282
- HPNetwork.query_router(hParams[:network_connection], sQuery)
283
- when :port
284
- required?(hParams, :network_connection)
285
- HPNetwork.query_port(hParams[:network_connection], sQuery)
286
- when :security_groups
287
- required?(hParams, :network_connection)
288
- HPSecurityGroups.query_sg(hParams[:network_connection], sQuery)
289
- when :rule
290
- required?(hParams, :network_connection)
291
- HPSecurityGroups.query_rule(hParams[:network_connection], sQuery)
292
- when :keypairs
293
- required?(hParams, :compute_connection)
294
- HPKeyPairs.query_keypair(hParams[:compute_connection], sQuery)
295
- when :flavor
296
- required?(hParams, :compute_connection)
297
- HPCompute.query_flavor(hParams[:compute_connection], sQuery)
298
- else
299
- Error "'%s' is not a valid object for 'query'" % sObjectType
300
- end
301
- end
302
-
303
- def delete(sObjectType, hParams)
304
- case sObjectType
305
- when :network
306
- HPNetwork.delete_network(hParams[:network_connection], hParams[:network])
307
- when :rule
308
- HPSecurityGroups.delete_rule(hParams[:network_connection], hParams[:id])
309
- hParams[:network_connection].security_group_rules.get(hParams[:id]).destroy
310
- when :server
311
- required?(hParams, :compute_connection)
312
- required?(hParams, :server)
313
- HPCompute.delete_server(hParams[:compute_connection], hParams[:server] )
314
- else
315
- nil
316
- end
317
- end
318
-
319
- def get(sObjectType, sUniqId, hParams)
320
- case sObjectType
321
- when :server_log
322
- required?(hParams, :server)
323
-
324
- hParams[:server].console_output(sUniqId)
325
- when :server
326
- required?(hParams, :compute_connection)
327
- HPCompute.get_server(hParams[:compute_connection], sUniqId)
328
- when :image
329
- required?(hParams, :compute_connection)
330
- HPCompute.get_image(hParams[:compute_connection], sUniqId)
331
- when :network
332
- required?(hParams, :network_connection)
333
- HPNetwork.get_network(hParams[:network_connection], sUniqId)
334
- when :keypairs
335
- required?(hParams, :compute_connection)
336
- HPKeyPairs.get_keypair(hParams[:compute_connection], sUniqId)
337
- else
338
- forjError "'%s' is not a valid object for 'get'" % sObjectType
339
- end
340
- end
341
-
342
- def query_each(oFogObject)
343
- case oFogObject.class.to_s
344
- when "Fog::HP::Network::Networks"
345
- oFogObject.each { | value |
346
- yield(value)
347
- }
348
- else
349
- Error "'%s' is not a valid list for 'each'" % oFogObject.class
350
- end
351
- end
352
-
353
- def get_attr(oControlerObject, key)
354
- begin
355
- if oControlerObject.is_a?(Excon::Response)
356
- Lorj::rhGet(oControlerObject.data, :body, key)
357
- else
358
- attributes = oControlerObject.attributes
359
- raise "attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, oControlerObject.class.attributes ] unless oControlerObject.class.attributes.include?(key[0])
360
- Lorj::rhGet(attributes, key)
361
- end
362
- rescue => e
363
- Error "Unable to map '%s'. %s" % [key, e.message]
364
- end
365
- end
366
-
367
- def set_attr(oControlerObject, key, value)
368
- begin
369
- raise "No set feature for '%s'" % oControlerObject.class if oControlerObject.is_a?(Excon::Response)
370
- attributes = oControlerObject.attributes
371
- raise "attribute '%s' is unknown in '%s'. Valid one are : '%s'" % [key[0], oControlerObject.class, oControlerObject.class.attributes ] unless oControlerObject.class.attributes.include?(key[0])
372
- Lorj::rhSet(attributes, value, key)
373
- rescue => e
374
- Error "Unable to map '%s' on '%s'" % [key, sObjectType]
375
- end
376
- end
377
-
378
-
379
- def update(sObjectType, oObject, hParams)
380
- case sObjectType
381
- when :router
382
- Error "Object to update is nil" if oObject.nil?
383
-
384
- HPNetwork.update_router(oObject[:object])
385
- else
386
- Error "'%s' is not a valid list for 'update'" % oFogObject.class
387
- end
388
- end
389
-
390
- # This function requires to return an Array of values or nil.
391
- def get_services(sObjectType, oParams)
392
- case sObjectType
393
- when :services
394
- # oParams[sObjectType] will provide the controller object.
395
- # This one can be interpreted only by controller code,
396
- # except if controller declares how to map with this object.
397
- # Processes can deal only process mapped data.
398
- # Currently there is no services process function. No need to map.
399
- hServices = oParams[:services]
400
- if not oParams[:list_services].is_a?(Array)
401
- hServiceToFind = [oParams[:list_services]]
402
- else
403
- hServiceToFind = oParams[:list_services]
404
- end
405
- # Search for service. Ex: Can be :Networking or network. I currently do not know why...
406
- hSearchServices= Lorj::rhGet(hServices, :service_catalog)
407
- sService = nil
408
- hServiceToFind.each { | sServiceElem |
409
- if hSearchServices.key?(sServiceElem)
410
- sService = sServiceElem
411
- break
412
- end
413
- }
414
-
415
- Error "Unable to find services %s" % hServiceToFind if sService.nil?
416
- result = Lorj::rhGet(hServices, :service_catalog, sService).keys
417
- result.delete("name")
418
- result.each_index { | iIndex |
419
- result[iIndex] = result[iIndex].to_s if result[iIndex].is_a?(Symbol)
420
- }
421
- return result
422
- else
423
- Error "'%s' is not a valid object for 'get_services'" % sObjectType
424
- end
425
- end
426
- end