Class: OperateDyn

Inherits:
Object
  • Object
show all
Defined in:
lib/dyntool.rb

Instance Method Summary collapse

Instance Method Details

#BuildIPs(ips) ⇒ Object

building the ip hash



691
692
693
694
695
696
697
698
699
700
# File 'lib/dyntool.rb', line 691

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



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
652
653
654
655
656
657
658
659
660
661
662
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
# File 'lib/dyntool.rb', line 617

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
		@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

#GetArgsObject



606
607
608
# File 'lib/dyntool.rb', line 606

def GetArgs
	return(@@args)
end

#GetGeoNodeService(services, node) ⇒ Object



609
610
611
612
613
614
615
# File 'lib/dyntool.rb', line 609

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

#GetOPObject



603
604
605
# File 'lib/dyntool.rb', line 603

def GetOP
	return(@@op)
end

#RunOPObject

run the operation set by setoperation method in the validation phase



560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/dyntool.rb', line 560

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



552
553
554
# File 'lib/dyntool.rb', line 552

def SetArgs(*args)
	@@args=args
end

#SetOperation(op) ⇒ Object

set the relevant operation



548
549
550
# File 'lib/dyntool.rb', line 548

def SetOperation(op)
	@@op=op
end

#SetSession(session) ⇒ Object

set the session to dyn



556
557
558
# File 'lib/dyntool.rb', line 556

def SetSession(session)
	@@session=session
end