Class: OperateDyn
- Inherits:
-
Object
- Object
- OperateDyn
- Defined in:
- lib/dyntool.rb
Instance Method Summary collapse
-
#BuildIPs(ips) ⇒ Object
building the ip hash.
-
#BuildService(service, flag, shiftfrom, shifto) ⇒ Object
building the record_data hash for generating geo service in dyn API.
- #GetArgs ⇒ Object
- #GetGeoNodeService(services, node) ⇒ Object
- #GetOP ⇒ Object
-
#RunOP ⇒ Object
run the operation set by setoperation method in the validation phase.
-
#SetArgs(*args) ⇒ Object
set the arguments.
-
#SetOperation(op) ⇒ Object
set the relevant operation.
-
#SetSession(session) ⇒ Object
set the session to dyn.
Instance Method Details
#BuildIPs(ips) ⇒ Object
building the ip hash
748 749 750 751 752 753 754 755 756 757 |
# File 'lib/dyntool.rb', line 748 def BuildIPs(ips) @ips_hash = "{ :a_rdata => [" ips.each do |ip| @ips_hash << "{ :address => \"#{ip}\"}," end @ips_hash = @ips_hash.chop @ips_hash << "]}" @ips_hash = eval(@ips_hash) return(@ips_hash) end |
#BuildService(service, flag, shiftfrom, shifto) ⇒ Object
building the record_data hash for generating geo service in dyn API
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
# File 'lib/dyntool.rb', line 663 def BuildService(service,flag,shiftfrom,shifto) puts "Generating the geo service data" @shiftfrom = [] @shifto = [] @shiftfrom << shiftfrom @shifto = shifto.split("-") @@conf = LoadConfig.new() @ftype = @@conf.ConfManipulate(shiftfrom,shifto) if @ftype == "dyn" @@conf.SetConfFile else @@conf.SetTmpFile end @@conf.GetHandler @regions = @@conf.GetRegions @dcs = @@conf.GetDcs @region_hash = [] @i = 0 @regions.each do |region| @ips = [] @labels = [] @weights = [] @countries = @@conf.GetCountries(region) @dcs = @@conf.GetDcsEnabled(region,service) if (flag == "dc") if @dcs.include? "#{shiftfrom}" @dcs = @dcs - @shiftfrom @dcs = @dcs + @shifto end if @ftype == "temp" @@conf.SetDcsEnabled(region,service,@dcs) end end if @dcs.nil? abort("The region #{region}, has empty dc list. aborting....") end @dcs.each do |dc| @providers = @@conf.GetDcProviders(dc) if @providers.nil? abort("The DC #{dc}, has empty providers list. aborting....") end if (flag == "provider") if @providers.include? "#{shiftfrom}" @providers = @providers - @shiftfrom @providers = @providers + @shifto end if @ftype == "temp" @@conf.SetDcProviders(dc,@providers) end end @providers.each do |provider| @ips += @@conf.GetProvierIP(provider) end @ips = @ips.uniq end @ips_len = @ips.size if @ips.nil? abort("The region #{region}, has empty ip list. aborting....") end @ips_hash = BuildIPs(@ips) @i += 1 @ips.each do |ip| @label = @@conf.GetIpLabel(ip) @weight = @@conf.GetIpWeight(ip,region) @labels << "#{@label}" @weights << "#{@weight}" end @wtc = 0 @weights.uniq.each do |wt| @wtc += 1 end if @wtc != 1 @ips_len = (@ips_len / 3).floor end if @ips_len > 13 @ips_len = 13 end @ttl = @@conf.GetIpTTL(region) @labels = @labels.uniq @region_hash[@i] = { :name => "#{region}", :label => { :a_label => @labels}, :weight => { :a_weight => @weights }, :serve_count => { :a_serve_count => @ips_len }, :ttl => { :a_ttl => "#{@ttl}" }, :countries => @countries, :rdata => @ips_hash } end @record_data = { :name => "#{service}", :groups => [ @region_hash[1],@region_hash[2],@region_hash[3],@region_hash[4],@region_hash[5],@region_hash[6],@region_hash[7],@region_hash[8],@region_hash[9] ]} return(@record_data) end |
#GetArgs ⇒ Object
652 653 654 |
# File 'lib/dyntool.rb', line 652 def GetArgs return(@@args) end |
#GetGeoNodeService(services, node) ⇒ Object
655 656 657 658 659 660 661 |
# File 'lib/dyntool.rb', line 655 def GetGeoNodeService(services,node) @services = services @services.each do |service| puts "Checking If node #{node} is attached to service #{service}" @result = @@session.CheckNodeService(service,node) end end |
#GetOP ⇒ Object
649 650 651 |
# File 'lib/dyntool.rb', line 649 def GetOP return(@@op) end |
#RunOP ⇒ Object
run the operation set by setoperation method in the validation phase
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
# File 'lib/dyntool.rb', line 606 def RunOP case(@@op) when "AddARecord" then @@session.AddARecord(@@args[0],@@args[1],@@args[2]) when "AddZone" then @@session.CreateZone(@@args[0],@@args[1]) when "DeleteNode" then @@session.DeleteNode(@@args[0],@@args[1]) when "DeleteService" then @@session.DeleteService(@@args[0]) when "AddCnameRecord" then @@session.AddCnameRecord(@@args[0],@@args[1],@@args[2],"post") when "AddTxtRecord" then @@session.AddTxtRecord(@@args[0],@@args[1],@@args[2]) when "ChangeCnameRecord" then @@session.AddCnameRecord(@@args[0],@@args[1],@@args[2],"put") when "GenerateGeoNode" then @record_data = BuildService(@@args[0],"","","") @@session.GenerateGeoService(@@args[0],@record_data,"create") @@session.GenerateGeoNode(@@args[0],@@args[1],@@args[2]) when "GetServices" then @services = @@session.GetServices() puts "Here is the list of Geo services:" puts @services when "GetNodeService" then @services = @@session.GetServices() GetGeoNodeService(@services,@@args[0]) when "GetCnameService" then @services = @@session.GetServices() @geonode = @@session.GetCnameService(@@args[1],@@args[0]) GetGeoNodeService(@services,@geonode) when "ShiftTraffic" then if @@args[0] == "all" @services = @@session.GetServices() @services.each do |s| @record_data = BuildService("#{s}",@@args[1],@@args[2],@@args[3]) @@session.GenerateGeoService("#{s}",@record_data,"update") end else @record_data = BuildService(@@args[0],@@args[1],@@args[2],@@args[3]) @@session.GenerateGeoService(@@args[0],@record_data,"update") end when "RevertGeo" then if @@args[0] == "all" @services = @@session.GetServices() @services.each do |s| @record_data = BuildService("#{s}","","","") @@session.GenerateGeoService("#{s}",@record_data,"update") end else @record_data = BuildService(@@args[0],"","","") @@session.GenerateGeoService(@@args[0],@record_data,"update") end end end |
#SetArgs(*args) ⇒ Object
set the arguments
598 599 600 |
# File 'lib/dyntool.rb', line 598 def SetArgs(*args) @@args=args end |
#SetOperation(op) ⇒ Object
set the relevant operation
594 595 596 |
# File 'lib/dyntool.rb', line 594 def SetOperation(op) @@op=op end |
#SetSession(session) ⇒ Object
set the session to dyn
602 603 604 |
# File 'lib/dyntool.rb', line 602 def SetSession(session) @@session=session end |