58 lines
1.4 KiB
Ruby
58 lines
1.4 KiB
Ruby
module Connectors
|
|
class Stack < Base
|
|
include Helpers::InsertCommand,
|
|
Helpers::ListCommand,
|
|
Helpers::DeleteCommand,
|
|
Helpers::UpdateCommand
|
|
|
|
def initialize(db)
|
|
super(db)
|
|
end
|
|
|
|
def collection_name
|
|
'stacks'
|
|
end
|
|
|
|
def stacks(options={})
|
|
list(options)
|
|
end
|
|
|
|
def set_stack_run_list id, run_list
|
|
collection.update({"_id" => id}, {"$set" => {"run_list" => run_list}})
|
|
end
|
|
|
|
def lock_persisting_stack(id)
|
|
collection.update({'_id' => id}, {'$set' => {'persisting_is_locked' => true}})
|
|
end
|
|
|
|
def unlock_persisting_stack(id)
|
|
collection.update({'_id' => id}, {'$set' => {'persisting_is_locked' => false}})
|
|
end
|
|
|
|
def stack(name, options={})
|
|
query = {'name' => name}.merge(options)
|
|
bson = collection.find(query).to_a.first
|
|
raise RecordNotFound.new("'#{name}' not found") unless bson
|
|
model_from_bson(bson)
|
|
end
|
|
|
|
def stack_by_id(id)
|
|
query = {'_id' => id}
|
|
bson = collection.find(query).to_a.first
|
|
raise RecordNotFound.new("'#{id}' not found") unless bson
|
|
model_from_bson(bson)
|
|
end
|
|
|
|
def change_stacks_deploy_env(from, to)
|
|
collection.update({deploy_env: from}, {'$set' => {deploy_env: to}}, {multi: true})
|
|
end
|
|
|
|
private
|
|
|
|
def model_from_bson(bson)
|
|
provider = bson['provider']
|
|
Devops::Model::StackFactory.get_class(provider).build_from_bson(bson)
|
|
end
|
|
end
|
|
end
|