Class: HCloud::Server
- Defined in:
- lib/hcloud/resources/server.rb
Overview
Represents a server
List all servers
HCloud::Server.all
# => [#<HCloud::Server id: 1, ...>, ...]
Sort servers
HCloud::Server.sort(name: :desc)
# => [#<HCloud::Server id: 1, ...>, ...]
HCloud::Server.sort(:id, name: :asc)
# => [#<HCloud::Server id: 1, ...>, ...]
Search servers
HCloud::Server.where(name: "my_server")
# => #<HCloud::Server id: 1, ...>
HCloud::Server.where(status: "running")
# => #<HCloud::Server id: 1, ...>
HCloud::Server.where(label_selector: { environment: "production" })
# => #<HCloud::Server id: 1, ...>
Find server by ID
HCloud::Server.find(1)
# => #<HCloud::Server id: 1, ...>
Create server
user_data = File.read("user_data.yml")
server = HCloud::Server.new(name: "my_server", image: "debian-11", server_type: "cx11", user_data: user_data)
server.create
server.created?
# => true
firewall = HCloud::Server.create(name: "my_server", image: "debian-11", server_type: "cx11")
# => #<HCloud::Server id: 1, ...>
Update server
server = HCloud::Server.find(1)
server.name = "another_server"
server.update
Delete server
server = HCloud::Server.find(1)
server.delete
server.deleted?
# => true
Get metrics
server = HCloud::Server.find(1)
server.metrics(type: :cpu, from: 2.minutes.ago, to: 1.minute.ago)
# => #<HCloud::Metrics ...>
server.metrics(type: [:cpu, :disk, :network], from: 2.minutes.ago, to: 1.minute.ago, step: 60)
# => #<HCloud::Metrics ...>
TODO: actions
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_attributes ⇒ Object
170 171 172 |
# File 'lib/hcloud/resources/server.rb', line 170 def creatable_attributes [:name, :automount, :start_after_create, :user_data, :labels, datacenter: [:id, :name], image: [:id, :name], location: [:id, :name], server_type: [:id, :name], ssh_keys: [:id, :name], firewalls: :id, networks: :id, volumes: :id] end |
#updatable_attributes ⇒ Object
174 175 176 |
# File 'lib/hcloud/resources/server.rb', line 174 def updatable_attributes [:name, :labels] end |