set project and deploy_env attrs to stack created from presets
This commit is contained in:
parent
589fc6ff84
commit
58e0f4d118
@ -79,13 +79,17 @@ class Stack < Handler
|
|||||||
end
|
end
|
||||||
|
|
||||||
def resources_handler
|
def resources_handler
|
||||||
stack_id = @args[2]
|
stack_id, resource_id = @args[2], @args[3]
|
||||||
r = inspect_parameters(@options_parser.sync_params, stack_id)
|
r = inspect_parameters(@options_parser.sync_params, stack_id)
|
||||||
unless r.nil?
|
unless r.nil?
|
||||||
@options_parser.invalid_sync_command
|
@options_parser.invalid_sync_command
|
||||||
abort(r)
|
abort(r)
|
||||||
end
|
end
|
||||||
@list = get "/stack/#{stack_id}/resources"
|
if resource_id
|
||||||
|
@list = get "/stack/#{stack_id}/resources/#{resource_id}"
|
||||||
|
else
|
||||||
|
@list = get "/stack/#{stack_id}/resources"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_handler
|
def delete_handler
|
||||||
|
|||||||
@ -49,6 +49,8 @@ class StackPreset < Handler
|
|||||||
params[:id] = @args[2]
|
params[:id] = @args[2]
|
||||||
params[:provider] = options[:provider] || resources_selector.select_available_provider
|
params[:provider] = options[:provider] || resources_selector.select_available_provider
|
||||||
params[:stack] = options[:stack] || enter_parameter(I18n.t('handler.stack_preset.create.stack'))
|
params[:stack] = options[:stack] || enter_parameter(I18n.t('handler.stack_preset.create.stack'))
|
||||||
|
params[:project] = options[:project] || resources_selector.select_available_project
|
||||||
|
params[:deploy_env] = options[:deploy_env] || enter_parameter(I18n.t('handler.stack.create.deploy_env'))
|
||||||
|
|
||||||
filepath = options[:parameters_file] || enter_parameter(I18n.t('handler.stack_preset.create.parameters_file'))
|
filepath = options[:parameters_file] || enter_parameter(I18n.t('handler.stack_preset.create.parameters_file'))
|
||||||
params[:parameters] = JSON.parse(File.read(filepath))
|
params[:parameters] = JSON.parse(File.read(filepath))
|
||||||
|
|||||||
@ -136,7 +136,7 @@ module Devops
|
|||||||
def to_hash_without_id
|
def to_hash_without_id
|
||||||
h = {}
|
h = {}
|
||||||
h["deploy_envs"] = self.deploy_envs.map {|e| e.to_hash} unless self.deploy_envs.nil?
|
h["deploy_envs"] = self.deploy_envs.map {|e| e.to_hash} unless self.deploy_envs.nil?
|
||||||
h["archived"] = self.archived
|
h["archived"] = self.archived if self.archived
|
||||||
h["description"] = self.description
|
h["description"] = self.description
|
||||||
if self.multi?
|
if self.multi?
|
||||||
h["type"] = MULTI_TYPE
|
h["type"] = MULTI_TYPE
|
||||||
|
|||||||
@ -7,8 +7,8 @@ module Devops
|
|||||||
|
|
||||||
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, nil: true},
|
project: {type: String},
|
||||||
deploy_env: {type: String, nil: true},
|
deploy_env: {type: String},
|
||||||
stack_template: {type: String, empty: false},
|
stack_template: {type: String, empty: false},
|
||||||
cloud_stack_id: {type: String, nil: true}
|
cloud_stack_id: {type: String, nil: true}
|
||||||
# details: {type: String, nil: true}
|
# details: {type: String, nil: true}
|
||||||
@ -59,6 +59,10 @@ module Devops
|
|||||||
provider_class.stack_resources(self)
|
provider_class.stack_resources(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def resource(resource_id)
|
||||||
|
provider_class.stack_resource(self, resource_id)
|
||||||
|
end
|
||||||
|
|
||||||
def template_body
|
def template_body
|
||||||
Devops::Api2.settings.mongo.stack_template(stack_template).template_body
|
Devops::Api2.settings.mongo.stack_template(stack_template).template_body
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,15 +13,22 @@ module Devops
|
|||||||
{id: id, template_body: template_body}
|
{id: id, template_body: template_body}
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_stack_from_preset(provider, stack_id, parameters)
|
# attrs should include
|
||||||
|
# 'provider'
|
||||||
|
# 'stack'
|
||||||
|
# 'parameters'
|
||||||
|
# 'project'
|
||||||
|
# 'deploy_env'
|
||||||
|
def create_stack_from_preset(attrs)
|
||||||
|
provider = attrs.fetch('provider')
|
||||||
template_name = 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, {
|
stack_attrs = attrs.merge(
|
||||||
'id' => stack_id,
|
'id' => attrs['stack'],
|
||||||
'provider' => provider,
|
|
||||||
'parameters' => parameters,
|
|
||||||
'stack_template' => template_name
|
'stack_template' => template_name
|
||||||
})
|
)
|
||||||
|
|
||||||
|
Model::StackFactory.create(provider, stack_attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
def template_body
|
def template_body
|
||||||
|
|||||||
@ -217,6 +217,10 @@ module Provider
|
|||||||
fog_stack(stack).resources
|
fog_stack(stack).resources
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stack_resource(stack, resource_id)
|
||||||
|
fog_stack(stack).resources.get(resource_id)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def convert_groups list
|
def convert_groups list
|
||||||
res = {}
|
res = {}
|
||||||
|
|||||||
@ -74,6 +74,14 @@ module Devops
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.resource
|
||||||
|
lambda {
|
||||||
|
check_privileges("stack", "r")
|
||||||
|
stack = settings.mongo.stack(params[:stack_id])
|
||||||
|
json stack.resource(params[:resource_id])
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -26,11 +26,8 @@ module Devops
|
|||||||
check_privileges('stack_template', 'w')
|
check_privileges('stack_template', 'w')
|
||||||
|
|
||||||
attrs = create_object_from_json_body
|
attrs = create_object_from_json_body
|
||||||
|
|
||||||
provider, stack_id, parameters = attrs.fetch('provider'), attrs.fetch('stack'), attrs.fetch('parameters')
|
|
||||||
|
|
||||||
preset = Devops::StackPresetsFactory.get(attrs.fetch('id'))
|
preset = Devops::StackPresetsFactory.get(attrs.fetch('id'))
|
||||||
stack = preset.create_stack_from_preset(provider, stack_id, parameters)
|
stack = preset.create_stack_from_preset(attrs)
|
||||||
settings.mongo.stack_insert(stack)
|
settings.mongo.stack_insert(stack)
|
||||||
|
|
||||||
create_response 'Created', stack.to_hash, 201
|
create_response 'Created', stack.to_hash, 201
|
||||||
|
|||||||
@ -18,6 +18,8 @@ module Devops
|
|||||||
|
|
||||||
app.get_with_headers "/stack/:stack_id/resources", :headers => [:accept], &Devops::Version2_0::Handler::Stack.resources
|
app.get_with_headers "/stack/:stack_id/resources", :headers => [:accept], &Devops::Version2_0::Handler::Stack.resources
|
||||||
|
|
||||||
|
app.get_with_headers "/stack/:stack_id/resources/:resource_id", :headers => [:accept], &Devops::Version2_0::Handler::Stack.resource
|
||||||
|
|
||||||
hash = {}
|
hash = {}
|
||||||
|
|
||||||
hash['GET'] = Devops::Version2_0::Handler::Stack.get_stack
|
hash['GET'] = Devops::Version2_0::Handler::Stack.get_stack
|
||||||
|
|||||||
@ -71,12 +71,16 @@ class Provider::Openstack
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def stack_details
|
def stack_details(stack)
|
||||||
{stack_status: 'stubbed'}
|
{stack_status: 'stubbed'}
|
||||||
end
|
end
|
||||||
|
|
||||||
def stack_resources
|
def stack_resources(stack)
|
||||||
['stubbed']
|
[{'stubbed' => 'stubbed'}]
|
||||||
|
end
|
||||||
|
|
||||||
|
def stack_resource(stack, resource_id)
|
||||||
|
{'stubbed' => 'stubbed'}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Loading…
Reference in New Issue
Block a user