remove unused stack_presets functionality

This commit is contained in:
Anton Chuchkalov 2016-01-21 19:39:14 +03:00
parent 7745686ab4
commit f5e3dbd679
16 changed files with 0 additions and 450 deletions

View File

@ -47,9 +47,6 @@ class HandlerFactory
when "stack_template" when "stack_template"
require "devops-client/handler/stack_template" require "devops-client/handler/stack_template"
StackTemplate StackTemplate
when "stack_preset"
require "devops-client/handler/stack_preset"
StackPreset
when "stack" when "stack"
require "devops-client/handler/stack" require "devops-client/handler/stack"
Stack Stack

View File

@ -1,62 +0,0 @@
require "devops-client/handler/handler"
require "devops-client/options/stack_preset_options"
require "devops-client/output/stack_preset"
class StackPreset < Handler
output_with Output::StackPreset
def initialize(host, def_options={})
@host, @options = host, def_options
@options_parser = StackPresetOptions.new(ARGV, def_options)
end
def handle
@options, @args = @options_parser.parse_options_for!(current_command)
case current_command
when :list
list_handler
output
when :show
show_handler
output
when :apply
apply_handler
output
end
end
def show_handler
wrong_params = inspect_parameters(@options_parser.show_params, @args[2])
if wrong_params
@options_parser.invalid_show_command
abort(wrong_params)
end
@show = get "/stack_presets/#{@args[2]}"
end
def list_handler
@list = get('/stack_presets')
end
def apply_handler
wrong_params = inspect_parameters(@options_parser.apply_params, @args[2])
if wrong_params
@options_parser.invalid_apply_command
abort(wrong_params)
end
params = {}
params[:id] = @args[2]
params[:provider] = options[:provider] || resources_selector.select_available_provider
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'))
params[:parameters] = JSON.parse(File.read(filepath))
@list = post_body("/stack_presets/#{params[:id]}/apply", JSON.pretty_generate(params))
end
end

View File

@ -1,37 +0,0 @@
require "devops-client/options/common_options"
class StackPresetOptions < CommonOptions
commands :list, :show, :apply
def initialize args, def_options
super(args, def_options)
self.header = I18n.t("headers.stack_preset")
self.banner_header = "stack_preset"
self.list_params = ["[provider]", "[ec2|openstack]"]
self.show_params = ["STACK"]
self.apply_params = ["PRESET"]
end
def apply_options
self.options do |parser, options|
parser.banner << self.apply_banner
parser.recognize_option_value(:provider, 'stack_preset')
parser.recognize_option_value(:project, 'stack_preset')
parser.recognize_option_value(:deploy_env, 'stack_preset')
parser.recognize_option_value(:stack, 'stack_preset')
parser.recognize_option_value(:project, 'stack_preset')
parser.recognize_option_value(:deploy_env, 'stack_preset')
parser.recognize_option_value(:parameters_file, 'stack_preset')
end
end
extend_options_method :list_options do |options|
if args[2]
options[:given_provider] = args[2]
end
end
end

View File

@ -1,45 +0,0 @@
require "devops-client/output/base"
module Output
class StackPreset < Base
def table
if outputting_list?
title = I18n.t("output.title.stack_preset.list")
headers, rows = create_list
else
title = I18n.t("output.title.stack.show", id: @data["id"])
headers, rows = create_apply
end
create_table headers, rows, title, with_num?
end
def csv
if outputting_list?
headers, rows = create_list
else
headers, rows = create_show
end
create_csv headers, rows, with_num?
end
def json
JSON.pretty_generate(@data)
end
private
def create_list
abort(I18n.t("output.not_found.stack_preset.list")) if @data.empty?
fields_to_output = %w(id)
headers_and_rows(@data, fields_to_output)
end
def create_apply
headers_and_rows([@data], %w(id deploy_env stack_template cloud_stack_id stack_status))
end
end
end

View File

@ -43,7 +43,6 @@ en:
user: "User" user: "User"
stack: "Stack" stack: "Stack"
stack_template: "Stack template" stack_template: "Stack template"
stack_preset: "Stack template preset"
handler: handler:
flavor: flavor:
list: list:
@ -119,10 +118,6 @@ en:
question: question:
create: "Are you sure to create stack?" create: "Are you sure to create stack?"
delete: "Are you sure to delete stack '%{name}'?" delete: "Are you sure to delete stack '%{name}'?"
stack_preset:
create:
parameters_file: "Path to file with JSON parameters: "
stack: 'Name of stack to create: '
message: message:
choose_list_default: "Choose %{name} (comma separated), like 1,2,3 or empty for default value '%{default}': " choose_list_default: "Choose %{name} (comma separated), like 1,2,3 or empty for default value '%{default}': "
choose_list: "Choose %{name} (comma separated), like 1,2,3: " choose_list: "Choose %{name} (comma separated), like 1,2,3: "
@ -236,9 +231,6 @@ en:
stack_template: stack_template:
list: "Stack Templates" list: "Stack Templates"
show: "Stack Template" show: "Stack Template"
stack_preset:
list: "Stack Template Presets"
show: "Stack Template Preset"
stack: stack:
list: "Stacks" list: "Stacks"
show: "Stack" show: "Stack"
@ -274,9 +266,6 @@ en:
stack_template: stack_template:
list: "No stack templates found" list: "No stack templates found"
show: "There isn't such stack template" show: "There isn't such stack template"
stack_preset:
list: "No stack template presets found"
show: "There isn't such stack template preset"
stack: stack:
list: "No stacks found" list: "No stacks found"
show: "There isn't such stack" show: "There isn't such stack"
@ -382,9 +371,5 @@ en:
provider: Stack template provider provider: Stack template provider
id: Stack template id id: Stack template id
template_file: Stack template file template_file: Stack template file
stack_preset:
parameters_file: Path to file with JSON parameters
stack: 'Name of stack to build: '
provider: Stack provider
user: user:
new_password: New user password new_password: New user password

View File

@ -1,43 +0,0 @@
require 'json'
require 'lib/stack_presets/factory'
require 'workers/stack_bootstrap_worker'
require "app/api2/parsers/stack_preset"
require_relative "request_handler"
module Devops
module API2_0
module Handler
class StackPreset < RequestHandler
set_parser Devops::API2_0::Parser::StackPresetParser
def presets
Devops::StackPresetsFactory.list
end
def preset id
Devops::StackPresetsFactory.get(id)
end
def apply id
body = parser.apply
preset = Devops::StackPresetsFactory.get(id)
stack = preset.create_stack_from_preset(body)
stack.owner = owner_from_request
Devops::Db.connector.stack_insert(stack)
file = JobStarter.start_job(:worker, :stack_bootstrap,
provider: stack.provider,
stack_id: stack.id,
request: @request
)
puts "Syncing report is located here: #{file}"
stack
end
end
end
end
end

View File

@ -1,16 +0,0 @@
require_relative "request_parser"
module Devops
module API2_0
module Parser
class StackPresetParser < RequestParser
def apply
create_object_from_json_body
end
end
end
end
end

View File

@ -1,70 +0,0 @@
module Devops
module API2_0
module Routes
module StackPresetRoutes
def self.registered(app)
# Get list of available stack_template_presets
#
# * *Request*
# - method : GET
# - headers :
# - Accept: application/json
#
# * *Returns* : array of hashes
# [ {id: 'preset id', template_preset_body: 'long body'} ]
#
app.get_with_headers "/stack_presets", :headers => [:accept] do
# check_privileges("stack_template_presets", "r")
json Devops::API2_0::Handler::StackPreset.new(request).presets.map(&:to_hash)
end
# Get information about stack_template_preset
#
# * *Request*
# - method : GET
# - headers :
# - Accept: application/json
#
# * *Returns* : hash
# {id: 'preset id', template_preset_body: 'long body'}
#
app.get_with_headers "/stack_presets/:id", :headers => [:accept] do |id|
# check_privileges("stack_template_presets", "r")
json Devops::API2_0::Handler::StackPreset.new(request).preset(id).to_hash
end
# Build stack template from preset
#
# * *Request*
# - method : POST
# - headers :
# - Accept: application/json
# - params :
# - provider: string
# - stack_template_id: id of stack template to create
# - template_attrs: hash with template attributes
#
# TODO: not stack template, but stack itself
#
# * *Returns* : created stack template model
# {
# id: 'template id',
# provider: 'provider',
# template_body: 'long body'
# }
#
app.post_with_headers "/stack_presets/:id/apply", :headers => [:accept] do |id|
# check_privileges("stack_template_presets", "r")
check_privileges('stack_template', 'w')
stack = Devops::API2_0::Handler::StackPreset.new(request).apply(id)
create_response 'Created', stack.to_hash, 201
end
puts "Stack template presets routes initialized"
end
end
end
end
end

View File

@ -22,7 +22,6 @@ module Devops
require_relative "api2/handlers/stack" require_relative "api2/handlers/stack"
require_relative "api2/handlers/stack_template" require_relative "api2/handlers/stack_template"
require_relative "api2/handlers/stack_preset"
require 'lib/stubber' require 'lib/stubber'
end end
@ -69,7 +68,6 @@ module Devops
require_relative "api2/routes/bootstrap_templates" require_relative "api2/routes/bootstrap_templates"
require_relative "api2/routes/stack" require_relative "api2/routes/stack"
require_relative "api2/routes/stack_template" require_relative "api2/routes/stack_template"
require_relative "api2/routes/stack_presets"
require_relative "api2/routes/statistic" require_relative "api2/routes/statistic"
require_relative "api2/routes/report" require_relative "api2/routes/report"

View File

@ -1,76 +0,0 @@
require 'lib/string_helper'
require 'db/mongo/models/stack_template/stack_template_factory'
module Devops
module StackPresets
class Base
def id
StringHelper.underscore_class(self.class)
end
def to_hash
{id: id, template_body: template_body}
end
# 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)
stack_attrs = attrs.merge(
'id' => attrs['stack'],
'stack_template' => template_name
)
Model::StackFactory.create(provider, stack_attrs)
end
def template_body
@template_body ||= File.read("lib/stack_presets/#{id}.#{template_file_extension}")
end
# some templates may be YAML files
def template_file_extension
:json
end
private
def find_or_create_stack_template!(provider)
name = stack_template_name(provider)
begin
stack_template = Devops::Api2.settings.mongo.stack_template(name)
update_stack_template(stack_template) if stack_template.template_body != template_body
rescue RecordNotFound
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

View File

@ -1,23 +0,0 @@
require_relative 'base'
require_relative 'postgres_cluster'
require_relative 'preset_not_found'
class Devops::StackPresetsFactory
# find all classes in Devops::StackPresets modules excluding Base and factory.
# This list can be extended in external gems via defining new classes in Devops::StackPresets module.
def self.list
@list ||= Devops::StackPresets.constants.select do |class_name|
class_name != :Base
end.map do |class_name|
Devops::StackPresets.const_get(class_name).new
end
end
def self.get(id)
preset = list.detect { |preset| preset.id == id }
raise PresetNotFound, "Preset '#{preset}' not found" unless preset
preset
end
end

View File

@ -1,7 +0,0 @@
module Devops::StackPresets
class PostgresCluster < Base
def template_file_extension
:yml
end
end
end

View File

@ -1,19 +0,0 @@
heat_template_version: 2013-05-23
description: Simple template to deploy a single compute instance
parameters:
key_name:
type: string
label: Key Name
description: Name of key-pair to be used for compute instance
resources:
my_instance:
type: OS::Nova::Server
properties:
key_name: { get_param: key_name }
image: 5f4020a1-b6ab-47e4-a0ed-de4324a17c3a
flavor: m1.micro
networks:
- network: devops-net-1

View File

@ -1,3 +0,0 @@
class PresetNotFound < StandardError
end

View File

@ -94,7 +94,6 @@ templates = {
#list #list
"templates/api_v2/00_list/flavor.feature.erb" => "features/api_v2/00_list/flavor.feature", "templates/api_v2/00_list/flavor.feature.erb" => "features/api_v2/00_list/flavor.feature",
"templates/api_v2/00_list/stack_preset.feature.erb" => "features/api_v2/00_list/stack_preset.feature",
"templates/api_v2/00_list/00_network.feature.erb" => "features/api_v2/00_list/00_network.feature", "templates/api_v2/00_list/00_network.feature.erb" => "features/api_v2/00_list/00_network.feature",
"templates/api_v2/00_list/10_user.feature.erb" => "features/api_v2/00_list/10_user.feature", "templates/api_v2/00_list/10_user.feature.erb" => "features/api_v2/00_list/10_user.feature",
"templates/api_v2/00_list/10_group.feature.erb" => "features/api_v2/00_list/10_group.feature", "templates/api_v2/00_list/10_group.feature.erb" => "features/api_v2/00_list/10_group.feature",

View File

@ -1,28 +0,0 @@
@stack_preset @list
Feature: stack template preset list
Scenario: Get list of all stack template presets
When I send GET '/v2.0/stack_presets' query
Then response should be '200'
And the Content-Type header should include 'application/json'
And the JSON response should be an array
And response array should contains elements like:
"""
[
{
"id": "test",
"template_body": "long body"
}
]
"""
Scenario: Get information about particular stack template preset
When I send GET '/v2.0/stack_presets/postgres_cluster' query
Then response should be '200'
And the Content-Type header should include 'application/json'
And response should be JSON object like:
"""
{
"id": "postgres_cluster", "template_body": "long body"
}
"""