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



630
631
632
633
634
635
636
637
638
639
# File 'lib/dyntool.rb', line 630

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



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
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
# File 'lib/dyntool.rb', line 567

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
		@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 => 60 }, :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



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

def GetArgs
	return(@@args)
end

#GetGeoNodeService(services, node) ⇒ Object



559
560
561
562
563
564
565
# File 'lib/dyntool.rb', line 559

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



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

def GetOP
	return(@@op)
end

#RunOPObject

run the operation set by setoperation method in the validation phase



527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/dyntool.rb', line 527

def RunOP
	case(@@op)
		when "AddARecord" then @@session.AddARecord(@@args[0],@@args[1],@@args[2])
		when "AddZone" then @@session.CreateZone(@@args[0])
		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



519
520
521
# File 'lib/dyntool.rb', line 519

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

#SetOperation(op) ⇒ Object

set the relevant operation



515
516
517
# File 'lib/dyntool.rb', line 515

def SetOperation(op)
	@@op=op
end

#SetSession(session) ⇒ Object

set the session to dyn



523
524
525
# File 'lib/dyntool.rb', line 523

def SetSession(session)
	@@session=session
end