#789: account fields

This commit is contained in:
amartynov 2015-11-02 11:42:20 +03:00
parent f452b1aa32
commit 8d0cd797a2
8 changed files with 56 additions and 7 deletions

View File

@ -20,6 +20,10 @@ module Devops
::Provider::ProviderFactory.get(provider).accounts ::Provider::ProviderFactory.get(provider).accounts
end end
def account_fields provider
::Provider::ProviderFactory.get_account_class(provider).account_fields
end
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 key = Devops::Db.connector.key account.ssh_key

View File

@ -26,6 +26,22 @@ module Devops
json Devops::API2_0::Handler::Provider.new(request).providers json Devops::API2_0::Handler::Provider.new(request).providers
end end
# Get list of provider account fields
#
# * *Request*
# - method : GET
# - headers :
# - Accept: application/json
#
# * *Returns* : hash
# key - field
# value - description
app.get_with_headers "/provider/:provider/account/fields", :headers => [:accept] do |provider|
check_privileges("provider", "r")
check_provider(provider)
json Devops::API2_0::Handler::Provider.new(request).account_fields(provider)
end
# Get list of provider accounts # Get list of provider accounts
# #
# * *Request* # * *Request*

View File

@ -34,6 +34,14 @@ module Devops
Ec2ProviderAccount.new a Ec2ProviderAccount.new a
end end
def self.account_fields
{
access_key_id: "AWS account access key",
secret_access_key: "AWS account secret key",
availability_zone: "Availability zone, todo: remove field?"
}.merge(ProviderAccount::ACCOUNT_FIELDS)
end
# TODO: remove # TODO: remove
def validate_fields_types def validate_fields_types

View File

@ -6,6 +6,15 @@ module Devops
attr_accessor :username, :auth_url, :tenant, :api_key attr_accessor :username, :auth_url, :tenant, :api_key
def self.account_fields
{
username: "Openstack user name",
auth_url: "Identity API endpoint",
tenant: "Tenant to access",
api_key: "Openstack user password"
}.merge(ProviderAccount::ACCOUNT_FIELDS)
end
def initialize a={} def initialize a={}
super(a) super(a)
self.username = a["username"] self.username = a["username"]

View File

@ -7,14 +7,19 @@ module Devops
include ModelWithProvider include ModelWithProvider
attr_accessor :account_name, :description, :ssh_key, :certificate attr_accessor :account_name, :description, :ssh_key
ACCOUNT_FIELDS = {
account_name: "Account name (id)",
description: "Account description",
ssh_key: "Ssh key id"
}
def initialize a={} def initialize a={}
self.account_name = a["account_name"] self.account_name = a["account_name"]
self.description = a["description"] self.description = a["description"]
self.ssh_key = a["ssh_key"] self.ssh_key = a["ssh_key"]
self.provider = a["provider"] self.provider = a["provider"]
self.certificate = a["certificate"]
self.created_at = a["created_at"] self.created_at = a["created_at"]
end end
@ -28,7 +33,6 @@ module Devops
"description" => self.description, "description" => self.description,
"ssh_key" => self.ssh_key, "ssh_key" => self.ssh_key,
"provider" => self.provider, "provider" => self.provider,
"certificate" => self.certificate,
"created_at" => self.created_at "created_at" => self.created_at
} }
end end
@ -38,8 +42,7 @@ module Devops
"_id" => self.account_name, "_id" => self.account_name,
"description" => self.description, "description" => self.description,
"ssh_key" => self.ssh_key, "ssh_key" => self.ssh_key,
"provider" => self.provider, "provider" => self.provider
"certificate" => self.certificate
} }
end end

View File

@ -9,6 +9,9 @@ module Devops
StaticProviderAccount.new a StaticProviderAccount.new a
end end
def self.account_fields
ProviderAccount::ACCOUNT_FIELDS
end
end end
end end
end end

View File

@ -8,11 +8,11 @@ module Provider
create_connection_from_account(config, account) create_connection_from_account(config, account)
puts "\tFound ec2 account '#{account.account_name}'" puts "\tFound ec2 account '#{account.account_name}'"
end end
ProviderFactory.add_provider Ec2::PROVIDER unless @connections.empty?
end end
def create_connection_from_account config, account def create_connection_from_account config, account
options = { options = {
aws_certificate: account.certificate,
aws_ssh_key: account.ssh_key, aws_ssh_key: account.ssh_key,
aws_access_key_id: account.access_key_id, aws_access_key_id: account.access_key_id,
aws_secret_access_key: account.secret_access_key, aws_secret_access_key: account.secret_access_key,

View File

@ -3,11 +3,12 @@ require "sinatra"
module Provider module Provider
module ProviderFactory module ProviderFactory
@@available_providers = []
@@providers = {} @@providers = {}
@@providers_with_accounts_factories = {} @@providers_with_accounts_factories = {}
def self.providers def self.providers
@@providers.keys @@available_providers
end end
def self.get provider, account=nil def self.get provider, account=nil
@ -25,6 +26,10 @@ module Provider
@@providers.values @@providers.values
end end
def self.add_provider provider
@@available_providers << provider unless @@available_providers.include?(provider)
end
def self.init conf def self.init conf
# require providers here to get access to debug properties # require providers here to get access to debug properties
require_all require_all
@ -34,6 +39,7 @@ module Provider
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
@@available_providers << p
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