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.
76 77 78 79 |
# File 'lib/nexpose/pool.rb', line 76 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.
74 75 76 |
# File 'lib/nexpose/pool.rb', line 74 def engines @engines end |
#id ⇒ Object
Unique identifier of the engine pool.
68 69 70 |
# File 'lib/nexpose/pool.rb', line 68 def id @id end |
#name ⇒ Object
Name of the engine pool.
70 71 72 |
# File 'lib/nexpose/pool.rb', line 70 def name @name end |
#scope ⇒ Object
Whether the engine pool has global or silo scope.
72 73 74 |
# File 'lib/nexpose/pool.rb', line 72 def scope @scope end |
Class Method Details
.load(connection, name, scope = 'silo') ⇒ EnginePool
Returns detailed information about a single engine pool.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/nexpose/pool.rb', line 99 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' }
88 89 90 |
# File 'lib/nexpose/pool.rb', line 88 def add(engine_name) @engines << EngineSummary.new(-1, engine_name, nil, 40814, nil) end |
#delete(connection) ⇒ Object
Deletes an engine pool
152 153 154 155 156 157 158 159 |
# File 'lib/nexpose/pool.rb', line 152 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.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/nexpose/pool.rb', line 128 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 |