class ProfitBricks::LAN
LAN
class
Public Class Methods
create(datacenter_id, options = {})
click to toggle source
Create a new LAN
.
# File lib/profitbricks/lan.rb, line 34 def create(datacenter_id, options = {}) entities = {} # Retrieve nics collection if present and generate appropriate JSON. if options.key?('nics') entities[:nics] =collect_entities(options.delete('nics')) end response = ProfitBricks.request( method: :post, path: "/datacenters/#{datacenter_id}/lans", expects: 202, body: { properties: options, entities: entities }.to_json ) add_parent_identities(response) instantiate_objects(response) end
get(datacenter_id, lan_id)
click to toggle source
Retrieve a LAN
under a datacenter.
# File lib/profitbricks/lan.rb, line 62 def get(datacenter_id, lan_id) response = ProfitBricks.request( method: :get, path: "/datacenters/#{datacenter_id}/lans/#{lan_id}", expects: 200 ) add_parent_identities(response) instantiate_objects(response) end
list(datacenter_id)
click to toggle source
List all LANs under a datacenter.
# File lib/profitbricks/lan.rb, line 51 def list(datacenter_id) response = ProfitBricks.request( method: :get, path: "/datacenters/#{datacenter_id}/lans", expects: 200 ) add_parent_identities(response) instantiate_objects(response) end
Private Class Methods
collect_entities(entities)
click to toggle source
# File lib/profitbricks/lan.rb, line 75 def self.collect_entities(entities) items = [] if entities.is_a?(Array) && entities.length > 0 entities.each do |entity| items << { id: entity } end {items: items} end end
Public Instance Methods
delete()
click to toggle source
Delete the LAN
.
# File lib/profitbricks/lan.rb, line 6 def delete response = ProfitBricks.request( method: :delete, path: "/datacenters/#{self.datacenterId}/lans/#{self.id}", expects: 202 ) self.requestId = response[:requestId] self end
update(options = {})
click to toggle source
Update the LAN
.
# File lib/profitbricks/lan.rb, line 17 def update(options = {}) response = ProfitBricks.request( method: :patch, path: "/datacenters/#{self.datacenterId}/lans/#{self.id}", expects: 202, body: options.to_json ) if response self.requestId = response['requestId'] @properties = @properties.merge(response['properties']) end self end