Class: Restcall
- Inherits:
-
Object
- Object
- Restcall
- Defined in:
- lib/dyntool.rb
Overview
contains restcalls to get and set data upon dyn API
Instance Method Summary collapse
-
#AddARecord(zone, arecord, ip) ⇒ Object
Adding new A record.
-
#AddCnameRecord(zone, cname, arecord, flag) ⇒ Object
Adding Cname record.
-
#AddTxtRecord(zone, arecord, txt) ⇒ Object
Adding txt record.
- #CheckARecord(zone, arecord) ⇒ Object
- #CheckCnameRecord(zone, cname) ⇒ Object
-
#CheckNodes(zone, node, state) ⇒ Object
Get List of nodes to compare with given node.
-
#CheckNodeService(service, fqdn) ⇒ Object
checking to which gee service geo node is attached.
-
#CheckZone(zone) ⇒ Object
Check if the zone exist in dyn configuration.
-
#CloseSession ⇒ Object
closing dyn session.
- #CreateZone(zone, contacts) ⇒ Object
- #DeleteDyn ⇒ Object
-
#DeleteNode(zone, fqdn) ⇒ Object
deleting node.
-
#DeleteService(service) ⇒ Object
deleting service.
-
#GenerateGeoNode(service, zone, geonode) ⇒ Object
Generating geo node and attaching to service.
-
#GenerateGeoService(service, record_data, flag) ⇒ Object
Generating or modifying Geo service.
-
#GetCnameService(cname, zone) ⇒ Object
Gets cname and zone and return the geo node that the cname point to.
-
#GetDyn ⇒ Object
get method to dyn.
- #GetGeoData(service) ⇒ Object
-
#GetServices ⇒ Object
return list of geo service defined for the account.
-
#OpenSession(customer, username, password) ⇒ Object
Open a session to syn Restful API.
-
#PostDyn ⇒ Object
post method to dyn.
- #PrintNodes(nodes) ⇒ Object
-
#PublishDyn(zone) ⇒ Object
publishing data to dyn.
-
#PutDyn ⇒ Object
put method to dyn.
Instance Method Details
#AddARecord(zone, arecord, ip) ⇒ Object
Adding new A record
823 824 825 826 827 828 |
# File 'lib/dyntool.rb', line 823 def AddARecord(zone,arecord,ip) @url = URI.parse("https://api2.dynect.net/REST/ARecord/#{zone}/#{arecord}") @record_data = { :rdata => { :address => "#{ip}" }, :ttl => "0" } PostDyn() PublishDyn(zone) end |
#AddCnameRecord(zone, cname, arecord, flag) ⇒ Object
Adding Cname record
851 852 853 854 855 856 857 858 859 860 861 862 863 864 |
# File 'lib/dyntool.rb', line 851 def AddCnameRecord(zone,cname,arecord,flag) @url = URI.parse("https://api2.dynect.net/REST/CNAMERecord/#{zone}/#{cname}") @record_data = { :rdata => { :cname => "#{arecord}" }, :ttl => "0" } if (flag == "post") puts "Adding cname record" puts "arecord #{arecord}, cname: #{cname}" PostDyn() elsif (flag == "put") puts "Changing cname record" puts "arecord #{arecord}, cname: #{cname}" PutDyn() end PublishDyn(zone) end |
#AddTxtRecord(zone, arecord, txt) ⇒ Object
Adding txt record
866 867 868 869 870 871 |
# File 'lib/dyntool.rb', line 866 def AddTxtRecord(zone,arecord,txt) @url = URI.parse("https://api2.dynect.net/REST/TXTRecord/#{zone}/#{arecord}") @record_data = { :rdata => { :txtdata => "#{txt}" }, :ttl => "0" } PostDyn() PublishDyn(zone) end |
#CheckARecord(zone, arecord) ⇒ Object
814 815 816 817 |
# File 'lib/dyntool.rb', line 814 def CheckARecord(zone,arecord) @dynquery = URI.parse("https://api2.dynect.net/REST/ARecord/#{zone}/#{arecord}") GetDyn() end |
#CheckCnameRecord(zone, cname) ⇒ Object
818 819 820 821 |
# File 'lib/dyntool.rb', line 818 def CheckCnameRecord(zone,cname) @dynquery = URI.parse("https://api2.dynect.net/REST/CNAMERecord/#{zone}/#{cname}") GetDyn() end |
#CheckNodes(zone, node, state) ⇒ Object
Get List of nodes to compare with given node
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 |
# File 'lib/dyntool.rb', line 797 def CheckNodes(zone,node,state) @url = URI.parse("https://api2.dynect.net/REST/NodeList/#{zone}/") GetDyn() @nodes = [] @result['data'].each do |fqdn| @nodes << fqdn end if state == "true" if ! @nodes.include? node abort("The node you entered does not exist") end elsif state == "false" if @nodes.include? node abort("The node you entered already exist") end end end |
#CheckNodeService(service, fqdn) ⇒ Object
checking to which gee service geo node is attached
930 931 932 933 934 935 936 937 938 939 940 941 942 |
# File 'lib/dyntool.rb', line 930 def CheckNodeService(service,fqdn) @url = URI.parse("https://api2.dynect.net/REST/Geo/#{service}") @result = GetDyn() @nodes = @result['data']['nodes'] @nodes.each do |node| if (node['fqdn'] == "#{fqdn}") puts "Yes!!!" puts "here are all the nodes that linked to that service:" PrintNodes(@nodes) exit(0) end end end |
#CheckZone(zone) ⇒ Object
Check if the zone exist in dyn configuration
789 790 791 792 793 794 795 |
# File 'lib/dyntool.rb', line 789 def CheckZone(zone) @url = URI.parse("https://api2.dynect.net/REST/Zone/#{zone}/") GetDyn() if @result['status'] != "success" abort("The zone name is invalid") end end |
#CloseSession ⇒ Object
closing dyn session
784 785 786 787 |
# File 'lib/dyntool.rb', line 784 def CloseSession @url = URI.parse('https://api2.dynect.net/REST/Session/') @resp, @data = @http.delete(@url.path, @headers) end |
#CreateZone(zone, contacts) ⇒ Object
955 956 957 958 959 960 |
# File 'lib/dyntool.rb', line 955 def CreateZone(zone,contacts) @url = URI.parse("https://api2.dynect.net/REST/Zone/#{zone}/") @record_data = { :rname => "[email protected]", :ttl => "3600" } PostDyn() PublishDyn(zone) end |
#DeleteDyn ⇒ Object
901 902 903 904 905 |
# File 'lib/dyntool.rb', line 901 def DeleteDyn() @headers = { "Content-Type" => 'application/json', 'Auth-Token' => @auth_token } @resp, @data = @http.delete(@url.path, @headers) puts @data end |
#DeleteNode(zone, fqdn) ⇒ Object
deleting node
873 874 875 876 877 |
# File 'lib/dyntool.rb', line 873 def DeleteNode(zone,fqdn) @url = URI.parse("https://api2.dynect.net/REST/Node/#{zone}/#{fqdn}") DeleteDyn() PublishDyn(zone) end |
#DeleteService(service) ⇒ Object
deleting service
879 880 881 882 883 |
# File 'lib/dyntool.rb', line 879 def DeleteService(service) @url = URI.parse("https://api2.dynect.net/REST/Geo/#{service}/") DeleteDyn() #PublishDyn(zone) end |
#GenerateGeoNode(service, zone, geonode) ⇒ Object
Generating geo node and attaching to service
843 844 845 846 847 848 849 |
# File 'lib/dyntool.rb', line 843 def GenerateGeoNode(service,zone,geonode) puts "Creating geo node" @url = URI.parse("https://api2.dynect.net/REST/GeoNode/#{service}") @record_data = { :fqdn => "#{geonode}", :zone => "#{zone}" } PostDyn() PublishDyn(zone) end |
#GenerateGeoService(service, record_data, flag) ⇒ Object
Generating or modifying Geo service
830 831 832 833 834 835 836 837 838 839 840 841 |
# File 'lib/dyntool.rb', line 830 def GenerateGeoService(service,record_data,flag) @record_data = record_data @url = URI.parse("https://api2.dynect.net/REST/Geo/#{service}/") if flag == "create" puts "Creating geo service #{service}" PostDyn() else puts "Changing geo service #{service}" PutDyn() end #PublishDyn(zone) end |
#GetCnameService(cname, zone) ⇒ Object
Gets cname and zone and return the geo node that the cname point to
944 945 946 947 948 949 950 951 952 953 954 |
# File 'lib/dyntool.rb', line 944 def GetCnameService(cname,zone) @url = URI.parse("https://api2.dynect.net/REST/CNAMERecord/#{zone}/#{cname}/") @result = GetDyn() @cn_data = @result['data'] @cn_array = @cn_data[0].split("/") @id = @cn_array.last @url = URI.parse("https://api2.dynect.net/REST/CNAMERecord/#{zone}/#{cname}/#{@id}") @result = GetDyn() @geonode = @result['data']['rdata']['cname'].chomp('.') return(@geonode) end |
#GetDyn ⇒ Object
get method to dyn
885 886 887 888 889 890 |
# File 'lib/dyntool.rb', line 885 def GetDyn() @headers = { "Content-Type" => 'application/json', 'Auth-Token' => @auth_token } @resp, @data = @http.get(@url.path, @headers) @result = JSON.parse(@data) return(@result) end |
#GetGeoData(service) ⇒ Object
923 924 925 926 927 928 |
# File 'lib/dyntool.rb', line 923 def GetGeoData(service) puts "Getting geo data" @url = URI.parse("https://api2.dynect.net/REST/Geo/#{service}") @result = GetDyn() return(@result) end |
#GetServices ⇒ Object
return list of geo service defined for the account
916 917 918 919 920 921 922 |
# File 'lib/dyntool.rb', line 916 def GetServices() @@conf = LoadConfig.new() @@conf.SetConfFile @@conf.GetHandler @gservices = @@conf.GetGeos return(@gservices) end |
#OpenSession(customer, username, password) ⇒ Object
Open a session to syn Restful API
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 |
# File 'lib/dyntool.rb', line 763 def OpenSession(customer,username,password) # Set up our HTTP object with the required host and path @url = URI.parse('https://api2.dynect.net/REST/Session/') @headers = { "Content-Type" => 'application/json' } @http = Net::HTTP.new(@url.host, @url.port) @http.verify_mode = OpenSSL::SSL::VERIFY_NONE @http.use_ssl = true @session_data = { :customer_name => customer, :user_name => username, :password => password } @resp, @data = @http.post(@url.path, @session_data.to_json, @headers) @result = JSON.parse(@data) if @result['status'] == 'success' @auth_token = @result['data']['token'] else puts "Command Failed:\n" # the messages returned from a failed command are a list @result['msgs'][0].each{|key, value| print key, " : ", value, "\n"} exit(2) end return(@result) end |
#PostDyn ⇒ Object
post method to dyn
892 893 894 895 |
# File 'lib/dyntool.rb', line 892 def PostDyn() @headers = { "Content-Type" => 'application/json', 'Auth-Token' => @auth_token } @resp, @data = @http.post(@url.path, @record_data.to_json, @headers) end |
#PrintNodes(nodes) ⇒ Object
961 962 963 964 965 |
# File 'lib/dyntool.rb', line 961 def PrintNodes(nodes) nodes.each do |node| puts node['fqdn'] end end |
#PublishDyn(zone) ⇒ Object
publishing data to dyn
907 908 909 910 911 912 913 914 |
# File 'lib/dyntool.rb', line 907 def PublishDyn(zone) puts "Publishing to Dyn" @url = URI.parse("https://api2.dynect.net/REST/Zone/#{zone}/") @publish_data = { "publish" => "true" } @resp, @data = @http.put(@url.path, @publish_data.to_json, @headers) @result = JSON.parse(@data) puts @result['status'] end |
#PutDyn ⇒ Object
put method to dyn
897 898 899 900 |
# File 'lib/dyntool.rb', line 897 def PutDyn() @headers = { "Content-Type" => 'application/json', 'Auth-Token' => @auth_token } @resp, @data = @http.put(@url.path, @record_data.to_json, @headers) end |