Module: EPPClient::HostmasterHost
- Included in:
- Hostmaster
- Defined in:
- lib/epp-client/hostmaster-host.rb
Instance Method Summary collapse
-
#host_check(*hosts) ⇒ Object
Check the availability of hosts.
-
#host_check_process(xml) ⇒ Object
:nodoc:.
-
#host_check_xml(*hosts) ⇒ Object
:nodoc:.
-
#host_create(host) ⇒ Object
Creates a host.
-
#host_create_process(xml) ⇒ Object
:nodoc:.
-
#host_create_xml(host) ⇒ Object
:nodoc:.
-
#host_delete(host) ⇒ Object
Deletes a host.
-
#host_delete_xml(host) ⇒ Object
:nodoc:.
-
#host_info(args) ⇒ Object
Returns the informations about a host.
-
#host_info_process(xml) ⇒ Object
:nodoc:.
-
#host_info_xml(args) ⇒ Object
:nodoc:.
-
#host_update(args) ⇒ Object
Updates a host.
-
#host_update_xml(args) ⇒ Object
:nodoc:.
Instance Method Details
#host_check(*hosts) ⇒ Object
Check the availability of hosts
takes list of hosts as arguments
returns an array of hashes containing three fields :
:name-
the host name
:avail-
availability
:reason-
the server-specific text to help explain why the object cannot be provisioned.
24 25 26 27 28 29 |
# File 'lib/epp-client/hostmaster-host.rb', line 24 def host_check(*hosts) hosts.flatten! response = send_request(host_check_xml(*hosts)) get_result(:xml => response, :callback => :host_check_process) end |
#host_check_process(xml) ⇒ Object
:nodoc:
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/epp-client/hostmaster-host.rb', line 31 def host_check_process(xml) #:nodoc: xml.xpath('epp:resData/host:chkData/host:cd', EPPClient::SCHEMAS_URL).map do |dom| ret = { name: dom.xpath('host:name', EPPClient::SCHEMAS_URL).text, avail: dom.xpath('host:name', EPPClient::SCHEMAS_URL).attr('avail').value == '1', } unless (reason = dom.xpath('host:reason', EPPClient::SCHEMAS_URL).text).empty? ret[:reason] = reason end ret end end |
#host_check_xml(*hosts) ⇒ Object
:nodoc:
3 4 5 6 7 8 9 10 11 |
# File 'lib/epp-client/hostmaster-host.rb', line 3 def host_check_xml(*hosts) #:nodoc: command do |xml| xml.check do xml.host :check, 'xmlns:host' => EPPClient::SCHEMAS_URL['host-1.1'] do hosts.each { |host| xml.host :name, host } end end end end |
#host_create(host) ⇒ Object
Creates a host
Takes a hash as an argument containing the following keys :
:name-
host name.
:addrv4-
array with IPv4 addresses.
:addrv6-
array with IPv6 addresses.
140 141 142 143 144 145 146 147 |
# File 'lib/epp-client/hostmaster-host.rb', line 140 def host_create(host) %w(addrv4 addrv6).each do |type| next unless host.key? type host[type] = [ host[type] ] unless host[type].is_a? Array end response = send_request(host_create_xml(host)) get_result(:xml => response, :callback => :host_create_process) end |
#host_create_process(xml) ⇒ Object
:nodoc:
149 150 151 152 153 154 155 |
# File 'lib/epp-client/hostmaster-host.rb', line 149 def host_create_process(xml) #:nodoc: host = xml.xpath('epp:resData/host:creData', EPPClient::SCHEMAS_URL) { name: host.xpath('host:name', EPPClient::SCHEMAS_URL).text, crDate: DateTime.parse(host.xpath('host:crDate', EPPClient::SCHEMAS_URL).text) } end |
#host_create_xml(host) ⇒ Object
:nodoc:
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/epp-client/hostmaster-host.rb', line 118 def host_create_xml(host) #:nodoc: command do |xml| xml.create do xml.host :create, 'xmlns:host' => EPPClient::SCHEMAS_URL['host-1.1'] do xml.host :name, host[:name] if host.key? :addrv4 host[:addrv4].each { |ip| xml.host :addr, { ip: 'v4' }, ip } end if host.key? :addrv6 host[:addrv6].each { |ip| xml.host :addr, { ip: 'v6' }, ip } end end end end end |
#host_delete(host) ⇒ Object
Deletes a host
Takes a single host for argument.
Returns true on success, or raises an exception.
172 173 174 175 |
# File 'lib/epp-client/hostmaster-host.rb', line 172 def host_delete(host) response = send_request(host_delete_xml(host)) get_result(response) end |
#host_delete_xml(host) ⇒ Object
:nodoc:
157 158 159 160 161 162 163 164 165 |
# File 'lib/epp-client/hostmaster-host.rb', line 157 def host_delete_xml(host) #:nodoc: command do |xml| xml.delete do xml.host :delete, 'xmlns:host' => EPPClient::SCHEMAS_URL['host-1.1'] do xml.host :name, host end end end end |
#host_info(args) ⇒ Object
Returns the informations about a host
Takes either a unique argument, either a string, representing the host name or a hash with the following keys :
:name-
the host name
Returned is a hash mapping:
:name-
host name.
:roid-
the Repository Object IDentifier assigned to the host object when the object was created.
:status-
the status or array of statuses of the host object.
:addrv4-
array with IPv4 addresses.
:addrv6-
array with IPv6 addresses.
:clID-
the identifier of the sponsoring client.
:crID-
the identifier of the client that created the host object.
:crDate-
the date and time of host object creation.
:upID-
the optional identifier of the client that last updated the host object.
:upDate-
the optional date and time of the most recent host object modification.
:trDate-
the optional date and time of the most recent successful host object transfer.
82 83 84 85 86 |
# File 'lib/epp-client/hostmaster-host.rb', line 82 def host_info(args) args = { name: args } if args.is_a? String response = send_request(host_info_xml(args)) get_result(:xml => response, :callback => :host_info_process) end |
#host_info_process(xml) ⇒ Object
:nodoc:
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/epp-client/hostmaster-host.rb', line 88 def host_info_process(xml) #:nodoc: host = xml.xpath('epp:resData/host:infData', EPPClient::SCHEMAS_URL) ret = { name: host.xpath('host:name', EPPClient::SCHEMAS_URL).text, roid: host.xpath('host:roid', EPPClient::SCHEMAS_URL).text, } if (status = host.xpath('host:status', EPPClient::SCHEMAS_URL)).size > 0 ret[:status] = status.map {|s| s.attr('s')} end if (value = host.xpath('host:addr[@ip="v4"]', EPPClient::SCHEMAS_URL)).size > 0 ret[:addrv4] = value.map {|ip| ip.text } end if (value = host.xpath('host:addr[@ip="v6"]', EPPClient::SCHEMAS_URL)).size > 0 ret[:addrv6] = value.map {|ip| ip.text } end %w(clID crID upID).each do |val| if (value = host.xpath("host:#{val}", EPPClient::SCHEMAS_URL)).size > 0 ret[val.to_sym] = value.text end end %w(crDate upDate trDate).each do |val| if (date = host.xpath("host:#{val}", EPPClient::SCHEMAS_URL)).size > 0 ret[val.to_sym] = DateTime.parse(date.text) end end ret end |
#host_info_xml(args) ⇒ Object
:nodoc:
44 45 46 47 48 49 50 51 52 |
# File 'lib/epp-client/hostmaster-host.rb', line 44 def host_info_xml(args) #:nodoc: command do |xml| xml.info do xml.host :info, 'xmlns:host' => EPPClient::SCHEMAS_URL['host-1.1'] do xml.host :name, args[:name] end end end end |
#host_update(args) ⇒ Object
Updates a host
Takes a hash with the name, and at least one of the following keys :
:name-
the server-unique identifier of the host object to be updated.
:add/:rem-
adds or removes the following data from the host object :
:addrv4-
an array of IPv4 addresses.
:addrv6-
an array of IPv6 addresses.
:status-
an array of status to add to/remove from the object.
Returns true on success, or raises an exception.
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/epp-client/hostmaster-host.rb', line 212 def host_update(args) [:add, :rem].each do |operation| next unless args.key?(operation) %w(addrv4 addrv6).each do |type| next unless args[operation].key? type args[operation][type] = [ args[operation[type]] ] unless args[operation][type].is_a? Array end end response = send_request(host_update_xml(args)) get_result(response) end |
#host_update_xml(args) ⇒ Object
:nodoc:
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/epp-client/hostmaster-host.rb', line 177 def host_update_xml(args) #:nodoc: command do |xml| xml.update do xml.host :update, 'xmlns:host' => EPPClient::SCHEMAS_URL['host-1.1'] do xml.host :name, args[:name] [:add, :rem].each do |operation| if args.key? operation xml.host operation do args[operation][:status].each {|s| xml.host :status, s: s} if args[operation].key? :status if args[operation].key? :addrv4 args[operation][:addrv4].each { |ip| xml.host :addr, { ip: 'v4' }, ip } end if args[operation].key? :addrv6 args[operation][:addrv6].each { |ip| xml.host :addr, { ip: 'v6' }, ip } end end end end end end end end |