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
653 654 655 656 657 658 659 660 661 662 |
# File 'lib/dyntool.rb', line 653 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
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 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 649 650 651 |
# File 'lib/dyntool.rb', line 589 def BuildService(service,flag,shiftfrom,shifto) puts "Generating the geo service data" @@conf = LoadConfig.new() @@conf.SetConfFile @@conf.GetHandler @regions = @@conf.GetRegions @dcs = @@conf.GetDcs @shiftfrom = [] @shifto = [] @shiftfrom << shiftfrom @shifto = shifto.split("-") @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 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 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 @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
578 579 580 |
# File 'lib/dyntool.rb', line 578 def GetArgs return(@@args) end |
#GetGeoNodeService(services, node) ⇒ Object
581 582 583 584 585 586 587 |
# File 'lib/dyntool.rb', line 581 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
575 576 577 |
# File 'lib/dyntool.rb', line 575 def GetOP return(@@op) end |
#RunOP ⇒ Object
run the operation set by setoperation method in the validation phase
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 |
# File 'lib/dyntool.rb', line 549 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 @record_data = BuildService(@@args[0],@@args[1],@@args[2],@@args[3]) @@session.GenerateGeoService(@@args[0],@record_data,"update") when "RevertGeo" then @record_data = BuildService(@@args[0],"","","") @@session.GenerateGeoService(@@args[0],@record_data,"update") end end |
#SetArgs(*args) ⇒ Object
set the arguments
541 542 543 |
# File 'lib/dyntool.rb', line 541 def SetArgs(*args) @@args=args end |
#SetOperation(op) ⇒ Object
set the relevant operation
537 538 539 |
# File 'lib/dyntool.rb', line 537 def SetOperation(op) @@op=op end |
#SetSession(session) ⇒ Object
set the session to dyn
545 546 547 |
# File 'lib/dyntool.rb', line 545 def SetSession(session) @@session=session end |