Merge branch '#789' of git.stu.neva.ru:cloudtechlab/devops-service into #789

This commit is contained in:
Anton Martynov 2015-10-28 21:55:11 +03:00
commit f92eca17b2
11 changed files with 53 additions and 21 deletions

View File

@ -22,7 +22,9 @@ module Devops
def add_account provider
account = ::Provider::ProviderFactory.get(provider).create_account(parser.account)
key = Devops::Db.connector.key account.ssh_key
Devops::Db.connector.provider_accounts_insert(account)
::Provider::ProviderFactory.add_account(provider, account)
account.to_hash
end

View File

@ -35,7 +35,11 @@ module Devops
end
def provider_servers provider
::Provider::ProviderFactory.get(provider).servers
provider_servers_with_account provider, nil
end
def provider_servers_with_account provider, account
::Provider::ProviderFactory.get(provider, account).servers
end
def server id

View File

@ -84,7 +84,7 @@ module Devops
app.post_with_headers "/provider/:provider/account", :headers => [:accept, :content_type] do |provider|
check_privileges("provider", "w")
check_provider(provider)
create_response("Updated", {:account => Devops::API2_0::Handler::Provider.new(request).add_account(provider)}, 201)
create_response("Created", {:account => Devops::API2_0::Handler::Provider.new(request).add_account(provider)}, 201)
end
# Delete account with name :account_name for :provider

View File

@ -85,6 +85,11 @@ module Devops
json Devops::API2_0::Handler::Server.new(request).provider_servers(provider)
end
app.get_with_headers "/servers/provider/:provider/:account", :headers => [:accept] do |provider, account|
check_privileges("server", "r")
json Devops::API2_0::Handler::Server.new(request).provider_servers_with_account(provider, account)
end
# Get server info by :name
#
# * *Request*

View File

@ -73,7 +73,9 @@ EOH
end
def knife cmd
o = `bundle exec knife #{cmd} -c #{self.config} 2>&1`
cmd = "bundle exec knife #{cmd} -c #{self.config} 2>&1"
DevopsLogger.logger.info("Going to invoke command: #{cmd}")
o = `#{cmd}`
return o, $?.success?
end

View File

@ -145,7 +145,7 @@ module Devops
}
end
def deploy_info deploy_env, build_number
def deploy_info deploy_env, build_number=nil
{
"use_json_file" => true,
# "run_list" => Set.new.merge(self.run_list).merge(deploy_env.run_list).to_a,

View File

@ -78,6 +78,7 @@ module Devops
provider = @deploy_env.provider_instance
mongo = ::Devops::Db.connector
begin
@out.puts "Using '#{@deploy_env.provider}' account '#{@deploy_env.provider_account}'\n" if @deploy_env.provider_account
@out.puts "Create server..."
@out.flush
@ -137,6 +138,7 @@ module Devops
end
ja = {
:provider => @server.provider,
:provider_account => @server.provider_account,
:devops_host => `hostname`.strip
}
ip = @server.private_ip
@ -210,7 +212,7 @@ module Devops
bootstrap_options.push "--sudo" unless @server.remote_user == "root"
bootstrap_options.push "-t #{options[:bootstrap_template]}" if options[:bootstrap_template]
rl = options[:run_list]
bootstrap_options.push "-r #{rl.join(",")}" unless rl.nil?# rl.empty?
bootstrap_options.push "-r #{rl.join(",")}" unless rl.nil? or rl.empty?
bootstrap_options.push "-c #{options[:config]}" if options[:config]
bootstrap_options
end
@ -269,6 +271,7 @@ module Devops
end
rescue => e
@out << "\nError: #{e.message}\n"
DevopsLogger.logger.error(e.message + "\n" + e.backtrace.join("\n"))
result_code(:deploy_unknown_error)
end
end

View File

@ -9,6 +9,13 @@ module Provider
def connection account_name
@connections[account_name]
end
def add_connection name, conn
@connections[name] = conn
end
def create_connection_from_account config, account
end
end
end

View File

@ -94,7 +94,7 @@ module Provider
def servers
list = self.compute.describe_instances.body["reservationSet"]
list.select{|l| l["instancesSet"][0]["instanceState"]["name"].to_s != "terminated"}.map do |server|
list.select{|l| l["instancesSet"][0]["instanceState"]["name"].to_s == "running"}.map do |server|
convert_server server["instancesSet"][0]
end
end

View File

@ -5,6 +5,12 @@ module Provider
def init config
@connections = {}
Devops::Db.connector.provider_accounts(Ec2::PROVIDER).each do |account|
create_connection_from_account(config, account)
puts "\tFound ec2 account '#{account.account_name}'"
end
end
def create_connection_from_account config, account
options = {
aws_certificate: account.certificate,
aws_ssh_key: account.ssh_key,
@ -16,10 +22,7 @@ module Provider
aws_no_proxy: config[:aws_no_proxy],
aws_integration_run_list: config[:aws_integration_run_list]
}
@connections[account.account_name] = Ec2.new(options)
#DevopsLogger.logger.info("Found ec2 account '#{account.account_name}'")
puts "\tFound ec2 account '#{account.account_name}'"
end
add_connection(account.account_name, Ec2.new(options))
end
end

View File

@ -32,10 +32,10 @@ module Provider
["ec2", "openstack", "static"].each do |p|
begin
o = Provider.const_get(p.capitalize).new(conf)
if o.configured?
#if o.configured?
@@providers[p] = o
puts "Provider '#{p}' has been loaded"
end
#end
factory = Provider.const_get(p.capitalize + "AccountsFactory").new
factory.init(conf)
@@providers_with_accounts_factories[p] = factory
@ -46,6 +46,12 @@ module Provider
end
end
def self.add_account provider, account
factory = @@providers_with_accounts_factories[provider]
factory.create_connection_from_account(DevopsConfig.config, account)
DevopsLogger.logger.info("Added #{provider} account '#{account.account_name}'")
end
def self.require_all
["ec2", "openstack", "static"].each do |provider|
begin