Class: Nexpose::Silo
- Inherits:
-
Object
- Object
- Nexpose::Silo
- Defined in:
- lib/nexpose/silo.rb
Defined Under Namespace
Classes: Address, Merchant, Organization
Instance Attribute Summary collapse
-
#description ⇒ Object
Optional fields.
-
#id ⇒ Object
Required fields.
-
#max_assets ⇒ Object
Returns the value of attribute max_assets.
-
#max_hosted_assets ⇒ Object
Returns the value of attribute max_hosted_assets.
-
#max_users ⇒ Object
Returns the value of attribute max_users.
-
#merchant ⇒ Object
Returns the value of attribute merchant.
-
#name ⇒ Object
Returns the value of attribute name.
-
#organization ⇒ Object
Returns the value of attribute organization.
-
#profile_id ⇒ Object
Returns the value of attribute profile_id.
Class Method Summary collapse
-
.copy(connection, id) ⇒ Silo
Copy an existing configuration from a Nexpose instance.
-
.load(connection, id) ⇒ Silo
Load an existing configuration from a Nexpose instance.
- .parse(xml) ⇒ Object
Instance Method Summary collapse
- #as_xml ⇒ Object
-
#create(connection) ⇒ String
Saves a new silo to a Nexpose console.
- #delete(connection) ⇒ Object
-
#initialize(&block) ⇒ Silo
constructor
A new instance of Silo.
- #save(connection) ⇒ Object
- #to_xml ⇒ Object
-
#update(connection) ⇒ String
Updates this silo on a Nexpose console.
Constructor Details
#initialize(&block) ⇒ Silo
Returns a new instance of Silo.
47 48 49 |
# File 'lib/nexpose/silo.rb', line 47 def initialize(&block) instance_eval(&block) if block_given? end |
Instance Attribute Details
#description ⇒ Object
Optional fields
43 44 45 |
# File 'lib/nexpose/silo.rb', line 43 def description @description end |
#id ⇒ Object
Required fields
35 36 37 |
# File 'lib/nexpose/silo.rb', line 35 def id @id end |
#max_assets ⇒ Object
Returns the value of attribute max_assets.
38 39 40 |
# File 'lib/nexpose/silo.rb', line 38 def max_assets @max_assets end |
#max_hosted_assets ⇒ Object
Returns the value of attribute max_hosted_assets.
40 41 42 |
# File 'lib/nexpose/silo.rb', line 40 def max_hosted_assets @max_hosted_assets end |
#max_users ⇒ Object
Returns the value of attribute max_users.
39 40 41 |
# File 'lib/nexpose/silo.rb', line 39 def max_users @max_users end |
#merchant ⇒ Object
Returns the value of attribute merchant.
44 45 46 |
# File 'lib/nexpose/silo.rb', line 44 def merchant @merchant end |
#name ⇒ Object
Returns the value of attribute name.
37 38 39 |
# File 'lib/nexpose/silo.rb', line 37 def name @name end |
#organization ⇒ Object
Returns the value of attribute organization.
45 46 47 |
# File 'lib/nexpose/silo.rb', line 45 def organization @organization end |
#profile_id ⇒ Object
Returns the value of attribute profile_id.
36 37 38 |
# File 'lib/nexpose/silo.rb', line 36 def profile_id @profile_id end |
Class Method Details
.copy(connection, id) ⇒ Silo
Copy an existing configuration from a Nexpose instance. Returned object will reset the silo ID and name
58 59 60 61 62 63 |
# File 'lib/nexpose/silo.rb', line 58 def self.copy(connection, id) silo = load(connection, id) silo.id = nil silo.name = nil silo end |
.load(connection, id) ⇒ Silo
Load an existing configuration from a Nexpose instance.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/nexpose/silo.rb', line 71 def self.load(connection, id) r = connection.execute(connection.make_xml('SiloConfigRequest', { 'silo-id' => id }), '1.2') if r.success r.res.elements.each('SiloConfigResponse/SiloConfig') do |config| return Silo.parse(config) end end nil end |
.parse(xml) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/nexpose/silo.rb', line 130 def self.parse(xml) new do |silo| silo.id = xml.attributes['id'] silo.profile_id = xml.attributes['silo-profile-id'] silo.name = xml.attributes['name'] silo.max_assets = xml.attributes['max-assets'].to_i silo.max_users = xml.attributes['max-users'].to_i silo.max_hosted_assets = xml.attributes['max-hosted-assets'].to_i silo.description = xml.attributes['description'] xml.elements.each('Merchant') do |merchant| silo.merchant = Merchant.parse(merchant) end xml.elements.each('Organization') do |organization| silo.organization = Organization.parse(organization) end end end |
Instance Method Details
#as_xml ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/nexpose/silo.rb', line 117 def as_xml xml = REXML::Element.new('SiloConfig') xml.add_attributes({ 'description' => @description, 'name' => @name, 'id' => @id, 'silo-profile-id' => @profile_id, 'max-assets' => @max_assets, 'max-users' => @max_users, 'max-hosted-assets' => @max_hosted_assets }) xml.add(@merchant.as_xml) if @merchant xml.add(@organization.as_xml) if @organization xml end |
#create(connection) ⇒ String
Saves a new silo to a Nexpose console.
106 107 108 109 110 111 |
# File 'lib/nexpose/silo.rb', line 106 def create(connection) xml = connection.make_xml('SiloCreateRequest') xml.add_element(as_xml) r = connection.execute(xml, '1.2') @id = r.attributes['id'] if r.success end |
#delete(connection) ⇒ Object
113 114 115 |
# File 'lib/nexpose/silo.rb', line 113 def delete(connection) connection.delete_silo(@id) end |
#save(connection) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/nexpose/silo.rb', line 82 def save(connection) update(connection) rescue APIError => error raise error unless error. =~ /A silo .* does not exist./ create(connection) end |
#to_xml ⇒ Object
126 127 128 |
# File 'lib/nexpose/silo.rb', line 126 def to_xml as_xml.to_s end |
#update(connection) ⇒ String
Updates this silo on a Nexpose console.
94 95 96 97 98 99 |
# File 'lib/nexpose/silo.rb', line 94 def update(connection) xml = connection.make_xml('SiloUpdateRequest') xml.add_element(as_xml) r = connection.execute(xml, '1.2') @id = r.attributes['id'] if r.success end |