#789: add account in runtime

This commit is contained in:
amartynov 2015-10-28 17:27:02 +03:00
parent 8d145c10b4
commit 04646a7430
5 changed files with 33 additions and 16 deletions

View File

@ -24,6 +24,7 @@ module Devops
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
end

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

@ -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

@ -5,22 +5,25 @@ module Provider
def init config
@connections = {}
Devops::Db.connector.provider_accounts(Ec2::PROVIDER).each do |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]
}
@connections[account.account_name] = Ec2.new(options)
#DevopsLogger.logger.info("Found ec2 account '#{account.account_name}'")
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,
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

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