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



601
602
603
604
605
606
607
608
609
610
# File 'lib/dyntool.rb', line 601

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



544
545
546
547
548
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
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
# File 'lib/dyntool.rb', line 544

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
		@dcs.each do |dc|
			@providers = @@conf.GetDcProviders(dc)
			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_len == 0
			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 }, :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



533
534
535
# File 'lib/dyntool.rb', line 533

def GetArgs
	return(@@args)
end

#GetGeoNodeService(services, node) ⇒ Object



536
537
538
539
540
541
542
# File 'lib/dyntool.rb', line 536

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



530
531
532
# File 'lib/dyntool.rb', line 530

def GetOP
	return(@@op)
end

#RunOPObject

run the operation set by setoperation method in the validation phase



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# File 'lib/dyntool.rb', line 504

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



496
497
498
# File 'lib/dyntool.rb', line 496

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

#SetOperation(op) ⇒ Object

set the relevant operation



492
493
494
# File 'lib/dyntool.rb', line 492

def SetOperation(op)
	@@op=op
end

#SetSession(session) ⇒ Object

set the session to dyn



500
501
502
# File 'lib/dyntool.rb', line 500

def SetSession(session)
	@@session=session
end