add ability to view project stacks
This commit is contained in:
parent
7ff7fd6731
commit
499d05ad32
@ -49,6 +49,10 @@ class Project < Handler
|
|||||||
self.options = @options_parser.servers_options
|
self.options = @options_parser.servers_options
|
||||||
servers_handler @options_parser.args
|
servers_handler @options_parser.args
|
||||||
output(output_type: :servers)
|
output(output_type: :servers)
|
||||||
|
when "stacks"
|
||||||
|
self.options = @options_parser.stacks_options
|
||||||
|
stacks_handler @options_parser.args
|
||||||
|
output(output_type: :stacks)
|
||||||
when "set"
|
when "set"
|
||||||
case ARGV[2]
|
case ARGV[2]
|
||||||
when "run_list"
|
when "run_list"
|
||||||
@ -162,6 +166,20 @@ class Project < Handler
|
|||||||
@servers = get "/project/#{args[2]}/servers", o
|
@servers = get "/project/#{args[2]}/servers", o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def stacks_handler args
|
||||||
|
project, deploy_env = args[2], args[3]
|
||||||
|
r = inspect_parameters @options_parser.stacks_params, project, deploy_env
|
||||||
|
unless r.nil?
|
||||||
|
@options_parser.invalid_stacks_command
|
||||||
|
abort(r)
|
||||||
|
end
|
||||||
|
options = {}
|
||||||
|
unless deploy_env.nil?
|
||||||
|
options[:deploy_env] = deploy_env
|
||||||
|
end
|
||||||
|
@list = get "/project/#{args[2]}/stacks", options
|
||||||
|
end
|
||||||
|
|
||||||
def user_add_handler args
|
def user_add_handler args
|
||||||
r = inspect_parameters @options_parser.user_add_params, args[3], args[4]
|
r = inspect_parameters @options_parser.user_add_params, args[3], args[4]
|
||||||
unless r.nil?
|
unless r.nil?
|
||||||
|
|||||||
@ -3,7 +3,7 @@ require "set"
|
|||||||
|
|
||||||
class ProjectOptions < CommonOptions
|
class ProjectOptions < CommonOptions
|
||||||
|
|
||||||
commands :create, :delete, :deploy, :list, {:multi => [:create]}, :servers, {:set => [:run_list]}, :show, :test, :update, {:user => [:add, :delete]}
|
commands :create, :delete, :deploy, :list, {:multi => [:create]}, :servers, :stacks, {:set => [:run_list]}, :show, :test, :update, {:user => [:add, :delete]}
|
||||||
|
|
||||||
def initialize args, def_options
|
def initialize args, def_options
|
||||||
super(args, def_options)
|
super(args, def_options)
|
||||||
@ -17,6 +17,7 @@ class ProjectOptions < CommonOptions
|
|||||||
self.deploy_params = [id, "[#{env}]"]
|
self.deploy_params = [id, "[#{env}]"]
|
||||||
self.set_run_list_params = [id, env, "[(recipe[mycookbook::myrecipe])|(role[myrole]) ...]"]
|
self.set_run_list_params = [id, env, "[(recipe[mycookbook::myrecipe])|(role[myrole]) ...]"]
|
||||||
self.servers_params = [id, "[#{env}]"]
|
self.servers_params = [id, "[#{env}]"]
|
||||||
|
self.stacks_params = [id, "[#{env}]"]
|
||||||
self.multi_create_params = [id]
|
self.multi_create_params = [id]
|
||||||
self.update_params = [id, "FILE"]
|
self.update_params = [id, "FILE"]
|
||||||
self.user_add_params = [id, "USER_NAME", "[USER_NAME ...]"]
|
self.user_add_params = [id, "USER_NAME", "[USER_NAME ...]"]
|
||||||
|
|||||||
@ -19,6 +19,11 @@ module Output
|
|||||||
title += " " + ARGV[3] unless ARGV[3].nil?
|
title += " " + ARGV[3] unless ARGV[3].nil?
|
||||||
title = I18n.t("output.title.project.servers", :title => title)
|
title = I18n.t("output.title.project.servers", :title => title)
|
||||||
create_servers(@data)
|
create_servers(@data)
|
||||||
|
when :stacks
|
||||||
|
title = ARGV[2]
|
||||||
|
title += " " + ARGV[3] unless ARGV[3].nil?
|
||||||
|
title = I18n.t("output.title.project.stacks", :title => title)
|
||||||
|
create_stacks(@data)
|
||||||
when :test
|
when :test
|
||||||
title = I18n.t("output.title.project.test", :project => ARGV[2], :env => ARGV[3])
|
title = I18n.t("output.title.project.test", :project => ARGV[2], :env => ARGV[3])
|
||||||
create_test(@data)
|
create_test(@data)
|
||||||
@ -101,7 +106,7 @@ module Output
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_servers servers
|
def create_servers servers
|
||||||
abort(I18n.t("output.not_found.project.servers")) if servers.empty?
|
abort(I18n.t("output.not_found.project.servers", name: ARGV[2])) if servers.empty?
|
||||||
rows = []
|
rows = []
|
||||||
servers.each do |s|
|
servers.each do |s|
|
||||||
rows.push [ s["project"], s["deploy_env"], s["chef_node_name"], s["remote_user"], s["provider"], s["id"] ]
|
rows.push [ s["project"], s["deploy_env"], s["chef_node_name"], s["remote_user"], s["provider"], s["id"] ]
|
||||||
@ -136,5 +141,13 @@ module Output
|
|||||||
return headers, rows
|
return headers, rows
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_stacks(stacks)
|
||||||
|
abort(I18n.t("output.not_found.project.stacks", name: ARGV[2])) if stacks.empty?
|
||||||
|
|
||||||
|
fields_to_output = %w(id deploy_env stack_template cloud_stack_id stack_status provider)
|
||||||
|
|
||||||
|
headers_and_rows(stacks, fields_to_output)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -37,14 +37,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 cloud_stack_id stack_status)
|
fields_to_output = %w(id project 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 stack_status))
|
headers_and_rows([@data], %w(id project deploy_env stack_template cloud_stack_id stack_status))
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_servers_list
|
def create_servers_list
|
||||||
|
|||||||
@ -259,6 +259,7 @@ en:
|
|||||||
project:
|
project:
|
||||||
list: "No project found"
|
list: "No project found"
|
||||||
servers: "No servers for project '%{name}' found"
|
servers: "No servers for project '%{name}' found"
|
||||||
|
stacks: "No stacks for project '%{name}' found"
|
||||||
provider:
|
provider:
|
||||||
list: "Empty providers list"
|
list: "Empty providers list"
|
||||||
script:
|
script:
|
||||||
|
|||||||
@ -10,9 +10,8 @@ module Connectors
|
|||||||
self.collection = db.collection('stacks')
|
self.collection = db.collection('stacks')
|
||||||
end
|
end
|
||||||
|
|
||||||
def stacks(provider=nil)
|
def stacks(options={})
|
||||||
query = (provider.nil? ? {} : {'provider' => provider})
|
list(options)
|
||||||
list(query)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@ -42,6 +42,16 @@ module Devops
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.get_project_stacks
|
||||||
|
lambda {
|
||||||
|
check_privileges("project", "r")
|
||||||
|
settings.mongo.project(params[:project])
|
||||||
|
options = {project: params[:project]}
|
||||||
|
options[:deploy_env] = params[:deploy_env] if params[:deploy_env]
|
||||||
|
json settings.mongo.stacks(options).map{|s| s.to_hash}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: multi project
|
# TODO: multi project
|
||||||
def self.create_project
|
def self.create_project
|
||||||
lambda {
|
lambda {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ module Devops
|
|||||||
lambda {
|
lambda {
|
||||||
check_privileges("stack", "r")
|
check_privileges("stack", "r")
|
||||||
check_provider(params[:provider])
|
check_provider(params[:provider])
|
||||||
stacks = settings.mongo.stacks(params[:provider])
|
stacks = settings.mongo.stacks(provider: params[:provider])
|
||||||
json stacks.map(&:to_hash)
|
json stacks.map(&:to_hash)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@ -137,6 +137,33 @@ module Devops
|
|||||||
# ]
|
# ]
|
||||||
app.get_with_headers "/project/:project/servers", :headers => [:accept], &Devops::Version2_0::Handler::Project.get_project_servers
|
app.get_with_headers "/project/:project/servers", :headers => [:accept], &Devops::Version2_0::Handler::Project.get_project_servers
|
||||||
|
|
||||||
|
# Get project stacks
|
||||||
|
#
|
||||||
|
# * *Request*
|
||||||
|
# - method : GET
|
||||||
|
# - headers :
|
||||||
|
# - Accept: application/json
|
||||||
|
# - parameters :
|
||||||
|
# - deploy_env=:env -> show stacks with environment :env
|
||||||
|
#
|
||||||
|
# * *Returns* :
|
||||||
|
# [
|
||||||
|
# "provider": "openstack",
|
||||||
|
# "project": "test_openstack",
|
||||||
|
# "deploy_env": "test",
|
||||||
|
# "stack_template": "openstack_template",
|
||||||
|
# "cloud_stack_id": "4c712026-dcd5-4664-90b8-0915494c1332",
|
||||||
|
# "parameters": {
|
||||||
|
# "admin_pass": "Pass12",
|
||||||
|
# "key_name": "devops",
|
||||||
|
# "image": "CirrOS_0.3.1"
|
||||||
|
# },
|
||||||
|
# "details": null,
|
||||||
|
# "stack_status": null,
|
||||||
|
# "id": "openstack_stack"
|
||||||
|
# ]
|
||||||
|
app.get_with_headers "/project/:project/stacks", :headers => [:accept], &Devops::Version2_0::Handler::Project.get_project_stacks
|
||||||
|
|
||||||
# Create project and chef roles
|
# Create project and chef roles
|
||||||
#
|
#
|
||||||
# * *Request*
|
# * *Request*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user