opennebula 6.10.3 → 6.99.85.pre

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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cloud/CloudClient.rb +3 -3
  3. data/lib/models/role.rb +349 -823
  4. data/lib/models/service.rb +156 -80
  5. data/lib/models/vmrole.rb +703 -0
  6. data/lib/models/vrrole.rb +284 -0
  7. data/lib/models.rb +3 -1
  8. data/lib/opennebula/acl.rb +1 -1
  9. data/lib/opennebula/acl_pool.rb +1 -1
  10. data/lib/opennebula/backupjob.rb +1 -1
  11. data/lib/opennebula/backupjob_pool.rb +1 -1
  12. data/lib/opennebula/client.rb +1 -1
  13. data/lib/opennebula/cluster.rb +45 -2
  14. data/lib/opennebula/cluster_pool.rb +1 -1
  15. data/lib/opennebula/datastore.rb +1 -1
  16. data/lib/opennebula/datastore_pool.rb +1 -1
  17. data/lib/opennebula/document.rb +1 -1
  18. data/lib/opennebula/document_json.rb +1 -1
  19. data/lib/opennebula/document_pool.rb +1 -1
  20. data/lib/opennebula/document_pool_json.rb +1 -1
  21. data/lib/opennebula/error.rb +1 -1
  22. data/lib/opennebula/flow/grammar.rb +1 -1
  23. data/lib/opennebula/flow/service_pool.rb +1 -1
  24. data/lib/opennebula/flow/service_template.rb +353 -97
  25. data/lib/opennebula/flow/service_template_ext.rb +3 -3
  26. data/lib/opennebula/flow/service_template_pool.rb +1 -1
  27. data/lib/opennebula/flow/validator.rb +458 -410
  28. data/lib/opennebula/flow.rb +1 -1
  29. data/lib/opennebula/group.rb +1 -1
  30. data/lib/opennebula/group_pool.rb +1 -1
  31. data/lib/opennebula/hook.rb +1 -1
  32. data/lib/opennebula/hook_log.rb +1 -1
  33. data/lib/opennebula/hook_pool.rb +1 -1
  34. data/lib/opennebula/host.rb +1 -60
  35. data/lib/opennebula/host_pool.rb +1 -1
  36. data/lib/opennebula/image.rb +1 -1
  37. data/lib/opennebula/image_pool.rb +1 -1
  38. data/lib/opennebula/ldap_auth.rb +1 -1
  39. data/lib/opennebula/ldap_auth_spec.rb +1 -1
  40. data/lib/opennebula/lockable_ext.rb +1 -1
  41. data/lib/opennebula/marketplace.rb +1 -1
  42. data/lib/opennebula/marketplace_pool.rb +1 -1
  43. data/lib/opennebula/marketplaceapp.rb +1 -1
  44. data/lib/opennebula/marketplaceapp_ext.rb +14 -211
  45. data/lib/opennebula/marketplaceapp_pool.rb +1 -1
  46. data/lib/opennebula/oneflow_client.rb +11 -9
  47. data/lib/opennebula/pool.rb +1 -1
  48. data/lib/opennebula/pool_element.rb +1 -1
  49. data/lib/opennebula/security_group.rb +1 -1
  50. data/lib/opennebula/security_group_pool.rb +1 -1
  51. data/lib/opennebula/server_cipher_auth.rb +1 -1
  52. data/lib/opennebula/server_x509_auth.rb +1 -1
  53. data/lib/opennebula/ssh_auth.rb +1 -1
  54. data/lib/opennebula/system.rb +1 -1
  55. data/lib/opennebula/template.rb +1 -1
  56. data/lib/opennebula/template_ext.rb +1 -1
  57. data/lib/opennebula/template_pool.rb +1 -1
  58. data/lib/opennebula/user.rb +1 -1
  59. data/lib/opennebula/user_pool.rb +1 -1
  60. data/lib/opennebula/utils.rb +2 -2
  61. data/lib/opennebula/vdc.rb +1 -1
  62. data/lib/opennebula/vdc_pool.rb +1 -1
  63. data/lib/opennebula/virtual_machine.rb +3 -12
  64. data/lib/opennebula/virtual_machine_ext.rb +2 -31
  65. data/lib/opennebula/virtual_machine_pool.rb +1 -1
  66. data/lib/opennebula/virtual_network.rb +1 -1
  67. data/lib/opennebula/virtual_network_pool.rb +1 -1
  68. data/lib/opennebula/virtual_router.rb +1 -1
  69. data/lib/opennebula/virtual_router_pool.rb +1 -1
  70. data/lib/opennebula/vm_group.rb +1 -1
  71. data/lib/opennebula/vm_group_pool.rb +1 -1
  72. data/lib/opennebula/vntemplate.rb +1 -1
  73. data/lib/opennebula/vntemplate_pool.rb +1 -1
  74. data/lib/opennebula/wait_ext.rb +1 -1
  75. data/lib/opennebula/x509_auth.rb +1 -1
  76. data/lib/opennebula/xml_element.rb +2 -2
  77. data/lib/opennebula/xml_pool.rb +1 -1
  78. data/lib/opennebula/xml_utils.rb +1 -1
  79. data/lib/opennebula/zone.rb +1 -1
  80. data/lib/opennebula/zone_pool.rb +1 -1
  81. data/lib/opennebula.rb +2 -2
  82. metadata +6 -67
  83. data/lib/ActionManager.rb +0 -280
  84. data/lib/CommandManager.rb +0 -328
  85. data/lib/DriverExecHelper.rb +0 -213
  86. data/lib/HostSyncManager.rb +0 -111
  87. data/lib/OpenNebulaDriver.rb +0 -223
  88. data/lib/VirtualMachineDriver.rb +0 -404
  89. data/lib/datacenter.rb +0 -1319
  90. data/lib/datastore.rb +0 -1049
  91. data/lib/distributed_firewall.rb +0 -293
  92. data/lib/file_helper.rb +0 -374
  93. data/lib/host.rb +0 -1518
  94. data/lib/logical_port.rb +0 -50
  95. data/lib/logical_switch.rb +0 -77
  96. data/lib/memoize.rb +0 -74
  97. data/lib/network.rb +0 -705
  98. data/lib/nsx_client.rb +0 -157
  99. data/lib/nsx_component.rb +0 -28
  100. data/lib/nsx_constants.rb +0 -162
  101. data/lib/nsx_driver.rb +0 -91
  102. data/lib/nsx_error.rb +0 -77
  103. data/lib/nsx_rule.rb +0 -206
  104. data/lib/nsxt_client.rb +0 -189
  105. data/lib/nsxt_dfw.rb +0 -196
  106. data/lib/nsxt_logical_port.rb +0 -94
  107. data/lib/nsxt_rule.rb +0 -188
  108. data/lib/nsxt_tz.rb +0 -38
  109. data/lib/nsxv_client.rb +0 -189
  110. data/lib/nsxv_dfw.rb +0 -202
  111. data/lib/nsxv_logical_port.rb +0 -107
  112. data/lib/nsxv_rule.rb +0 -172
  113. data/lib/nsxv_tz.rb +0 -41
  114. data/lib/opaque_network.rb +0 -134
  115. data/lib/rest_client.rb +0 -191
  116. data/lib/scripts_common.rb +0 -176
  117. data/lib/transport_zone.rb +0 -43
  118. data/lib/vcenter_driver.rb +0 -152
  119. data/lib/vcenter_importer.rb +0 -626
  120. data/lib/vi_client.rb +0 -273
  121. data/lib/vi_helper.rb +0 -328
  122. data/lib/virtual_machine.rb +0 -3574
  123. data/lib/virtual_wire.rb +0 -158
  124. data/lib/vm_device.rb +0 -80
  125. data/lib/vm_disk.rb +0 -202
  126. data/lib/vm_folder.rb +0 -69
  127. data/lib/vm_helper.rb +0 -30
  128. data/lib/vm_monitor.rb +0 -305
  129. data/lib/vm_nic.rb +0 -70
  130. data/lib/vm_template.rb +0 -2112
  131. data/lib/vmm_importer.rb +0 -165
@@ -1,213 +0,0 @@
1
- # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
3
- # #
4
- # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
- # not use this file except in compliance with the License. You may obtain #
6
- # a copy of the License at #
7
- # #
8
- # http://www.apache.org/licenses/LICENSE-2.0 #
9
- # #
10
- # Unless required by applicable law or agreed to in writing, software #
11
- # distributed under the License is distributed on an "AS IS" BASIS, #
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
- # See the License for the specific language governing permissions and #
14
- # limitations under the License. #
15
- #--------------------------------------------------------------------------- #
16
-
17
- # This module provides an abstraction to generate an execution context for
18
- # OpenNebula Drivers. The module has been designed to be included as part
19
- # of a driver and not to be used standalone.
20
- module DriverExecHelper
21
-
22
- # Action result strings for messages
23
- RESULT = {
24
- :success => 'SUCCESS',
25
- :failure => 'FAILURE'
26
- }
27
-
28
- def self.failed?(rc_str)
29
- rc_str == RESULT[:failure]
30
- end
31
-
32
- # Initialize module variables
33
- def initialize_helper(directory, options)
34
- @config = read_configuration
35
- @remote_scripts_base_path = @config['SCRIPTS_REMOTE_DIR']
36
-
37
- @local_actions = options[:local_actions]
38
- @per_drvr_local_actions = options[:per_drvr_local_actions] || []
39
-
40
- if ENV['ONE_LOCATION'].nil?
41
- @local_scripts_base_path = '/var/lib/one/remotes'
42
- else
43
- @local_scripts_base_path = "#{ENV['ONE_LOCATION']}/var/remotes"
44
- end
45
-
46
- # dummy paths
47
- @remote_scripts_path = File.join(@remote_scripts_base_path, directory)
48
- @local_scripts_path = File.join(@local_scripts_base_path, directory)
49
-
50
- # mutex for logging
51
- @send_mutex = Mutex.new
52
- end
53
-
54
- #
55
- # METHODS FOR COMMAND LINE & ACTION PATHS
56
- #
57
- # Given the action name and the parameter returns full path of the script
58
- # and appends its parameters. It uses @local_actions hash to know if the
59
- # actions is remote or local. If the local actions has defined an special
60
- # script name this is used, otherwise the action name in downcase is
61
- # used as the script name.
62
- # When action is a String starting with '/' it's considered alreay full
63
- # path command and no modification is performed apart from adding params.
64
- #
65
- # @param [String, Symbol] action name of the action
66
- # @param [String] parameters arguments for the script
67
- # @param [String, nil] default_name alternative name for the script
68
- # @param [String, ''] directory to append to the scripts path for actions
69
- # @return [String] command line needed to execute the action
70
- def action_command_line(action, parameters, default_name = nil, directory = '')
71
- if action.is_a?(String) && action[0] == '/'
72
- return action + ' ' + parameters if parameters
73
-
74
- return action
75
- elsif action_is_local?(action, directory)
76
- script_path=File.join(@local_scripts_path, directory)
77
- else
78
- script_path=File.join(@remote_scripts_path, directory)
79
- end
80
-
81
- File.join(script_path, action_script_name(action, default_name))+
82
- ' '+parameters
83
- end
84
-
85
- # True if the action is meant to be executed locally
86
- #
87
- # @param [String, Symbol] action name of the action
88
- # @param [String, Symbol] driver name
89
- def action_is_local?(action, driver = '')
90
- @local_actions.include? action.to_s.upcase if driver.empty?
91
-
92
- @local_actions.include? action.to_s.upcase or
93
- @per_drvr_local_actions.include? "#{driver}-#{action}"
94
- end
95
-
96
- # Name of the script file for the given action
97
- #
98
- # @param [String, Symbol] action name of the action
99
- # @param [String, nil] default_name alternative name for the script
100
- def action_script_name(action, default_name = nil)
101
- name=@local_actions[action.to_s.upcase]
102
-
103
- name || default_name || action.to_s.downcase
104
- end
105
-
106
- #
107
- # METHODS FOR LOGS & COMMAND OUTPUT
108
- #
109
- # Sends a message to the OpenNebula core through stdout
110
- # rubocop:disable Metrics/ParameterLists
111
- def send_message(action = '-', result = RESULT[:failure], id = '-', info = '-')
112
- @send_mutex.synchronize do
113
- STDOUT.puts "#{action} #{result} #{id} #{info}"
114
- STDOUT.flush
115
- end
116
- end
117
- # rubocop:enable Metrics/ParameterLists
118
-
119
- # Sends a log message to ONE. The +message+ can be multiline, it will
120
- # be automatically splitted by lines.
121
- def log(number, message, all = true)
122
- msg = message.strip
123
-
124
- msg.each_line do |line|
125
- all ? severity='I' : severity=nil
126
-
127
- if line.match(/^(ERROR|DEBUG|INFO):(.*)$/)
128
- line=Regexp.last_match(2)
129
-
130
- case Regexp.last_match(1)
131
- when 'ERROR'
132
- severity='E'
133
- when 'DEBUG'
134
- severity='D'
135
- when 'INFO'
136
- severity='I'
137
- end
138
- end
139
-
140
- send_message('LOG', severity, number, line.strip) if severity
141
- end
142
- end
143
-
144
- # Generates a proc with that calls log with a hardcoded number. It will
145
- # be used to add loging to command actions
146
- def log_method(num)
147
- lambda {|message, all = true|
148
- log(num, message, all)
149
- }
150
- end
151
-
152
- # This method returns the result in terms
153
- def get_info_from_execution(command_exe)
154
- if command_exe.code == 0
155
- result = RESULT[:success]
156
- info = command_exe.stdout
157
- else
158
- result = RESULT[:failure]
159
- info = command_exe.get_error_message
160
- end
161
-
162
- info = '-' if info.nil? || info.empty?
163
-
164
- [result, info]
165
- end
166
-
167
- #
168
- #
169
- # Simple parser for the config file generated by OpenNebula
170
- def read_configuration
171
- one_config=nil
172
-
173
- if ENV['ONE_LOCATION']
174
- one_config = ENV['ONE_LOCATION']+'/var/config'
175
- else
176
- one_config = '/var/lib/one/config'
177
- end
178
-
179
- config = {}
180
- cfg = ''
181
-
182
- begin
183
- File.open(one_config, 'r') do |file|
184
- cfg=file.read
185
- end
186
-
187
- cfg.split("\n").each do |line|
188
- m=line.match(/^([^=]+)=(.*)$/)
189
-
190
- next unless m
191
-
192
- name = m[1].strip.upcase
193
- value = m[2].strip
194
-
195
- if config[name]
196
- if config[name].instance_of? Array
197
- config[name] << value
198
- else
199
- config[name] = [config[name], value]
200
- end
201
- else
202
- config[name]=value
203
- end
204
- end
205
- rescue StandardError => e
206
- STDERR.puts "Error reading config: #{e.inspect}"
207
- STDERR.flush
208
- end
209
-
210
- config
211
- end
212
-
213
- end
@@ -1,111 +0,0 @@
1
- # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
3
- # #
4
- # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
- # not use this file except in compliance with the License. You may obtain #
6
- # a copy of the License at #
7
- # #
8
- # http://www.apache.org/licenses/LICENSE-2.0 #
9
- # #
10
- # Unless required by applicable law or agreed to in writing, software #
11
- # distributed under the License is distributed on an "AS IS" BASIS, #
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
- # See the License for the specific language governing permissions and #
14
- # limitations under the License. #
15
- # -------------------------------------------------------------------------- #
16
-
17
- # rubocop:disable Lint/MissingCopEnableDirective
18
- # rubocop:disable Layout/FirstArgumentIndentation
19
- # rubocop:disable Layout/FirstHashElementIndentation
20
- # rubocop:disable Layout/HashAlignment
21
- # rubocop:disable Layout/HeredocIndentation
22
- # rubocop:disable Layout/IndentationWidth
23
- # rubocop:disable Style/HashSyntax
24
- # rubocop:disable Style/ParallelAssignment
25
-
26
- require 'CommandManager'
27
-
28
- # This helper module introduces a common routine that synchronizes
29
- # the "remotes".
30
- class HostSyncManager
31
-
32
- def initialize(one_config = nil)
33
- one_location = ENV['ONE_LOCATION']&.delete("'")
34
- if one_location.nil?
35
- @one_config_path = '/var/lib/one/config'
36
- @local_scripts_base_path = '/var/lib/one/remotes'
37
- else
38
- @one_config_path = one_location + '/var/config'
39
- @local_scripts_base_path = one_location + '/var/remotes'
40
- end
41
-
42
- # Do a simple parsing of the config file unless the values
43
- # are already provided. NOTE: We don't care about "arrays" here..
44
- one_config ||= File.read(@one_config_path).lines.each_with_object({}) \
45
- do |line, object|
46
- key, value = line.split('=').map(&:strip)
47
- object[key.upcase] = value
48
- end
49
-
50
- @remote_scripts_base_path = one_config['SCRIPTS_REMOTE_DIR']
51
- @remote_scripts_base_path&.delete!("'")
52
- end
53
-
54
- def update_remotes(hostname, logger = nil, copy_method = :rsync, subset = nil)
55
- sources = '.'
56
-
57
- if subset && copy_method == :rsync
58
- # Make sure all files in the subset exist (and are relative).
59
- subset.each do |path|
60
- File.realpath path, @local_scripts_base_path
61
- end
62
-
63
- sources = subset.join(' ')
64
- end
65
-
66
- assemble_cmd = lambda do |steps|
67
- "exec 2>/dev/null; #{steps.join(' && ')}"
68
- end
69
-
70
- case copy_method
71
- when :ssh
72
- mkdir_cmd = assemble_cmd.call [
73
- "rm -rf '#{@remote_scripts_base_path}'/",
74
- "mkdir -p '#{@remote_scripts_base_path}'/"
75
- ]
76
-
77
- sync_cmd = assemble_cmd.call [
78
- "cd '#{@local_scripts_base_path}'/",
79
- "scp -rp #{sources} " \
80
- "'#{hostname}':'#{@remote_scripts_base_path}'/"
81
- ]
82
- when :rsync
83
- mkdir_cmd = assemble_cmd.call [
84
- "mkdir -p '#{@remote_scripts_base_path}'/"
85
- ]
86
-
87
- sync_cmd = assemble_cmd.call [
88
- "cd '#{@local_scripts_base_path}'/",
89
- "rsync -LRaz --delete #{sources} " \
90
- "'#{hostname}':'#{@remote_scripts_base_path}'/"
91
- ]
92
- end
93
-
94
- cmd = SSHCommand.run(mkdir_cmd, hostname, logger)
95
- return cmd.code if error?(cmd)
96
-
97
- cmd = LocalCommand.run(sync_cmd, logger)
98
- return cmd.code if error?(cmd)
99
-
100
- 0
101
- end
102
-
103
- def error?(cmd)
104
- return false if cmd.code == 0
105
-
106
- STDERR.puts cmd.stderr
107
- STDOUT.puts cmd.stdout
108
- true
109
- end
110
-
111
- end
@@ -1,223 +0,0 @@
1
- # -------------------------------------------------------------------------- #
2
- # Copyright 2002-2024, OpenNebula Project, OpenNebula Systems #
3
- # #
4
- # Licensed under the Apache License, Version 2.0 (the "License"); you may #
5
- # not use this file except in compliance with the License. You may obtain #
6
- # a copy of the License at #
7
- # #
8
- # http://www.apache.org/licenses/LICENSE-2.0 #
9
- # #
10
- # Unless required by applicable law or agreed to in writing, software #
11
- # distributed under the License is distributed on an "AS IS" BASIS, #
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13
- # See the License for the specific language governing permissions and #
14
- # limitations under the License. #
15
- #--------------------------------------------------------------------------- #
16
-
17
- require 'ActionManager'
18
- require 'CommandManager'
19
-
20
- require 'DriverExecHelper'
21
- require 'base64'
22
-
23
- # This class provides basic messaging and logging functionality
24
- # to implement OpenNebula Drivers. A driver is a program that
25
- # specialize the OpenNebula behavior by interfacing with specific
26
- # infrastructure functionalities.
27
- #
28
- # A Driver inherits this class and only has to provide methods
29
- # for each action it wants to receive. The method must be associated
30
- # with the action name through the register_action function
31
- class OpenNebulaDriver < ActionManager
32
-
33
- include DriverExecHelper
34
-
35
- # @return [String] Base path for scripts
36
- attr_reader :local_scripts_base_path, :remote_scripts_base_path
37
- # @return [String] Path for scripts
38
- attr_reader :local_scripts_path, :remote_scripts_path
39
-
40
- # Initialize OpenNebulaDriver object
41
- #
42
- # @param [String] directory path inside the remotes directory where the
43
- # scripts are located
44
- # @param [Hash] options named options to change the object's behaviour
45
- # @option options [Number] :concurrency (10) max number of threads
46
- # @option options [Boolean] :threaded (true) enables or disables threads
47
- # @option options [Number] :retries (0) number of retries to copy scripts
48
- # to the remote host
49
- # @option options [Hash] :local_actions ({}) hash with the actions
50
- # executed locally and the name of the script if it differs from the
51
- # default one. This hash can be constructed using {parse_actions_list}
52
- def initialize(directory, options = {})
53
- @options={
54
- :concurrency => 10,
55
- :threaded => true,
56
- :retries => 0,
57
- :local_actions => {},
58
- :timeout => nil
59
- }.merge!(options)
60
-
61
- super(@options[:concurrency], @options[:threaded])
62
-
63
- @retries = @options[:retries]
64
- @timeout = @options[:timeout]
65
-
66
- # Set default values
67
- initialize_helper(directory, @options)
68
-
69
- register_action(:INIT, method('init'))
70
- end
71
-
72
- # Calls remotes or local action checking the action name and
73
- # @local_actions. Optional arguments can be specified as a hash
74
- #
75
- # @param [String] parameters arguments passed to the script
76
- # @param [Number, String] id action identifier
77
- # @param [String] host hostname where the action is going to be executed
78
- # @param [String, Symbol] aname name of the action
79
- # @param [Hash] ops extra options for the command
80
- # @option ops [String] :stdin text to be writen to stdin
81
- # @option ops [String] :script_name default script name for the action,
82
- # action name is used by defaults
83
- # @option ops [Bool] :respond if defined will send result to ONE core
84
- # @option ops [Bool] :base64 encode the information sent to ONE core
85
- # @option ops [Bool] :zip compress the information sent to ONE core
86
- def do_action(parameters, id, host, aname, ops = {})
87
- options = {
88
- :stdin => nil,
89
- :script_name => nil,
90
- :respond => true,
91
- :ssh_stream => nil,
92
- :base64 => false,
93
- :zip => false,
94
- :no_extra_params => false
95
- }.merge(ops)
96
-
97
- params = parameters
98
- params = "#{params} #{id} #{host}" unless options[:no_extra_params]
99
- command = action_command_line(aname, params, options[:script_name])
100
-
101
- # if options[:is_local] is not specified (nil)
102
- # we rely uniquely in actions_is_local?
103
- if action_is_local?(aname) or options[:is_local]
104
- stdin = Base64.strict_encode64(options[:stdin].to_s)
105
- execution = LocalCommand.run(command,
106
- log_method(id),
107
- stdin,
108
- @timeout)
109
- elsif options[:ssh_stream]
110
- if options[:stdin]
111
- cmdin = "cat << 'EOT' | #{command}"
112
- stdin = "#{options[:stdin]}\nEOT\n"
113
- else
114
- cmdin = command
115
- stdin = nil
116
- end
117
-
118
- execution = options[:ssh_stream].run(cmdin,
119
- stdin,
120
- command,
121
- @timeout)
122
- else
123
- execution = RemotesCommand.run(command,
124
- host,
125
- @remote_scripts_base_path,
126
- log_method(id),
127
- options[:stdin],
128
- @retries,
129
- @timeout)
130
- end
131
-
132
- result, info = get_info_from_execution(execution)
133
-
134
- if options[:respond]
135
- info = Zlib::Deflate.deflate(info, Zlib::BEST_COMPRESSION) if options[:zip]
136
- info = Base64.strict_encode64(info) if options[:base64]
137
-
138
- send_message(aname, result, id, info)
139
- end
140
-
141
- [result, info]
142
- end
143
-
144
- # Start the driver. Reads from STDIN and executes methods associated with
145
- # the messages
146
- def start_driver
147
- Thread.new { loop }
148
- start_listener
149
- end
150
-
151
- # This function parses a string with this form:
152
- #
153
- # 'deploy,shutdown,poll=poll_ganglia, cancel '
154
- #
155
- # and returns a hash:
156
- #
157
- # {"POLL"=>"poll_ganglia", "DEPLOY"=>nil, "SHUTDOWN"=>nil,
158
- # "CANCEL"=>nil}
159
- #
160
- # @param [String] str imput string to parse
161
- # @return [Hash] parsed actions
162
- def self.parse_actions_list(str)
163
- actions = {}
164
- str_splitted = str.split(/\s*,\s*/).map {|s| s.strip }
165
-
166
- str_splitted.each do |a|
167
- m=a.match(/([^=]+)(=(.*))?/)
168
- next unless m
169
-
170
- action=m[1].upcase
171
-
172
- if m[2]
173
- script=m[3]
174
- script.strip! if script
175
- else
176
- script=nil
177
- end
178
-
179
- actions[action]=script
180
- end
181
-
182
- actions
183
- end
184
-
185
- private
186
-
187
- def init
188
- send_message('INIT', RESULT[:success])
189
- end
190
-
191
- def loop
192
- Kernel.loop do
193
- exit!(-1) if STDIN.eof?
194
-
195
- str = STDIN.gets
196
- next unless str
197
-
198
- args = str.split(/\s+/)
199
- next if args.empty?
200
-
201
- if args.first.empty?
202
- STDERR.puts "Malformed message: #{str.inspect}"
203
- next
204
- end
205
-
206
- action = args.shift.upcase.to_sym
207
-
208
- if args.empty? || !args[0]
209
- action_id = 0
210
- else
211
- action_id = args[0].to_i
212
- end
213
-
214
- if action == :DRIVER_CANCEL
215
- cancel_action(action_id)
216
- log(action_id, "Driver command for #{action_id} cancelled")
217
- else
218
- trigger_action(action, action_id, *args)
219
- end
220
- end
221
- end
222
-
223
- end