class Profitbricks::Nic

Public Class Methods

create(options = {}) click to toggle source

Creates a NIC on an existing virtual server.

The user can specify and assign local IPs manually to a NIC, which is connected to a Private LAN. Valid IP addresses for Private LANs are 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16. In a Public LAN, a random DHCP IP address is assigned to each connected NIC by default. This IP Address is automatically generated and will change eventually, e.g. during a server reboot or while disconnecting and reconnecting a LAN to the internet.

@param [Hash] options parameters for the new NIC @option options [Fixnum] :server_id Identifier of the target virtual server (required) @option options [Fixnum] :lan_id Identifier of the target LAN > 0 that is to be connected to the specified virtual server. If no LAN exists for such ID, a new LAN with the given ID will be created. (required) @option options [String] :ip Public/private IP address. @option options [String] :name Names the NIC @option options [Boolean] :dhcpActive Toggles usage of ProfitBricks DHCP @return [Nic] The created NIC

# File lib/profitbricks/nic.rb, line 82
def create(options = {})
  options[:nic_name] = options.delete :name if options[:name]
  response = Profitbricks.request :create_nic, options
  self.find(:id => response[:nic_id])
end
find(options = {}) click to toggle source

Returns information about the state and configuration of an existing NIC.

@param [Hash] options currently just :id is supported @option options [String] :id The id of the NIC to locate

# File lib/profitbricks/nic.rb, line 92
def find(options = {})
  raise "Unable to locate the Nic named '#{options[:name]}'" unless options[:id]
  response = Profitbricks.request :get_nic, nic_id: options[:id]
  PB::Nic.new(response)
end
new(hash, parent=nil) click to toggle source
Calls superclass method Profitbricks::Model::new
# File lib/profitbricks/nic.rb, line 6
def initialize(hash, parent=nil)
  super(hash)
  @ips = [@ips] if @ips.class != Array
end

Public Instance Methods

add_ip(ip) click to toggle source

Adds an existing reserved public IP to a NIC. This operation is required, when dealing with reserved public IPs to ensure proper routing by the ProfitBricks cloud networking layer.

@param [String] Reserved IP

# File lib/profitbricks/nic.rb, line 38
def add_ip(ip)
  response = Profitbricks.request :add_public_ip_to_nic, nic_id: self.id, ip: ip
  @ips.push ip
  return true
end
delete() click to toggle source

Deletes an existing NIC.

@return [Boolean] true on success, false otherwise

# File lib/profitbricks/nic.rb, line 56
def delete
  response = Profitbricks.request :delete_nic, nic_id: self.id
  return true
end
ip() click to toggle source
# File lib/profitbricks/nic.rb, line 61
def ip
  if @ips.length <= 1
    @ips.first 
  else
    raise ArgumentError.new("This Nic has more then one IP assigned")
  end
end
remove_ip(ip) click to toggle source

Removes a reserved public IP from a NIC. This operation is required, when dealing with reserved public IPs to ensure proper routing by the ProfitBricks cloud networking layer.

@param [String] Reserved IP

# File lib/profitbricks/nic.rb, line 47
def remove_ip(ip)
  response = Profitbricks.request :remove_public_ip_from_nic, nic_id: self.id, ip: ip
  @ips.delete ip
  return true
end
set_internet_access=(value) click to toggle source

Connects or disconnects an existing NIC to a public LAN to get internet access.

@param [Boolean] Internet access (trUe/false) @return [Boolean] true on success, false otherwise

# File lib/profitbricks/nic.rb, line 15
def set_internet_access=(value)
  response = Profitbricks.request :set_internet_access, data_center_id: self.data_center_id, lan_id: self.lan_id, internet_access: value
  return true
end
update(options = {}) click to toggle source

Changes the settings of an existing NIC.

@param [Hash] options parameters to update @option options [Fixnum] :server_id Identifier of the target virtual server (required) @option options [Fixnum] :lan_id Identifier of the target LAN > 0 that is to be connected to the specified virtual server. If no LAN exists for such ID, a new LAN with the given ID will be created. @option options [String] :ip Public/private IP address. @option options [String] :name Names the NIC @return [Boolean] true on success, false otherwise

# File lib/profitbricks/nic.rb, line 28
def update(options = {})
  update_attributes_from_hash options
  options[:nic_name] = options.delete :name if options[:name]
  response = Profitbricks.request :update_nic, options.merge(:nic_id => self.id)
  return true
end