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
766 767 768 769 770 771 |
# File 'lib/dyntool.rb', line 766 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
794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
# File 'lib/dyntool.rb', line 794 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
809 810 811 812 813 814 |
# File 'lib/dyntool.rb', line 809 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
757 758 759 760 |
# File 'lib/dyntool.rb', line 757 def CheckARecord(zone,arecord) @dynquery = URI.parse("https://api2.dynect.net/REST/ARecord/#{zone}/#{arecord}") GetDyn() end |
#CheckCnameRecord(zone, cname) ⇒ Object
761 762 763 764 |
# File 'lib/dyntool.rb', line 761 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
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 |
# File 'lib/dyntool.rb', line 740 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
880 881 882 883 884 885 886 887 888 889 890 891 892 |
# File 'lib/dyntool.rb', line 880 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
732 733 734 735 736 737 738 |
# File 'lib/dyntool.rb', line 732 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
727 728 729 730 |
# File 'lib/dyntool.rb', line 727 def CloseSession @url = URI.parse('https://api2.dynect.net/REST/Session/') @resp, @data = @http.delete(@url.path, @headers) end |
#CreateZone(zone, contacts) ⇒ Object
905 906 907 908 909 910 |
# File 'lib/dyntool.rb', line 905 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
844 845 846 847 848 |
# File 'lib/dyntool.rb', line 844 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
816 817 818 819 820 |
# File 'lib/dyntool.rb', line 816 def DeleteNode(zone,fqdn) @url = URI.parse("https://api2.dynect.net/REST/Node/#{zone}/#{fqdn}") DeleteDyn() PublishDyn(zone) end |
#DeleteService(service) ⇒ Object
deleting service
822 823 824 825 826 |
# File 'lib/dyntool.rb', line 822 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
786 787 788 789 790 791 792 |
# File 'lib/dyntool.rb', line 786 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
773 774 775 776 777 778 779 780 781 782 783 784 |
# File 'lib/dyntool.rb', line 773 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
894 895 896 897 898 899 900 901 902 903 904 |
# File 'lib/dyntool.rb', line 894 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
828 829 830 831 832 833 |
# File 'lib/dyntool.rb', line 828 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
873 874 875 876 877 878 |
# File 'lib/dyntool.rb', line 873 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
859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/dyntool.rb', line 859 def GetServices() @excluded = [] @excluded << "geo10" puts "Getting the list of geo services" @url = URI.parse("https://api2.dynect.net/REST/Geo/") @result = GetDyn() @services = @result['data'] @gservices = [] @services.each do |service| @gservices << service.gsub(/\/REST\/Geo\/|\//,"") end @gservices = @gservices - @excluded return(@gservices) end |
#OpenSession(customer, username, password) ⇒ Object
Open a session to syn Restful API
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
# File 'lib/dyntool.rb', line 706 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
835 836 837 838 |
# File 'lib/dyntool.rb', line 835 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
911 912 913 914 915 |
# File 'lib/dyntool.rb', line 911 def PrintNodes(nodes) nodes.each do |node| puts node['fqdn'] end end |
#PublishDyn(zone) ⇒ Object
publishing data to dyn
850 851 852 853 854 855 856 857 |
# File 'lib/dyntool.rb', line 850 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
840 841 842 843 |
# File 'lib/dyntool.rb', line 840 def PutDyn() @headers = { "Content-Type" => 'application/json', 'Auth-Token' => @auth_token } @resp, @data = @http.put(@url.path, @record_data.to_json, @headers) end |