Class: Nexpose::EnginePool
- Inherits:
-
Object
- Object
- Nexpose::EnginePool
- Defined in:
- lib/nexpose/scan_engine.rb
Overview
Core objects for creating an engine pool Example usage:
pool = EnginePool.new('East Coast Pool')
pool.add('New York Engine')
pool.add('Georgia Engine')
pool.create(@nsc)
Instance Attribute Summary collapse
-
#engines ⇒ Object
Array containing (EngineSummary*).
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
-
#add(engine) ⇒ Object
Add an engine to the pool by name (not ID).
-
#create(connection) ⇒ Object
Creates a new engine pool, and adds scan engines to the pool.
-
#delete(connection) ⇒ Object
Deletes an engine pool.
-
#initialize(name, id = -1,, scope = 'silo') ⇒ EnginePool
constructor
A new instance of EnginePool.
-
#load_details(connection) ⇒ Object
Returns detailed information about a single engine pool.
- #to_s ⇒ Object
-
#update(connection) ⇒ Object
Updates a specific role with new information.
Constructor Details
#initialize(name, id = -1,, scope = 'silo') ⇒ EnginePool
Returns a new instance of EnginePool.
189 190 191 192 193 194 |
# File 'lib/nexpose/scan_engine.rb', line 189 def initialize(name, id = -1, scope = 'silo') @name = name @id = id @scope = scope @engines = [] end |
Instance Attribute Details
#engines ⇒ Object
Array containing (EngineSummary*)
187 188 189 |
# File 'lib/nexpose/scan_engine.rb', line 187 def engines @engines end |
#id ⇒ Object
Returns the value of attribute id.
183 184 185 |
# File 'lib/nexpose/scan_engine.rb', line 183 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
184 185 186 |
# File 'lib/nexpose/scan_engine.rb', line 184 def name @name end |
#scope ⇒ Object
Returns the value of attribute scope.
185 186 187 |
# File 'lib/nexpose/scan_engine.rb', line 185 def scope @scope end |
Instance Method Details
#add(engine) ⇒ Object
Add an engine to the pool by name (not ID). Only use this for creating pools.
198 199 200 |
# File 'lib/nexpose/scan_engine.rb', line 198 def add(engine) @engines << EngineSummary.new(-1, engine, 'nowhere', 40814, 'unknown') end |
#create(connection) ⇒ Object
Creates a new engine pool, and adds scan engines to the pool.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/nexpose/scan_engine.rb', line 203 def create(connection) xml = '<EnginePoolCreateRequest session-id="' + connection.session_id + '">' xml << %Q{<EnginePool name="#{@name}" scope="#{@scope}">} @engines.each do |engine| xml << %Q{<Engine name="#{engine.name}" />} end xml << '</EnginePool>' xml << '</EnginePoolCreateRequest>' r = connection.execute(xml, '1.2') if r.success r.res.elements.each('EnginePoolCreateResponse') do |v| @id = v.attributes['id'] end else @error = true @error_msg = 'EnginePoolCreateResponse Parse Error' end end |
#delete(connection) ⇒ Object
Deletes an engine pool
224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/nexpose/scan_engine.rb', line 224 def delete(connection) xml = '<EnginePoolDeleteRequest session-id="' + connection.session_id + '">' xml << %Q{<EnginePool name="#{@name}" scope="#{@scope}" />} xml << '</EnginePoolDeleteRequest>' r = connection.execute(xml, '1.2') unless r.success @error = true @error_msg = 'EnginePoolDeleteResponse Parse Error' end end |
#load_details(connection) ⇒ Object
Returns detailed information about a single engine pool.
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/nexpose/scan_engine.rb', line 261 def load_details(connection) xml = '<EnginePoolDetailsRequest session-id="' + connection.session_id + '">' xml << %Q{<EnginePool name="#{@name}" scope="#{@scope}" />} xml << '</EnginePoolDetailsRequest>' r = connection.execute(xml, '1.2') if r.success r.res.elements.each('EnginePoolDetailsResponse/EnginePool') do |pool| @id = pool.attributes['id'] @name = pool.attributes['name'] @scope = pool.attributes['scope'] @engines = [] r.res.elements.each('EnginePoolDetailsResponse/EnginePool/EngineSummary') do |summary| @engines.push(EngineSummary.new(summary.attributes['id'].to_i, summary.attributes['name'], summary.attributes['address'], summary.attributes['port'].to_i, summary.attributes['status'], summary.attributes['scope'])) end end else @error = true @error_msg = 'EnginePoolListingResponse Parse Error' end end |
#to_s ⇒ Object
288 289 290 |
# File 'lib/nexpose/scan_engine.rb', line 288 def to_s "Engine Pool: #{@name} [ID: #{@id}], Scope: #{@scope}\n" + @engines.map { |engine| " #{engine}" }.join("\n") end |
#update(connection) ⇒ Object
Updates a specific role with new information. An EnginePoolUpdate is similar to an EnginePoolCreate, except that an EnginePoolUpdate replaces any previously existing information with the new information specified in the EnginePoolUpdateRequest.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/nexpose/scan_engine.rb', line 240 def update(connection) xml = '<EnginePoolUpdateRequest session-id="' + connection.session_id + '">' xml << %Q{<EnginePool id="#{@id}" name="#{@name}" scope="#{@scope}">} @engines.each do |engine| xml << %Q{<Engine name="#{engine.name}" />} end xml << '</EnginePool>' xml << '</EnginePoolUpdateRequest>' r = connection.execute(xml, '1.2') if r.success r.res.elements.each('EnginePoolUpdateResponse') do |v| @id = v.attributes['id'] end else @error = true @error_msg = 'EnginePoolCreateResponse Parse Error' end end |