Class: HCloud::FloatingIP

Inherits:
Resource show all
Defined in:
lib/hcloud/resources/floating_ip.rb

Overview

Represents a floating IP

List all floating IPs

HCloud::FloatingIP.all
# => [#<HCloud::FloatingIP id: 1, ...>, ...]

Sort floating IPs

HCloud::FloatingIP.sort(id: :asc)
# => [#<HCloud::FloatingIP id: 1, ...>, ...]

HCloud::FloatingIP.sort(:id, created: :asc)
# => [#<HCloud::FloatingIP id: 1, ...>, ...]

Search floating IPs

HCloud::FloatingIP.where(name: "my_floating_ip")
# => #<HCloud::FloatingIP id: 1, ...>

HCloud::FloatingIP.where(label_selector: { environment: "production" })
# => #<HCloud::FloatingIP id: 1, ...>

Find floating IP by ID

HCloud::FloatingIP.find(1)
# => #<HCloud::FloatingIP id: 1, ...>

Create floating IP

floating IP = HCloud::FloatingIP.new(name: "my_floating_ip", type: "ipv4", home_location: "fsn1")
floating IP.create
floating IP.created?
# => true

firewall = HCloud::FloatingIP.create(name: "my_floating_ip")
# => #<HCloud::FloatingIP id: 1, ...>

Update floating IP

floating IP = HCloud::FloatingIP.find(1)
floating IP.name = "another_floating_ip"
floating IP.update

Delete floating IP

floating IP = HCloud::FloatingIP.find(1)
floating IP.delete
floating IP.deleted?
# => true

Actions

List actions

actions = HCloud::FloatingIP.find(1).actions
# => [#<HCloud::Action id: 1, ...>, ...]

Sort actions

HCloud::FloatingIP.find(1).actions.sort(finished: :desc)
# => [#<HCloud::Action id: 1, ...>, ...]

HCloud::FloatingIP.find(1).actions.sort(:command, finished: :asc)
# => [#<HCloud::Actions id: 1, ...>, ...]

Search actions

HCloud::FloatingIP.find(1).actions.where(command: "assign_floating_ip")
# => #<HCloud::Action id: 1, ...>

HCloud::FloatingIP.find(1).actions.where(status: "success")
# => #<HCloud::Action id: 1, ...>

Find action by ID

HCloud::FloatingIP.find(1).actions.find(1)
# => #<HCloud::Action id: 1, ...>

Resource-specific actions

Assign a floating IP to a server

HCloud::FloatingIP.find(1).assign(server: 1)
# => #<HCloud::Action id: 1, ...>

Unassign a floating IP from a server

HCloud::FloatingIP.find(1).unassign
# => #<HCloud::Action id: 1, ...>

Change reverse DNS entry

HCloud::FloatingIP.find(1).change_dns_ptr(dns_ptr: "server.example.com", ip: "1.2.3.4")
# => #<HCloud::Action id: 1, ...>

Change protection

HCloud::FloatingIP.find(1).change_protection(delete: true)
# => #<HCloud::Action id: 1, ...>

Instance Method Summary collapse

Methods inherited from Resource

#==, attribute, client, #initialize, #inspect, resource_name, #to_h

Constructor Details

This class inherits a constructor from HCloud::Resource

Instance Method Details

#creatable_attributesObject



137
138
139
# File 'lib/hcloud/resources/floating_ip.rb', line 137

def creatable_attributes
  [:name, :description, :type, :labels, home_location: [:id, :name], server: [:id, :name]]
end

#updatable_attributesObject



141
142
143
# File 'lib/hcloud/resources/floating_ip.rb', line 141

def updatable_attributes
  [:name, :labels]
end