stack name

This commit is contained in:
amartynov 2015-08-12 13:32:26 +03:00
parent d09ae85ab4
commit 9f48b54ffc
5 changed files with 30 additions and 20 deletions

View File

@ -18,13 +18,10 @@ module Devops
end
def create_stack object
stack = Model::StackFactory.create(object['provider'], object)
stack.owner = owner_from_request
Devops::Db.connector.stack_insert(stack)
object[:owner] = owner_from_request
file = JobStarter.start_job(:worker, :stack_bootstrap,
provider: stack.provider,
stack_id: stack.id,
provider: object['provider'],
stack_attributes: object,
request: @request
)
puts "Syncing report is located here: #{file}"

View File

@ -6,10 +6,13 @@ module Devops
class StackParser < RequestParser
def create
body = create_object_from_json_body
list = check_array(body["run_list"], "Body must contains not empty array of strings", String, true, true)
@body ||= create_object_from_json_body
project_name = check_string(@body["project"], "Parameter 'project' must be a not empty string")
env_name = check_string(@body["deploy_env"], "Parameter 'deploy_env' must be a not empty string")
check_string(@body["name"], "Parameter 'name' must be a not empty string", true, false)
list = check_array(@body["run_list"], "Parameter 'run_list' is invalid, it should be not empty array of strings", String, true, true)
Validators::Helpers::RunList.new(list).validate! unless list.nil?
body
@body
end
def run_list

View File

@ -5,15 +5,14 @@ module Devops
include ModelWithProvider
attr_accessor :id, :project, :deploy_env, :stack_template,
:cloud_stack_id, :parameters, :details, :owner, :run_list
attr_accessor :id, :name, :project, :deploy_env, :stack_template, :parameters, :details, :owner, :run_list
types id: {type: String, empty: false},
provider: {type: String, empty: false},
project: {type: String},
deploy_env: {type: String},
stack_template: {type: String, empty: false},
cloud_stack_id: {type: String, nil: true},
name: {type: String, nil: true},
owner: {type: String},
run_list: {type: Array, value_type: String, empty: true, nil: true}
# details: {type: Hash, nil: true} # Hash type isn't supported yet
@ -25,7 +24,7 @@ module Devops
self.project = attrs['project']
self.deploy_env = attrs['deploy_env']
self.stack_template = attrs['stack_template']
self.cloud_stack_id = attrs['cloud_stack_id']
self.name = attrs['name']
self.parameters = attrs['parameters']
self.details = attrs['details']
self.owner = attrs['owner']
@ -39,7 +38,7 @@ module Devops
project: project,
deploy_env: deploy_env,
stack_template: stack_template,
cloud_stack_id: cloud_stack_id,
name: name,
parameters: parameters,
details: details,
stack_status: stack_status,

View File

@ -165,6 +165,10 @@ module Provider
"#{self.ssh_key}-#{s.project}-#{s.deploy_env}-#{Time.now.to_i}"
end
def create_default_stack_name s
"stack_#{self.ssh_key}-#{s.project}-#{s.deploy_env}-#{Time.now.to_i}"
end
def delete_server s
r = self.compute.delete_server(s.id)
return r.status == 204 ? "Server with id '#{s.id}' terminated" : r.body
@ -196,15 +200,20 @@ module Provider
connection_network(self.connection_options)
end
def create_stack(stack)
def create_stack(stack, out)
begin
out << "Creating stack for project '#{stack.project}' and environment '#{stack.deploy_env}'...\n"
stack.name = create_default_stack_name(stack) unless stack.name
out << "Stack name: #{stack.name}\n"
out << "Stack template: #{stack.stack_template}\n"
out << "Stack parameters: #{stack.parameters}\n"
response = orchestration.create_stack(
stack_name: stack.id,
stack_name: stack.name,
template: stack.template_body,
tenant_id: connection_options[:openstack_tenant],
# tenant_id: connection_options[:openstack_tenant],
parameters: stack.parameters
)
response[:body]['stack']['id']
stack.id = response[:body]['stack']['id']
rescue Excon::Errors::Conflict => e
raise ProviderErrors::NameConflict
end

View File

@ -12,9 +12,11 @@ class StackBootstrapWorker < Worker
# :stack_id
def perform(options)
call(options['config'], options['provider'], options['dir']) do |provider, out, file|
mongo = ::Devops::Db.connector
stack = mongo.stack(options['stack_id'])
save_report(mongo, stack, file)
stack = Model::StackFactory.create(options['provider'], options['stack_attributes'])
stack.owner = options['owner']
mongo = ::Devops::Db.connector
mongo.stack_insert(stack)
sync_bootstrap_proc.call(out, stack, mongo)
servers = persist_stack_servers!(stack, provider)