2010-12-14 00:04:23 -05:00
module Fog
2011-06-15 20:25:01 -04:00
module DNS
class AWS
2010-12-14 00:04:23 -05:00
class Real
2011-08-24 21:00:45 -04:00
require 'fog/aws/parsers/dns/create_hosted_zone'
2010-12-14 00:04:23 -05:00
# Creates a new hosted zone
#
# ==== Parameters
# * name<~String> - The name of the domain. Must be a fully-specified domain that ends with a period
# * options<~Hash>
2011-01-26 02:08:22 -05:00
# * caller_ref<~String> - unique string that identifies the request & allows failed
2010-12-14 00:04:23 -05:00
# calls to be retried without the risk of executing the operation twice
2011-12-06 00:24:07 -05:00
# * comment<~String> -
2010-12-14 00:04:23 -05:00
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'HostedZone'<~Hash>:
2011-01-26 02:08:22 -05:00
# * 'Id'<~String> -
# * 'Name'<~String> -
2010-12-14 00:04:23 -05:00
# * 'CallerReference'<~String>
2011-01-26 02:08:22 -05:00
# * 'Comment'<~String> -
2010-12-14 00:04:23 -05:00
# * 'ChangeInfo'<~Hash> -
# * 'Id'<~String>
# * 'Status'<~String>
# * 'SubmittedAt'<~String>
# * 'NameServers'<~Array>
# * 'NameServer'<~String>
# * status<~Integer> - 201 when successful
2010-12-17 19:48:38 -05:00
def create_hosted_zone ( name , options = { } )
2010-12-14 00:04:23 -05:00
optional_tags = ''
2010-12-17 18:08:56 -05:00
if options [ :caller_ref ]
2011-12-06 00:24:07 -05:00
optional_tags += " <CallerReference> #{ options [ :caller_ref ] } </CallerReference> "
2010-12-17 18:08:56 -05:00
else
#make sure we have a unique call reference
2010-12-14 00:04:23 -05:00
caller_ref = " ref- #{ rand ( 1000000 ) . to_s } "
2011-12-06 00:24:07 -05:00
optional_tags += " <CallerReference> #{ caller_ref } </CallerReference> "
2010-12-14 00:04:23 -05:00
end
2010-12-17 18:08:56 -05:00
if options [ :comment ]
2011-12-06 00:24:07 -05:00
optional_tags += " <HostedZoneConfig><Comment> #{ options [ :comment ] } </Comment></HostedZoneConfig> "
2010-12-17 18:08:56 -05:00
end
2011-01-26 02:08:22 -05:00
2010-12-14 00:04:23 -05:00
request ( {
2012-03-28 16:50:56 -04:00
:body = > %Q{ <?xml version="1.0" encoding="UTF-8"?><CreateHostedZoneRequest xmlns="https://route53.amazonaws.com/doc/ #{ @version } /"><Name> #{ name } </Name> #{ optional_tags } </CreateHostedZoneRequest> } ,
2011-12-06 00:24:07 -05:00
:parser = > Fog :: Parsers :: DNS :: AWS :: CreateHostedZone . new ,
:expects = > 201 ,
:method = > 'POST' ,
:path = > " hostedzone "
2010-12-14 00:04:23 -05:00
} )
end
end
2012-06-07 13:46:35 -04:00
class Mock
require 'time'
def create_hosted_zone ( name , options = { } )
response = Excon :: Response . new
if list_hosted_zones . body [ 'HostedZones' ] . find_all { | z | z [ 'Name' ] == name } . size < self . data [ :limits ] [ :duplicate_domains ]
2012-06-07 17:56:00 -04:00
response . status = 201
2012-06-07 13:46:35 -04:00
if options [ :caller_ref ]
caller_ref = options [ :caller_ref ]
else
#make sure we have a unique call reference
caller_ref = " ref- #{ rand ( 1000000 ) . to_s } "
end
2012-06-07 18:28:07 -04:00
zone_id = " /hostedzone/ #{ Fog :: AWS :: Mock . zone_id } "
self . data [ :zones ] [ zone_id ] = {
2012-06-07 13:46:35 -04:00
:id = > zone_id ,
:name = > name ,
:reference = > caller_ref ,
:comment = > options [ :comment ] ,
2012-06-07 17:56:00 -04:00
:records = > { }
2012-06-07 13:46:35 -04:00
}
response . body = {
'HostedZone' = > {
2012-06-07 20:44:34 -04:00
'Id' = > zone_id ,
2012-06-07 13:46:35 -04:00
'Name' = > name ,
'CallerReference' = > caller_ref ,
'Comment' = > options [ :comment ]
} ,
'ChangeInfo' = > {
2012-06-07 17:56:00 -04:00
'Id' = > " /change/ #{ Fog :: AWS :: Mock . change_id } " ,
2012-06-07 13:46:35 -04:00
'Status' = > 'INSYNC' ,
'SubmittedAt' = > Time . now . utc . iso8601
} ,
'NameServers' = > Fog :: AWS :: Mock . nameservers
}
response
else
response . status = 400
response . body = " <?xml version= \" 1.0 \" ?><Response><Errors><Error><Code>DelegationSetNotAvailable</Code><Message>Amazon Route 53 allows some duplication, but Amazon Route 53 has a maximum threshold of duplicated domains. This error is generated when you reach that threshold. In this case, the error indicates that too many hosted zones with the given domain name exist. If you want to create a hosted zone and Amazon Route 53 generates this error, contact Customer Support.</Message></Error></Errors><RequestID> #{ Fog :: AWS :: Mock . request_id } </RequestID></Response> "
raise ( Excon :: Errors . status_error ( { :expects = > 200 } , response ) )
end
end
end
2010-12-14 00:04:23 -05:00
end
end
end