| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  | module Devops | 
					
						
							|  |  |  |   module Model | 
					
						
							|  |  |  |     class StackBase < MongoModel | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-08 18:42:36 +03:00
										 |  |  |       attr_accessor :id, :project, :deploy_env, :stack_template, :cloud_stack_id, :provider, :parameters, :template_body | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       types id: {type: String, empty: false}, | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |             provider: {type: String, empty: false}, | 
					
						
							| 
									
										
										
										
											2015-07-08 18:42:36 +03:00
										 |  |  |             project: {type: String, empty: true}, | 
					
						
							|  |  |  |             deploy_env: {type: String, empty: true}, | 
					
						
							|  |  |  |             stack_template: {type: String, empty: true}, | 
					
						
							|  |  |  |             template_body: {type: String, empty: true} | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |             # cloud_stack_id: {type: String, empty: true} | 
					
						
							|  |  |  |             # TODO: add parameters Hash | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |       def initialize attrs={} | 
					
						
							|  |  |  |         self.id = attrs['id'] | 
					
						
							|  |  |  |         self.provider = attrs['provider'] | 
					
						
							|  |  |  |         self.project = attrs['project'] | 
					
						
							|  |  |  |         self.deploy_env = attrs['deploy_env'] | 
					
						
							|  |  |  |         self.stack_template = attrs['stack_template'] | 
					
						
							| 
									
										
										
										
											2015-07-08 18:42:36 +03:00
										 |  |  |         self.template_body = attrs['template_body'] | 
					
						
							|  |  |  |         # self.cloud_stack_id = attrs['cloud_stack_id'] | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |         self.parameters = attrs['parameters'] | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |         self | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def to_hash_without_id | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           provider: provider, | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |           project: project, | 
					
						
							|  |  |  |           deploy_env: deploy_env, | 
					
						
							|  |  |  |           stack_template: stack_template, | 
					
						
							|  |  |  |           cloud_stack_id: cloud_stack_id, | 
					
						
							|  |  |  |           parameters: parameters | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |         } | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |       # attrs should include: | 
					
						
							|  |  |  |       # - id (String) | 
					
						
							|  |  |  |       # - provider (String) | 
					
						
							|  |  |  |       # - deploy_env (String) | 
					
						
							|  |  |  |       # - stack_template (String) | 
					
						
							|  |  |  |       def self.create(attrs) | 
					
						
							|  |  |  |         model = new(attrs) | 
					
						
							|  |  |  |         model.create_stack_in_cloud! | 
					
						
							|  |  |  |         model | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def self.build_from_bson(attrs) | 
					
						
							|  |  |  |         attrs['id'] = attrs["_id"] | 
					
						
							|  |  |  |         self.new(attrs) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def create_stack_in_cloud! | 
					
						
							|  |  |  |         raise 'override me' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |       def delete_stack_in_cloud! | 
					
						
							|  |  |  |         raise 'override me' | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-08 18:42:36 +03:00
										 |  |  |       # if not set in constructor, assume stack was created via stack_template. | 
					
						
							|  |  |  |       # It is need to support presets. | 
					
						
							|  |  |  |       # TODO: refactore it. | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |       def template_body | 
					
						
							| 
									
										
										
										
											2015-07-08 18:42:36 +03:00
										 |  |  |         @template_body ||= DevopsService.mongo.stack_template(stack_template).template_body | 
					
						
							| 
									
										
										
										
											2015-04-16 17:54:40 +03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-06 12:20:30 +03:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-02-12 13:01:05 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |