return model in mongo insert and update commands

This commit is contained in:
Anton Chuchkalov 2015-07-30 01:22:54 +02:00
parent 5203455436
commit 9c8f685f44
5 changed files with 12 additions and 12 deletions

View File

@ -49,7 +49,6 @@ module Output
def create_servers_list
headers = ['Logical id', 'Physical id']
byebug
rows = @data.map do |resource|
[resource['resource_name'], resource['physical_resource_id']]
end

View File

@ -17,7 +17,6 @@ module Devops
def create_stack object
stack_model = Model::StackFactory.create(object['provider'], object)
Devops::Db.connector.stack_insert(stack_model)
stack_model
end
def stack id
@ -34,8 +33,6 @@ module Devops
stack = self.stack(id)
stack.sync_details!
Devops::Db.connector.stack_update(stack)
stack
end
def resources id
@ -43,7 +40,7 @@ module Devops
stack.resources
end
def resources id, resource_id
def resource id, resource_id
stack = Devops::Db.connector.stack(id)
stack.resource(resource_id)
end

View File

@ -44,7 +44,7 @@ module Devops
app.get_with_headers "/stack/:stack_id/resources", :headers => [:accept] do |stack_id|
check_privileges("stack", "r")
json Devops::API2_0::Handler::Stack.new(request, params).resources(stack_id, nil)
json Devops::API2_0::Handler::Stack.new(request, params).resources(stack_id)
end
app.get_with_headers "/stack/:stack_id/resources/:resource_id", :headers => [:accept] do |stack_id, resource_id|

View File

@ -18,6 +18,7 @@ module Connectors
begin
record.validate!
collection.insert(record.to_mongo_hash)
record
rescue Mongo::OperationFailure => e
if e.message =~ /^11000/
resource_name = StringHelper.underscore_class(record.class)

View File

@ -14,12 +14,15 @@ module Connectors
end
def update(record)
record.validate!
collection.update({"_id" => record.id}, record.to_mongo_hash)
rescue Mongo::OperationFailure => e
if e.message =~ /^11000/
resource_name = StringHelper.underscore_class(record.class)
raise InvalidRecord.new("Duplicate key error: #{resource_name} with id '#{record.id}'")
begin
record.validate!
collection.update({"_id" => record.id}, record.to_mongo_hash)
record
rescue Mongo::OperationFailure => e
if e.message =~ /^11000/
resource_name = StringHelper.underscore_class(record.class)
raise InvalidRecord.new("Duplicate key error: #{resource_name} with id '#{record.id}'")
end
end
end