Class: Fog::DNS::Rackspace::Real

Inherits:
Rackspace::Service show all
Defined in:
lib/fog/rackspace/dns.rb,
lib/fog/rackspace/requests/dns/callback.rb,
lib/fog/rackspace/requests/dns/add_records.rb,
lib/fog/rackspace/requests/dns/list_domains.rb,
lib/fog/rackspace/requests/dns/list_records.rb,
lib/fog/rackspace/requests/dns/modify_domain.rb,
lib/fog/rackspace/requests/dns/modify_record.rb,
lib/fog/rackspace/requests/dns/remove_domain.rb,
lib/fog/rackspace/requests/dns/remove_record.rb,
lib/fog/rackspace/requests/dns/create_domains.rb,
lib/fog/rackspace/requests/dns/remove_domains.rb,
lib/fog/rackspace/requests/dns/remove_records.rb,
lib/fog/rackspace/requests/dns/list_subdomains.rb,
lib/fog/rackspace/requests/dns/list_domain_details.rb,
lib/fog/rackspace/requests/dns/list_record_details.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/fog/rackspace/dns.rb', line 86

def initialize(options={})
  @rackspace_api_key = options[:rackspace_api_key]
  @rackspace_username = options[:rackspace_username]
  @rackspace_auth_url = options[:rackspace_auth_url]
  @connection_options = options[:connection_options] || {}
  @rackspace_endpoint = Fog::Rackspace.normalize_url(options[:rackspace_dns_url] || options[:rackspace_dns_endpoint])
  @rackspace_region = options[:rackspace_region]

  authenticate

  deprecation_warnings(options)

  @connection_options[:headers] ||= {}
  @connection_options[:headers].merge!({ 'Content-Type' => 'application/json', 'X-Auth-Token' => auth_token })

  @persistent = options[:persistent] || false
  @connection = Fog::Connection.new(endpoint_uri.to_s, @persistent, @connection_options)
end

Instance Method Details

#add_records(domain_id, records) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fog/rackspace/requests/dns/add_records.rb', line 5

def add_records(domain_id, records)

  validate_path_fragment :domain_id, domain_id

  data = {
    'records' => records.collect do |record|
      record_data = {
        'name' => record[:name],
        'type' => record[:type],
        'data' => record[:data]
      }
      
      if record.has_key? :ttl
        record_data['ttl'] = record[:ttl]
      end
      
      if record.has_key? :priority
        record_data['priority'] = record[:priority]
      end
      record_data
    end
  }

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

#callback(job_id, show_details = true) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/fog/rackspace/requests/dns/callback.rb', line 5

def callback(job_id, show_details=true)

  validate_path_fragment :job_id, job_id

  request(
    :expects  => [200, 202, 204],
    :method   => 'GET',
    :path     => "status/#{job_id}",
    :query    => "showDetails=#{show_details}"
  )
end

#create_domains(domains) ⇒ Object



5
6
7
8
9
10
11
12
13
14
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
# File 'lib/fog/rackspace/requests/dns/create_domains.rb', line 5

def create_domains(domains)
  data = {
    'domains' => []
  }

  domains.each do |domain|
    domain_data =
      {
        'name' => domain[:name],
        'emailAddress' => domain[:email]
      }

    if domain.has_key? :records
      domain_data['recordsList'] = {
        'records' => domain[:records].collect do |record|
          record_data = {
            'ttl' => record[:ttl],
            'data' => record[:data],
            'name' => record[:name],
            'type' => record[:type],
          }

          if record.has_key? :priority
            record_data.merge!({'priority' => record[:priority]})
          else
            record_data
          end
        end
      }
    end
    data['domains'] << domain_data
  end

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

#endpoint_uri(service_endpoint_url = nil) ⇒ Object



105
106
107
# File 'lib/fog/rackspace/dns.rb', line 105

def endpoint_uri(service_endpoint_url=nil)
  @uri = super(@rackspace_endpoint || service_endpoint_url, :rackspace_dns_url)
end

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fog/rackspace/requests/dns/list_domain_details.rb', line 5

def list_domain_details(domain_id, options={})

  validate_path_fragment :domain_id, domain_id

  path = "domains/#{domain_id}"
  query_data = {}

  if options.has_key? :show_records
    query_data['showRecords'] = options[:show_records]
  end
  if options.has_key? :show_subdomains
    query_data['showSubdomains'] = options[:show_subdomains]
  end

  if !query_data.empty?
    path = path + '?' + array_to_query_string(query_data)
  end

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

#list_domains(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/rackspace/requests/dns/list_domains.rb', line 5

def list_domains(options={})

  path = 'domains'
  if !options.empty?
    path = path + '?' + array_to_query_string(options)
  end

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

#list_record_details(domain_id, record_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/rackspace/requests/dns/list_record_details.rb', line 5

def list_record_details(domain_id, record_id)

  validate_path_fragment :domain_id, domain_id
  validate_path_fragment :record_id, record_id

  path = "domains/#{domain_id}/records/#{record_id}"

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

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/rackspace/requests/dns/list_records.rb', line 5

def list_records(domain_id, options={})

  validate_path_fragment :domain_id, domain_id

  path = "domains/#{domain_id}/records"
  if !options.empty?
    path = path + '?' + array_to_query_string(options)
  end

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

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fog/rackspace/requests/dns/list_subdomains.rb', line 5

def list_subdomains(domain_id, options={})

  validate_path_fragment :domain_id, domain_id

  path = "domains/#{domain_id}/subdomains"
  if !options.empty?
    path = path + '?' + array_to_query_string(options)
  end

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

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/rackspace/requests/dns/modify_domain.rb', line 5

def modify_domain(domain_id, options={})

  validate_path_fragment :domain_id, domain_id

  path = "domains/#{domain_id}"
  data = {}

  if options.has_key? :ttl
    data['ttl'] = options[:ttl]
  end
  if options.has_key? :comment
    data['comment'] = options[:comment]
  end
  if options.has_key? :email
    data['emailAddress'] = options[:email]
  end

  if data.empty?
    return
  end

  request(
    :expects  => [202, 204],
    :method   => 'PUT',
    :path     => path,
    :body     => Fog::JSON.encode(data)
  )
end

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fog/rackspace/requests/dns/modify_record.rb', line 5

def modify_record(domain_id, record_id, options={})

  validate_path_fragment :domain_id, domain_id
  validate_path_fragment :record_id, record_id

  path = "domains/#{domain_id}/records/#{record_id}"
  data = {}

  if options.has_key? :ttl
    data['ttl'] = options[:ttl]
  end
  if options.has_key? :name
    data['name'] = options[:name]
  end
  if options.has_key? :data
    data['data'] = options[:data]
  end

  if data.empty?
    return
  end

  request(
    :expects  => [202, 204],
    :method   => 'PUT',
    :path     => path,
    :body     => Fog::JSON.encode(data)
  )
end

#regionObject



81
82
83
84
# File 'lib/fog/rackspace/dns.rb', line 81

def region
  #Note: DNS does not currently support multiple regions
  @rackspace_region
end

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/rackspace/requests/dns/remove_domain.rb', line 5

def remove_domain(domain_id, options={})

  validate_path_fragment :domain_id, domain_id

  path = "domains/#{domain_id}"
  query_data = {}

  if options.has_key? :delete_subdomains
    query_data['deleteSubdomains'] = options[:delete_subdomains].to_s
  end

  if !query_data.empty?
    path = path + '?' + array_to_query_string(query_data)
  end

  request(
    :expects  => [202, 204],
    :method   => 'DELETE',
    :path     => path
  )
end

#remove_domains(domain_ids, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fog/rackspace/requests/dns/remove_domains.rb', line 5

def remove_domains(domain_ids, options={})

  path = "domains?" + domain_ids.collect { |domain_id| "id=#{domain_id}" }.join('&')
  query_data = {}

  if options.has_key? :delete_subdomains
    query_data['deleteSubdomains'] = options[:delete_subdomains]
  end

  if !query_data.empty?
    path = path + '&' + array_to_query_string(query_data)
  end

  request(
    :expects  => [202, 204],
    :method   => 'DELETE',
    :path     => path
  )
end

#remove_record(domain_id, record_id) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/rackspace/requests/dns/remove_record.rb', line 5

def remove_record(domain_id, record_id)

  validate_path_fragment :domain_id, domain_id
  validate_path_fragment :record_id, record_id

  path = "domains/#{domain_id}/records/#{record_id}"

  request(
    :expects  => [202, 204],
    :method   => 'DELETE',
    :path     => path
  )
end

#remove_records(domain_id, record_ids) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/rackspace/requests/dns/remove_records.rb', line 5

def remove_records(domain_id, record_ids)

  validate_path_fragment :domain_id, domain_id

  path = "domains/#{domain_id}/records?" + record_ids.collect { |record_id| "id=#{record_id}" }.join('&')

  request(
    :expects  => [202, 204],
    :method   => 'DELETE',
    :path     => path
  )
end

#service_nameObject



77
78
79
# File 'lib/fog/rackspace/dns.rb', line 77

def service_name
  :cloudDNS
end