1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

added dns files

This commit is contained in:
Mike Hagedorn 2013-02-27 15:59:31 -06:00 committed by Rupak Ganguly
parent 5f443c0289
commit 8b092910b9
12 changed files with 397 additions and 0 deletions

View file

@ -0,0 +1,18 @@
require 'fog/core/model'
module Fog
module HP
class DNS
class Domain
identity :id
attribute :name
attribute :ttl
attribute :serial
attribute :email
attribute :created_at
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/core/collection'
require 'fog/hp/models/dns/domain'
module Fog
module HP
class DNS
class Domains < Fog::Collection
model Fog::HP::DNS::Domain
def all
data = connection.list_domains.body['domains']
load(data)
end
def get(record_id)
record = connection.get_domain_details(record_id).body['domain']
new(flavor)
rescue Fog::HP::DNS::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,23 @@
require 'fog/core/model'
module Fog
module HP
class DNS
class Record
#TODO attributes taken from early openstack ref
identity :id
attribute :name
attribute :type
attribute :ttl
attribute :data
attribute :domain_id
attribute :tenant_id
attribute :priority
attribute :version
end
end
end
end

View file

@ -0,0 +1,26 @@
require 'fog/core/collection'
require 'fog/hp/models/dns/record'
module Fog
module HP
class DNS
class Records < Fog::Collection
model Fog::HP::DNS : Record
def all
data = connection.list_records.body['records']
load(data)
end
def get(record_id)
record = connection.get_record_details(record_id).body['record']
new(flavor)
rescue Fog::HP::DNS::NotFound
nil
end
end
end
end
end

View file

@ -0,0 +1,16 @@
require 'fog/core/model'
module Fog
module HP
class DNS
class Server
identity :id
attribute :name
attribute :created_at
attribute :updated_at
end
end
end
end

View file

@ -0,0 +1,40 @@
module Fog
module HP
class DNS
class Real
def create_domain(name, ttl, email)
data = {
name: name,
ttl: ttl,
email:email
}
request(
:body => MultiJson.encode(data),
:expects => 200,
:method => 'POST',
:path => 'domains.json'
)
end
end
class Mock
def create_domain
response = Excon::Response.new
response.status = 200
data = {
id : SecureRandom.uuid,
name : "domain1.com.",
ttl : 3600,
serial : 1351800588,
email : "nsadmin@example.org",
created_at : "2012-11-01T20:09:48.094457"
}
response.body = data
response
end
end
end
end
end

View file

@ -0,0 +1,43 @@
module Fog
module HP
class DNS
class Real
# Delete a Domain
#
# ==== Parameters
# * domain_id<~Integer> - Id of domain to delete
#
def delete_domain(domain_id)
request(
:expects => 200,
:method => 'DELETE',
:path => "domains/#{domain_id}"
)
end
end
class Mock
def delete_domain(domain_id)
response = Excon::Response.new
if image = find_domain(domain_id)
response.status = 202
response
else
response.status = 404
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response
end
def find_domain(domain_id)
list_domains.body['domains'].detect { |_| _['id'] == domain_id }
end
end
end
end
end

View file

@ -0,0 +1,40 @@
module Fog
module HP
class DNS
# Get details for existing domain
#
# ==== Parameters
# * instance_id<~Integer> - Id of the domain to get
#
# ==== Returns
# * response<~Excon::Response>:
# *TBD
class Real
def get_domain(instance_id)
response = request(
:expects => 200,
:method => 'GET',
:path => "domains/#{instance_id}",
)
response
end
end
class Mock
def get_domain(instance_id)
response = Excon::Response.new
if domain = find_domain(instance_id)
response.status = 200
response.body = {'domain' => domain}
response
else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response
end
end
end
end
end

View file

@ -0,0 +1,40 @@
module Fog
module HP
class DNS
class Real
# Get servers for existing domain
#
# ==== Parameters
# * instance_id<~Integer> - Id of the domain with servers
#
# ==== Returns
# * response<~Excon::Response>:
# *TBD
def get_servers_hosting_domain(instance_id)
request(
:expects => [200, 203],
:method => 'GET',
:path => "domains/#{instance_id}/servers.json"
)
end
end
class Mock
def get_servers_hosting_domain(instance_id)
if domain = find_domain(instance_id)
response.status = 200
response.body = {'domain' => domain}
response
else
response.status = 400
raise(Excon::Errors.status_error({:expects => 200}, response))
end
response
end
end
end
end
end

View file

@ -0,0 +1,33 @@
module Fog
module HP
module DNS
class Real
# List all flavors (IDs and names only)
def list_domains
request(
:expects => [200],
:method => 'GET',
:path => 'domains',
)
end
end
class Mock
def list_domains
response = Excon::Response.new
response.status = 200
response.body = {
"domains" => [
{ "name" => "domain1.com.", "created_at" => "2012-11-01T20:11:08.000000", "email" => "nsadmin@example.org", "ttl" => 3600, "serial" => 1351800668, "id" => "09494b72-b65b-4297-9efb-187f65a0553e" },
{ "name" => "domain2.com.", "created_at" => "2012-11-01T20:09:48.000000", "email" => "nsadmin@example.org", "ttl" => 3600, "serial" => 1351800588, "id" => "89acac79-38e7-497d-807c-a011e1310438" }
]
}
response
end
end
end
end
end

View file

@ -0,0 +1,57 @@
module Fog
module HP
module DNS
class Real
# List all flavors (IDs and names only)
def list_records
request(
:expects => [200],
:method => 'GET',
:path => 'records',
)
end
end
class Mock
def list_records
response = Excon::Response.new
response.status = 200
response.body = {
"records" => [
{
"id" => "2e32e609-3a4f-45ba-bdef-e50eacd345ad",
"name" => "www.example.com.",
"type" => "A",
"ttl" => 3600,
"created_at" => "2012-11-02T19:56:26.000000",
"updated_at" => "2012-11-04T13:22:36.000000",
"data" => "15.185.172.153",
"domain_id" => "89acac79-38e7-497d-807c-a011e1310438",
"tenant_id" => null,
"priority" => null,
"version" => 1,
},
{
"id" => "8e9ecf3e-fb92-4a3a-a8ae-7596f167bea3",
"name" => "host1.example.com.",
"type" => "A",
"ttl" => 3600,
"created_at" => "2012-11-04T13:57:50.000000",
"updated_at" => null,
"data" => "15.185.172.154",
"domain_id" => "89acac79-38e7-497d-807c-a011e1310438",
"tenant_id" => null,
"priority" => null,
"version" => 1
}
]
}
response
end
end
end
end
end

View file

@ -0,0 +1,34 @@
module Fog
module HP
class DNS
class Real
def update_domain(domain_id,options)
request(
:body => MultiJson.encode(options),
:expects => 200,
:method => 'PUT',
:path => "servers/#{server_id}.json"
)
end
end
class Mock
def update_domain(domain_id, options)
response = Excon::Response.new
if domain = list_domains.body['domains'].detect { |_| _['id'] == domain_id }
if options['name']
domain['name'] = options['name']
end
response.status = 200
response.body = domain
response
else
raise Fog::HP::DNS::NotFound
end
end
end
end
end
end