fluke/devops-service/db/mongo/models/deploy_env/deploy_env_base.rb

60 lines
1.3 KiB
Ruby
Raw Normal View History

2014-06-24 13:40:52 +04:00
require "db/mongo/models/mongo_model"
2015-02-12 13:01:05 +03:00
require "providers/provider_factory"
2014-06-24 13:40:52 +04:00
require "commands/deploy_env"
2015-03-06 12:20:30 +03:00
module Devops
module Model
class DeployEnvBase < MongoModel
2014-06-24 13:40:52 +04:00
2015-03-06 12:20:30 +03:00
include DeployEnvCommands
2014-06-24 13:40:52 +04:00
attr_accessor :identifier, :run_list, :expires, :provider, :users, :chef_env
2014-06-24 13:40:52 +04:00
2015-03-06 12:20:30 +03:00
def initialize d={}
self.identifier = d["identifier"]
b = d["run_list"] || []
self.run_list = (b.is_a?(Array) ? b.uniq : b)
self.expires = d["expires"]
self.provider = d["provider"]
b = d["users"] || []
self.users = (b.is_a?(Array) ? b.uniq : b)
end
2014-06-24 13:40:52 +04:00
2015-03-06 12:20:30 +03:00
def to_hash
{
"identifier" => self.identifier,
"run_list" => self.run_list,
"expires" => self.expires,
"provider" => self.provider,
"users" => self.users
}
end
2014-06-24 13:40:52 +04:00
2015-03-06 12:20:30 +03:00
def provider_instance
@provider_instance ||= ::Provider::ProviderFactory.get(self.provider)
end
2014-11-27 18:45:35 +03:00
2015-03-06 12:20:30 +03:00
def build_error_message(message)
"Deploy environment '#{self.identifier}'. " + message
end
2015-02-12 13:01:05 +03:00
2014-11-26 18:46:04 +03:00
2015-03-06 12:20:30 +03:00
# class methods
class << self
2014-11-26 18:46:04 +03:00
2015-03-06 12:20:30 +03:00
def validators
@validators
end
2014-11-26 18:46:04 +03:00
2015-03-06 12:20:30 +03:00
private
2014-11-26 18:46:04 +03:00
2015-03-06 12:20:30 +03:00
def set_validators(*validators)
@validators = validators
end
2014-11-26 18:46:04 +03:00
2015-03-06 12:20:30 +03:00
end
2014-11-26 18:46:04 +03:00
2015-03-06 12:20:30 +03:00
end
end
2014-06-24 13:40:52 +04:00
end