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