Class: Profitbricks::Nic
Class Method Summary collapse
-
.create(options = {}) ⇒ Nic
Creates a NIC on an existing virtual server.
-
.find(options = {}) ⇒ Object
Returns information about the state and configuration of an existing NIC.
Instance Method Summary collapse
-
#add_ip(ip) ⇒ Object
Adds an existing reserved public IP to a NIC.
-
#delete ⇒ Boolean
Deletes an existing NIC.
-
#initialize(hash, parent = nil) ⇒ Nic
constructor
A new instance of Nic.
- #ip ⇒ Object
-
#remove_ip(ip) ⇒ Object
Removes a reserved public IP from a NIC.
-
#set_internet_access=(value) ⇒ Boolean
Connects or disconnects an existing NIC to a public LAN to get internet access.
-
#update(options = {}) ⇒ Boolean
Changes the settings of an existing NIC.
Methods inherited from Model
#attributes, belongs_to, has_many, #reload
Constructor Details
#initialize(hash, parent = nil) ⇒ Nic
Returns a new instance of Nic.
6 7 8 9 |
# File 'lib/profitbricks/nic.rb', line 6 def initialize(hash, parent=nil) super(hash) @ips = [@ips] if @ips.class != Array end |
Class Method Details
.create(options = {}) ⇒ Nic
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.
82 83 84 85 86 |
# File 'lib/profitbricks/nic.rb', line 82 def create( = {}) [:nic_name] = .delete :name if [:name] response = Profitbricks.request :create_nic, self.find(:id => response[:nic_id]) end |
.find(options = {}) ⇒ Object
Returns information about the state and configuration of an existing NIC.
92 93 94 95 96 |
# File 'lib/profitbricks/nic.rb', line 92 def find( = {}) raise "Unable to locate the Nic named '#{[:name]}'" unless [:id] response = Profitbricks.request :get_nic, nic_id: [:id] PB::Nic.new(response) end |
Instance Method Details
#add_ip(ip) ⇒ Object
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.
38 39 40 41 42 |
# 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 ⇒ Boolean
Deletes an existing NIC.
56 57 58 59 |
# File 'lib/profitbricks/nic.rb', line 56 def delete response = Profitbricks.request :delete_nic, nic_id: self.id return true end |
#ip ⇒ Object
61 62 63 64 65 66 67 |
# 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) ⇒ Object
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.
47 48 49 50 51 |
# 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) ⇒ Boolean
Connects or disconnects an existing NIC to a public LAN to get internet access.
15 16 17 18 |
# 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 = {}) ⇒ Boolean
Changes the settings of an existing NIC.
28 29 30 31 32 33 |
# File 'lib/profitbricks/nic.rb', line 28 def update( = {}) update_attributes_from_hash [:nic_name] = .delete :name if [:name] response = Profitbricks.request :update_nic, .merge(:nic_id => self.id) return true end |