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
676 677 678 679 680 681 |
# File 'lib/dyntool.rb', line 676 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
704 705 706 707 708 709 710 711 712 713 714 715 716 717 |
# File 'lib/dyntool.rb', line 704 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
719 720 721 722 723 724 |
# File 'lib/dyntool.rb', line 719 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
667 668 669 670 |
# File 'lib/dyntool.rb', line 667 def CheckARecord(zone,arecord) @dynquery = URI.parse("https://api2.dynect.net/REST/ARecord/#{zone}/#{arecord}") GetDyn() end |
#CheckCnameRecord(zone, cname) ⇒ Object
671 672 673 674 |
# File 'lib/dyntool.rb', line 671 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
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
# File 'lib/dyntool.rb', line 650 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
787 788 789 790 791 792 793 794 795 796 797 798 799 |
# File 'lib/dyntool.rb', line 787 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
642 643 644 645 646 647 648 |
# File 'lib/dyntool.rb', line 642 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
637 638 639 640 |
# File 'lib/dyntool.rb', line 637 def CloseSession @url = URI.parse('https://api2.dynect.net/REST/Session/') @resp, @data = @http.delete(@url.path, @headers) end |
#CreateZone(zone) ⇒ Object
812 813 814 815 816 817 |
# File 'lib/dyntool.rb', line 812 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
754 755 756 757 758 |
# File 'lib/dyntool.rb', line 754 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
726 727 728 729 730 |
# File 'lib/dyntool.rb', line 726 def DeleteNode(zone,fqdn) @url = URI.parse("https://api2.dynect.net/REST/Node/#{zone}/#{fqdn}") DeleteDyn() PublishDyn(zone) end |
#DeleteService(service) ⇒ Object
deleting service
732 733 734 735 736 |
# File 'lib/dyntool.rb', line 732 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
696 697 698 699 700 701 702 |
# File 'lib/dyntool.rb', line 696 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
683 684 685 686 687 688 689 690 691 692 693 694 |
# File 'lib/dyntool.rb', line 683 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
801 802 803 804 805 806 807 808 809 810 811 |
# File 'lib/dyntool.rb', line 801 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
738 739 740 741 742 743 |
# File 'lib/dyntool.rb', line 738 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
780 781 782 783 784 785 |
# File 'lib/dyntool.rb', line 780 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
769 770 771 772 773 774 775 776 777 778 779 |
# File 'lib/dyntool.rb', line 769 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
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
# File 'lib/dyntool.rb', line 616 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
745 746 747 748 |
# File 'lib/dyntool.rb', line 745 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
818 819 820 821 822 |
# File 'lib/dyntool.rb', line 818 def PrintNodes(nodes) nodes.each do |node| puts node['fqdn'] end end |
#PublishDyn(zone) ⇒ Object
publishing data to dyn
760 761 762 763 764 765 766 767 |
# File 'lib/dyntool.rb', line 760 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
750 751 752 753 |
# File 'lib/dyntool.rb', line 750 def PutDyn() @headers = { "Content-Type" => 'application/json', 'Auth-Token' => @auth_token } @resp, @data = @http.put(@url.path, @record_data.to_json, @headers) end |