| 
									
										
										
										
											2015-08-13 15:49:37 +03:00
										 |  |  | require "db/mongo/models/deploy_env/cloud_deploy_env" | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  | module Devops | 
					
						
							|  |  |  |   module Model | 
					
						
							| 
									
										
										
										
											2015-08-13 15:49:37 +03:00
										 |  |  |     class DeployEnvEc2 < CloudDeployEnv | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  | #      attr_accessor :vpc_id | 
					
						
							| 
									
										
										
										
											2015-11-17 12:14:02 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  |       set_field_validators :vpc_id, [::Validators::FieldValidator::Nil, | 
					
						
							| 
									
										
										
										
											2015-11-17 12:14:02 +03:00
										 |  |  |                                     ::Validators::FieldValidator::FieldType::String, | 
					
						
							| 
									
										
										
										
											2015-11-19 14:09:38 +03:00
										 |  |  |                                     ::Validators::FieldValidator::Vpc], order: 3
 | 
					
						
							| 
									
										
										
										
											2015-10-06 13:50:26 +03:00
										 |  |  | =begin | 
					
						
							|  |  |  | @Deprecated | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       types :identifier => {:type => String, :empty => false}, | 
					
						
							|  |  |  |         :image => {:type => String, :empty => false}, | 
					
						
							|  |  |  |         :flavor => {:type => String, :empty => false}, | 
					
						
							|  |  |  |         :provider => {:type => String, :empty => false}, | 
					
						
							|  |  |  |         :expires => {:type => String, :empty => false, :nil => true}, | 
					
						
							|  |  |  |         :run_list => {:type => Array, :empty => true}, | 
					
						
							|  |  |  |         :users => {:type => Array, :empty => true}, | 
					
						
							|  |  |  |         :subnets => {:type => Array, :empty => true}, | 
					
						
							| 
									
										
										
										
											2015-08-13 15:49:37 +03:00
										 |  |  |         :groups => {:type => Array, :empty => false}, | 
					
						
							|  |  |  |         :stack_template => {:type => String, :empty => false, :nil => true} | 
					
						
							| 
									
										
										
										
											2015-10-06 13:50:26 +03:00
										 |  |  | =end | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-13 15:49:37 +03:00
										 |  |  | =begin | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       set_validators ::Validators::DeployEnv::RunList, | 
					
						
							|  |  |  |                      ::Validators::DeployEnv::Expiration, | 
					
						
							|  |  |  |                      ::Validators::DeployEnv::Users, | 
					
						
							|  |  |  |                      ::Validators::DeployEnv::Flavor, | 
					
						
							|  |  |  |                      ::Validators::DeployEnv::Image, | 
					
						
							|  |  |  |                      ::Validators::DeployEnv::SubnetBelongsToProvider, | 
					
						
							| 
									
										
										
										
											2015-08-13 15:49:37 +03:00
										 |  |  |                      ::Validators::DeployEnv::Groups, | 
					
						
							|  |  |  |                      ::Validators::DeployEnv::StackTemplate | 
					
						
							|  |  |  | =end | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       def initialize d={} | 
					
						
							|  |  |  |         super(d) | 
					
						
							| 
									
										
										
										
											2015-08-13 15:49:37 +03:00
										 |  |  |         if self.subnets.size > 1
 | 
					
						
							|  |  |  |           self.subnets = [ self.subnets[0] ] | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2015-11-17 12:14:02 +03:00
										 |  |  |         self.vpc_id = d["vpc_id"] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def to_hash | 
					
						
							|  |  |  |         super().merge({"vpc_id" => self.vpc_id}) | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def self.create hash | 
					
						
							|  |  |  |         DeployEnvEc2.new(hash) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def subnets_filter | 
					
						
							|  |  |  |         networks = provider_instance.networks | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         unless self.subnets.empty? | 
					
						
							| 
									
										
										
										
											2015-11-20 15:15:06 +03:00
										 |  |  |           network = networks.detect {|n| n["name"] == self.subnets[0]} | 
					
						
							|  |  |  |           if network | 
					
						
							|  |  |  |             {"vpc-id" => network["vpcId"] } | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |