stack name
This commit is contained in:
parent
d09ae85ab4
commit
9f48b54ffc
@ -18,13 +18,10 @@ module Devops
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_stack object
|
def create_stack object
|
||||||
stack = Model::StackFactory.create(object['provider'], object)
|
object[:owner] = owner_from_request
|
||||||
stack.owner = owner_from_request
|
|
||||||
Devops::Db.connector.stack_insert(stack)
|
|
||||||
|
|
||||||
file = JobStarter.start_job(:worker, :stack_bootstrap,
|
file = JobStarter.start_job(:worker, :stack_bootstrap,
|
||||||
provider: stack.provider,
|
provider: object['provider'],
|
||||||
stack_id: stack.id,
|
stack_attributes: object,
|
||||||
request: @request
|
request: @request
|
||||||
)
|
)
|
||||||
puts "Syncing report is located here: #{file}"
|
puts "Syncing report is located here: #{file}"
|
||||||
|
|||||||
@ -6,10 +6,13 @@ module Devops
|
|||||||
class StackParser < RequestParser
|
class StackParser < RequestParser
|
||||||
|
|
||||||
def create
|
def create
|
||||||
body = create_object_from_json_body
|
@body ||= create_object_from_json_body
|
||||||
list = check_array(body["run_list"], "Body must contains not empty array of strings", String, true, true)
|
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?
|
Validators::Helpers::RunList.new(list).validate! unless list.nil?
|
||||||
body
|
@body
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_list
|
def run_list
|
||||||
|
|||||||
@ -5,15 +5,14 @@ module Devops
|
|||||||
|
|
||||||
include ModelWithProvider
|
include ModelWithProvider
|
||||||
|
|
||||||
attr_accessor :id, :project, :deploy_env, :stack_template,
|
attr_accessor :id, :name, :project, :deploy_env, :stack_template, :parameters, :details, :owner, :run_list
|
||||||
:cloud_stack_id, :parameters, :details, :owner, :run_list
|
|
||||||
|
|
||||||
types id: {type: String, empty: false},
|
types id: {type: String, empty: false},
|
||||||
provider: {type: String, empty: false},
|
provider: {type: String, empty: false},
|
||||||
project: {type: String},
|
project: {type: String},
|
||||||
deploy_env: {type: String},
|
deploy_env: {type: String},
|
||||||
stack_template: {type: String, empty: false},
|
stack_template: {type: String, empty: false},
|
||||||
cloud_stack_id: {type: String, nil: true},
|
name: {type: String, nil: true},
|
||||||
owner: {type: String},
|
owner: {type: String},
|
||||||
run_list: {type: Array, value_type: String, empty: true, nil: true}
|
run_list: {type: Array, value_type: String, empty: true, nil: true}
|
||||||
# details: {type: Hash, nil: true} # Hash type isn't supported yet
|
# details: {type: Hash, nil: true} # Hash type isn't supported yet
|
||||||
@ -25,7 +24,7 @@ module Devops
|
|||||||
self.project = attrs['project']
|
self.project = attrs['project']
|
||||||
self.deploy_env = attrs['deploy_env']
|
self.deploy_env = attrs['deploy_env']
|
||||||
self.stack_template = attrs['stack_template']
|
self.stack_template = attrs['stack_template']
|
||||||
self.cloud_stack_id = attrs['cloud_stack_id']
|
self.name = attrs['name']
|
||||||
self.parameters = attrs['parameters']
|
self.parameters = attrs['parameters']
|
||||||
self.details = attrs['details']
|
self.details = attrs['details']
|
||||||
self.owner = attrs['owner']
|
self.owner = attrs['owner']
|
||||||
@ -39,7 +38,7 @@ module Devops
|
|||||||
project: project,
|
project: project,
|
||||||
deploy_env: deploy_env,
|
deploy_env: deploy_env,
|
||||||
stack_template: stack_template,
|
stack_template: stack_template,
|
||||||
cloud_stack_id: cloud_stack_id,
|
name: name,
|
||||||
parameters: parameters,
|
parameters: parameters,
|
||||||
details: details,
|
details: details,
|
||||||
stack_status: stack_status,
|
stack_status: stack_status,
|
||||||
|
|||||||
@ -165,6 +165,10 @@ module Provider
|
|||||||
"#{self.ssh_key}-#{s.project}-#{s.deploy_env}-#{Time.now.to_i}"
|
"#{self.ssh_key}-#{s.project}-#{s.deploy_env}-#{Time.now.to_i}"
|
||||||
end
|
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
|
def delete_server s
|
||||||
r = self.compute.delete_server(s.id)
|
r = self.compute.delete_server(s.id)
|
||||||
return r.status == 204 ? "Server with id '#{s.id}' terminated" : r.body
|
return r.status == 204 ? "Server with id '#{s.id}' terminated" : r.body
|
||||||
@ -196,15 +200,20 @@ module Provider
|
|||||||
connection_network(self.connection_options)
|
connection_network(self.connection_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_stack(stack)
|
def create_stack(stack, out)
|
||||||
begin
|
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(
|
response = orchestration.create_stack(
|
||||||
stack_name: stack.id,
|
stack_name: stack.name,
|
||||||
template: stack.template_body,
|
template: stack.template_body,
|
||||||
tenant_id: connection_options[:openstack_tenant],
|
# tenant_id: connection_options[:openstack_tenant],
|
||||||
parameters: stack.parameters
|
parameters: stack.parameters
|
||||||
)
|
)
|
||||||
response[:body]['stack']['id']
|
stack.id = response[:body]['stack']['id']
|
||||||
rescue Excon::Errors::Conflict => e
|
rescue Excon::Errors::Conflict => e
|
||||||
raise ProviderErrors::NameConflict
|
raise ProviderErrors::NameConflict
|
||||||
end
|
end
|
||||||
|
|||||||
@ -12,9 +12,11 @@ class StackBootstrapWorker < Worker
|
|||||||
# :stack_id
|
# :stack_id
|
||||||
def perform(options)
|
def perform(options)
|
||||||
call(options['config'], options['provider'], options['dir']) do |provider, out, file|
|
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)
|
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)
|
sync_bootstrap_proc.call(out, stack, mongo)
|
||||||
servers = persist_stack_servers!(stack, provider)
|
servers = persist_stack_servers!(stack, provider)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user