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

#initialize(hash, parent = nil) ⇒ IpBlock

Returns a new instance of IpBlock.



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

#ipsObject (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

.allArray<IpBlock>

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

Returns:

  • (Array<IpBlock>)

    List of all IpBlocks



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

.reserve(amount) ⇒ IpBlock

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

Parameters:

  • Block (Fixnum)

    size / amount of IPs to reserve

Returns:

  • (IpBlock)

    The reserved IpBlock



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

#idObject



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

def id
  @block_id
end

#releaseBoolean

Releases an existing block of reserved public IPs.

Returns:

  • (Boolean)

    true on success, false otherwise



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