autoupdate stack template preset body
This commit is contained in:
parent
7ac62a2a36
commit
e11788afb7
@ -10,6 +10,7 @@ module Output
|
||||
title = I18n.t("output.title.stack.list")
|
||||
headers, rows = create_list
|
||||
else
|
||||
puts 'Details are not displayed in table view'
|
||||
title = I18n.t("output.title.stack.show", id: @data["id"])
|
||||
headers, rows = create_show
|
||||
end
|
||||
@ -30,14 +31,14 @@ module Output
|
||||
def create_list
|
||||
abort(I18n.t("output.not_found.stack.list")) if @data.empty?
|
||||
|
||||
fields_to_output = %w(id deploy_env stack_template)
|
||||
fields_to_output = %w(id deploy_env stack_template cloud_stack_id stack_status)
|
||||
fields_to_output << 'provider' unless provider_given?
|
||||
|
||||
headers_and_rows(@data, fields_to_output)
|
||||
end
|
||||
|
||||
def create_show
|
||||
headers_and_rows([@data], %w(id deploy_env stack_template cloud_stack_id details))
|
||||
headers_and_rows([@data], %w(id deploy_env stack_template cloud_stack_id stack_status))
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -196,7 +196,7 @@ en:
|
||||
template_preset_body: "Template preset body"
|
||||
stack_template: "Stack Template"
|
||||
cloud_stack_id: "Cloud Stack id"
|
||||
details: "Details are not displayed in table view"
|
||||
stack_status: Stack status
|
||||
title:
|
||||
flavor:
|
||||
list: "Flavors"
|
||||
|
||||
@ -3,7 +3,8 @@ module Connectors
|
||||
include Helpers::InsertCommand,
|
||||
Helpers::ShowCommand,
|
||||
Helpers::ListCommand,
|
||||
Helpers::DeleteCommand
|
||||
Helpers::DeleteCommand,
|
||||
Helpers::UpdateCommand
|
||||
|
||||
def initialize(db)
|
||||
self.collection = db.collection('stack_templates')
|
||||
|
||||
@ -34,7 +34,8 @@ module Devops
|
||||
stack_template: stack_template,
|
||||
cloud_stack_id: cloud_stack_id,
|
||||
parameters: parameters,
|
||||
details: details
|
||||
details: details,
|
||||
stack_status: stack_status
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@ -2,6 +2,10 @@ module Devops
|
||||
module Model
|
||||
class StackOpenstack < StackBase
|
||||
self.provider = 'openstack'
|
||||
|
||||
def stack_status
|
||||
details[:body]['stack']['stack_status'] if details
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -12,7 +12,7 @@ class MongoConnector
|
||||
|
||||
delegate(
|
||||
[:images, :image, :image_insert, :image_delete, :image_update] => :images_connector,
|
||||
[:stack_templates, :stack_template, :stack_template_insert, :stack_template_delete] => :stack_templates_connector,
|
||||
[:stack_templates, :stack_template, :stack_template_insert, :stack_template_delete, :stack_template_update] => :stack_templates_connector,
|
||||
[:stacks, :stack, :stack_insert, :stack_delete, :stack_update] => :stacks_connector,
|
||||
[:available_images, :add_available_images, :delete_available_images] => :filters_connector,
|
||||
[:project, :projects_all, :projects, :project_names_with_envs,
|
||||
|
||||
@ -14,18 +14,18 @@ module Devops
|
||||
end
|
||||
|
||||
def create_stack_from_preset(provider, stack_id, parameters)
|
||||
find_or_create_stack_template!(provider)
|
||||
template_name = find_or_create_stack_template!(provider)
|
||||
puts "Using #{template_name} stack_template to create new stack"
|
||||
Model::StackFactory.create(provider, {
|
||||
'id' => stack_id,
|
||||
'provider' => provider,
|
||||
'parameters' => parameters,
|
||||
'stack_template' => stack_template_name(provider)
|
||||
'stack_template' => template_name
|
||||
})
|
||||
end
|
||||
|
||||
def template_body
|
||||
file_name = File.join("lib/stack_template_presets/#{id}.#{template_file_extension}")
|
||||
File.read(file_name)
|
||||
@template_body ||= File.read("lib/stack_template_presets/#{id}.#{template_file_extension}")
|
||||
end
|
||||
|
||||
# some templates may be YAML files
|
||||
@ -38,21 +38,32 @@ module Devops
|
||||
def find_or_create_stack_template!(provider)
|
||||
name = stack_template_name(provider)
|
||||
begin
|
||||
Devops::Api2.settings.mongo.stack_template(name)
|
||||
stack_template = Devops::Api2.settings.mongo.stack_template(name)
|
||||
update_stack_template(stack_template) if stack_template.template_body != template_body
|
||||
rescue RecordNotFound
|
||||
template = Model::StackTemplateFactory.create(provider, {
|
||||
'id' => name,
|
||||
'provider' => provider,
|
||||
'template_body' => template_body
|
||||
})
|
||||
Devops::Api2.settings.mongo.stack_template_insert(template)
|
||||
create_stack_template(provider)
|
||||
end
|
||||
name
|
||||
end
|
||||
|
||||
def stack_template_name(provider)
|
||||
"#{id}_#{provider}_preset"
|
||||
end
|
||||
|
||||
def create_stack_template(provider)
|
||||
stack_template = Model::StackTemplateFactory.create(provider, {
|
||||
'id' => stack_template_name(provider),
|
||||
'provider' => provider,
|
||||
'template_body' => template_body
|
||||
})
|
||||
Devops::Api2.settings.mongo.stack_template_insert(stack_template)
|
||||
end
|
||||
|
||||
def update_stack_template(stack_template)
|
||||
stack_template.template_body = template_body
|
||||
Devops::Api2.settings.mongo.stack_template_update(stack_template)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -15,3 +15,4 @@ resources:
|
||||
key_name: { get_param: key_name }
|
||||
image: 227f4be7-be1c-498d-ab88-54f8b5df249f
|
||||
flavor: m1.small
|
||||
network: devops-net-1
|
||||
@ -199,7 +199,6 @@ module Provider
|
||||
tenant_id: connection_options[:openstack_tenant],
|
||||
parameters: stack.parameters
|
||||
)
|
||||
# byebug
|
||||
response[:body]['stack']['id']
|
||||
rescue Excon::Errors::Conflict => e
|
||||
raise ProviderErrors::NameConflict
|
||||
@ -211,6 +210,7 @@ module Provider
|
||||
end
|
||||
|
||||
def stack_details(stack)
|
||||
puts "Fetching information about stack #{stack.id}/#{stack.cloud_stack_id}"
|
||||
orchestration.show_stack_details(stack.id, stack.cloud_stack_id).data
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user