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 def add_account provider
account = ::Provider::ProviderFactory.get(provider).create_account(parser.account) account = ::Provider::ProviderFactory.get(provider).create_account(parser.account)
key = Devops::Db.connector.key account.ssh_key
Devops::Db.connector.provider_accounts_insert(account) Devops::Db.connector.provider_accounts_insert(account)
::Provider::ProviderFactory.add_account(provider, account)
account.to_hash account.to_hash
end end

View File

@ -35,7 +35,11 @@ module Devops
end end
def provider_servers provider 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 end
def server id def server id

View File

@ -84,7 +84,7 @@ module Devops
app.post_with_headers "/provider/:provider/account", :headers => [:accept, :content_type] do |provider| app.post_with_headers "/provider/:provider/account", :headers => [:accept, :content_type] do |provider|
check_privileges("provider", "w") check_privileges("provider", "w")
check_provider(provider) 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 end
# Delete account with name :account_name for :provider # 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) json Devops::API2_0::Handler::Server.new(request).provider_servers(provider)
end 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 # Get server info by :name
# #
# * *Request* # * *Request*

View File

@ -73,7 +73,9 @@ EOH
end end
def knife cmd 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? return o, $?.success?
end end

View File

@ -145,7 +145,7 @@ module Devops
} }
end end
def deploy_info deploy_env, build_number def deploy_info deploy_env, build_number=nil
{ {
"use_json_file" => true, "use_json_file" => true,
# "run_list" => Set.new.merge(self.run_list).merge(deploy_env.run_list).to_a, # "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 provider = @deploy_env.provider_instance
mongo = ::Devops::Db.connector mongo = ::Devops::Db.connector
begin begin
@out.puts "Using '#{@deploy_env.provider}' account '#{@deploy_env.provider_account}'\n" if @deploy_env.provider_account
@out.puts "Create server..." @out.puts "Create server..."
@out.flush @out.flush
@ -137,6 +138,7 @@ module Devops
end end
ja = { ja = {
:provider => @server.provider, :provider => @server.provider,
:provider_account => @server.provider_account,
:devops_host => `hostname`.strip :devops_host => `hostname`.strip
} }
ip = @server.private_ip ip = @server.private_ip
@ -210,7 +212,7 @@ module Devops
bootstrap_options.push "--sudo" unless @server.remote_user == "root" bootstrap_options.push "--sudo" unless @server.remote_user == "root"
bootstrap_options.push "-t #{options[:bootstrap_template]}" if options[:bootstrap_template] bootstrap_options.push "-t #{options[:bootstrap_template]}" if options[:bootstrap_template]
rl = options[:run_list] 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.push "-c #{options[:config]}" if options[:config]
bootstrap_options bootstrap_options
end end
@ -269,6 +271,7 @@ module Devops
end end
rescue => e rescue => e
@out << "\nError: #{e.message}\n" @out << "\nError: #{e.message}\n"
DevopsLogger.logger.error(e.message + "\n" + e.backtrace.join("\n"))
result_code(:deploy_unknown_error) result_code(:deploy_unknown_error)
end end
end end

View File

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

View File

@ -94,7 +94,7 @@ module Provider
def servers def servers
list = self.compute.describe_instances.body["reservationSet"] 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] convert_server server["instancesSet"][0]
end end
end end

View File

@ -5,22 +5,25 @@ module Provider
def init config def init config
@connections = {} @connections = {}
Devops::Db.connector.provider_accounts(Ec2::PROVIDER).each do |account| Devops::Db.connector.provider_accounts(Ec2::PROVIDER).each do |account|
options = { create_connection_from_account(config, account)
aws_certificate: account.certificate,
aws_ssh_key: account.ssh_key,
aws_access_key_id: account.access_key_id,
aws_secret_access_key: account.secret_access_key,
aws_availability_zone: account.availability_zone,
aws_proxy: config[:aws_proxy],
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}'" puts "\tFound ec2 account '#{account.account_name}'"
end end
end end
def create_connection_from_account config, account
options = {
aws_certificate: account.certificate,
aws_ssh_key: account.ssh_key,
aws_access_key_id: account.access_key_id,
aws_secret_access_key: account.secret_access_key,
aws_availability_zone: account.availability_zone,
aws_proxy: config[:aws_proxy],
aws_no_proxy: config[:aws_no_proxy],
aws_integration_run_list: config[:aws_integration_run_list]
}
add_connection(account.account_name, Ec2.new(options))
end
end end
end end

View File

@ -32,10 +32,10 @@ module Provider
["ec2", "openstack", "static"].each do |p| ["ec2", "openstack", "static"].each do |p|
begin begin
o = Provider.const_get(p.capitalize).new(conf) o = Provider.const_get(p.capitalize).new(conf)
if o.configured? #if o.configured?
@@providers[p] = o @@providers[p] = o
puts "Provider '#{p}' has been loaded" puts "Provider '#{p}' has been loaded"
end #end
factory = Provider.const_get(p.capitalize + "AccountsFactory").new factory = Provider.const_get(p.capitalize + "AccountsFactory").new
factory.init(conf) factory.init(conf)
@@providers_with_accounts_factories[p] = factory @@providers_with_accounts_factories[p] = factory
@ -46,6 +46,12 @@ module Provider
end end
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 def self.require_all
["ec2", "openstack", "static"].each do |provider| ["ec2", "openstack", "static"].each do |provider|
begin begin