Class: Fog::HP::DNS::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/hp/requests/dns/get_domain.rb,
lib/fog/hp/dns.rb,
lib/fog/hp/requests/dns/get_record.rb,
lib/fog/hp/requests/dns/list_domains.rb,
lib/fog/hp/requests/dns/create_domain.rb,
lib/fog/hp/requests/dns/create_record.rb,
lib/fog/hp/requests/dns/delete_domain.rb,
lib/fog/hp/requests/dns/delete_record.rb,
lib/fog/hp/requests/dns/update_domain.rb,
lib/fog/hp/requests/dns/update_record.rb,
lib/fog/hp/requests/dns/list_records_in_a_domain.rb,
lib/fog/hp/requests/dns/get_servers_hosting_domain.rb

Overview

Create a new DNS domain

Parameters

  • ‘name’<~String> - Name of the domain

  • ‘email’<~String> - Email for the domain

  • options<~Hash>:

    • ‘description’<~String> - Description for the domain

    • ‘ttl’<~String> - TTL for the domain

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’<~String> - UUID of the domain

      • ‘name’<~String> - Name of the domain

      • ‘description’<~String> - Description for the domain

      • ‘ttl’<~Integer> - TTL for the domain

      • ‘email’<~String> - Email for the domain

      • ‘serial’<~Integer> - Serial number for the domain

      • ‘created_at’<~String> - created date time stamp

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fog/hp/dns.rb', line 62

def initialize(options={})
  @hp_access_key = options[:hp_access_key]
  @hp_secret_key      = options[:hp_secret_key]
  @hp_auth_uri        = options[:hp_auth_uri]
  @connection_options = options[:connection_options] || {}
  ### Set an option to use the style of authentication desired; :v1 or :v2 (default)
  auth_version        = options[:hp_auth_version] || :v2
  ### Pass the service name for object storage to the authentication call
  options[:hp_service_type] ||= "hpext:dns"
  @hp_tenant_id       = options[:hp_tenant_id]
  @hp_avl_zone        = options[:hp_avl_zone]

  ### Make the authentication call
  if (auth_version == :v2)
    # Call the control services authentication
    credentials = Fog::HP.authenticate_v2(options, @connection_options)
    # the CS service catalog returns the block storage endpoint
    @hp_block_uri = credentials[:endpoint_url]
    @credentials = credentials
  else
    # Call the legacy v1.0/v1.1 authentication
    credentials = Fog::HP.authenticate_v1(options, @connection_options)
    # the user sends in the block storage endpoint
    @hp_block_uri = options[:hp_auth_uri]
  end

  @auth_token = credentials[:auth_token]
  @persistent = options[:persistent] || false

  uri     = URI.parse(@hp_block_uri)
  @host   = uri.host
  @path   = uri.path
  @port   = uri.port
  @scheme = uri.scheme

  @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



60
61
62
# File 'lib/fog/hp/dns.rb', line 60

def credentials
  @credentials
end

Instance Method Details

#create_domain(name, email, options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/hp/requests/dns/create_domain.rb', line 24

def create_domain(name, email, options={})
  data = {
    :name => name,
    :email => email
  }

  l_options = [:description, :ttl]
  l_options.select{|o| options[o]}.each do |key|
    data[key] = options[key]
  end

  request(
      :body    => Fog::JSON.encode(data),
      :expects => 200,
      :method  => 'POST',
      :path    => 'domains'
  )
end

#create_record(domain_id, name, type, data, options = {}) ⇒ Object

Create a new DNS record

Parameters

  • ‘domain_id’<~String> - UUId of the domain

  • ‘name’<~String> - Name of record

  • ‘type’<~String> - Type of the record i.e. ‘A’

  • ‘data’<~String> - Data required by the record

  • options<~Hash>:

    • ‘description’<~String> - Description for the record

    • ‘priority’<~Integer> - Priority

    • ‘ttl’<~Integer> - TTL of the record

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’<~String> - UUID of the record

      • ‘name’<~String> - Name of the record

      • ‘description’<~String> - Description for the record

      • ‘type’<~String> - Type of the record

      • ‘domain_id’<~String> - UUID of the domain

      • ‘ttl’<~Integer> - TTL of the record

      • ‘data’<~String> - Data required by the record

      • ‘priority’<~Integer> - Priority for the record

      • ‘created_at’<~String> - created date time stamp

      • ‘updated_at’<~String> - updated date time stamp



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/hp/requests/dns/create_record.rb', line 30

def create_record(domain_id, name, type, data, options={})
  data = {
      :name => name,
      :type => type,
      :data => data
  }
  l_options = [:description, :priority, :ttl]
  l_options.select{|o| options[o]}.each do |key|
    data[key] = options[key]
  end

  request(
      :body    => Fog::JSON.encode(data),
      :expects => 200,
      :method  => 'POST',
      :path    => "domains/#{domain_id}/records"
  )
end

#delete_domain(domain_id) ⇒ Object

Delete a DNS domain

Parameters

  • domain_id<~String> - UUId of domain to delete



10
11
12
13
14
15
16
# File 'lib/fog/hp/requests/dns/delete_domain.rb', line 10

def delete_domain(domain_id)
  request(
      :expects => 200,
      :method  => 'DELETE',
      :path    => "domains/#{domain_id}"
  )
end

#delete_record(domain_id, record_id) ⇒ Object

Delete a DNS Record

Parameters

  • ‘domain_id’<~String> - UUId of domain for record

  • ‘record_id’<~String> - UUId of record to delete



11
12
13
14
15
16
17
# File 'lib/fog/hp/requests/dns/delete_record.rb', line 11

def delete_record(domain_id, record_id)
  request(
      :expects => 200,
      :method  => 'DELETE',
      :path    => "domains/#{domain_id}/records/#{record_id}"
  )
end

#get_domain(domain_id) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/fog/hp/requests/dns/get_domain.rb', line 19

def get_domain(domain_id)
  request(
      :expects => 200,
      :method  => 'GET',
      :path    => "domains/#{domain_id}"
  )
end

#get_record(domain_id, record_id) ⇒ Object

Get details of an existing DNS record

Parameters

  • ‘domain_id’<~String> - UUId of domain for record

  • ‘record_id’<~String> - UUId of record to get

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’<~String> - UUID of the record

      • ‘name’<~String> - Name of the record

      • ‘description’<~String> - Description for the record

      • ‘type’<~String> - Type of the record

      • ‘domain_id’<~String> - UUId of the domain

      • ‘ttl’<~Integer> - TTL of the record

      • ‘data’<~String> - Data required by the record

      • ‘priority’<~Integer> - Priority for the record

      • ‘created_at’<~String> - created date time stamp

      • ‘updated_at’<~String> - updated date time stamp



24
25
26
27
28
29
30
# File 'lib/fog/hp/requests/dns/get_record.rb', line 24

def get_record(domain_id, record_id)
  request(
      :expects => 200,
      :method  => 'GET',
      :path    => "domains/#{domain_id}/records/#{record_id}"
  )
end

#get_servers_hosting_domain(domain_id) ⇒ Object

Get authoritative nameservers for existing DNS domain

Parameters

  • domain_id<~String> - UUId of the domain to get nameservers for

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘nameservers’<~Array>:

        • ‘id’<~String> - UUID of the domain

        • ‘name’<~String> - Name of the domain

        • ‘ttl’<~Integer> - TTL for the domain

        • ‘email’<~String> - Email for the domain

        • ‘serial’<~Integer> - Serial number for the domain

        • ‘created_at’<~String> - created date time stamp



20
21
22
23
24
25
26
# File 'lib/fog/hp/requests/dns/get_servers_hosting_domain.rb', line 20

def get_servers_hosting_domain(domain_id)
  request(
      :expects => 200,
      :method  => 'GET',
      :path    => "domains/#{domain_id}/servers"
  )
end

#list_domainsObject

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘domains’<~Array>:

        • ‘id’<~String> - UUID of the domain

        • ‘name’<~String> - Name of the domain

        • ‘ttl’<~Integer> - TTL for the domain

        • ‘email’<~String> - Email for the domain

        • ‘serial’<~Integer> - Serial number for the domain

        • ‘created_at’<~String> - created date time stamp



16
17
18
19
20
21
22
# File 'lib/fog/hp/requests/dns/list_domains.rb', line 16

def list_domains
  request(
      :expects => 200,
      :method  => 'GET',
      :path    => 'domains'
  )
end

#list_records_in_a_domain(domain_id) ⇒ Object

List DNS records for a given domain

Parameters

  • ‘domain_id’<~String> - UUId of domain for record

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘records’<~Array>:

        • ‘id’<~String> - UUID of the record

        • ‘name’<~String> - Name of the record

        • ‘description’<~String> - Description for the record

        • ‘type’<~String> - Type of the record

        • ‘domain_id’<~String> - UUID of the domain

        • ‘ttl’<~Integer> - TTL of the record

        • ‘data’<~String> - Data required by the record

        • ‘priority’<~Integer> - Priority for the record

        • ‘created_at’<~String> - created date time stamp

        • ‘updated_at’<~String> - updated date time stamp



24
25
26
27
28
29
30
# File 'lib/fog/hp/requests/dns/list_records_in_a_domain.rb', line 24

def list_records_in_a_domain(domain_id)
  request(
      :expects => 200,
      :method  => 'GET',
      :path    => "domains/#{domain_id}/records"
  )
end

#reloadObject



100
101
102
# File 'lib/fog/hp/dns.rb', line 100

def reload
  @connection.reset
end

#request(params, parse_json = true, &block) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/fog/hp/dns.rb', line 104

def request(params, parse_json = true, &block)
  begin
    response = @connection.request(params.merge!({
     :headers => {
         'Content-Type' => 'application/json',
         'Accept'       => 'application/json',
         'X-Auth-Token' => @auth_token
     }.merge!(params[:headers] || {}),
     :path    => "#{@path}/#{params[:path]}",
    }), &block)
  rescue Excon::Errors::HTTPStatusError => error
    raise case error
            when Excon::Errors::NotFound
              Fog::HP::DNS::NotFound.slurp(error)
            else
              error
          end
  end
  if !response.body.empty? && parse_json && response.headers['Content-Type'] =~ %r{application/json}
    response.body = Fog::JSON.decode(response.body)
  end
  response
end

#update_domain(domain_id, options = {}) ⇒ Object

Update an existing DNS domain

Parameters

  • domain_id<~String> - UUId of domain to delete

  • options<~Hash>:

    • ‘name’<~String> - Name of domain

    • ‘description’<~String> - Description for the domain

    • ‘ttl’<~String> - TTL for the domain

    • ‘email’<~String> - email for the domain

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’<~String> - UUID of the domain

      • ‘name’<~String> - Name of the domain

      • ‘description’<~String> - Description for the domain

      • ‘ttl’<~Integer> - TTL for the domain

      • ‘email’<~String> - Email for the domain

      • ‘serial’<~Integer> - Serial number for the domain

      • ‘created_at’<~String> - created date time stamp



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fog/hp/requests/dns/update_domain.rb', line 25

def update_domain(domain_id, options={})
  data = {}
  l_options = [:name, :description, :ttl, :email]
  l_options.select{|o| options[o]}.each do |key|
    data[key] = options[key]
  end

  request(
    :body    => Fog::JSON.encode(data),
    :expects => 200,
    :method  => 'PUT',
    :path    => "domains/#{domain_id}"
  )
end

#update_record(domain_id, record_id, options = {}) ⇒ Object

Update an existing DNS record

Parameters

  • ‘domain_id’<~String> - UUId of domain of record

  • ‘record_id’<~String> - UUId of record to update

  • options<~Hash>:

    • ‘name’<~String> - Name of record

    • ‘description’<~String> - Description for the record

    • ‘type’<~String> - Type of the record i.e. ‘A’

    • ‘data’<~String> - Data required by the record

    • ‘priority’<~Integer> - Priority

    • ‘ttl’<~Integer> - TTL of the record

Returns

  • response<~Excon::Response>:

    • body<~Hash>:

      • ‘id’<~String> - UUID of the record

      • ‘name’<~String> - Name of the record

      • ‘description’<~String> - Description for the record

      • ‘type’<~String> - Type of the record

      • ‘domain_id’<~String> - UUID of the domain

      • ‘ttl’<~Integer> - TTL of the record

      • ‘data’<~String> - Data required by the record

      • ‘priority’<~Integer> - Priority for the record

      • ‘created_at’<~String> - created date time stamp

      • ‘updated_at’<~String> - updated date time stamp



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fog/hp/requests/dns/update_record.rb', line 31

def update_record(domain_id, record_id, options={})
  data = {}
  l_options = [:name, :description, :type, :data, :priority, :ttl]
  l_options.select{|o| options[o]}.each do |key|
    data[key] = options[key]
  end

  request(
    :body    => Fog::JSON.encode(data),
    :expects => 200,
    :method  => 'PUT',
    :path    => "domains/#{domain_id}/records/#{record_id}"
  )
end