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) ⇒ 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
705 706 707 708 709 710 |
# File 'lib/dyntool.rb', line 705 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
733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
# File 'lib/dyntool.rb', line 733 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
748 749 750 751 752 753 |
# File 'lib/dyntool.rb', line 748 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
696 697 698 699 |
# File 'lib/dyntool.rb', line 696 def CheckARecord(zone,arecord) @dynquery = URI.parse("https://api2.dynect.net/REST/ARecord/#{zone}/#{arecord}") GetDyn() end |
#CheckCnameRecord(zone, cname) ⇒ Object
700 701 702 703 |
# File 'lib/dyntool.rb', line 700 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
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/dyntool.rb', line 679 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
816 817 818 819 820 821 822 823 824 825 826 827 828 |
# File 'lib/dyntool.rb', line 816 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
671 672 673 674 675 676 677 |
# File 'lib/dyntool.rb', line 671 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
666 667 668 669 |
# File 'lib/dyntool.rb', line 666 def CloseSession @url = URI.parse('https://api2.dynect.net/REST/Session/') @resp, @data = @http.delete(@url.path, @headers) end |
#CreateZone(zone) ⇒ Object
841 842 843 844 845 846 |
# File 'lib/dyntool.rb', line 841 def CreateZone(zone) @url = URI.parse("https://api2.dynect.net/REST/Zone/#{zone}/") @record_data = { :rname => "[email protected]", :ttl => "3600" } PostDyn() PublishDyn(zone) end |
#DeleteDyn ⇒ Object
783 784 785 786 787 |
# File 'lib/dyntool.rb', line 783 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
755 756 757 758 759 |
# File 'lib/dyntool.rb', line 755 def DeleteNode(zone,fqdn) @url = URI.parse("https://api2.dynect.net/REST/Node/#{zone}/#{fqdn}") DeleteDyn() PublishDyn(zone) end |
#DeleteService(service) ⇒ Object
deleting service
761 762 763 764 765 |
# File 'lib/dyntool.rb', line 761 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
725 726 727 728 729 730 731 |
# File 'lib/dyntool.rb', line 725 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
712 713 714 715 716 717 718 719 720 721 722 723 |
# File 'lib/dyntool.rb', line 712 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" PostDyn() else puts "Changing geo service" PutDyn() end #PublishDyn(zone) end |
#GetCnameService(cname, zone) ⇒ Object
Gets cname and zone and return the geo node that the cname point to
830 831 832 833 834 835 836 837 838 839 840 |
# File 'lib/dyntool.rb', line 830 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
767 768 769 770 771 772 |
# File 'lib/dyntool.rb', line 767 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
809 810 811 812 813 814 |
# File 'lib/dyntool.rb', line 809 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
798 799 800 801 802 803 804 805 806 807 808 |
# File 'lib/dyntool.rb', line 798 def GetServices() 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 return(@gservices) end |
#OpenSession(customer, username, password) ⇒ Object
Open a session to syn Restful API
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
# File 'lib/dyntool.rb', line 645 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
774 775 776 777 |
# File 'lib/dyntool.rb', line 774 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
847 848 849 850 851 |
# File 'lib/dyntool.rb', line 847 def PrintNodes(nodes) nodes.each do |node| puts node['fqdn'] end end |
#PublishDyn(zone) ⇒ Object
publishing data to dyn
789 790 791 792 793 794 795 796 |
# File 'lib/dyntool.rb', line 789 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
779 780 781 782 |
# File 'lib/dyntool.rb', line 779 def PutDyn() @headers = { "Content-Type" => 'application/json', 'Auth-Token' => @auth_token } @resp, @data = @http.put(@url.path, @record_data.to_json, @headers) end |