class Fog::HP::DNS::Mock

Public Class Methods

data() click to toggle source
# File lib/fog/hp/dns.rb, line 33
def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {
      :domains => {},
      :records => {}
    }
  end
end
new(options={}) click to toggle source
# File lib/fog/hp/dns.rb, line 46
def initialize(options={})
  @hp_access_key = options[:hp_access_key]
end
reset() click to toggle source
# File lib/fog/hp/dns.rb, line 42
def self.reset
  @data = nil
end

Public Instance Methods

create_domain(name, email, options={}) click to toggle source
# File lib/fog/hp/requests/dns/create_domain.rb, line 45
def create_domain(name, email, options={})
  response        = Excon::Response.new
  response.status = 200

  data = {
      'id'         => Fog::HP::Mock.uuid.to_s,
      'name'       => name || 'domain1.com.',
      'email'      => email || 'nsadmin@example.org',
      'description' => options[:description] || 'desc domain1.com.',
      'ttl'        => options[:ttl] || 3600,
      'serial'     => Fog::Mock.random_numbers(10).to_i,
      'created_at' => '2012-01-01T13:32:20Z'
  }
  self.data[:domains][data['id']] = data
  response.body = data
  response
end
create_record(domain_id, name, type, data, options={}) click to toggle source
# File lib/fog/hp/requests/dns/create_record.rb, line 50
def create_record(domain_id, name, type, data, options={})
  response        = Excon::Response.new
  if list_domains.body['domains'].find {|_| _['id'] == domain_id}
    response.status = 200
    data = {
        'id'           => Fog::HP::Mock.uuid.to_s,
        'domain_id'    => domain_id,
        'name'         => name || 'www.example.com.',
        'type'         => type || 'A',
        'data'         => data || '15.185.172.152',
        'ttl'          => options['ttl'] || 3600,
        'description'  => options['description'] || 'desc for www.example.com.',
        'priority'     => options['priority'] || nil,
        'created_at'   => '2012-11-02T19:56:26.366792',
        'updated_at'   => '2012-11-02T19:56:26.366792'
    }
    self.data[:records][data['id']] = data
    response.body = data
    response
  else
    raise Fog::HP::DNS::NotFound
  end
end
data() click to toggle source
# File lib/fog/hp/dns.rb, line 50
def data
  self.class.data[@hp_access_key]
end
delete_domain(domain_id) click to toggle source
# File lib/fog/hp/requests/dns/delete_domain.rb, line 20
def delete_domain(domain_id)
  response = Excon::Response.new
  if list_domains.body['domains'].find { |_| _['id'] == domain_id }
    response.status = 202
    response
  else
    raise Fog::HP::DNS::NotFound
  end
end
delete_record(domain_id, record_id) click to toggle source
# File lib/fog/hp/requests/dns/delete_record.rb, line 21
def delete_record(domain_id, record_id)
  response = Excon::Response.new
  if list_records_in_a_domain(domain_id).body['records'].find { |_| _['id'] == record_id }
    response.status = 200
    response
  else
    raise Fog::HP::DNS::NotFound
  end
  response
end
dummy_servers() click to toggle source
# File lib/fog/hp/requests/dns/get_servers_hosting_domain.rb, line 41
def dummy_servers
  [
      {
          'id'         => Fog::HP::Mock.uuid.to_s,
          'name'       => 'ns1.provider.com.',
          'created_at' => '2012-01-01T13:32:20Z',
          'updated_at' => '2012-01-01T13:32:20Z'
      },
      {
          'id'         => Fog::HP::Mock.uuid.to_s,
          'name'       => 'ns2.provider.com.',
          'created_at' => '2012-01-01T13:32:20Z',
          'updated_at' => '2012-01-01T13:32:20Z'
      },
  ]
end
get_domain(domain_id) click to toggle source
# File lib/fog/hp/requests/dns/get_domain.rb, line 28
def get_domain(domain_id)
  response = Excon::Response.new
  if domain = list_domains.body['domains'].find { |_| _['id'] == domain_id }
    response.status = 200
    response.body = domain
    response
  else
    raise Fog::HP::DNS::NotFound
  end
end
get_record(domain_id, record_id) click to toggle source
# File lib/fog/hp/requests/dns/get_record.rb, line 33
def get_record(domain_id, record_id)
  response = Excon::Response.new
  if record = list_records_in_a_domain(domain_id).body['records'].find { |_| _['id'] == record_id }
    response.status = 200
    response.body = record
    response
  else
    raise Fog::HP::DNS::NotFound
  end
end
get_servers_hosting_domain(domain_id) click to toggle source
# File lib/fog/hp/requests/dns/get_servers_hosting_domain.rb, line 30
def get_servers_hosting_domain(domain_id)
  response = Excon::Response.new
  if list_domains.body['domains'].find { |_| _['id'] == domain_id }
    response.status = 200
    response.body   = { 'servers' => dummy_servers }
    response
  else
    raise Fog::HP::DNS::NotFound
  end
end
list_domains() click to toggle source
# File lib/fog/hp/requests/dns/list_domains.rb, line 26
def list_domains
  response        = Excon::Response.new
  domains = self.data[:domains].values
  response.status = 200
  response.body = { 'domains' => domains }
  response
end
list_records_in_a_domain(domain_id) click to toggle source
# File lib/fog/hp/requests/dns/list_records_in_a_domain.rb, line 33
def list_records_in_a_domain(domain_id)
  response = Excon::Response.new
  if domain = list_domains.body['domains'].find { |_| _['id'] == domain_id }
    response.status = 200
    response.body = { 'records' => records_for_domain(domain_id) }
  else
    raise Fog::HP::DNS::NotFound
  end
  response
end
records_for_domain(domain_id) click to toggle source
# File lib/fog/hp/requests/dns/list_records_in_a_domain.rb, line 44
def records_for_domain(domain_id)
  rdata = data[:records].select { |_,v| v['domain_id'] == domain_id}
  records = []
  rdata.each { |_,v| records << v }
  records
end
reset_data() click to toggle source
# File lib/fog/hp/dns.rb, line 54
def reset_data
  self.class.data.delete(@hp_access_key)
end
update_domain(domain_id, options={}) click to toggle source
# File lib/fog/hp/requests/dns/update_domain.rb, line 42
def update_domain(domain_id, options={})
  response = Excon::Response.new
  if domain = list_domains.body['domains'].find { |_| _['id'] == domain_id }

    domain['name']          = options[:name]   if options[:name]
    domain['description']   = options[:description]   if options[:description]
    domain['ttl']           = options[:ttl]    if options[:ttl]
    domain['email']         = options[:email]  if options[:email]

    response.status = 200
    response.body   = domain
    response
  else
    raise Fog::HP::DNS::NotFound
  end
end
update_record(domain_id, record_id, options) click to toggle source
# File lib/fog/hp/requests/dns/update_record.rb, line 48
def update_record(domain_id, record_id, options)
  response = Excon::Response.new
  if record = list_records_in_a_domain(domain_id).body['records'].find { |_| _['id'] == record_id }
    record['name']      = options[:name]      if options[:name]
    record['type']      = options[:type]      if options[:type]
    record['data']      = options[:data]      if options[:data]
    record['priority']  = options[:priority]  if options[:priority]

    response.status = 200
    response.body   = record
    response
  else
    raise Fog::HP::DNS::NotFound
  end
end