Class: Profitbricks::IpBlock

Inherits:
Model
  • Object
show all
Defined in:
lib/profitbricks/ip_block.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Model

#attributes, belongs_to, has_many, #reload

Constructor Details

- (IpBlock) initialize(hash, parent = nil)



5
6
7
8
9
10
11
# File 'lib/profitbricks/ip_block.rb', line 5

def initialize(hash, parent=nil)
  if hash[:public_ips]
    @ips = [hash.delete(:public_ips)].flatten.compact.collect { |ip| ip[:ip] }
  end
  super(hash)
  @ips = [@ips] if @ips.class != Array
end

Instance Attribute Details

- (Object) ips (readonly)

Returns the value of attribute ips



3
4
5
# File 'lib/profitbricks/ip_block.rb', line 3

def ips
  @ips
end

Class Method Details

+ (Array<IpBlock>) all

Returns a list of all public IP blocks reserved by the user, including the reserved IPs and connected NICs.



29
30
31
32
33
34
# File 'lib/profitbricks/ip_block.rb', line 29

def all
  response = Profitbricks.request :get_all_public_ip_blocks
  [response].flatten.compact.collect do |block|
    PB::IpBlock.new(block)
  end
end

+ (IpBlock) reserve(amount)

Reserves a specific amount of public IPs which can be manually assigned to a NIC by the user.



40
41
42
43
# File 'lib/profitbricks/ip_block.rb', line 40

def reserve(amount)
  response = Profitbricks.request :reserve_public_ip_block, block_size: amount
  return PB::IpBlock.new(response)
end

Instance Method Details

- (Object) id



13
14
15
# File 'lib/profitbricks/ip_block.rb', line 13

def id
  @block_id
end

- (Boolean) release

Releases an existing block of reserved public IPs.



20
21
22
23
# File 'lib/profitbricks/ip_block.rb', line 20

def release
  response = Profitbricks.request :release_public_ip_block, block_id: self.id
  return true
end