| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | require "commands/image" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module DeployEnvCommands | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   include ImageCommands | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-28 16:12:51 +03:00
										 |  |  |   # All these commands should be removed when all deploy envs are switched to new validation system | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |   def check_expires! val | 
					
						
							|  |  |  |     raise InvalidRecord.new "Parameter 'expires' is invalid" if val.match(/^[0-9]+[smhdw]$/).nil? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_flavor! p, val | 
					
						
							|  |  |  |     f = p.flavors.detect{|f| f["id"] == val} | 
					
						
							|  |  |  |     raise InvalidRecord.new "Invalid flavor '#{val}'" if f.nil? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_image! p, val | 
					
						
							| 
									
										
										
										
											2015-02-18 11:08:44 +03:00
										 |  |  |     images = get_images(::Devops::Db.connector, p.name) | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |     raise InvalidRecord.new "Invalid image '#{val}'" unless images.map{|i| i["id"]}.include?(val) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_subnets_and_groups! p, subnets, groups | 
					
						
							|  |  |  |     networks = p.networks | 
					
						
							|  |  |  |     n = subnets - networks.map{|n| n["name"]} | 
					
						
							|  |  |  |     raise InvalidRecord.new "Invalid networks '#{n.join("', '")}'" unless n.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-24 13:40:52 +04:00
										 |  |  |     filter = yield(networks) | 
					
						
							|  |  |  | =begin | 
					
						
							| 
									
										
										
										
											2014-06-18 15:11:47 +04:00
										 |  |  |     if p.name == ::Provider::Ec2::PROVIDER | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |       unless subnets.empty? | 
					
						
							|  |  |  |         subnets = [ subnets[0] ] if subnets.size > 1
 | 
					
						
							|  |  |  |         filter = {"vpc-id" => networks.detect{|n| n["name"] == subnets[0]}["vpcId"] } | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-06-18 15:11:47 +04:00
										 |  |  |     elsif p.name == ::Provider::Openstack::PROVIDER | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |       if subnets.empty? | 
					
						
							|  |  |  |         raise InvalidRecord.new "Subnets array can not be empty" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-06-24 13:40:52 +04:00
										 |  |  | =end | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     g = groups - p.groups(filter).keys | 
					
						
							|  |  |  |     raise InvalidRecord.new "Invalid groups '#{g.join("', '")}'" unless g.empty? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_users! val | 
					
						
							| 
									
										
										
										
											2015-02-18 11:08:44 +03:00
										 |  |  |     users = ::Devops::Db.connector.users_names(val) | 
					
						
							| 
									
										
										
										
											2014-05-08 15:34:26 +04:00
										 |  |  |     buf = val - users | 
					
						
							|  |  |  |     raise InvalidRecord.new("Invalid users: '#{buf.join("', '")}'") unless buf.empty? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | end |