Class: GandiV5::LiveDNS::Zone::Snapshot

Inherits:
Object
  • Object
show all
Includes:
Data
Defined in:
lib/gandi_v5/live_dns/zone/snapshot.rb

Overview

A snapshot (backup) of a zone.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Data

#from_gandi, included, #initialize, #to_gandi, #to_h, #values_at

Instance Attribute Details

#created_atTime (readonly)

Returns:

  • (Time)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gandi_v5/live_dns/zone/snapshot.rb', line 15

class Snapshot
  include GandiV5::Data

  members :uuid, :zone_uuid
  member :created_at, gandi_key: 'date_created', converter: GandiV5::Data::Converter::Time
  member(
    :records,
    gandi_key: 'zone_data',
    converter: GandiV5::LiveDNS::RecordSet,
    array: true
  )

  alias snapshot_uuid uuid

  # Delete this snapshot.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    _response, data = GandiV5.delete url
    data['message']
  end

  # @see GandiV5::LiveDNS::Zone.fetch
  def fetch_zone
    GandiV5::LiveDNS::Zone.fetch zone_uuid
  end

  # The snapshot's zone (fetching from Gandi if required).
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def zone
    @zone ||= fetch_zone
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(zone_uuid)
    _response, data = GandiV5.get url(zone_uuid)
    Hash[data.map { |snapshot| [snapshot['uuid'], Time.parse(snapshot['date_created'])] }]
  end

  # Get snapshot from Gandi.
  # @param zone_uuid [String, #to_s] the UUID of the zone the snapshot was made of.
  # @param snapshot_uuid [String, #to_s] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(zone_uuid, snapshot_uuid)
    _response, data = GandiV5.get url(zone_uuid, snapshot_uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape zone_uuid}/snapshots/#{CGI.escape uuid}"
  end

  def self.url(zone_uuid, snapshot_uuid = nil)
    "#{BASE}zones/#{CGI.escape zone_uuid}/snapshots" +
      (snapshot_uuid ? "/#{CGI.escape snapshot_uuid}" : '')
  end
  private_class_method :url
end

#recordsArray<GandiV5::LiveDNS::RecordSet> (readonly)

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gandi_v5/live_dns/zone/snapshot.rb', line 15

class Snapshot
  include GandiV5::Data

  members :uuid, :zone_uuid
  member :created_at, gandi_key: 'date_created', converter: GandiV5::Data::Converter::Time
  member(
    :records,
    gandi_key: 'zone_data',
    converter: GandiV5::LiveDNS::RecordSet,
    array: true
  )

  alias snapshot_uuid uuid

  # Delete this snapshot.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    _response, data = GandiV5.delete url
    data['message']
  end

  # @see GandiV5::LiveDNS::Zone.fetch
  def fetch_zone
    GandiV5::LiveDNS::Zone.fetch zone_uuid
  end

  # The snapshot's zone (fetching from Gandi if required).
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def zone
    @zone ||= fetch_zone
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(zone_uuid)
    _response, data = GandiV5.get url(zone_uuid)
    Hash[data.map { |snapshot| [snapshot['uuid'], Time.parse(snapshot['date_created'])] }]
  end

  # Get snapshot from Gandi.
  # @param zone_uuid [String, #to_s] the UUID of the zone the snapshot was made of.
  # @param snapshot_uuid [String, #to_s] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(zone_uuid, snapshot_uuid)
    _response, data = GandiV5.get url(zone_uuid, snapshot_uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape zone_uuid}/snapshots/#{CGI.escape uuid}"
  end

  def self.url(zone_uuid, snapshot_uuid = nil)
    "#{BASE}zones/#{CGI.escape zone_uuid}/snapshots" +
      (snapshot_uuid ? "/#{CGI.escape snapshot_uuid}" : '')
  end
  private_class_method :url
end

#uuidString (readonly) Also known as: snapshot_uuid

Returns:

  • (String)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gandi_v5/live_dns/zone/snapshot.rb', line 15

class Snapshot
  include GandiV5::Data

  members :uuid, :zone_uuid
  member :created_at, gandi_key: 'date_created', converter: GandiV5::Data::Converter::Time
  member(
    :records,
    gandi_key: 'zone_data',
    converter: GandiV5::LiveDNS::RecordSet,
    array: true
  )

  alias snapshot_uuid uuid

  # Delete this snapshot.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    _response, data = GandiV5.delete url
    data['message']
  end

  # @see GandiV5::LiveDNS::Zone.fetch
  def fetch_zone
    GandiV5::LiveDNS::Zone.fetch zone_uuid
  end

  # The snapshot's zone (fetching from Gandi if required).
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def zone
    @zone ||= fetch_zone
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(zone_uuid)
    _response, data = GandiV5.get url(zone_uuid)
    Hash[data.map { |snapshot| [snapshot['uuid'], Time.parse(snapshot['date_created'])] }]
  end

  # Get snapshot from Gandi.
  # @param zone_uuid [String, #to_s] the UUID of the zone the snapshot was made of.
  # @param snapshot_uuid [String, #to_s] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(zone_uuid, snapshot_uuid)
    _response, data = GandiV5.get url(zone_uuid, snapshot_uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape zone_uuid}/snapshots/#{CGI.escape uuid}"
  end

  def self.url(zone_uuid, snapshot_uuid = nil)
    "#{BASE}zones/#{CGI.escape zone_uuid}/snapshots" +
      (snapshot_uuid ? "/#{CGI.escape snapshot_uuid}" : '')
  end
  private_class_method :url
end

#zone_uuidString (readonly)

Returns:

  • (String)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gandi_v5/live_dns/zone/snapshot.rb', line 15

class Snapshot
  include GandiV5::Data

  members :uuid, :zone_uuid
  member :created_at, gandi_key: 'date_created', converter: GandiV5::Data::Converter::Time
  member(
    :records,
    gandi_key: 'zone_data',
    converter: GandiV5::LiveDNS::RecordSet,
    array: true
  )

  alias snapshot_uuid uuid

  # Delete this snapshot.
  # @return [String] The confirmation message from Gandi.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def delete
    _response, data = GandiV5.delete url
    data['message']
  end

  # @see GandiV5::LiveDNS::Zone.fetch
  def fetch_zone
    GandiV5::LiveDNS::Zone.fetch zone_uuid
  end

  # The snapshot's zone (fetching from Gandi if required).
  # @return [GandiV5::LiveDNS::Zone]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def zone
    @zone ||= fetch_zone
  end

  # Get snapshot UUIDs for this zone from Gandi.
  # @return [Hash{String => Time}] Mapping UUID to time made.
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.list(zone_uuid)
    _response, data = GandiV5.get url(zone_uuid)
    Hash[data.map { |snapshot| [snapshot['uuid'], Time.parse(snapshot['date_created'])] }]
  end

  # Get snapshot from Gandi.
  # @param zone_uuid [String, #to_s] the UUID of the zone the snapshot was made of.
  # @param snapshot_uuid [String, #to_s] the UUID of the snapshot to fetch.
  # @return [GandiV5::LiveDNS::Zone::Snapshot]
  # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
  def self.fetch(zone_uuid, snapshot_uuid)
    _response, data = GandiV5.get url(zone_uuid, snapshot_uuid)
    from_gandi data
  end

  private

  def url
    "#{BASE}zones/#{CGI.escape zone_uuid}/snapshots/#{CGI.escape uuid}"
  end

  def self.url(zone_uuid, snapshot_uuid = nil)
    "#{BASE}zones/#{CGI.escape zone_uuid}/snapshots" +
      (snapshot_uuid ? "/#{CGI.escape snapshot_uuid}" : '')
  end
  private_class_method :url
end

Class Method Details

.fetch(zone_uuid, snapshot_uuid) ⇒ GandiV5::LiveDNS::Zone::Snapshot

Get snapshot from Gandi.

Parameters:

  • zone_uuid (String, #to_s)

    the UUID of the zone the snapshot was made of.

  • snapshot_uuid (String, #to_s)

    the UUID of the snapshot to fetch.

Returns:

Raises:



62
63
64
65
# File 'lib/gandi_v5/live_dns/zone/snapshot.rb', line 62

def self.fetch(zone_uuid, snapshot_uuid)
  _response, data = GandiV5.get url(zone_uuid, snapshot_uuid)
  from_gandi data
end

.list(zone_uuid) ⇒ Hash{String => Time}

Get snapshot UUIDs for this zone from Gandi.

Returns:

  • (Hash{String => Time})

    Mapping UUID to time made.

Raises:



52
53
54
55
# File 'lib/gandi_v5/live_dns/zone/snapshot.rb', line 52

def self.list(zone_uuid)
  _response, data = GandiV5.get url(zone_uuid)
  Hash[data.map { |snapshot| [snapshot['uuid'], Time.parse(snapshot['date_created'])] }]
end

Instance Method Details

#deleteString

Delete this snapshot.

Returns:

  • (String)

    The confirmation message from Gandi.

Raises:



32
33
34
35
# File 'lib/gandi_v5/live_dns/zone/snapshot.rb', line 32

def delete
  _response, data = GandiV5.delete url
  data['message']
end

#fetch_zoneObject



38
39
40
# File 'lib/gandi_v5/live_dns/zone/snapshot.rb', line 38

def fetch_zone
  GandiV5::LiveDNS::Zone.fetch zone_uuid
end

#zoneGandiV5::LiveDNS::Zone

The snapshot’s zone (fetching from Gandi if required).

Returns:

Raises:



45
46
47
# File 'lib/gandi_v5/live_dns/zone/snapshot.rb', line 45

def zone
  @zone ||= fetch_zone
end