Class: HCloud::Zone
Overview
Represents a DNS zone
List all zones
HCloud::Zone.all
# => [#<HCloud::Zone id: 1, ...>, ...]
Sort zones
HCloud::Zone.sort(name: :desc)
# => [#<HCloud::Zone id: 1, ...>, ...]
HCloud::Zone.sort(:id, name: :asc)
# => [#<HCloud::Zone id: 1, ...>, ...]
Search zones
HCloud::Zone.where(name: "my_zone")
# => #<HCloud::Zone id: 1, ...>
HCloud::Zone.where(mode: "primary")
# => #<HCloud::Zone id: 1, ...>
HCloud::Zone.where(label_selector: "environment=production")
# => #<HCloud::Zone id: 1, ...>
Find zone by ID
HCloud::Zone.find(1)
# => #<HCloud::Zone id: 1, ...>
Create zone
zone = HCloud::Zone.new(name: "my_zone", mode: "primary", ttl: 10800)
zone.create
zone.created?
# => true
zone = HCloud::Zone.create(name: "my_zone", mode: "primary", ttl: 10800)
# => #<HCloud::Zone id: 1, ...>
Update zone
zone = HCloud::Zone.find(1)
zone.labels = { environment: "production" }
zone.update
Delete zone
zone = HCloud::Zone.find(1)
zone.delete
zone.deleted?
# => true
Export zone file
zone = HCloud::Zone.find(1)
zone.export
# => "$ORIGIN\texample.com.\n$TTL\t3600\n\n@\tIN\tSOA\thydrogen.ns.hetzner.com. dns.hetzner.com. ..."
Actions
List actions
actions = HCloud::Zone.find(1).actions
# => [#<HCloud::Action id: 1, ...>, ...]
Sort actions
HCloud::Zone.find(1).actions.sort(finished: :desc)
# => [#<HCloud::Action id: 1, ...>, ...]
HCloud::Zone.find(1).actions.sort(:command, finished: :asc)
# => [#<HCloud::Actions id: 1, ...>, ...]
Search actions
HCloud::Zone.find(1).actions.where(command: "import_zonefile")
# => #<HCloud::Action id: 1, ...>
HCloud::Zone.find(1).actions.where(status: "success")
# => #<HCloud::Action id: 1, ...>
Find action by ID
HCloud::Zone.find(1).actions.find(1)
# => #<HCloud::Action id: 1, ...>
Resource-specific actions
Change a zone’s primary nameservers
HCloud::Zone.find(1).change_primary_nameservers(primary_nameservers: [{ address: "198.51.100.1", port: 53 }, { address: "203.0.113.1", port: 53 }])
# => #<HCloud::Action id: 1, ...>
Change protection
HCloud::Zone.find(1).change_protection(delete: true)
# => #<HCloud::Action id: 1, ...>
Change default TTL
HCloud::Zone.find(1).change_ttl(ttl: 10800)
# => #<HCloud::Action id: 1, ...>
Import zone file
HCloud::Zone.find(1).import_zonefile(zonefile: "$ORIGIN\texample.com.\n$TTL\t3600\n\n@\tIN\tSOA\thydrogen.ns.hetzner.com. dns.hetzner.com. ...")
# => #<HCloud::Action id: 1, ...>
Instance Method Summary collapse
Methods inherited from Resource
#==, attribute, client, #initialize, #inspect, #mutable?, resource_name, #to_h
Constructor Details
This class inherits a constructor from HCloud::Resource
Instance Method Details
#creatable_attributes ⇒ Object
149 150 151 |
# File 'lib/hcloud/resources/zone.rb', line 149 def creatable_attributes [:name, :mode, :ttl, :labels, :primary_nameservers, :rrsets] end |
#export ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/hcloud/resources/zone.rb', line 141 def export raise Errors::MissingIDError unless id client .get("#{resource_path}/#{id}/zonefile") .fetch(:zonefile) end |
#updatable_attributes ⇒ Object
153 154 155 |
# File 'lib/hcloud/resources/zone.rb', line 153 def updatable_attributes [:labels] end |