Class: Nexpose::EnginePool
- Inherits:
-
Object
- Object
- Nexpose::EnginePool
- Defined in:
- lib/nexpose/pool.rb
Overview
Engine pool configuration object.
Instance Attribute Summary collapse
-
#engines ⇒ Object
Array containing (EngineSummary*) for each engine assigned to the pool.
-
#id ⇒ Object
Unique identifier of the engine pool.
-
#name ⇒ Object
Name of the engine pool.
-
#scope ⇒ Object
Whether the engine pool has global or silo scope.
Class Method Summary collapse
-
.load(connection, name, scope = 'silo') ⇒ EnginePool
Returns detailed information about a single engine pool.
Instance Method Summary collapse
-
#add(engine_name) ⇒ Object
Add an engine to the pool by name (not ID).
-
#delete(connection) ⇒ Object
Deletes an engine pool.
-
#initialize(name, scope = 'silo', id = -1)) ⇒ EnginePool
constructor
A new instance of EnginePool.
-
#save(connection) ⇒ Object
Save an engine pool to a security console.
Constructor Details
#initialize(name, scope = 'silo', id = -1)) ⇒ EnginePool
Returns a new instance of EnginePool.
58 59 60 61 |
# File 'lib/nexpose/pool.rb', line 58 def initialize(name, scope = 'silo', id = -1) @name, @scope, @id = name, scope, id.to_i @engines = [] end |
Instance Attribute Details
#engines ⇒ Object
Array containing (EngineSummary*) for each engine assigned to the pool.
56 57 58 |
# File 'lib/nexpose/pool.rb', line 56 def engines @engines end |
#id ⇒ Object
Unique identifier of the engine pool.
50 51 52 |
# File 'lib/nexpose/pool.rb', line 50 def id @id end |
#name ⇒ Object
Name of the engine pool.
52 53 54 |
# File 'lib/nexpose/pool.rb', line 52 def name @name end |
#scope ⇒ Object
Whether the engine pool has global or silo scope.
54 55 56 |
# File 'lib/nexpose/pool.rb', line 54 def scope @scope end |
Class Method Details
.load(connection, name, scope = 'silo') ⇒ EnginePool
Returns detailed information about a single engine pool.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nexpose/pool.rb', line 81 def self.load(connection, name, scope = 'silo') xml = %(<EnginePoolDetailsRequest session-id="#{connection.session_id}">) xml << %(<EnginePool name="#{name}" scope="#{scope}"/>) xml << '</EnginePoolDetailsRequest>' r = connection.execute(xml, '1.2') if r.success r.res.elements.each('EnginePoolDetailsResponse/EnginePool') do |pool| config = EnginePool.new(pool.attributes['name'], pool.attributes['scope'], pool.attributes['id'].to_i) r.res.elements.each('EnginePoolDetailsResponse/EnginePool/EngineSummary') do |summary| config.engines << 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 return config end end nil end |
Instance Method Details
#add(engine_name) ⇒ Object
Add an engine to the pool by name (not ID).
EngineSummary objects should just be appended to the pool directly,
e.g., pool.engines << nsc.engines.find { |e| e.name == 'Cleveland' }
70 71 72 |
# File 'lib/nexpose/pool.rb', line 70 def add(engine_name) @engines << EngineSummary.new(-1, engine_name, nil, 40814, nil) end |
#delete(connection) ⇒ Object
Deletes an engine pool
134 135 136 137 138 139 140 141 |
# File 'lib/nexpose/pool.rb', line 134 def delete(connection) xml = %(<EnginePoolDeleteRequest session-id="#{connection.session_id}">) xml << %(<EnginePool name="#{@name}" scope="#{@scope}" />) xml << '</EnginePoolDeleteRequest>' r = connection.execute(xml, '1.2') r.success end |
#save(connection) ⇒ Object
Save an engine pool to a security console.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/nexpose/pool.rb', line 110 def save(connection) request = @id > 0 ? 'EnginePoolUpdateRequest' : 'EnginePoolCreateRequest' xml = %(<#{request} session-id="#{connection.session_id}">) xml << '<EnginePool' xml << %( id="#{@id}") if @id > 0 xml << %( name="#{@name}" scope="#{@scope}">) @engines.each do |engine| xml << %(<Engine name="#{engine.name}" />) end xml << '</EnginePool>' xml << %(</#{request}>) r = connection.execute(xml, '1.2') if r.success r.res.elements.each(request.gsub('Request', 'Response')) do |v| return @id = v.attributes['id'].to_i end end end |