[PATCH] Fix REST API mapping.
by Ian Main
This fixes an argument mapping that still references the old
cloud_account_id. This allows the condor quota plugin to work again.
Signed-off-by: Ian Main <imain(a)redhat.com>
---
src/config/routes.rb | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 61e4221..1bcb88f 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -38,8 +38,8 @@ ActionController::Routing::Routes.draw do |map|
r.resources :instances, :collection => {:start => :get, :stop => :get, :select_template => :get, :remove_failed => :get, :can_start => :get, :can_create => :get }, :member => {:key => :get}
end
- map.can_start_instance '/resources/instances/:instance_id/can_start/:cloud_account_id', :controller => 'resources/instances', :action => 'can_start', :conditions => { :method => :get }
- map.can_create_instance '/resources/instances/:instance_id/can_create/:cloud_account_id', :controller => 'resources/instances', :action => 'can_create', :conditions => { :method => :get }
+ map.can_start_instance '/resources/instances/:instance_id/can_start/:provider_account_id', :controller => 'resources/instances', :action => 'can_start', :conditions => { :method => :get }
+ map.can_create_instance '/resources/instances/:instance_id/can_create/:provider_account_id', :controller => 'resources/instances', :action => 'can_create', :conditions => { :method => :get }
map.namespace 'image_factory' do |r|
r.resources :assemblies
--
1.7.4
13 years, 1 month
[PATCH] Crappy rpm workaround
by Ian Main
Since 'make rpms' uses the existing directory to build an rpm from, it's
possible that it can pick up an existing condor plugin .so and install
it even if it's got the wrong prefix set etc.
This patch just adds a 'make clean' before 'make' so that it is forced
to rebuild a new plugin when making the rpm. Clearly however the rpm
needs to be fixed.
Signed-off-by: Ian Main <imain(a)redhat.com>
---
deltacloud-aggregator.spec.in | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/deltacloud-aggregator.spec.in b/deltacloud-aggregator.spec.in
index c7d6a7b..3bd0b43 100644
--- a/deltacloud-aggregator.spec.in
+++ b/deltacloud-aggregator.spec.in
@@ -85,6 +85,7 @@ Documentation and tests for the Deltacloud Aggregator
%build
%configure
+make clean
make
%install
--
1.7.4
13 years, 1 month
[PATCH] Crappy rpm workaround
by Ian Main
Since 'make rpms' uses the existing directory to build an rpm from, it's
possible that it can pick up an existing condor plugin .so and install
it even if it's got the wrong prefix set etc.
This patch just adds a 'make clean' before 'make' so that it is forced
to rebuild a new plugin when making the rpm. Clearly however the rpm
needs to be fixed.
Signed-off-by: Ian Main <imain(a)redhat.com>
---
deltacloud-aggregator.spec.in | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/deltacloud-aggregator.spec.in b/deltacloud-aggregator.spec.in
index c7d6a7b..3bd0b43 100644
--- a/deltacloud-aggregator.spec.in
+++ b/deltacloud-aggregator.spec.in
@@ -85,6 +85,7 @@ Documentation and tests for the Deltacloud Aggregator
%build
%configure
+make clean
make
%install
--
1.7.4
13 years, 1 month
[PATCH aeolus] Task 197 - Remove any logic forcing one provider only
by jzigmund@redhat.com
From: Jozef Zigmund <jzigmund(a)redhat.com>
Inside this patch I rename model of CloudAccount to ProviderAccount. Also I refactor all codes where this model was called. All supported providers are included in constant hash, that is named PROVIDER_TYPES in Provider model. So now, attribute of class "cloud_type" is renamed to "provider_type" and it must be one of these PROVIDER_TYPES value. I fixed all Rspecs and Cucumbers for provider_account model.
In this revision added fixing failing rspec in next.
When you'll test this patch won't forget to run "rake db:migrate", because some of the attributes were changed in DB.
---
.../admin/provider_accounts_controller.rb | 92 ++++++----
src/app/controllers/admin/providers_controller.rb | 11 +-
src/app/controllers/permissions_controller.rb | 6 +-
src/app/controllers/quotas_controller.rb | 2 +-
.../controllers/resources/instances_controller.rb | 8 +-
src/app/helpers/admin/provider_accounts_helper.rb | 21 ++
src/app/models/cloud_account.rb | 205 -------------------
src/app/models/cloud_account_observer.rb | 33 ---
src/app/models/image.rb | 6 +-
src/app/models/instance.rb | 2 +-
src/app/models/instance_observer.rb | 6 +-
src/app/models/instance_task.rb | 2 +-
src/app/models/permission.rb | 2 +-
src/app/models/pool.rb | 4 +-
src/app/models/pool_family.rb | 2 +-
src/app/models/privilege.rb | 8 +-
src/app/models/provider.rb | 38 +++--
src/app/models/provider_account.rb | 206 ++++++++++++++++++++
src/app/models/provider_account_observer.rb | 33 +++
src/app/models/quota.rb | 2 +-
src/app/services/data_service_active_record.rb | 8 +-
src/app/services/graph_service.rb | 4 +-
src/app/util/condormatic.rb | 2 +-
src/app/views/admin/provider_accounts/_aws.haml | 39 ++++
src/app/views/admin/provider_accounts/_gogrid.haml | 16 ++
src/app/views/admin/provider_accounts/_mock.haml | 16 ++
.../views/admin/provider_accounts/_opennebula.haml | 16 ++
.../provider_accounts/_provider_selection.haml | 24 +++
.../views/admin/provider_accounts/_rackspace.haml | 16 ++
src/app/views/admin/provider_accounts/_rhevm.haml | 2 +
src/app/views/admin/provider_accounts/new.haml | 21 +-
src/app/views/admin/providers/_form.haml | 9 +-
src/app/views/admin/providers/_list.haml | 1 +
src/app/views/image_factory/builds/new.haml | 6 +-
src/app/views/layouts/application.haml | 1 -
src/app/views/resources/instances/_list.haml | 2 +-
src/app/views/resources/instances/_properties.haml | 2 +-
src/classad_plugin/classad_plugin.rb | 2 +-
src/config/environment.rb | 2 +-
src/config/locales/en.yml | 6 +
src/config/routes.rb | 3 +-
...824_rename_cloud_account_to_provider_account.rb | 13 ++
...123410_rename_cloud_account_id_for_instances.rb | 9 +
..._families_to_provider_accounts_pool_families.rb | 11 +
...l_properties_of_columns_in_provider_accounts.rb | 13 ++
...e_to_provideraccount_in_privileges_and_roles.rb | 11 +
...0110202165053_change_column_target_in_images.rb | 11 +
src/db/seeds.rb | 12 +-
src/dbomatic/dbomatic | 2 +-
src/features/api.feature | 6 +-
src/features/provider.feature | 15 +-
src/features/provider_account.feature | 20 +--
src/features/step_definitions/api_steps.rb | 6 +-
.../step_definitions/provider_account_steps.rb | 14 +-
src/features/step_definitions/provider_steps.rb | 8 +-
src/features/step_definitions/template_steps.rb | 8 +-
src/features/support/custom.rb | 6 +-
src/features/support/paths.rb | 2 +-
src/features/template.feature | 13 +-
src/image_builder_service/image_builder_service | 2 +-
src/lib/tasks/dc_tasks.rake | 2 +-
src/lib/tasks/demo_data.rake | 4 +-
src/script/use-existing-ec2-templates | 6 +-
src/spec/controllers/builds_controller_spec.rb | 6 +-
.../controllers/cloud_accounts_controller_spec.rb | 92 ---------
.../provider_accounts_controller_spec.rb | 93 +++++++++
src/spec/factories/cloud_account.rb | 22 --
src/spec/factories/instance.rb | 4 +-
src/spec/factories/provider.rb | 8 +-
src/spec/factories/provider_account.rb | 22 ++
src/spec/models/cloud_account_observer_spec.rb | 22 --
src/spec/models/cloud_account_spec.rb | 80 --------
src/spec/models/image_spec.rb | 6 +-
src/spec/models/instance_observer_spec.rb | 20 +-
src/spec/models/instance_spec.rb | 14 +-
src/spec/models/pool_family_spec.rb | 10 +-
src/spec/models/provider_account_observer_spec.rb | 22 ++
src/spec/models/provider_account_spec.rb | 80 ++++++++
src/spec/models/provider_spec.rb | 12 +-
src/spec/models/quota_spec.rb | 48 +++---
.../services/data_service_active_record_spec.rb | 61 +++---
src/test/fixtures/providers.yml | 2 +-
src/test/fixtures/roles.yml | 4 +-
src/test/unit/cloud_account_test.rb | 8 -
src/test/unit/provider_account_test.rb | 8 +
src/test/unit/provider_test.rb | 2 +-
86 files changed, 994 insertions(+), 733 deletions(-)
create mode 100644 src/app/helpers/admin/provider_accounts_helper.rb
delete mode 100644 src/app/models/cloud_account.rb
delete mode 100644 src/app/models/cloud_account_observer.rb
create mode 100644 src/app/models/provider_account.rb
create mode 100644 src/app/models/provider_account_observer.rb
create mode 100644 src/app/views/admin/provider_accounts/_aws.haml
create mode 100644 src/app/views/admin/provider_accounts/_gogrid.haml
create mode 100644 src/app/views/admin/provider_accounts/_mock.haml
create mode 100644 src/app/views/admin/provider_accounts/_opennebula.haml
create mode 100644 src/app/views/admin/provider_accounts/_provider_selection.haml
create mode 100644 src/app/views/admin/provider_accounts/_rackspace.haml
create mode 100644 src/app/views/admin/provider_accounts/_rhevm.haml
create mode 100644 src/db/migrate/20110117140824_rename_cloud_account_to_provider_account.rb
create mode 100644 src/db/migrate/20110125123410_rename_cloud_account_id_for_instances.rb
create mode 100644 src/db/migrate/20110125154113_rename_cloud_accounts_pool_families_to_provider_accounts_pool_families.rb
create mode 100644 src/db/migrate/20110126161751_change_null_properties_of_columns_in_provider_accounts.rb
create mode 100644 src/db/migrate/20110202151950_change_cloudaccount_value_to_provideraccount_in_privileges_and_roles.rb
create mode 100644 src/db/migrate/20110202165053_change_column_target_in_images.rb
delete mode 100644 src/spec/controllers/cloud_accounts_controller_spec.rb
create mode 100644 src/spec/controllers/provider_accounts_controller_spec.rb
delete mode 100644 src/spec/factories/cloud_account.rb
create mode 100644 src/spec/factories/provider_account.rb
delete mode 100644 src/spec/models/cloud_account_observer_spec.rb
delete mode 100644 src/spec/models/cloud_account_spec.rb
create mode 100644 src/spec/models/provider_account_observer_spec.rb
create mode 100644 src/spec/models/provider_account_spec.rb
delete mode 100644 src/test/unit/cloud_account_test.rb
create mode 100644 src/test/unit/provider_account_test.rb
diff --git a/src/app/controllers/admin/provider_accounts_controller.rb b/src/app/controllers/admin/provider_accounts_controller.rb
index 132d8a1..fb76436 100644
--- a/src/app/controllers/admin/provider_accounts_controller.rb
+++ b/src/app/controllers/admin/provider_accounts_controller.rb
@@ -8,7 +8,7 @@ class Admin::ProviderAccountsController < ApplicationController
if @search_term.blank?
load_accounts
else
- search = CloudAccount.search do
+ search = ProviderAccount.search do
keywords(params[:q])
end
@accounts = search.results
@@ -17,7 +17,7 @@ class Admin::ProviderAccountsController < ApplicationController
def show
@tab_captions = ['Properties', 'Credentials', 'History', 'Permissions']
- @account = CloudAccount.find(params[:id])
+ @account = ProviderAccount.find(params[:id])
require_privilege(Privilege::VIEW, @account)
@details_tab = params[:details_tab].blank? ? 'properties' : params[:details_tab]
@@ -38,72 +38,78 @@ class Admin::ProviderAccountsController < ApplicationController
end
def new
- @cloud_account = CloudAccount.new
+ @provider_account = ProviderAccount.new
@quota = Quota.new
@providers = Provider.all
+ if @providers.empty?
+ flash[:error] = "You don't have any provider yet. Please create one!"
+ else
+ @selected_provider = @providers.first unless @providers.blank?
+ end
end
def create
- @provider = Provider.find(params[:provider_id])
- require_privilege(Privilege::CREATE, CloudAccount, @provider)
+ @selected_provider = @provider = Provider.find(params[:provider_account][:provider_id])
+ require_privilege(Privilege::CREATE, ProviderAccount, @provider)
@providers = Provider.all
- @cloud_account = CloudAccount.new(params[:cloud_account])
- @cloud_account.provider = @provider
- @cloud_account.quota = @quota = Quota.new
+ @provider_account = ProviderAccount.new(params[:provider_account])
+ @provider_account.provider = @provider
+ @provider_account.quota = @quota = Quota.new
if params.delete :test_account
- test_account(@cloud_account)
+ test_account(@provider_account)
render :action => 'new' and return
end
limit = params[:quota][:maximum_running_instances] if params[:quota]
- @cloud_account.quota.set_maximum_running_instances(limit)
+ @provider_account.quota.set_maximum_running_instances(limit)
- if @cloud_account.invalid?
- if not @cloud_account.valid_credentials?
+ if @provider_account.invalid?
+ if not @provider_account.valid_credentials?
flash.now[:error] = "The entered credential information is incorrect"
- elsif @cloud_account.errors.on(:username)
- flash.now[:error] = "The access key '#{params[:cloud_account][:username]}' has already been taken."
+ elsif @provider_account.errors.on(:username)
+ flash.now[:error] = "The access key '#{params[:provider_account][:username]}' has already been taken."
else
flash.now[:error] = "You must fill in all the required fields"
end
render :action => 'new' and return
end
- @cloud_account.pool_families << PoolFamily.default
- @cloud_account.save!
- @cloud_account.assign_owner_roles(current_user)
- if @cloud_account.populate_realms
+ @provider_account.pool_families << PoolFamily.default
+ @provider_account.save!
+ @provider_account.assign_owner_roles(current_user)
+ if @provider_account.populate_realms
flash[:notice] = "Provider account added."
end
- redirect_to admin_provider_account_path(@cloud_account)
+ redirect_to admin_provider_account_path(@provider_account)
kick_condor
end
def edit
- @cloud_account = CloudAccount.find(params[:id])
- @quota = @cloud_account.quota
- @provider = @cloud_account.provider
- require_privilege(Privilege::MODIFY,@cloud_account)
+ @provider_account = ProviderAccount.find(params[:id])
+ @quota = @provider_account.quota
+ @provider = @provider_account.provider
+ require_privilege(Privilege::MODIFY,@provider_account)
end
def update
- @cloud_account = CloudAccount.find(params[:id])
- @provider = @cloud_account.provider
- require_privilege(Privilege::MODIFY,@cloud_account)
- @quota = @cloud_account.quota
+ @provider_account = ProviderAccount.find(params[:id])
+ @provider = @provider_account.provider
+ require_privilege(Privilege::MODIFY, @provider)
+ require_privilege(Privilege::MODIFY,@provider_account)
+ @quota = @provider_account.quota
if params.delete :test_account
- test_account(@cloud_account)
+ test_account(@provider_account)
render :action => 'edit' and return
end
limit = params[:quota][:maximum_running_instances] if params[:quota]
- @cloud_account.quota.set_maximum_running_instances(limit)
- if @cloud_account.update_attributes(params[:cloud_account])
- flash[:notice] = "Cloud Account updated!"
- redirect_to admin_provider_account_path(@cloud_account)
+ @provider_account.quota.set_maximum_running_instances(limit)
+ if @provider_account.update_attributes(params[:provider_account])
+ flash[:notice] = "Provider Account updated!"
+ redirect_to admin_provider_account_path(@provider_account)
else
render :action => :edit
end
@@ -113,13 +119,30 @@ class Admin::ProviderAccountsController < ApplicationController
if (not params[:accounts_selected]) or (params[:accounts_selected].length == 0)
flash[:notice] = "You must select some accounts first."
else
- CloudAccount.find(params[:accounts_selected]).each do |account|
+ ProviderAccount.find(params[:accounts_selected]).each do |account|
account.destroy if check_privilege(Privilege::MODIFY, account)
end
end
redirect_to admin_provider_accounts_url
end
+ def set_selected_provider
+ @quota = Quota.new
+ @provider_account = ProviderAccount.new
+ respond_to do |format|
+ format.js {
+ @providers = Provider.find(:all)
+ @selected_provider = Provider.find(params[:provider_account][:provider_id])
+ render :partial => 'provider_selection'
+ }
+ format.html {
+ @providers = Provider.find(:all)
+ @selected_provider = Provider.find(params[:provider_account][:provider_id])
+ render :action => 'new', :layout => true
+ }
+ end
+ end
+
protected
def test_account(account)
@@ -136,12 +159,13 @@ class Admin::ProviderAccountsController < ApplicationController
@header = [
{ :name => "Name", :sort_attr => :name },
{ :name => "Username", :sort_attr => :username},
+ { :name => "Provider Type", :sort_attr => :provider_type }
]
@url_params = params
end
def load_accounts
- @accounts = CloudAccount.paginate(:all,
+ @accounts = ProviderAccount.paginate(:all,
:page => params[:page] || 1,
:order => (params[:order_field] || 'label') +' '+ (params[:order_dir] || 'asc')
)
diff --git a/src/app/controllers/admin/providers_controller.rb b/src/app/controllers/admin/providers_controller.rb
index 95c9561..022b5bf 100644
--- a/src/app/controllers/admin/providers_controller.rb
+++ b/src/app/controllers/admin/providers_controller.rb
@@ -55,7 +55,7 @@ class Admin::ProvidersController < ApplicationController
test_connection(@provider)
render :action => 'new'
else
- @provider.set_cloud_type!
+ #(a)provider.set_provider_type!
if @provider.save && @provider.populate_hardware_profiles
@provider.assign_owner_roles(current_user)
flash[:notice] = "Provider added."
@@ -71,14 +71,14 @@ class Admin::ProvidersController < ApplicationController
def update
@provider = Provider.find_by_id(params[:id])
require_privilege(Privilege::MODIFY, @provider)
- previous_cloud_type = @provider.cloud_type
+ previous_provider_type = @provider.provider_type
@provider.update_attributes(params[:provider])
if params[:test_connection]
test_connection(@provider)
render :action => 'edit'
else
- @provider.set_cloud_type!
- if previous_cloud_type != @provider.cloud_type
+ @provider.set_provider_type!
+ if previous_provider_type != @provider.provider_type
@provider.errors.add :url, "points to a different provider"
end
@@ -120,7 +120,8 @@ class Admin::ProvidersController < ApplicationController
def load_providers
@header = [{ :name => "Provider name", :sort_attr => :name },
- { :name => "Provider URL", :sort_attr => :name }
+ { :name => "Provider URL", :sort_attr => :name },
+ { :name => "Provider Type", :sort_attr => :name }
]
@providers = Provider.list_for_user(@current_user, Privilege::VIEW)
@url_params = params.clone
diff --git a/src/app/controllers/permissions_controller.rb b/src/app/controllers/permissions_controller.rb
index 622f776..380b97c 100644
--- a/src/app/controllers/permissions_controller.rb
+++ b/src/app/controllers/permissions_controller.rb
@@ -67,20 +67,20 @@ class PermissionsController < ApplicationController
def set_permission_object(action)
if !params[:permission_object_type].nil?
- @permission_object =
+ @permission_object =
params[:permission_object_type].constantize.find(params[:permission_object_id])
elsif !params[:pool_id].nil?
@permission_object = Pool.find params[:pool_id]
elsif !params[:provider_id].nil?
@permission_object = Provider.find params[:provider_id]
elsif !params[:cloud_account_id].nil?
- @permission_object = CloudAccount.find params[:cloud_account_id]
+ @permission_object = ProviderAccount.find params[:cloud_account_id]
elsif !params[:base_permission_object_id].nil?
@permission_object = BasePermissionObject.find params[:base_permission_object_id]
else
@permission_object = BasePermissionObject.general_permission_scope
end
-
+
raise ActiveRecord::RecordNotFound if @permission_object.nil?
require_privilege(action, @permission_object)
diff --git a/src/app/controllers/quotas_controller.rb b/src/app/controllers/quotas_controller.rb
index cfa85fb..0beb386 100644
--- a/src/app/controllers/quotas_controller.rb
+++ b/src/app/controllers/quotas_controller.rb
@@ -77,7 +77,7 @@ class QuotasController < ApplicationController
if params[:parent_type] == "pool"
return Pool.find(params[:id])
elsif params[:parent_type] == "cloud_account"
- return CloudAccount.find(params[:id])
+ return ProviderAccount.find(params[:id])
end
#TODO Throw no match to pool or cloud account exception
end
diff --git a/src/app/controllers/resources/instances_controller.rb b/src/app/controllers/resources/instances_controller.rb
index 910c2c1..109a92c 100644
--- a/src/app/controllers/resources/instances_controller.rb
+++ b/src/app/controllers/resources/instances_controller.rb
@@ -132,10 +132,10 @@ class Resources::InstancesController < ApplicationController
def can_create
begin
- cloud_account = CloudAccount.find(params[:cloud_account_id])
+ provider_account = ProviderAccount.find(params[:provider_account_id])
@instance = Instance.find(params[:instance_id])
@action_request = "can_create"
- @value = Quota.can_create_instance?(@instance, cloud_account)
+ @value = Quota.can_create_instance?(@instance, provider_account)
render :partial => 'can_perform_state_change.xml'
rescue ActiveRecord::RecordNotFound
head :not_found
@@ -146,10 +146,10 @@ class Resources::InstancesController < ApplicationController
def can_start
begin
- cloud_account = CloudAccount.find(params[:cloud_account_id])
+ provider_account = ProviderAccount.find(params[:provider_account_id])
@instance = Instance.find(params[:instance_id])
@action_request = "can_start"
- @value = Quota.can_start_instance?(@instance, cloud_account)
+ @value = Quota.can_start_instance?(@instance, provider_account)
render :partial => 'can_perform_state_change.xml'
rescue ActiveRecord::RecordNotFound => e
puts e.inspect
diff --git a/src/app/helpers/admin/provider_accounts_helper.rb b/src/app/helpers/admin/provider_accounts_helper.rb
new file mode 100644
index 0000000..d4c234d
--- /dev/null
+++ b/src/app/helpers/admin/provider_accounts_helper.rb
@@ -0,0 +1,21 @@
+module Admin::ProviderAccountsHelper
+
+ def display_provider_account_login_form(provider_type)
+ case provider_type
+ when 0
+ render :partial => "mock"
+ when 1
+ render :partial => "aws"
+ when 2
+ render :partial => "gogrid"
+ when 3
+ render :partial => "rackspace"
+ when 4
+ render :partial => "rhevm"
+ when 5
+ render :partial => "opennebula"
+ else
+ flash.now[:warning] = "You don't have any provider yet"
+ end
+ end
+end
diff --git a/src/app/models/cloud_account.rb b/src/app/models/cloud_account.rb
deleted file mode 100644
index 4eba087..0000000
--- a/src/app/models/cloud_account.rb
+++ /dev/null
@@ -1,205 +0,0 @@
- #
-# Copyright (C) 2009 Red Hat, Inc.
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; version 2 of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-# MA 02110-1301, USA. A copy of the GNU General Public License is
-# also available at http://www.gnu.org/copyleft/gpl.html.
-
-# Filters added to this controller apply to all controllers in the application.
-# Likewise, all the methods added will be available for all controllers.
-
-require 'nokogiri'
-require 'sunspot_rails'
-
-class CloudAccount < ActiveRecord::Base
-
- searchable do
- text :name, :as => :code_substring
- text :username, :as => :code_substring
- end
-
- include PermissionedObject
-
- # Relations
- belongs_to :provider
- belongs_to :quota, :autosave => true
- has_many :instances
- has_and_belongs_to_many :pool_families
- has_many :permissions, :as => :permission_object, :dependent => :destroy,
- :include => [:role],
- :order => "permissions.id ASC"
-
- has_one :instance_key, :as => :instance_key_owner, :dependent => :destroy
-
- # Helpers
- attr_accessor :x509_cert_priv_file, :x509_cert_pub_file
-
- # Validations
- validates_presence_of :provider
- validates_presence_of :label
- validates_presence_of :username
- validates_uniqueness_of :username, :scope => :provider_id
- validates_presence_of :password
- validates_presence_of :account_number
- validate :validate_presence_of_x509_certs
- validate :validate_credentials
-
- # We're using this instead of <tt>validates_presence_of</tt> helper because
- # we want to show errors on different attributes ending with '_file'.
- def validate_presence_of_x509_certs
- errors.add(:x509_cert_pub_file, "can't be blank") if x509_cert_pub.blank?
- errors.add(:x509_cert_priv_file, "can't be blank") if x509_cert_priv.blank?
- end
-
- def validate_credentials
- unless valid_credentials?
- errors.add(:base, "Login Credentials are Invalid for this Provider")
- end
- end
-
- # Hooks
- before_destroy :destroyable?
- before_validation :read_x509_files
-
- def object_list
- super << provider
- end
- class << self
- alias orig_list_for_user_include list_for_user_include
- alias orig_list_for_user_conditions list_for_user_conditions
- end
-
- def self.list_for_user_include
- includes = orig_list_for_user_include
- includes << { :provider => {:permissions => {:role => :privileges}}}
- includes
- end
-
- def self.list_for_user_conditions
- "(#{orig_list_for_user_conditions}) or
- (permissions_providers.user_id=:user and
- privileges_roles.target_type=:target_type and
- privileges_roles.action=:action)"
- end
-
- def destroyable?
- instances.empty?
- end
-
- def read_x509_files
- if x509_cert_pub_file.respond_to?(:read)
- x509_cert_pub_file.rewind # Sometimes the file has to rewind, becuase something already read from it.
- self.x509_cert_pub = x509_cert_pub_file.read
- end
- if x509_cert_priv_file.respond_to?(:read)
- x509_cert_priv_file.rewind
- self.x509_cert_priv = x509_cert_priv_file.read
- end
- end
-
- def connect
- begin
- return DeltaCloud.new(username, password, provider.url)
- rescue Exception => e
- logger.error("Error connecting to framework: #{e.message}")
- logger.error("Backtrace: #{e.backtrace.join("\n")}")
- return nil
- end
- end
-
- def self.find_or_create(account)
- a = CloudAccount.find_by_username_and_provider_id(account["username"], account["provider_id"])
- return a.nil? ? CloudAccount.new(account) : a
- end
-
- def pools
- pools = []
- instances.each do |instance|
- pools << instance.pool
- end
- end
-
- def name
- label.blank? ? username : label
- end
-
- # FIXME: for already-mapped accounts, update rather than add new
- def populate_realms
- client = connect
- realms = client.realms
- # FIXME: this should probably be in the same transaction as cloud_account.save
- self.transaction do
- realms.each do |realm|
- #ignore if it exists
- #FIXME: we need to handle keeping in sync forupdates as well as
- # account permissions
- unless Realm.find_by_external_key_and_provider_id(realm.id,
- provider.id)
- ar_realm = Realm.new(:external_key => realm.id,
- :name => realm.name ? realm.name : realm.id,
- :provider_id => provider.id)
- ar_realm.save!
-
- frontend_realm = Realm.new(:external_key => ar_realm.external_key,
- :name => ar_realm.name,
- :provider_id => nil)
-
- available_realms = Realm.frontend.find(:all, :conditions => {
- :external_key => frontend_realm.external_key })
-
- if available_realms.empty?
- frontend_realm.backend_realms << ar_realm
- frontend_realm.save!
- else
- available_realms.each do |r|
- r.backend_realms << ar_realm
- end
- end
- end
- end
- end
- end
-
- def valid_credentials?
- DeltaCloud::valid_credentials?(username, password, provider.url)
- end
-
- def build_credentials
- xml = Nokogiri::XML <<EOT
-<?xml version="1.0"?>
-<provider_credentials>
- <ec2_credentials>
- <account_number></account_number>
- <access_key></access_key>
- <secret_access_key></secret_access_key>
- <certificate></certificate>
- <key></key>
- </ec2_credentials>
-</provider_credentials>
-EOT
- node = xml.at_xpath('/provider_credentials/ec2_credentials')
- node.at_xpath('./account_number').content = account_number
- node.at_xpath('./access_key').content = username
- node.at_xpath('./secret_access_key').content = password
- node.at_xpath('./certificate').content = x509_cert_pub
- node.at_xpath('./key').content = x509_cert_priv
- return xml.to_s
- end
-
- def generate_auth_key
- client = connect
- return nil unless client && client.feature?(:instances, :authentication_key)
- client.create_key(:name => "#{self.name}_#{Time.now.to_i}_key_#{self.object_id}")
- end
-end
diff --git a/src/app/models/cloud_account_observer.rb b/src/app/models/cloud_account_observer.rb
deleted file mode 100644
index 299b9db..0000000
--- a/src/app/models/cloud_account_observer.rb
+++ /dev/null
@@ -1,33 +0,0 @@
-class CloudAccountObserver < ActiveRecord::Observer
- def after_create(account)
- # FIXME: new boxgrinder doesn't create bucket for amis automatically,
- # for now we create bucket from conductor
- # remove this hotfix when fixed on boxgrinder side
- if account.provider.cloud_type == 'ec2'
- create_bucket(account)
- end
- if key = account.generate_auth_key
- account.update_attribute(:instance_key, InstanceKey.create!(:pem => key.pem, :name => key.id, :instance_key_owner => account))
- end
- end
-
- private
-
- def create_bucket(account)
- client = account.connect
- bucket_name = "#{account.account_number}-imagefactory-amis"
- # TODO (jprovazn): getting particular bucket takes long time (core fetches all
- # buckets from provider), so we call directly create_bucket, if bucket exists,
- # exception should be thrown (actually existing bucket is returned - this
- # bug should be fixed soon)
- #client.create_bucket(:name => bucket_name) unless client.bucket(bucket_name)
- begin
- client.create_bucket(:name => bucket_name)
- rescue Exception => e
- Rails.logger.error e.message
- Rails.logger.error e.backtrace.join("\n ")
- end
- end
-end
-
-CloudAccountObserver.instance
diff --git a/src/app/models/image.rb b/src/app/models/image.rb
index 2cb15b7..120fd56 100644
--- a/src/app/models/image.rb
+++ b/src/app/models/image.rb
@@ -52,7 +52,7 @@ class Image < ActiveRecord::Base
INACTIVE_STATES = [STATE_COMPLETE, STATE_FAILED, STATE_CANCELED]
def self.available_targets
- return YAML.load_file("#{RAILS_ROOT}/config/image_descriptor_targets.yml")
+ Provider::PROVIDER_TYPES.invert
end
def generate_uuid
@@ -129,7 +129,7 @@ class Image < ActiveRecord::Base
image = Image.new(
:name => raw_image.name,
:status => 'complete',
- :target => account.provider.cloud_type,
+ :target => account.provider.provider_type,
:template_id => template.id
)
image.save!
@@ -155,7 +155,7 @@ class Image < ActiveRecord::Base
raise "There is not provider with name '#{providername}'"
end
- account = CloudAccount.new(:provider => provider, :username => username, :password => password)
+ account = ProviderAccount.new(:provider => provider, :username => username, :password => password)
unless account.valid_credentials?
raise "Invalid credentials for provider '#{providername}'"
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index b84a596..3d24404 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -36,7 +36,7 @@ class Instance < ActiveRecord::Base
@@per_page = 15
belongs_to :pool
- belongs_to :cloud_account
+ belongs_to :provider_account
belongs_to :hardware_profile
belongs_to :template
diff --git a/src/app/models/instance_observer.rb b/src/app/models/instance_observer.rb
index 80b39c5..e14e8d2 100644
--- a/src/app/models/instance_observer.rb
+++ b/src/app/models/instance_observer.rb
@@ -36,9 +36,9 @@ class InstanceObserver < ActiveRecord::Observer
hwp = an_instance.hardware_profile
pool = an_instance.pool
user = an_instance.owner
- cloud_account = an_instance.cloud_account
+ provider_account = an_instance.provider_account
- [cloud_account, pool, user].each do |parent|
+ [provider_account, pool, user].each do |parent|
if parent
quota = parent.quota
if quota
@@ -65,7 +65,7 @@ class InstanceObserver < ActiveRecord::Observer
# we try to generate key only when instance is running
# and instance_key is not generated yet
return if instance.state != Instance::STATE_RUNNING or instance.instance_key
- if key = instance.cloud_account.generate_auth_key
+ if key = instance.provider_account.generate_auth_key
instance.instance_key = InstanceKey.create!(:pem => key.pem, :name => key.id, :instance_key_owner => instance)
end
end
diff --git a/src/app/models/instance_task.rb b/src/app/models/instance_task.rb
index be76a6e..42bed29 100644
--- a/src/app/models/instance_task.rb
+++ b/src/app/models/instance_task.rb
@@ -46,7 +46,7 @@ class InstanceTask < Task
actions = []
# FIXME: cloud_account won't always be set here, but we're requiring
# front end realm for now.
- if cloud_account = instance.cloud_account and
+ if cloud_account = instance.provider_account and
conn = cloud_account.connect and c_state = conn.instance_state(state)
transitions = c_state.transitions
transitions.each do |transition|
diff --git a/src/app/models/permission.rb b/src/app/models/permission.rb
index 22b228a..7cd02a1 100644
--- a/src/app/models/permission.rb
+++ b/src/app/models/permission.rb
@@ -37,7 +37,7 @@ class Permission < ActiveRecord::Base
:foreign_key => "permission_object_id"
belongs_to :provider, :class_name => "Provider",
:foreign_key => "permission_object_id"
- belongs_to :cloud_account, :class_name => "CloudAccount",
+ belongs_to :provider_account, :class_name => "ProviderAccount",
:foreign_key => "permission_object_id"
belongs_to :template, :class_name => "Template",
:foreign_key => "permission_object_id"
diff --git a/src/app/models/pool.rb b/src/app/models/pool.rb
index 550ca79..0f9a4fb 100644
--- a/src/app/models/pool.rb
+++ b/src/app/models/pool.rb
@@ -47,8 +47,8 @@ class Pool < ActiveRecord::Base
def cloud_accounts
accounts = []
instances.each do |instance|
- if instance.cloud_account and !accounts.include?(instance.cloud_account)
- accounts << instance.cloud_account
+ if instance.provider_account and !accounts.include?(instance.provider_account)
+ accounts << instance.provider_account
end
end
end
diff --git a/src/app/models/pool_family.rb b/src/app/models/pool_family.rb
index bc96fee..e083920 100644
--- a/src/app/models/pool_family.rb
+++ b/src/app/models/pool_family.rb
@@ -24,7 +24,7 @@ class PoolFamily < ActiveRecord::Base
DEFAULT_POOL_FAMILY_KEY = "default_pool_family"
has_many :pools, :dependent => :destroy
- has_and_belongs_to_many :cloud_accounts
+ has_and_belongs_to_many :provider_accounts
validates_presence_of :name
validates_uniqueness_of :name
diff --git a/src/app/models/privilege.rb b/src/app/models/privilege.rb
index f7a61ef..1ef514c 100644
--- a/src/app/models/privilege.rb
+++ b/src/app/models/privilege.rb
@@ -33,7 +33,7 @@ class Privilege < ActiveRecord::Base
# Deployable: choose this deployable to launch
# Instance: may perform actions on this instance
# Realm: may map this realm
- # CloudAccount: May add this account to PoolFamily
+ # ProviderAccount: May add this account to PoolFamily
ACTIONS = [ CREATE, MODIFY, USE, VIEW,
@@ -47,7 +47,7 @@ class Privilege < ActiveRecord::Base
HardwareProfile => ACTIONS - [USE, VIEW],
Realm => ACTIONS - [VIEW],
Provider => ACTIONS - [USE],
- CloudAccount => ACTIONS,
+ ProviderAccount => ACTIONS,
User => [ CREATE, MODIFY, VIEW] }
belongs_to :role
@@ -99,7 +99,7 @@ class Privilege < ActiveRecord::Base
# view_perms Can view permissions
# set_perms Can set permissions (or can set instance permissions on this pool)
#
- # Quota The Pool/CloudAccount/PoolFamily/User assigned the quota
+ # Quota The Pool/ProviderAccount/PoolFamily/User assigned the quota
# view Can view quota on this obj
# modify Can edit quota on this obj
#
@@ -123,7 +123,7 @@ class Privilege < ActiveRecord::Base
# view_perms Can view permissions
# set_perms Can set permissions
#
- # CloudAccount This CloudAccount
+ # ProviderAccount This ProviderAccount
# view Can view
# use Can map to PoolFamily
# modify Can modify
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index 31eb7bb..fc15ebf 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -29,7 +29,18 @@ class Provider < ActiveRecord::Base
require 'util/deltacloud'
include PermissionedObject
- has_many :cloud_accounts, :dependent => :destroy
+ MOCK = 0
+ AWS = 1
+ GOGRID = 2
+ RACKSPACE = 3
+ RHEVM = 4
+ OPENNEBULA = 5
+
+ PROVIDER_TYPES = { MOCK => "mock", AWS => "AWS",
+ GOGRID => "GoGrid", RACKSPACE => "Rackspace", RHEVM => "RHEVM",
+ OPENNEBULA => "OpenNebula" }
+
+ has_many :provider_accounts, :dependent => :destroy
has_many :hardware_profiles, :dependent => :destroy
has_many :provider_images, :dependent => :destroy
has_many :realms, :dependent => :destroy
@@ -37,12 +48,13 @@ class Provider < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
- validates_presence_of :cloud_type
validates_presence_of :url
validates_format_of :name, :with => /^[\w -]*$/n, :message => "must only contain: numbers, letters, spaces, '_' and '-'"
validates_length_of :name, :maximum => 255
+ validates_inclusion_of :provider_type, :in => PROVIDER_TYPES
+
has_many :permissions, :as => :permission_object, :dependent => :destroy,
:include => [:role],
:order => "permissions.id ASC"
@@ -53,8 +65,8 @@ class Provider < ActiveRecord::Base
# but a cloud account is silently not destroyed when there is
# an instance for the cloud account
def destroyable?
- unless self.cloud_accounts.empty?
- self.cloud_accounts.each do |c|
+ unless self.provider_accounts.empty?
+ self.provider_accounts.each do |c|
unless c.instances.empty?
inst_list = c.instances.map {|i| i.name}.join(', ')
self.errors.add_to_base "there are instances for cloud account '#{c.name}': #{inst_list}"
@@ -64,10 +76,10 @@ class Provider < ActiveRecord::Base
return self.errors.empty?
end
- def set_cloud_type!
- deltacloud = connect
- self.cloud_type = deltacloud.driver_name unless deltacloud.nil?
- end
+# def set_provider_type!
+# deltacloud = connect
+# self.provider_type = deltacloud.driver_name unless deltacloud.nil?
+# end
def connect
begin
@@ -117,16 +129,16 @@ class Provider < ActiveRecord::Base
cloud_accounts.collect {|account| account.pools}.flatten.uniq
end
- # returns first provider of cloud_type which has at least one cloud account
- def self.find_by_target_with_account(cloud_type)
- Provider.all(:conditions => {:cloud_type => cloud_type}).each do |p|
- return p unless p.cloud_accounts.empty?
+ # returns first provider of provider_type which has at least one cloud account
+ def self.find_by_target_with_account(provider_type)
+ Provider.all(:conditions => {:provider_type => provider_type}).each do |p|
+ return p unless p.provider_accounts.empty?
end
nil
end
# TODO: implement or remove - this is meant to contain a hash of
- # supported cloud_types to use in populating form, though if we
+ # supported provider_types to use in populating form, though if we
# infer that field, we don't need this.
def supported_types
end
diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb
new file mode 100644
index 0000000..39dce11
--- /dev/null
+++ b/src/app/models/provider_account.rb
@@ -0,0 +1,206 @@
+ #
+# Copyright (C) 2009 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+# Filters added to this controller apply to all controllers in the application.
+# Likewise, all the methods added will be available for all controllers.
+
+require 'nokogiri'
+require 'sunspot_rails'
+
+class ProviderAccount < ActiveRecord::Base
+ include PermissionedObject
+
+ searchable do
+ text :name, :as => :code_substring
+ text :username, :as => :code_substring
+ end
+
+ # Relations
+ belongs_to :provider
+ belongs_to :quota, :autosave => true
+ has_many :instances
+ has_and_belongs_to_many :pool_families
+ has_many :permissions, :as => :permission_object, :dependent => :destroy,
+ :include => [:role],
+ :order => "permissions.id ASC"
+
+ has_one :instance_key, :as => :instance_key_owner, :dependent => :destroy
+
+ # Helpers
+ attr_accessor :x509_cert_priv_file, :x509_cert_pub_file
+
+ # Validations
+ validates_presence_of :provider
+ validates_presence_of :label
+ validates_presence_of :username
+ validates_uniqueness_of :username, :scope => :provider_id
+ validates_presence_of :password
+ validates_presence_of :account_number,:if => Proc.new{ |account| account.provider.provider_type == Provider::AWS}
+ validate :validate_presence_of_x509_certs
+ validate :validate_credentials
+
+ # We're using this instead of <tt>validates_presence_of</tt> helper because
+ # we want to show errors on different attributes ending with '_file'.
+ def validate_presence_of_x509_certs
+ if self.provider.provider_type == Provider::AWS
+ errors.add(:x509_cert_pub_file, "can't be blank") if x509_cert_pub.blank?
+ errors.add(:x509_cert_priv_file, "can't be blank") if x509_cert_priv.blank?
+ end
+ end
+
+ def validate_credentials
+ unless valid_credentials?
+ errors.add(:base, "Login Credentials are Invalid for this Provider")
+ end
+ end
+
+ # Hooks
+ before_destroy :destroyable?
+ before_validation :read_x509_files
+
+ def object_list
+ super << provider
+ end
+ class << self
+ alias orig_list_for_user_include list_for_user_include
+ alias orig_list_for_user_conditions list_for_user_conditions
+ end
+
+ def self.list_for_user_include
+ includes = orig_list_for_user_include
+ includes << { :provider => {:permissions => {:role => :privileges}}}
+ includes
+ end
+
+ def self.list_for_user_conditions
+ "(#{orig_list_for_user_conditions}) or
+ (permissions_providers.user_id=:user and
+ privileges_roles.target_type=:target_type and
+ privileges_roles.action=:action)"
+ end
+
+ def destroyable?
+ instances.empty?
+ end
+
+ def read_x509_files
+ if x509_cert_pub_file.respond_to?(:read)
+ x509_cert_pub_file.rewind # Sometimes the file has to rewind, becuase something already read from it.
+ self.x509_cert_pub = x509_cert_pub_file.read
+ end
+ if x509_cert_priv_file.respond_to?(:read)
+ x509_cert_priv_file.rewind
+ self.x509_cert_priv = x509_cert_priv_file.read
+ end
+ end
+
+ def connect
+ begin
+ return DeltaCloud.new(username, password, provider.url)
+ rescue Exception => e
+ logger.error("Error connecting to framework: #{e.message}")
+ logger.error("Backtrace: #{e.backtrace.join("\n")}")
+ return nil
+ end
+ end
+
+ def self.find_or_create(account)
+ a = ProviderAccount.find_by_username_and_provider_id(account["username"], account["provider_id"])
+ return a.nil? ? ProviderAccount.new(account) : a
+ end
+
+ def pools
+ pools = []
+ instances.each do |instance|
+ pools << instance.pool
+ end
+ end
+
+ def name
+ label.blank? ? username : label
+ end
+
+ # FIXME: for already-mapped accounts, update rather than add new
+ def populate_realms
+ client = connect
+ realms = client.realms
+ # FIXME: this should probably be in the same transaction as cloud_account.save
+ self.transaction do
+ realms.each do |realm|
+ #ignore if it exists
+ #FIXME: we need to handle keeping in sync forupdates as well as
+ # account permissions
+ unless Realm.find_by_external_key_and_provider_id(realm.id,
+ provider.id)
+ ar_realm = Realm.new(:external_key => realm.id,
+ :name => realm.name ? realm.name : realm.id,
+ :provider_id => provider.id)
+ ar_realm.save!
+
+ frontend_realm = Realm.new(:external_key => ar_realm.external_key,
+ :name => ar_realm.name,
+ :provider_id => nil)
+
+ available_realms = Realm.frontend.find(:all, :conditions => {
+ :external_key => frontend_realm.external_key })
+
+ if available_realms.empty?
+ frontend_realm.backend_realms << ar_realm
+ frontend_realm.save!
+ else
+ available_realms.each do |r|
+ r.backend_realms << ar_realm
+ end
+ end
+ end
+ end
+ end
+ end
+
+ def valid_credentials?
+ DeltaCloud::valid_credentials?(username, password, provider.url)
+ end
+
+ def build_credentials
+ xml = Nokogiri::XML <<EOT
+<?xml version="1.0"?>
+<provider_credentials>
+ <ec2_credentials>
+ <account_number></account_number>
+ <access_key></access_key>
+ <secret_access_key></secret_access_key>
+ <certificate></certificate>
+ <key></key>
+ </ec2_credentials>
+</provider_credentials>
+EOT
+ node = xml.at_xpath('/provider_credentials/ec2_credentials')
+ node.at_xpath('./account_number').content = account_number
+ node.at_xpath('./access_key').content = username
+ node.at_xpath('./secret_access_key').content = password
+ node.at_xpath('./certificate').content = x509_cert_pub
+ node.at_xpath('./key').content = x509_cert_priv
+ return xml.to_s
+ end
+
+ def generate_auth_key
+ client = connect
+ return nil unless client && client.feature?(:instances, :authentication_key)
+ client.create_key(:name => "#{self.name}_#{Time.now.to_i}_key_#{self.object_id}")
+ end
+end
diff --git a/src/app/models/provider_account_observer.rb b/src/app/models/provider_account_observer.rb
new file mode 100644
index 0000000..8d3ca9e
--- /dev/null
+++ b/src/app/models/provider_account_observer.rb
@@ -0,0 +1,33 @@
+class ProviderAccountObserver < ActiveRecord::Observer
+ def after_create(account)
+ # FIXME: new boxgrinder doesn't create bucket for amis automatically,
+ # for now we create bucket from conductor
+ # remove this hotfix when fixed on boxgrinder side
+ if account.provider.provider_type == Provider::AWS
+ create_bucket(account)
+ end
+ if key = account.generate_auth_key
+ account.update_attribute(:instance_key, InstanceKey.create!(:pem => key.pem, :name => key.id, :instance_key_owner => account))
+ end
+ end
+
+ private
+
+ def create_bucket(account)
+ client = account.connect
+ bucket_name = "#{account.account_number}-imagefactory-amis"
+ # TODO (jprovazn): getting particular bucket takes long time (core fetches all
+ # buckets from provider), so we call directly create_bucket, if bucket exists,
+ # exception should be thrown (actually existing bucket is returned - this
+ # bug should be fixed soon)
+ #client.create_bucket(:name => bucket_name) unless client.bucket(bucket_name)
+ begin
+ client.create_bucket(:name => bucket_name)
+ rescue Exception => e
+ Rails.logger.error e.message
+ Rails.logger.error e.backtrace.join("\n ")
+ end
+ end
+end
+
+ProviderAccountObserver.instance
diff --git a/src/app/models/quota.rb b/src/app/models/quota.rb
index 9f79e04..acb001a 100644
--- a/src/app/models/quota.rb
+++ b/src/app/models/quota.rb
@@ -22,7 +22,7 @@
class Quota < ActiveRecord::Base
has_one :pool
- has_one :cloud_account
+ has_one :provider_account
has_one :user
validates_numericality_of :maximum_total_instances,
diff --git a/src/app/services/data_service_active_record.rb b/src/app/services/data_service_active_record.rb
index 66da011..5833baa 100644
--- a/src/app/services/data_service_active_record.rb
+++ b/src/app/services/data_service_active_record.rb
@@ -65,7 +65,7 @@ class DataServiceActiveRecord
data_points = []
free_instances = 0
- cloud_accounts = CloudAccount.find(:all, :conditions => {:provider_id => provider.id})
+ cloud_accounts = ProviderAccount.find(:all, :conditions => {:provider_id => provider.id})
cloud_accounts.each do |cloud_account|
quota = cloud_account.quota
if quota
@@ -175,11 +175,11 @@ class DataServiceActiveRecord
instances = []
if parent.class == Provider
- cloud_accounts = CloudAccount.find(:all, :conditions => {:provider_id => parent.id})
+ cloud_accounts = ProviderAccount.find(:all, :conditions => {:provider_id => parent.id})
cloud_accounts.each do |cloud_account|
instances.concat(cloud_account.instances)
end
- elsif parent.class == Pool || parent.class == CloudAccount
+ elsif parent.class == Pool || parent.class == ProviderAccount
instances = parent.instances
else
return nil
@@ -209,7 +209,7 @@ class DataServiceActiveRecord
end
end
- # returns the failure rate of instance starts for instances associated with the parent, (pool/cloudaccount) given the failure code
+ # returns the failure rate of instance starts for instances associated with the parent, (pool/ProviderAccount) given the failure code
def self.failure_rate(parent, start_time, end_time, failure_code)
instances = get_parent_instances(parent)
tasks = Task.find(:all, :conditions => {:created_at => start_time...end_time,
diff --git a/src/app/services/graph_service.rb b/src/app/services/graph_service.rb
index 7266434..c5f3065 100644
--- a/src/app/services/graph_service.rb
+++ b/src/app/services/graph_service.rb
@@ -16,7 +16,7 @@ class GraphService
cloud_account_graphs[Graph::QUOTA_INSTANCES_IN_USE] = qos_failure_rate_graph(parent, opts = {})
graphs[cloud_account] = cloud_account_graphs
else
- CloudAccount.all.each do |cloud_account|
+ ProviderAccount.all.each do |cloud_account|
cloud_account_graphs = Hash.new
cloud_account_graphs[Graph::QUOTA_INSTANCES_IN_USE] = quota_instances_in_use_graph(cloud_account,opts)
graphs[cloud_account] = cloud_account_graphs
@@ -126,7 +126,7 @@ class GraphService
providers = Provider.all
providers.each do |provider|
running_instances = 0
- provider.cloud_accounts.each do |account|
+ provider.provider_accounts.each do |account|
running_instances = running_instances + account.quota.running_instances if account.quota
end
if running_instances > 0
diff --git a/src/app/util/condormatic.rb b/src/app/util/condormatic.rb
index 57ad075..6512940 100644
--- a/src/app/util/condormatic.rb
+++ b/src/app/util/condormatic.rb
@@ -216,7 +216,7 @@ def condormatic_classads_sync
# to it.
provider_images = provider.provider_images.find(:all,
:conditions => ['provider_image_key IS NOT NULL'])
- accounts = provider.cloud_accounts
+ accounts = provider.provider_accounts
hardware_profiles = provider.hardware_profiles
realms = provider.realms
accounts.each { |account|
diff --git a/src/app/views/admin/provider_accounts/_aws.haml b/src/app/views/admin/provider_accounts/_aws.haml
new file mode 100644
index 0000000..0d4ffb4
--- /dev/null
+++ b/src/app/views/admin/provider_accounts/_aws.haml
@@ -0,0 +1,39 @@
+%fieldset.nomargin.clearfix
+ = label_tag "Account name:"
+ = text_field :provider_account, :label
+ = label_tag "Username"
+ = text_field :provider_account, :username
+ = label_tag "Password"
+ = password_field :provider_account, :password
+ = label_tag "Quota"
+ = text_field :quota, :maximum_running_instances, :title => t('cloud_accounts.form.quota_instances'), :value => @quota.maximum_running_instances || "unlimited", :id => "quota_instances", :class => "grid_3 omega"
+%fieldset.nomargin.clearfix
+ .grid_3.prefix_10.alpha.omega
+ (
+ %button.linkbutton.nospace{ :type => 'button', :onclick => "set_unlimited_quota(\"quota_instances\");" }<>
+ = t('cloud_accounts.form.unlimited_quota')
+ )
+
+%fieldset.clearfix.nomargin
+ %label.grid_4.la.alpha
+ = t('cloud_accounts.form.account_number')
+ %span.required *
+ = text_field_tag :account_number
+ %label.grid_3.la
+ = t('cloud_accounts.form.account_private_cert')
+ %span.required *
+ = file_field :x509_cert_priv_file, :title => t('cloud_accounts.form.account_private_cert')
+ %label.grid_3.la
+ = t('cloud_accounts.form.account_public_cert')
+ %span.required *
+ = file_field :x509_cert_pub_file, :title => t('cloud_accounts.form.account_public_cert')
+ .grid_3.omega
+ (
+ %button.linkbutton.nospace{ :type => 'submit', :value => t('cloud_accounts.form.test_account'), :name => 'test_account', :id => 'test_account' }<>
+ = t('cloud_accounts.form.test_account')
+ )
+
+:javascript
+ function set_unlimited_quota(elem_id) {
+ $("#" + elem_id)[0].value = "unlimited";
+ }
diff --git a/src/app/views/admin/provider_accounts/_gogrid.haml b/src/app/views/admin/provider_accounts/_gogrid.haml
new file mode 100644
index 0000000..65b5998
--- /dev/null
+++ b/src/app/views/admin/provider_accounts/_gogrid.haml
@@ -0,0 +1,16 @@
+%fieldset.clear
+ = label_tag "Account name:"
+ = text_field :provider_account, :label
+%fieldset.clear
+ = label_tag :username, "API Key:"
+ = text_field :provider_account,:username
+%fieldset.clear
+ = label_tag :password, "Secret:"
+ = password_field :provider_account,:password
+ = label_tag "Quota"
+ = text_field :quota, :maximum_running_instances, :title => t('cloud_accounts.form.quota_instances'), :value => @quota.maximum_running_instances || "unlimited", :id => "quota_instances", :class => "grid_3 omega"
+.grid_3.omega
+ (
+ %button.linkbutton.nospace{ :type => 'submit', :value => t('cloud_accounts.form.test_account'), :name => 'test_account', :id => 'test_account' }<>
+ = t('cloud_accounts.form.test_account')
+ )
diff --git a/src/app/views/admin/provider_accounts/_mock.haml b/src/app/views/admin/provider_accounts/_mock.haml
new file mode 100644
index 0000000..65b5998
--- /dev/null
+++ b/src/app/views/admin/provider_accounts/_mock.haml
@@ -0,0 +1,16 @@
+%fieldset.clear
+ = label_tag "Account name:"
+ = text_field :provider_account, :label
+%fieldset.clear
+ = label_tag :username, "API Key:"
+ = text_field :provider_account,:username
+%fieldset.clear
+ = label_tag :password, "Secret:"
+ = password_field :provider_account,:password
+ = label_tag "Quota"
+ = text_field :quota, :maximum_running_instances, :title => t('cloud_accounts.form.quota_instances'), :value => @quota.maximum_running_instances || "unlimited", :id => "quota_instances", :class => "grid_3 omega"
+.grid_3.omega
+ (
+ %button.linkbutton.nospace{ :type => 'submit', :value => t('cloud_accounts.form.test_account'), :name => 'test_account', :id => 'test_account' }<>
+ = t('cloud_accounts.form.test_account')
+ )
diff --git a/src/app/views/admin/provider_accounts/_opennebula.haml b/src/app/views/admin/provider_accounts/_opennebula.haml
new file mode 100644
index 0000000..e04902e
--- /dev/null
+++ b/src/app/views/admin/provider_accounts/_opennebula.haml
@@ -0,0 +1,16 @@
+%fieldset.clear
+ = label_tag "Account name:"
+ = text_field :provider_account, :label
+%fieldset.clear
+ = label_tag :username, "API Key:"
+ = text_field :provider_account, :username
+%fieldset.clear
+ = label_tag :password, "Secret:"
+ = password_field :provider_account, :password
+ = label_tag "Quota"
+ = text_field :quota, :maximum_running_instances, :title => t('cloud_accounts.form.quota_instances'), :value => @quota.maximum_running_instances || "unlimited", :id => "quota_instances", :class => "grid_3 omega"
+.grid_3.omega
+ (
+ %button.linkbutton.nospace{ :type => 'submit', :value => t('cloud_accounts.form.test_account'), :name => 'test_account', :id => 'test_account' }<>
+ = t('cloud_accounts.form.test_account')
+ )
diff --git a/src/app/views/admin/provider_accounts/_provider_selection.haml b/src/app/views/admin/provider_accounts/_provider_selection.haml
new file mode 100644
index 0000000..6d6b6ad
--- /dev/null
+++ b/src/app/views/admin/provider_accounts/_provider_selection.haml
@@ -0,0 +1,24 @@
+%fieldset#provider_type.clear
+ = select(:provider_account ,:provider_id, options_for_select((a)providers.map{ |p| [p.name, p.id] }, :selected => @selected_provider.id))
+ = restful_submit_tag "Choose", 'set_selected_provider',set_selected_provider_admin_provider_accounts_path, 'GET', :class => 'button'
+ = label_tag "Cloud type: "
+ = t(Provider::PROVIDER_TYPES[@selected_provider.provider_type])
+ = display_provider_account_login_form((a)selected_provider.provider_type)
+ %fieldset.clearfix
+ .grid_13.alpha.omega
+ = submit_tag t(:add), :class => "ra nomargin dialogbutton"
+
+:javascript
+ $(document).ready(function(){
+ var selected_provider;
+ $("#provider_account_provider_id").change(function()
+ {
+ selected_provider = $("option:selected").attr('value');
+ $.get("#{set_selected_provider_admin_provider_accounts_url}", {'provider_account[provider_id]':selected_provider},
+ function(result) {
+ $("#provider_type").html(result);
+ }
+ );
+
+ });
+ });
diff --git a/src/app/views/admin/provider_accounts/_rackspace.haml b/src/app/views/admin/provider_accounts/_rackspace.haml
new file mode 100644
index 0000000..c13672c
--- /dev/null
+++ b/src/app/views/admin/provider_accounts/_rackspace.haml
@@ -0,0 +1,16 @@
+%fieldset.clear
+ = label_tag "Account name:"
+ = text_field :provider_account, :label
+%fieldset.clear
+ = label_tag:username, "API Key:"
+ = text_field :provider_account, :username
+%fieldset.clear
+ = label_tag :password, "Secret:"
+ = password_field :provider_account, :password
+ = label_tag "Quota"
+ = text_field :quota, :maximum_running_instances, :title => t('cloud_accounts.form.quota_instances'), :value => @quota.maximum_running_instances || "unlimited", :id => "quota_instances", :class => "grid_3 omega"
+.grid_3.omega
+ (
+ %button.linkbutton.nospace{ :type => 'submit', :value => t('cloud_accounts.form.test_account'), :name => 'test_account', :id => 'test_account' }<>
+ = t('cloud_accounts.form.test_account')
+ )
diff --git a/src/app/views/admin/provider_accounts/_rhevm.haml b/src/app/views/admin/provider_accounts/_rhevm.haml
new file mode 100644
index 0000000..dd86c72
--- /dev/null
+++ b/src/app/views/admin/provider_accounts/_rhevm.haml
@@ -0,0 +1,2 @@
+%fieldset.clear
+ Login form for RHEV-M (not implemented yet)
diff --git a/src/app/views/admin/provider_accounts/new.haml b/src/app/views/admin/provider_accounts/new.haml
index e567bce..8f82a0e 100644
--- a/src/app/views/admin/provider_accounts/new.haml
+++ b/src/app/views/admin/provider_accounts/new.haml
@@ -1,16 +1,15 @@
#details.grid_13
+ = error_messages_for :provider_account
%h2
= t('cloud_accounts.new.new_provider_account')
- - form_for @cloud_account, :url => admin_provider_accounts_path, :html => { :multipart => true } do |f|
%label{ :for => :provider_id }
Provider
- = select_tag :provider_id, options_for_select((a)providers.map{ |p| [p.name, p.id] })
- = render :partial => 'form', :locals => { :f => f }
- %fieldset.clearfix
- .grid_13.alpha.omega
- = submit_tag t(:add), :class => "ra nomargin dialogbutton"
- %section
- %p.requirement
- %span.required *
- \-
- = t('cloud_accounts.new.required_field')
+ %fieldset.clear
+ - unless @providers.empty?
+ - form_tag(admin_provider_accounts_path, :multipart => true) do
+ = render :partial => 'provider_selection'
+ %section
+ %p.requirement
+ %span.required *
+ \-
+ = t('cloud_accounts.new.required_field')
diff --git a/src/app/views/admin/providers/_form.haml b/src/app/views/admin/providers/_form.haml
index fe8c9ca..b81c47f 100644
--- a/src/app/views/admin/providers/_form.haml
+++ b/src/app/views/admin/providers/_form.haml
@@ -1,5 +1,6 @@
= form.error_message_on :name, 'Name'
= form.error_message_on :url, 'URL'
+= form.error_message_on :provider_type
%fieldset.clear
= form.label :name,'Provider name :'
= form.text_field :name, :title => 'provider_name', :value => @provider.name, :class => "clear grid_4 alpha"
@@ -10,5 +11,9 @@
%button.linkbutton.nospace{ :type => 'submit', :value => t('.test_connection'), :name => 'test_connection', :id => 'test_connection' }
Test connection
)
- %fieldset.clear
- = form.submit "Save", :class => "submit formbutton"
+%fieldset.clear
+ = form.label :provider_type
+ = form.select(:provider_type, Provider::PROVIDER_TYPES.collect {|id, provider_type| [t(provider_type),id] }, :prompt => "Select type of provider")
+
+%fieldset.clear
+ = form.submit "Save", :class => "submit formbutton"
diff --git a/src/app/views/admin/providers/_list.haml b/src/app/views/admin/providers/_list.haml
index 21ad381..7b660a3 100644
--- a/src/app/views/admin/providers/_list.haml
+++ b/src/app/views/admin/providers/_list.haml
@@ -17,3 +17,4 @@
%input{:name => "provider_selected[]", :type => "checkbox", :value => provider.id, :id => "provider_checkbox_#{provider.id}", :checked => selected }
= link_to provider.name, admin_provider_path(provider)
%td= provider.url
+ %td= t(Provider::PROVIDER_TYPES[provider.provider_type])
diff --git a/src/app/views/image_factory/builds/new.haml b/src/app/views/image_factory/builds/new.haml
index 3d85f98..6687ee0 100644
--- a/src/app/views/image_factory/builds/new.haml
+++ b/src/app/views/image_factory/builds/new.haml
@@ -46,10 +46,10 @@
%label Choose Provider Format:
%section.clearfix.gap
%ul.block
- - @all_targets.each do |target_id, target|
+ - @all_targets.each do |target, target_id|
%li
- = check_box_tag 'targets[]', target_id, false, :id => target_id
- = label_tag target_id, target['name']
+ = check_box_tag 'targets[]', target_id, false, :id => target
+ = label_tag target
= submit_tag "Submit to Build", :name => "build"
= link_to 'Cancel', image_factory_templates_path, :class => 'button'
diff --git a/src/app/views/layouts/application.haml b/src/app/views/layouts/application.haml
index 6d75bd7..357776d 100644
--- a/src/app/views/layouts/application.haml
+++ b/src/app/views/layouts/application.haml
@@ -5,7 +5,6 @@
%title
Red Hat Cloud Engine
= yield :title
-
= stylesheet_link_tag 'facebox'
= stylesheet_link_tag 'jquery.ui-1.8.1/jquery-ui-1.8.1.custom.css'
= stylesheet_link_tag 'jquery.loadmask'
diff --git a/src/app/views/resources/instances/_list.haml b/src/app/views/resources/instances/_list.haml
index a83b565..b62d9e7 100644
--- a/src/app/views/resources/instances/_list.haml
+++ b/src/app/views/resources/instances/_list.haml
@@ -19,5 +19,5 @@
%td= inst.state
%td= inst.template.name
%td= inst.public_addresses
- %td= inst.cloud_account ? inst.cloud_account.provider.name : ''
+ %td= inst.provider_account ? inst.provider_account.provider.name : ''
%td= owner_name(inst)
diff --git a/src/app/views/resources/instances/_properties.haml b/src/app/views/resources/instances/_properties.haml
index ebf7cc4..995cc00 100644
--- a/src/app/views/resources/instances/_properties.haml
+++ b/src/app/views/resources/instances/_properties.haml
@@ -19,7 +19,7 @@
%span= "#{(a)instance.template.xml.platform} #{(a)instance.template.xml.platform_version}"
%li
= label_tag :provider, 'Provider'
- %span= @instance.cloud_account.provider.name if @instance.cloud_account
+ %span= @instance.provider_account.provider.name if @instance.provider_account
%li
= label_tag :base_template, 'Base Template'
%span= @instance.template.name
diff --git a/src/classad_plugin/classad_plugin.rb b/src/classad_plugin/classad_plugin.rb
index 2aabfb9..14b5878 100644
--- a/src/classad_plugin/classad_plugin.rb
+++ b/src/classad_plugin/classad_plugin.rb
@@ -60,7 +60,7 @@ def classad_plugin(logf, conf_path, instance_key, account_id)
instance = Instance.find(:first,
:conditions => [ "condor_job_id = ?", instance_key ])
logf.puts "getting cloud account from id #{account_id}"
- cloud_account = CloudAccount.find(:first,
+ cloud_account = ProviderAccount.find(:first,
:conditions => [ "id = ?", account_id ])
logf.puts "instance is: #{instance}, cloud account is #{cloud_account}"
diff --git a/src/config/environment.rb b/src/config/environment.rb
index a897feb..986cfe4 100644
--- a/src/config/environment.rb
+++ b/src/config/environment.rb
@@ -57,7 +57,7 @@ Rails::Initializer.run do |config|
config.middleware.swap Rack::MethodOverride, 'Rack::RestfulSubmit'
- config.active_record.observers = :instance_observer, :task_observer, :cloud_account_observer
+ config.active_record.observers = :instance_observer, :task_observer, :provider_account_observer
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
# :all can be used as a placeholder for all plugins not explicitly named
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index 715c0a0..dcb379b 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -85,6 +85,12 @@ en:
pool_families: Pool Families
setting: Settings
name: Name
+ AWS: Amazon EC2
+ RHEVM: RHEV-M
+ GoGrid: GoGrid
+ Rackspace: Rackspace
+ OpenNebula: OpenNebula
+ mock: Mock
admin:
settings:
index:
diff --git a/src/config/routes.rb b/src/config/routes.rb
index d08689f..61e4221 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -53,7 +53,8 @@ ActionController::Routing::Routes.draw do |map|
r.resources :hardware_profiles, :collection => { :multi_destroy => :delete }
r.resources :providers, :collection => { :multi_destroy => :delete }
r.resources :users, :collection => { :multi_destroy => :delete }
- r.resources :provider_accounts, :collection => { :multi_destroy => :delete }
+ r.resources :provider_accounts, :collection => { :multi_destroy => :delete, :set_selected_provider => :get}
+
r.resources :roles, :collection => { :multi_destroy => :delete }
r.resources :settings, :collection => { :self_service => :get, :general_settings => :get }
r.resources :pool_families, :collection => { :multi_destroy => :delete }
diff --git a/src/db/migrate/20110117140824_rename_cloud_account_to_provider_account.rb b/src/db/migrate/20110117140824_rename_cloud_account_to_provider_account.rb
new file mode 100644
index 0000000..7b1a1d5
--- /dev/null
+++ b/src/db/migrate/20110117140824_rename_cloud_account_to_provider_account.rb
@@ -0,0 +1,13 @@
+class RenameCloudAccountToProviderAccount < ActiveRecord::Migration
+ def self.up
+ rename_table (:cloud_accounts,:provider_accounts)
+ remove_column (:providers, :cloud_type)
+ add_column (:providers, :provider_type, :integer)
+ end
+
+ def self.down
+ remove_column (:providers, :provider_type)
+ add_column (:providers, :cloud_type, :string, :null => false)
+ rename_table (:provider_accounts, :cloud_accounts)
+ end
+end
diff --git a/src/db/migrate/20110125123410_rename_cloud_account_id_for_instances.rb b/src/db/migrate/20110125123410_rename_cloud_account_id_for_instances.rb
new file mode 100644
index 0000000..674fc2d
--- /dev/null
+++ b/src/db/migrate/20110125123410_rename_cloud_account_id_for_instances.rb
@@ -0,0 +1,9 @@
+class RenameCloudAccountIdForInstances < ActiveRecord::Migration
+ def self.up
+ rename_column :instances, :cloud_account_id, :provider_account_id
+ end
+
+ def self.down
+ rename_column :instances, :provider_account_id, :cloud_account_id
+ end
+end
diff --git a/src/db/migrate/20110125154113_rename_cloud_accounts_pool_families_to_provider_accounts_pool_families.rb b/src/db/migrate/20110125154113_rename_cloud_accounts_pool_families_to_provider_accounts_pool_families.rb
new file mode 100644
index 0000000..d1ae154
--- /dev/null
+++ b/src/db/migrate/20110125154113_rename_cloud_accounts_pool_families_to_provider_accounts_pool_families.rb
@@ -0,0 +1,11 @@
+class RenameCloudAccountsPoolFamiliesToProviderAccountsPoolFamilies < ActiveRecord::Migration
+ def self.up
+ rename_table :cloud_accounts_pool_families, :pool_families_provider_accounts
+ rename_column :pool_families_provider_accounts, :cloud_account_id, :provider_account_id
+ end
+
+ def self.down
+ rename_column :pool_families_provider_accounts, :provider_account_id, :cloud_account_id
+ rename_table :pool_families_provider_accounts, :cloud_accounts_pool_families
+ end
+end
diff --git a/src/db/migrate/20110126161751_change_null_properties_of_columns_in_provider_accounts.rb b/src/db/migrate/20110126161751_change_null_properties_of_columns_in_provider_accounts.rb
new file mode 100644
index 0000000..7e6707e
--- /dev/null
+++ b/src/db/migrate/20110126161751_change_null_properties_of_columns_in_provider_accounts.rb
@@ -0,0 +1,13 @@
+class ChangeNullPropertiesOfColumnsInProviderAccounts < ActiveRecord::Migration
+ def self.up
+ change_column :provider_accounts, :account_number, :string, :null => true
+ change_column :provider_accounts, :x509_cert_priv, :text, :null => true
+ change_column :provider_accounts, :x509_cert_pub, :text, :null => true
+ end
+
+ def self.down
+ change_column :provider_accounts, :account_number, :string, :null => false
+ change_column :provider_accounts, :x509_cert_priv, :text, :null => false
+ change_column :provider_accounts, :x509_cert_pub, :text, :null => false
+ end
+end
diff --git a/src/db/migrate/20110202151950_change_cloudaccount_value_to_provideraccount_in_privileges_and_roles.rb b/src/db/migrate/20110202151950_change_cloudaccount_value_to_provideraccount_in_privileges_and_roles.rb
new file mode 100644
index 0000000..2db783c
--- /dev/null
+++ b/src/db/migrate/20110202151950_change_cloudaccount_value_to_provideraccount_in_privileges_and_roles.rb
@@ -0,0 +1,11 @@
+class ChangeCloudaccountValueToProvideraccountInPrivilegesAndRoles < ActiveRecord::Migration
+ def self.up
+ execute "UPDATE privileges SET target_type='ProviderAccount' WHERE target_type='CloudAccount';"
+ execute "UPDATE roles SET scope='ProviderAccount' WHERE scope='CloudAccount';"
+ end
+
+ def self.down
+ execute "UPDATE privileges SET target_type='CloudAccount' WHERE target_type='ProviderAccount';"
+ execute "UPDATE roles SET scope='CloudAccount' WHERE scope='ProviderAccount';"
+ end
+end
diff --git a/src/db/migrate/20110202165053_change_column_target_in_images.rb b/src/db/migrate/20110202165053_change_column_target_in_images.rb
new file mode 100644
index 0000000..135fddc
--- /dev/null
+++ b/src/db/migrate/20110202165053_change_column_target_in_images.rb
@@ -0,0 +1,11 @@
+class ChangeColumnTargetInImages < ActiveRecord::Migration
+ def self.up
+ remove_column :images, :target
+ add_column :images, :target, :integer
+ end
+
+ def self.down
+ remove_column :images, :target
+ add_column :images, :target, :string
+ end
+end
diff --git a/src/db/seeds.rb b/src/db/seeds.rb
index 71726bf..48146d3 100644
--- a/src/db/seeds.rb
+++ b/src/db/seeds.rb
@@ -30,17 +30,17 @@ roles =
Quota => [VIEW]}]},
Provider =>
{"Provider Owner" => [true, {Provider => [VIEW, MOD, VPRM,GPRM],
- CloudAccount => [VIEW,USE,MOD,CRE,VPRM,GPRM]}]},
- CloudAccount =>
- {"Provider Account User" => [false, {CloudAccount => [VIEW,USE]}],
- "Provider Account Owner" => [true, {CloudAccount => [VIEW,USE,MOD, VPRM,GPRM]}]},
+ ProviderAccount => [VIEW,USE,MOD,CRE,VPRM,GPRM]}]},
+ ProviderAccount =>
+ {"Provider Account User" => [false, {ProviderAccount => [VIEW,USE]}],
+ "Provider Account Owner" => [true, {ProviderAccount => [VIEW,USE,MOD, VPRM,GPRM]}]},
Template =>
{"Template User" => [false, {Template => [VIEW,USE]}],
"Template Owner" => [true, {Template => [VIEW,USE,MOD, VPRM,GPRM]}]},
BasePermissionObject =>
{"Provider Creator" => [false, {Provider => [ CRE]}],
"Provider Administrator" => [false, {Provider => [VIEW, MOD,CRE,VPRM,GPRM],
- CloudAccount => [VIEW,USE,MOD,CRE,VPRM,GPRM]}],
+ ProviderAccount => [VIEW,USE,MOD,CRE,VPRM,GPRM]}],
"HWP Administrator" => [false, {HardwareProfile => [ MOD,CRE,VPRM,GPRM]}],
"Realm Administrator" => [false, {Realm => [ USE,MOD,CRE,VPRM,GPRM]}],
"Pool Creator" => [false, {Pool => [ CRE]}],
@@ -50,7 +50,7 @@ roles =
PoolFamily => [VIEW, MOD,CRE,VPRM,GPRM]}],
"Template Administrator" => [false, {Template => [VIEW,USE,MOD,CRE,VPRM,GPRM]}],
"Administrator" => [false, {Provider => [VIEW, MOD,CRE,VPRM,GPRM],
- CloudAccount => [VIEW,USE,MOD,CRE,VPRM,GPRM],
+ ProviderAccount => [VIEW,USE,MOD,CRE,VPRM,GPRM],
HardwareProfile => [ MOD,CRE,VPRM,GPRM],
Realm => [ USE,MOD,CRE,VPRM,GPRM],
User => [VIEW, MOD,CRE],
diff --git a/src/dbomatic/dbomatic b/src/dbomatic/dbomatic
index 8a3e968..3ac7449 100755
--- a/src/dbomatic/dbomatic
+++ b/src/dbomatic/dbomatic
@@ -203,7 +203,7 @@ class CondorEventLog < Nokogiri::XML::SAX::Document
return
end
- cloud_account = CloudAccount.find(:first, :conditions => ['provider_id = ? AND username = ? AND password = ?', provider.id, username, password])
+ cloud_account = ProviderAccount.find(:first, :conditions => ['provider_id = ? AND username = ? AND password = ?', provider.id, username, password])
if cloud_account.nil?
@logger.error "Could not find the cloud account corresponding to #{link}, skipping cloud id update"
return
diff --git a/src/features/api.feature b/src/features/api.feature
index 64cc183..3ff944f 100644
--- a/src/features/api.feature
+++ b/src/features/api.feature
@@ -43,7 +43,7 @@ Feature: User authentication
| name | external_key | state | public_addresses | private_addresses |
| mock | ext_mock | stopped | mock.public.address | mock.private.address |
And user "testuser" owns instance "mock"
- When a client requests "can_start" for instance "mock" for cloud account "testaccount"
+ When a client requests "can_start" for instance "mock" for provider account "testaccount"
Then the root element should be "result"
And there should exist the following xpath: "/result/action_request"
And this path should have the value "can_start"
@@ -59,10 +59,10 @@ Feature: User authentication
| name | external_key | state | public_addresses | private_addresses |
| mock | ext_mock | stopped | mock.public.address | mock.private.address |
And user "testuser" owns instance "mock"
- When a client requests "can_create" for instance "mock" for cloud account "testaccount"
+ When a client requests "can_create" for instance "mock" for provider account "testaccount"
Then the root element should be "result"
And there should exist the following xpath: "/result/action_request"
And this path should have the value "can_create"
And there should exist the following xpath: "/result/instance_id"
And there should exist the following xpath: "/result/value"
- And this path should have the value "true"
\ No newline at end of file
+ And this path should have the value "true"
diff --git a/src/features/provider.feature b/src/features/provider.feature
index 2cdc80b..7566e61 100644
--- a/src/features/provider.feature
+++ b/src/features/provider.feature
@@ -34,6 +34,7 @@ Feature: Manage Providers
Then I should be on the new admin provider page
When I fill in "provider[name]" with "testprovider"
And I fill in "provider[url]" with "http://localhost:3001/api"
+ And I select "Amazon EC2" from "Provider type"
And I press "Save"
Then I should be on the admin providers page
And I should see "Provider added"
@@ -63,34 +64,34 @@ Feature: Manage Providers
And this provider has 5 provider images
And this provider has 5 hardware profiles
And this provider has a realm
- And this provider has a cloud account
+ And this provider has a provider account
When I go to the admin providers page
And I check "provider1" provider
And I press "Delete"
And there should not exist a provider named "provider1"
And there should not be any provider images
And there should not be any hardware profiles
- And there should not be a cloud account
+ And there should not be a provider account
And there should not be a realm
Scenario: Search for hardware profiles
Given there are these providers:
| name | url |
| Test | http://testprovider.com/api |
- | Mock | http://mockprovider.com/api |
+ | Kenny | http://mockprovider.com/api |
| Other | http://sometesturl.com/api |
And I am on the admin providers page
Then I should see the following:
| Test | http://testprovider.com/api |
- | Mock | http://mockprovider.com/ap |
+ | Kenny | http://mockprovider.com/ap |
| Other | http://sometesturl.com/api |
When I fill in "q" with "test"
And I press "Search"
Then I should see "Test"
And I should see "Other"
- And I should not see "Mock"
- When I fill in "q" with "Mock"
+ And I should not see "Kenny"
+ When I fill in "q" with "Kenny"
And I press "Search"
- Then I should see "Mock"
+ Then I should see "Kenny"
And I should not see "Test"
And I should not see "Other"
diff --git a/src/features/provider_account.feature b/src/features/provider_account.feature
index 7f645ee..af866e7 100644
--- a/src/features/provider_account.feature
+++ b/src/features/provider_account.feature
@@ -21,21 +21,17 @@ Feature: Manage Provider Accounts
When I follow "New Account"
Then I should be on the new admin provider account page
And I should see "New Account"
- When I select "testprovider" from "provider_id"
- And I fill in "cloud_account[label]" with "testaccount"
- And I fill in "cloud_account[username]" with "mockuser"
- And I fill in "cloud_account[password]" with "mockpassword"
+ When I select "testprovider" from "provider_account_provider_id"
+ And I fill in "provider_account[label]" with "testaccount"
+ And I fill in "provider_account[username]" with "mockuser"
+ And I fill in "provider_account[password]" with "mockpassword"
And I fill in "quota[maximum_running_instances]" with "13"
- And I fill in "cloud_account[account_number]" with "222222"
- And I attach the "private.key" file to "cloud_account[x509_cert_priv_file]"
- And I attach the "public.key" file to "cloud_account[x509_cert_pub_file]"
And I press "Add"
Then I should be on testaccount's provider account page
And I should see "Provider account added"
And I should have a provider account named "testaccount"
And I should see "Properties for testaccount"
And I should see "Running instances quota: 13"
- And I should see "Account ID: 222222"
Scenario: Test Provider Account Connection Successful
Given there is a provider named "testprovider"
@@ -43,8 +39,8 @@ Feature: Manage Provider Accounts
And I am on the admin provider accounts page
When I follow "New Account"
Then I should be on the new admin provider account page
- When I fill in "cloud_account[username]" with "mockuser"
- And I fill in "cloud_account[password]" with "mockpassword"
+ When I fill in "provider_account[username]" with "mockuser"
+ And I fill in "provider_account[password]" with "mockpassword"
And I press "Test Account"
Then I should see "Test Connection Success"
@@ -54,8 +50,8 @@ Feature: Manage Provider Accounts
And I am on the admin provider accounts page
When I follow "New Account"
Then I should be on the new admin provider account page
- When I fill in "cloud_account[username]" with "mockuser"
- And I fill in "cloud_account[password]" with "wrong password"
+ When I fill in "provider_account[username]" with "mockuser"
+ And I fill in "provider_account[password]" with "wrong password"
And I press "Test Account"
Then I should see "Test Connection Failed"
diff --git a/src/features/step_definitions/api_steps.rb b/src/features/step_definitions/api_steps.rb
index 8b1f868..5e09e2a 100644
--- a/src/features/step_definitions/api_steps.rb
+++ b/src/features/step_definitions/api_steps.rb
@@ -35,10 +35,10 @@ Given /^user "([^"]*)" owns instance "([^"]*)"$/ do |user, instance|
instance.save!
end
-When /^a client requests "([^"]*)" for instance "([^"]*)" for cloud account "([^"]*)"$/ do |action, instance, cloud_account|
+When /^a client requests "([^"]*)" for instance "([^"]*)" for provider account "([^"]*)"$/ do |action, instance, provider_account|
instance = Instance.find_by_name(instance)
- cloud_account = CloudAccount.find_by_label(cloud_account)
- uri = url_for :action => action, :controller => 'resources/instances', :instance_id => instance.id, :cloud_account_id => cloud_account.id
+ provider_account = ProviderAccount.find_by_label(provider_account)
+ uri = url_for :action => action, :controller => 'resources/instances', :instance_id => instance.id, :provider_account_id => provider_account.id
send_xml_get(uri)
end
diff --git a/src/features/step_definitions/provider_account_steps.rb b/src/features/step_definitions/provider_account_steps.rb
index 5d68b88..86a6d31 100644
--- a/src/features/step_definitions/provider_account_steps.rb
+++ b/src/features/step_definitions/provider_account_steps.rb
@@ -1,9 +1,9 @@
Then /^there should be no provider accounts$/ do
- CloudAccount.all.should be_empty
+ ProviderAccount.all.should be_empty
end
Given /^there are no provider accounts$/ do
- CloudAccount.all.should be_empty
+ ProviderAccount.all.should be_empty
end
When /^I attach the "([^"\s]+)" file to "([^"\s]+)"$/ do |file, field|
@@ -12,27 +12,27 @@ When /^I attach the "([^"\s]+)" file to "([^"\s]+)"$/ do |file, field|
end
Then /^I should have a provider account named "([^"]*)"$/ do |label|
- CloudAccount.find_by_label(label).should_not be_nil
+ ProviderAccount.find_by_label(label).should_not be_nil
end
Given /^there is a provider account named "([^"]*)"$/ do |label|
@provider = Provider.find_by_name('testprovider')
- @cloud_account = Factory(:mock_cloud_account, :provider => @provider, :label => label)
+ @provider_account = Factory(:mock_provider_account, :provider => @provider, :label => label)
end
Given /^there is a second provider account named "([^"]*)"$/ do |label|
@provider = Factory(:mock_provider, :name => 'secondprovider')
- @cloud_account = Factory(:mock_cloud_account, :provider => @provider, :label => label)
+ @provider_account = Factory(:mock_provider_account, :provider => @provider, :label => label)
end
When /^I check the "([^"]*)" account$/ do |label|
- account = CloudAccount.find_by_label(label)
+ account = ProviderAccount.find_by_label(label)
check("account_checkbox_#{account.id}")
end
Given /^that there are these provider accounts:$/ do |table|
table.hashes.each do |hash|
- Factory.create(:cloud_account, :name => hash['name'], :username => hash['username'])
+ Factory.create(:provider_account, :name => hash['name'], :username => hash['username'])
end
end
diff --git a/src/features/step_definitions/provider_steps.rb b/src/features/step_definitions/provider_steps.rb
index 927fb33..f679ba9 100644
--- a/src/features/step_definitions/provider_steps.rb
+++ b/src/features/step_definitions/provider_steps.rb
@@ -49,8 +49,8 @@ Given /^this provider has a realm$/ do
Factory(:realm, :provider => @provider)
end
-Given /^this provider has a cloud account$/ do
- Factory(:mock_cloud_account, :provider => @provider)
+Given /^this provider has a provider account$/ do
+ Factory(:mock_provider_account, :provider => @provider)
end
Then /^there should not be any provider images$/ do
@@ -61,8 +61,8 @@ Then /^there should not be any hardware profiles$/ do
HardwareProfile.find(:all, :conditions => { :provider_id => @provider.id} ).size.should == 0
end
-Then /^there should not be a cloud account$/ do
- CloudAccount.find(:all, :conditions => { :provider_id => @provider.id} ).size.should == 0
+Then /^there should not be a provider account$/ do
+ ProviderAccount.find(:all, :conditions => { :provider_id => @provider.id} ).size.should == 0
end
Then /^there should not be a realm$/ do
diff --git a/src/features/step_definitions/template_steps.rb b/src/features/step_definitions/template_steps.rb
index 5bae0a2..ff66fe6 100644
--- a/src/features/step_definitions/template_steps.rb
+++ b/src/features/step_definitions/template_steps.rb
@@ -92,13 +92,13 @@ When /^I choose this template$/ do
click_link((a)template.name)
end
-Given /^there is ec2 cloud account$/ do
- account = Factory.build(:ec2_cloud_account)
+Given /^there is Amazon AWS provider account$/ do
+ account = Factory.build(:ec2_provider_account)
account.save!
end
-Given /^there is ec2 build for this template$/ do
- Image.build(@template, 'ec2')
+Given /^there is Amazon AWS build for this template$/ do
+ Image.build(@template, Provider::AWS)
end
Given /^there is an imported template$/ do
diff --git a/src/features/support/custom.rb b/src/features/support/custom.rb
index c2c4987..8d44f9c 100644
--- a/src/features/support/custom.rb
+++ b/src/features/support/custom.rb
@@ -8,8 +8,8 @@ Provider.class_eval do
true
end
- def set_cloud_type
- self.cloud_type = Factory(:mock_provider).cloud_type
+ def set_provider_type
+ self.provider_type = Factory(:mock_provider).provider_type
end
def populate_hardware_profiles
@@ -23,7 +23,7 @@ Provider.class_eval do
end
-CloudAccount.class_eval do
+ProviderAccount.class_eval do
alias :generate_auth_key_original :generate_auth_key
diff --git a/src/features/support/paths.rb b/src/features/support/paths.rb
index d59e780..0633aca 100644
--- a/src/features/support/paths.rb
+++ b/src/features/support/paths.rb
@@ -102,7 +102,7 @@ module NavigationHelpers
url_for :action => 'edit', :controller => 'hardware_profiles', :only_path => true
when /^(.*)'s provider account page$/
- admin_provider_account_path(CloudAccount.find_by_label($1))
+ admin_provider_account_path(ProviderAccount.find_by_label($1))
when /^(.*)'s image factory deployable page$/
image_factory_deployable_path(Deployable.find_by_name($1))
diff --git a/src/features/template.feature b/src/features/template.feature
index 47a8d1b..3518a74 100644
--- a/src/features/template.feature
+++ b/src/features/template.feature
@@ -107,31 +107,32 @@ Feature: Manage Templates
Scenario: Build template
Given there is a "mock1" template
- And there is ec2 cloud account
+ And there is Amazon AWS provider account
And I am on the image factory templates page
When I choose this template
And I follow "Build"
Then I should be on the new image factory build page
And I should see "Build Request"
- When I check "ec2"
+ When I check "Aws"
And I press "Submit to Build"
Then I should be on the image factory template page
And I should see "mock1"
Scenario: Build template which is already built
Given there is a "mock1" template
- And there is ec2 cloud account
+ And there is Amazon AWS provider account
+ And I am on the image factory templates page
+ And there is Amazon AWS build for this template
And I am on the image factory templates page
- And there is ec2 build for this template
When I choose this template
And I follow "Build"
Then I should be on the new image factory build page
And I should see "Build Request"
- When I check "ec2"
+ When I check "Aws"
And I press "Submit to Build"
Then I should be on the image factory template page
And I should see "mock1"
- And I should see "An attempted build of this template for the target 'ec2' already exists"
+ And I should see "An attempted build of this template for the target '1' already exists"
Scenario: Build imported template
Given there is an imported template
diff --git a/src/image_builder_service/image_builder_service b/src/image_builder_service/image_builder_service
index c5e4822..3cc8d0a 100755
--- a/src/image_builder_service/image_builder_service
+++ b/src/image_builder_service/image_builder_service
@@ -121,7 +121,7 @@ class ImageBuilderService
# FIXME: this should be contained elsewhere (probably Image model) so we
# can keep logic out of here. Also, this currently only handles one
# account, we will need to be able to specify at some point.
- creds = image.provider_images.first.provider.cloud_accounts.first.build_credentials
+ creds = image.provider_images.first.provider.provider_accounts.first.build_credentials
#TODO: switch this back to uri once ActiveBuild retrieves it properly
ab = @console.build_image(image.template.xml.to_xml, image.target, image.uuid, creds)
if ab
diff --git a/src/lib/tasks/dc_tasks.rake b/src/lib/tasks/dc_tasks.rake
index f1d0c7d..cf713a5 100644
--- a/src/lib/tasks/dc_tasks.rake
+++ b/src/lib/tasks/dc_tasks.rake
@@ -105,7 +105,7 @@ namespace :dc do
unless provider = Provider.find_by_name(provider_name)
raise "There is no provider with '#{provider_name}' name"
end
- unless account = provider.cloud_accounts.find_by_label(account_name)
+ unless account = provider.provider_accounts.find_by_label(account_name)
raise "There is no account with '#{account_name}' label"
end
account
diff --git a/src/lib/tasks/demo_data.rake b/src/lib/tasks/demo_data.rake
index f38ebbd..f3326fd 100644
--- a/src/lib/tasks/demo_data.rake
+++ b/src/lib/tasks/demo_data.rake
@@ -32,7 +32,7 @@ namespace :db do
puts @number_of_tasks
- cloud_account = CloudAccount.find(args[:cloud_account_id])
+ cloud_account = ProviderAccount.find(args[:cloud_account_id])
user = User.find(args[:user_id])
instance = create_instance(cloud_account)
@@ -116,4 +116,4 @@ namespace :db do
return time_started
end
-end
\ No newline at end of file
+end
diff --git a/src/script/use-existing-ec2-templates b/src/script/use-existing-ec2-templates
index f073f9a..4e38b53 100755
--- a/src/script/use-existing-ec2-templates
+++ b/src/script/use-existing-ec2-templates
@@ -13,11 +13,11 @@ require 'optparse'
def add_ec2_template(xml_info, summary, ec2_ami)
provider = Provider.find(:first)
- if provider == nil || provider.cloud_type != "ec2"
+ if provider == nil || provider.provider_type != Provider::AWS
puts "You need to set up an EC2 provider before you can run this script."
exit
end
-
+
template = Template.new
# Incredibly, all the info actually comes from the xml..
@@ -46,7 +46,7 @@ def add_ec2_template(xml_info, summary, ec2_ami)
puts "Saved image #{summary} for use."
end
-
+
add_ec2_template("
<?xml version=\"1.0\"?>
<image>
diff --git a/src/spec/controllers/builds_controller_spec.rb b/src/spec/controllers/builds_controller_spec.rb
index 560290b..79eaa17 100644
--- a/src/spec/controllers/builds_controller_spec.rb
+++ b/src/spec/controllers/builds_controller_spec.rb
@@ -18,19 +18,19 @@ describe ImageFactory::BuildsController do
hydra = Typhoeus::Hydra.hydra
hydra.stub(:put, %r{http://localhost:9090/templates/.*}).and_return(
Typhoeus::Response.new(:code => 200))
- Factory.create(:mock_cloud_account)
+ Factory.create(:mock_provider_account)
Factory.create(:mock_provider)
end
it "should create a new Image" do
lambda do
- post :create, :template_id => @template.id, :targets => ["mock"]
+ post :create, :template_id => @template.id, :targets => ["0"]
end.should change(Image, :count).by(1)
end
it "should create a new ProviderImage" do
lambda do
- post :create, :template_id => @template.id, :targets => ["mock"]
+ post :create, :template_id => @template.id, :targets => ["0"]
end.should change(ProviderImage, :count).by(1)
end
end
diff --git a/src/spec/controllers/cloud_accounts_controller_spec.rb b/src/spec/controllers/cloud_accounts_controller_spec.rb
deleted file mode 100644
index 7f10af0..0000000
--- a/src/spec/controllers/cloud_accounts_controller_spec.rb
+++ /dev/null
@@ -1,92 +0,0 @@
-require 'spec_helper'
-
-describe Admin::ProviderAccountsController do
-
- fixtures :all
- before(:each) do
- @cloud_account = Factory :mock_cloud_account
- @provider = @cloud_account.provider
-
- @admin_permission = Permission.create :role => Role.find(:first, :conditions => ['name = ?', 'Provider Administrator']),
- :permission_object => @provider,
- :user => Factory(:provider_admin_user)
- @admin = @admin_permission.user
- activate_authlogic
- end
-
- it "shows provider accounts as list" do
- UserSession.create(@admin)
- get :index, :provider_id => @provider.id
- response.should be_success
- response.should render_template("index")
- end
-
- it "allows test account validity on create when passing test_account param" do
- UserSession.create(@admin)
- post :create, :provider_id => @provider.id, :cloud_account => {}, :test_account => true
- response.should be_success
- response.should render_template("new")
- response.flash[:error].should == "Test Connection Failed: Invalid Account Details"
- end
-
- it "doesn't allow to save provider's account if not valid credentials" do
- UserSession.create(@admin)
- post :create, :provider_id => @provider.id, :cloud_account => {}
- response.should be_success
- response.should render_template("new")
- response.flash[:error].should == "The entered credential information is incorrect"
- end
-
- it "should permit users with account modify permission to access edit cloud account interface" do
- UserSession.create(@admin)
- get :edit, :id => @cloud_account.id
- response.should be_success
- response.should render_template("edit")
- end
-
- it "should allow users with account modify password to update a cloud account" do
- UserSession.create(@admin)
-
- @cloud_account.password = "foobar"
- @cloud_account.stub!(:valid_credentials?).and_return(true)
- @cloud_account.quota = Quota.new
- @cloud_account.save.should be_true
-
- post :update, :id => @cloud_account.id, :cloud_account => { :password => 'mockpassword' }
- response.should redirect_to admin_provider_account_path(@provider)
- CloudAccount.find((a)cloud_account.id).password.should == "mockpassword"
- end
-
- it "should allow users with account modify permission to delete a cloud account" do
- UserSession.create(@admin)
- lambda do
- post :multi_destroy, :accounts_selected => [@cloud_account.id]
- end.should change(CloudAccount, :count).by(-1)
- response.should redirect_to admin_provider_accounts_url
- CloudAccount.find_by_id((a)cloud_account.id).should be_nil
- end
-
- it "should deny access to users without account modify permission" do
- get :edit, :id => @cloud_account.id
- response.should_not be_success
-
- post :update, :id => @cloud_account.id, :cloud_account => { :password => 'foobar' }
- response.should_not be_success
-
- post :destroy, :id => @cloud_account.id
- response.should_not be_success
- end
-
- it "should provide ui to create new account" do
- UserSession.create(@admin)
- get :new, :provider_id => @provider.id
- response.should be_success
- response.should render_template("new")
- end
-
- it "should fail to grant access to account UIs for unauthenticated user" do
- get :new
- response.should_not be_success
- end
-
-end
diff --git a/src/spec/controllers/provider_accounts_controller_spec.rb b/src/spec/controllers/provider_accounts_controller_spec.rb
new file mode 100644
index 0000000..abc7844
--- /dev/null
+++ b/src/spec/controllers/provider_accounts_controller_spec.rb
@@ -0,0 +1,93 @@
+require 'spec_helper'
+
+describe Admin::ProviderAccountsController do
+
+ fixtures :all
+ before(:each) do
+ @provider_account = Factory :mock_provider_account
+ @provider = @provider_account.provider
+
+ @admin_permission = Permission.create :role => Role.find(:first, :conditions => ['name = ?', 'Provider Administrator']),
+ :permission_object => @provider,
+ :user => Factory(:provider_admin_user)
+ @admin = @admin_permission.user
+ activate_authlogic
+ end
+
+ it "shows provider accounts as list" do
+ UserSession.create(@admin)
+ get :index, :provider_id => @provider.id
+ response.should be_success
+ response.should render_template("index")
+ end
+
+ it "allows test account validity on create when passing test_account param" do
+ UserSession.create(@admin)
+ require 'ruby-debug'
+ post :create, :provider_account => {:provider_id => @provider.id}, :test_account => true
+ response.should be_success
+ response.should render_template("new")
+ response.flash[:error].should == "Test Connection Failed: Invalid Account Details"
+ end
+
+ it "doesn't allow to save provider's account if not valid credentials" do
+ UserSession.create(@admin)
+ post :create, :provider_account => {:provider_id => @provider.id}
+ response.should be_success
+ response.should render_template("new")
+ response.flash[:error].should == "The entered credential information is incorrect"
+ end
+
+ it "should permit users with account modify permission to access edit cloud account interface" do
+ UserSession.create(@admin)
+ get :edit, :id => @provider_account.id
+ response.should be_success
+ response.should render_template("edit")
+ end
+
+ it "should allow users with account modify password to update a cloud account" do
+ UserSession.create(@admin)
+
+ @provider_account.password = "foobar"
+ @provider_account.stub!(:valid_credentials?).and_return(true)
+ @provider_account.quota = Quota.new
+ @provider_account.save.should be_true
+
+ post :update, :id => @provider_account.id, :provider_account => { :password => 'mockpassword' }
+ response.should redirect_to admin_provider_account_path(@provider_account)
+ ProviderAccount.find((a)provider_account.id).password.should == "mockpassword"
+ end
+
+ it "should allow users with account modify permission to delete a cloud account" do
+ UserSession.create(@admin)
+ lambda do
+ post :multi_destroy, :accounts_selected => [@provider_account.id]
+ end.should change(ProviderAccount, :count).by(-1)
+ response.should redirect_to admin_provider_accounts_url
+ ProviderAccount.find_by_id((a)provider_account.id).should be_nil
+ end
+
+ it "should deny access to users without account modify permission" do
+ get :edit, :id => @provider_account.id
+ response.should_not be_success
+
+ post :update, :id => @provider_account.id, :provider_account => { :password => 'foobar' }
+ response.should_not be_success
+
+ post :destroy, :id => @provider_account.id
+ response.should_not be_success
+ end
+
+ it "should provide ui to create new account" do
+ UserSession.create(@admin)
+ get :new, :provider_id => @provider.id
+ response.should be_success
+ response.should render_template("new")
+ end
+
+ it "should fail to grant access to account UIs for unauthenticated user" do
+ get :new
+ response.should_not be_success
+ end
+
+end
diff --git a/src/spec/factories/cloud_account.rb b/src/spec/factories/cloud_account.rb
deleted file mode 100644
index 6e301c8..0000000
--- a/src/spec/factories/cloud_account.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-Factory.define :cloud_account do |f|
- f.sequence(:username) { |n| "testUser#{n}" }
- f.password "testPassword"
- f.sequence(:label) { |n| "test label#{n}" }
- f.account_number "3141"
- f.x509_cert_priv "x509 private key"
- f.x509_cert_pub "x509 public key"
- f.association :provider
- f.association :quota
-end
-
-Factory.define :mock_cloud_account, :parent => :cloud_account do |f|
- f.username "mockuser"
- f.password "mockpassword"
- f.provider { |p| p.association(:mock_provider) }
-end
-
-Factory.define :ec2_cloud_account, :parent => :cloud_account do |f|
- f.username "mockuser"
- f.password "mockpassword"
- f.provider { |p| p.association(:ec2_provider) }
-end
diff --git a/src/spec/factories/instance.rb b/src/spec/factories/instance.rb
index 7533ba9..87938bd 100644
--- a/src/spec/factories/instance.rb
+++ b/src/spec/factories/instance.rb
@@ -2,7 +2,7 @@ Factory.define :instance do |i|
i.sequence(:name) { |n| "instance#{n}" }
i.sequence(:external_key) { |n| "key#{n}" }
i.association :hardware_profile, :factory => :mock_hwp1
- i.association :cloud_account, :factory => :mock_cloud_account
+ i.association :provider_account, :factory => :mock_provider_account
i.association :template, :factory => :template
i.association :pool, :factory => :pool
i.association :owner, :factory => :user
@@ -23,6 +23,6 @@ end
Factory.define :ec2_instance, :parent => :instance do |i|
i.association :hardware_profile, :factory => :ec2_hwp1
- i.association :cloud_account, :factory => :ec2_cloud_account
+ i.association :provider_account, :factory => :ec2_provider_account
i.association :instance_key, :factory => :ec2_instance_key1
end
diff --git a/src/spec/factories/provider.rb b/src/spec/factories/provider.rb
index 76fb4af..f6288dc 100644
--- a/src/spec/factories/provider.rb
+++ b/src/spec/factories/provider.rb
@@ -1,11 +1,11 @@
Factory.define :provider do |p|
p.sequence(:name) { |n| "provider#{n}" }
- p.cloud_type 'mock'
+ p.provider_type '0'
p.url { |p| "http://www." + p.name + ".com/api" }
end
Factory.define :mock_provider, :parent => :provider do |p|
- p.cloud_type 'mock'
+ p.provider_type '0'
p.url 'http://localhost:3001/api'
p.hardware_profiles { |hp| [hp.association(:mock_hwp1), hp.association(:mock_hwp2)] }
p.after_create { |p| p.realms << Factory(:realm1, :provider => p) << Factory(:realm2, :provider => p) }
@@ -13,14 +13,14 @@ end
Factory.define :mock_provider2, :parent => :provider do |p|
p.name 'mock2'
- p.cloud_type 'mock'
+ p.provider_type '0'
p.url 'http://localhost:3001/api'
p.after_create { |p| p.realms << Factory(:realm3, :provider => p) }
end
Factory.define :ec2_provider, :parent => :provider do |p|
p.name 'amazon-ec2'
- p.cloud_type 'ec2'
+ p.provider_type '1'
p.url 'http://localhost:3001/api'
p.hardware_profiles { |hp| [hp.association(:ec2_hwp1)] }
p.after_create { |p| p.realms << Factory(:realm4, :provider => p) }
diff --git a/src/spec/factories/provider_account.rb b/src/spec/factories/provider_account.rb
new file mode 100644
index 0000000..4aeb9b1
--- /dev/null
+++ b/src/spec/factories/provider_account.rb
@@ -0,0 +1,22 @@
+Factory.define :provider_account do |f|
+ f.sequence(:username) { |n| "testUser#{n}" }
+ f.password "testPassword"
+ f.sequence(:label) { |n| "test label#{n}" }
+ f.account_number "3141"
+ f.x509_cert_priv "x509 private key"
+ f.x509_cert_pub "x509 public key"
+ f.association :provider
+ f.association :quota
+end
+
+Factory.define :mock_provider_account, :parent => :provider_account do |f|
+ f.username "mockuser"
+ f.password "mockpassword"
+ f.provider { |p| p.association(:mock_provider) }
+end
+
+Factory.define :ec2_provider_account, :parent => :provider_account do |f|
+ f.username "mockuser"
+ f.password "mockpassword"
+ f.provider { |p| p.association(:ec2_provider) }
+end
diff --git a/src/spec/models/cloud_account_observer_spec.rb b/src/spec/models/cloud_account_observer_spec.rb
deleted file mode 100644
index 48491c0..0000000
--- a/src/spec/models/cloud_account_observer_spec.rb
+++ /dev/null
@@ -1,22 +0,0 @@
-require 'spec_helper'
-
-describe CloudAccountObserver do
- fixtures :all
-
- it "should create an instance_key if provider is EC2" do
- @client = mock('DeltaCloud', :null_object => true)
- @provider = Factory.build :ec2_provider
- @key = mock('Key', :null_object => true)
- @key.stub!(:pem).and_return("PEM")
- @key.stub!(:id).and_return("1_user")
- @client.stub!(:"feature?").and_return(true)
- @client.stub!(:"create_key").and_return(@key)
-
- cloud_account = Factory.build :ec2_cloud_account
- cloud_account.stub!(:connect).and_return(@client)
- cloud_account.save
- cloud_account.instance_key.should_not == nil
- cloud_account.instance_key.pem == "PEM"
- cloud_account.instance_key.id == "1_user"
- end
-end
diff --git a/src/spec/models/cloud_account_spec.rb b/src/spec/models/cloud_account_spec.rb
deleted file mode 100644
index fb04e40..0000000
--- a/src/spec/models/cloud_account_spec.rb
+++ /dev/null
@@ -1,80 +0,0 @@
-require 'spec_helper'
-
-describe CloudAccount do
- fixtures :all
- before(:each) do
- @cloud_account = Factory :mock_cloud_account
- end
-
- it "should not be destroyable if it has instances" do
- @cloud_account.instances << Instance.new
- @cloud_account.destroyable?.should be_false
- @cloud_account.destroy.should be_false
-
- @cloud_account.instances.clear
- @cloud_account.destroyable?.should be_true
- @cloud_account.destroy.equal?((a)cloud_account).should be_true
- @cloud_account.should be_frozen
- end
-
- it "should check the validitiy of the cloud account login credentials" do
- mock_provider = Factory :mock_provider
-
- invalid_cloud_account = Factory.build(:cloud_account, :username => "wrong_username", :password => "wrong_password", :provider => mock_provider)
- invalid_cloud_account.should_not be_valid
-
- valid_cloud_account = Factory.build(:mock_cloud_account, :provider => mock_provider)
- valid_cloud_account.should be_valid
- end
-
- it "should fail to create a cloud account if the provider credentials are invalid" do
- cloud_account = Factory.build(:mock_cloud_account, :password => "wrong_password")
- cloud_account.save.should == false
- end
-
- it "should create an instance_key if provider is EC2" do
- @client = mock('DeltaCloud', :null_object => true)
- @provider = Factory.build :ec2_provider
- @key = mock('Key', :null_object => true)
- @key.stub!(:pem).and_return("PEM")
- @key.stub!(:id).and_return("1_user")
- @client.stub!(:"feature?").and_return(true)
- @client.stub!(:"create_key").and_return(@key)
-
- cloud_account = Factory.build :ec2_cloud_account
- cloud_account.stub!(:connect).and_return(@client)
- cloud_account.save
- cloud_account.instance_key.should_not == nil
- cloud_account.instance_key.pem == "PEM"
- cloud_account.instance_key.id == "1_user"
- end
-
- it "when calling connect and it fails with exception it will return nil" do
- DeltaCloud.should_receive(:new).and_raise(Exception.new)
-
- @cloud_account.connect.should be_nil
- end
-
- it "should generate credentials xml" do
- expected_xml = <<EOT
-<?xml version="1.0"?>
-<provider_credentials>
- <ec2_credentials>
- <account_number>1234</account_number>
- <access_key>user</access_key>
- <secret_access_key>pass</secret_access_key>
- <certificate>cert</certificate>
- <key>priv_key</key>
- </ec2_credentials>
-</provider_credentials>
-EOT
- cloud_account = Factory.build(:mock_cloud_account,
- :username => 'user',
- :password => 'pass',
- :account_number => '1234',
- :x509_cert_priv => 'priv_key',
- :x509_cert_pub => 'cert'
- )
- cloud_account.build_credentials.should eql(expected_xml)
- end
-end
diff --git a/src/spec/models/image_spec.rb b/src/spec/models/image_spec.rb
index e16d43f..63b11dc 100644
--- a/src/spec/models/image_spec.rb
+++ b/src/spec/models/image_spec.rb
@@ -42,12 +42,12 @@ describe Image do
end
it "should build image if there is provider and cloud account for specified target" do
- acc = Factory.build(:mock_cloud_account)
+ acc = Factory.build(:mock_provider_account)
acc.stub!(:valid_credentials?).and_return(true)
acc.save!
tpl = Factory.build(:template)
tpl.save!
- img = Image.build(tpl, 'mock')
+ img = Image.build(tpl, '0')
Image.find(img).should == img
ProviderImage.find_by_image_id(img.id).should_not be_nil
end
@@ -55,7 +55,7 @@ describe Image do
it "should import image" do
image = OpenStruct.new(:id => 'mock', :name => 'mock', :description => 'imported mock', :architecture => 'i386')
client = mock('DeltaCloud', :feature? => false, :image => image)
- account = Factory.build(:ec2_cloud_account)
+ account = Factory.build(:ec2_provider_account)
account.stub!(:connect).and_return(client)
account.stub!(:valid_credentials?).and_return(true)
account.save!
diff --git a/src/spec/models/instance_observer_spec.rb b/src/spec/models/instance_observer_spec.rb
index be2665e..4acb78c 100644
--- a/src/spec/models/instance_observer_spec.rb
+++ b/src/spec/models/instance_observer_spec.rb
@@ -3,10 +3,8 @@ require 'spec_helper'
describe InstanceObserver do
before(:each) do
- Timecop.travel(Time.local(2008, 9, 1, 10, 5, 0, 0, 0))
-
- @cloud_account_quota = Factory :quota
- @cloud_account = Factory(:mock_cloud_account, :quota_id => @cloud_account_quota.id)
+ @provider_account_quota = Factory :quota
+ @provider_account = Factory(:mock_provider_account, :quota_id => @provider_account_quota.id)
@pool_quota = Factory :quota
@pool = Factory(:pool, :quota_id => @pool_quota.id)
@@ -15,7 +13,9 @@ describe InstanceObserver do
@user = Factory(:user, :quota_id => @user_quota.id)
@hwp = Factory :mock_hwp1
- @instance = Factory(:new_instance, :pool => @pool, :hardware_profile => @hwp, :cloud_account_id => @cloud_account.id, :owner => @user)
+ @instance = Factory(:new_instance, :pool => @pool, :hardware_profile => @hwp, :provider_account_id => @provider_account.id, :owner => @user)
+
+ Timecop.travel(Time.local(2008, 9, 1, 10, 5, 0, 0, 0))
end
after(:each) do
@@ -102,14 +102,14 @@ describe InstanceObserver do
end
it "should not update quota on pool, user and cloud account when an instance is state new" do
- [@cloud_account_quota, @pool_quota, @user_quota].each do |quota|
+ [@provider_account_quota, @pool_quota, @user_quota].each do |quota|
quota = Quota.find(quota)
quota.total_instances.should == 0
end
end
it "should update quota on pool, user and cloud account when an instance goes to state pending" do
- [@cloud_account_quota, @pool_quota, @user_quota].each do |quota|
+ [@provider_account_quota, @pool_quota, @user_quota].each do |quota|
@instance.state = Instance::STATE_PENDING
@instance.save!
@@ -122,7 +122,7 @@ describe InstanceObserver do
@instance.state = Instance::STATE_CREATE_FAILED
@instance.save!
- [@cloud_account_quota, @pool_quota, @user_quota].each do |quota|
+ [@provider_account_quota, @pool_quota, @user_quota].each do |quota|
quota = Quota.find(quota)
quota.total_instances.should == 0
end
@@ -132,7 +132,7 @@ describe InstanceObserver do
@instance.state = Instance::STATE_RUNNING
@instance.save!
- [@cloud_account_quota, @pool_quota, @user_quota].each do |quota|
+ [@provider_account_quota, @pool_quota, @user_quota].each do |quota|
quota = Quota.find(quota.id)
quota.running_instances.should == 1
quota.total_instances.should == 1
@@ -146,7 +146,7 @@ describe InstanceObserver do
@instance.state = Instance::STATE_SHUTTING_DOWN
@instance.save!
- [@cloud_account_quota, @pool_quota, @user_quota].each do |quota|
+ [@provider_account_quota, @pool_quota, @user_quota].each do |quota|
quota = Quota.find(quota.id)
quota.running_instances.should == 0
diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb
index 625718d..e4d3a9f 100644
--- a/src/spec/models/instance_spec.rb
+++ b/src/spec/models/instance_spec.rb
@@ -86,16 +86,9 @@ describe Instance do
describe "with time capsule" do
- before(:each) do
- Timecop.travel(Time.local(2008, 9, 1, 10, 5, 0, 0, 0))
- end
-
- after(:each) do
- Timecop.return
- end
-
it "should properly calculate the total time that the instance has been in a monitored state" do
instance = Factory :new_instance
+ Timecop.travel(Time.local(2008, 9, 1, 10, 5, 0, 0, 0))
[ Instance::STATE_PENDING, Instance::STATE_RUNNING, Instance::STATE_SHUTTING_DOWN, Instance::STATE_STOPPED ].each do |s|
@@ -121,18 +114,19 @@ describe Instance do
instance.total_state_time(s).should >= 3
instance.total_state_time(s).should <= 4
end
+ Timecop.return
end
end
it "should return empty list of instance actions when connect to provider fails" do
provider = Factory.build(:mock_provider2)
- cloud_account = Factory.build(:cloud_account, :provider => provider,
+ cloud_account = Factory.build(:provider_account, :provider => provider,
:username => 'john doe',
:password => 'asdf')
cloud_account.stub!(:connect).and_return(nil)
cloud_account.stub!(:valid_credentials?).and_return(true)
- instance = Factory.create(:instance, :cloud_account => cloud_account)
+ instance = Factory.create(:instance, :provider_account => cloud_account)
instance.get_action_list.should be_empty
end
diff --git a/src/spec/models/pool_family_spec.rb b/src/spec/models/pool_family_spec.rb
index 2b69eab..68dfb42 100644
--- a/src/spec/models/pool_family_spec.rb
+++ b/src/spec/models/pool_family_spec.rb
@@ -5,9 +5,9 @@ describe PoolFamily do
before(:each) do
@pool = Factory :pool
@pool_family = @pool.pool_family
- @cloud_account = Factory :mock_cloud_account
- @cloud_account.pool_families << @pool_family
- @cloud_account.save!
+ @provider_account = Factory :mock_provider_account
+ @provider_account.pool_families << @pool_family
+ @provider_account.save!
end
it "should validate default pool family" do
@@ -27,8 +27,8 @@ describe PoolFamily do
end
it "should have account" do
- @pool_family.cloud_accounts.size.should == 1
- @pool_family.cloud_accounts[0].id.should == @cloud_account.id
+ @pool_family.provider_accounts.size.should == 1
+ @pool_family.provider_accounts[0].id.should == @provider_account.id
end
end
diff --git a/src/spec/models/provider_account_observer_spec.rb b/src/spec/models/provider_account_observer_spec.rb
new file mode 100644
index 0000000..0c397db
--- /dev/null
+++ b/src/spec/models/provider_account_observer_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe ProviderAccountObserver do
+ fixtures :all
+
+ it "should create an instance_key if provider is EC2" do
+ @client = mock('DeltaCloud', :null_object => true)
+ @provider = Factory.build :ec2_provider
+ @key = mock('Key', :null_object => true)
+ @key.stub!(:pem).and_return("PEM")
+ @key.stub!(:id).and_return("1_user")
+ @client.stub!(:"feature?").and_return(true)
+ @client.stub!(:"create_key").and_return(@key)
+
+ provider_account = Factory.build :ec2_provider_account
+ provider_account.stub!(:connect).and_return(@client)
+ provider_account.save
+ provider_account.instance_key.should_not == nil
+ provider_account.instance_key.pem == "PEM"
+ provider_account.instance_key.id == "1_user"
+ end
+end
diff --git a/src/spec/models/provider_account_spec.rb b/src/spec/models/provider_account_spec.rb
new file mode 100644
index 0000000..48678e8
--- /dev/null
+++ b/src/spec/models/provider_account_spec.rb
@@ -0,0 +1,80 @@
+require 'spec_helper'
+
+describe ProviderAccount do
+ fixtures :all
+ before(:each) do
+ @provider_account = Factory :mock_provider_account
+ end
+
+ it "should not be destroyable if it has instances" do
+ @provider_account.instances << Instance.new
+ @provider_account.destroyable?.should be_false
+ @provider_account.destroy.should be_false
+
+ @provider_account.instances.clear
+ @provider_account.destroyable?.should be_true
+ @provider_account.destroy.equal?((a)provider_account).should be_true
+ @provider_account.should be_frozen
+ end
+
+ it "should check the validitiy of the cloud account login credentials" do
+ mock_provider = Factory :mock_provider
+
+ invalid_provider_account = Factory.build(:provider_account, :username => "wrong_username", :password => "wrong_password", :provider => mock_provider)
+ invalid_provider_account.should_not be_valid
+
+ valid_provider_account = Factory.build(:mock_provider_account, :provider => mock_provider)
+ valid_provider_account.should be_valid
+ end
+
+ it "should fail to create a cloud account if the provider credentials are invalid" do
+ provider_account = Factory.build(:mock_provider_account, :password => "wrong_password")
+ provider_account.save.should == false
+ end
+
+ it "should create an instance_key if provider is EC2" do
+ @client = mock('DeltaCloud', :null_object => true)
+ @provider = Factory.build :ec2_provider
+ @key = mock('Key', :null_object => true)
+ @key.stub!(:pem).and_return("PEM")
+ @key.stub!(:id).and_return("1_user")
+ @client.stub!(:"feature?").and_return(true)
+ @client.stub!(:"create_key").and_return(@key)
+
+ provider_account = Factory.build :ec2_provider_account
+ provider_account.stub!(:connect).and_return(@client)
+ provider_account.save
+ provider_account.instance_key.should_not == nil
+ provider_account.instance_key.pem == "PEM"
+ provider_account.instance_key.id == "1_user"
+ end
+
+ it "when calling connect and it fails with exception it will return nil" do
+ DeltaCloud.should_receive(:new).and_raise(Exception.new)
+
+ @provider_account.connect.should be_nil
+ end
+
+ it "should generate credentials xml" do
+ expected_xml = <<EOT
+<?xml version="1.0"?>
+<provider_credentials>
+ <ec2_credentials>
+ <account_number>1234</account_number>
+ <access_key>user</access_key>
+ <secret_access_key>pass</secret_access_key>
+ <certificate>cert</certificate>
+ <key>priv_key</key>
+ </ec2_credentials>
+</provider_credentials>
+EOT
+ provider_account = Factory.build(:mock_provider_account,
+ :username => 'user',
+ :password => 'pass',
+ :account_number => '1234',
+ :x509_cert_priv => 'priv_key',
+ :x509_cert_pub => 'cert'
+ )
+ provider_account.build_credentials.should eql(expected_xml)
+ end
+end
diff --git a/src/spec/models/provider_spec.rb b/src/spec/models/provider_spec.rb
index 1b86f92..c23227e 100644
--- a/src/spec/models/provider_spec.rb
+++ b/src/spec/models/provider_spec.rb
@@ -26,9 +26,9 @@ describe Provider do
end
end
- it "should require a valid cloud_type" do
+ it "should require a valid provider_type" do
[nil, ""].each do |invalid_value|
- @provider.cloud_type = invalid_value
+ @provider.provider_type = invalid_value
@provider.should_not be_valid
end
end
@@ -64,9 +64,9 @@ describe Provider do
end
it "should set valid cloud type" do
- @client.driver_name = @provider.cloud_type
- @provider.cloud_type = nil
- @provider.set_cloud_type!
+ @client.driver_name = @provider.provider_type
+ @provider.provider_type = nil
+ @provider.provider_type = 0
@provider.should be_valid
end
@@ -79,7 +79,7 @@ describe Provider do
HardwareProfile.destroy_all
instance = Factory(:instance)
- provider = instance.cloud_account.provider
+ provider = instance.provider_account.provider
provider.destroy
provider.destroyed?.should be_false
end
diff --git a/src/spec/models/quota_spec.rb b/src/spec/models/quota_spec.rb
index 9620e83..960b417 100644
--- a/src/spec/models/quota_spec.rb
+++ b/src/spec/models/quota_spec.rb
@@ -3,8 +3,8 @@ require 'spec_helper'
describe Quota do
before(:each) do
- @cloud_account_quota = Factory :quota
- @cloud_account = Factory(:mock_cloud_account, :quota_id => @cloud_account_quota.id)
+ @provider_account_quota = Factory :quota
+ @provider_account = Factory(:mock_provider_account, :quota_id => @provider_account_quota.id)
@pool_quota = Factory :quota
@pool = Factory(:pool, :quota_id => @pool_quota.id)
@@ -13,12 +13,12 @@ describe Quota do
@user = Factory(:user, :quota_id => @user_quota.id)
@hwp = Factory :mock_hwp1
- @instance = Factory(:new_instance, :pool => @pool, :hardware_profile => @hwp, :cloud_account_id => @cloud_account.id, :owner => @user)
+ @instance = Factory(:new_instance, :pool => @pool, :hardware_profile => @hwp, :provider_account_id => @provider_account.id, :owner => @user)
end
it "should return true when asking if an instance can be created/started when there is sufficient quota space" do
- Quota.can_create_instance?(@instance, @cloud_account).should == true
- Quota.can_start_instance?(@instance, @cloud_account).should == true
+ Quota.can_create_instance?(@instance, @provider_account).should == true
+ Quota.can_start_instance?(@instance, @provider_account).should == true
end
it "should return true when asking if an instance can be created/started when using unlimited Quotas" do
@@ -28,11 +28,11 @@ describe Quota do
@pool.quota = Factory :unlimited_quota
@pool.save!
- @cloud_account.quota = Factory :unlimited_quota
- @cloud_account.save!
+ @provider_account.quota = Factory :unlimited_quota
+ @provider_account.save!
- Quota.can_create_instance?(@instance, @cloud_account).should == true
- Quota.can_start_instance?(@instance, @cloud_account).should == true
+ Quota.can_create_instance?(@instance, @provider_account).should == true
+ Quota.can_start_instance?(@instance, @provider_account).should == true
end
it "should return false when asking if an instance can be created/started when the user quota is reached" do
@@ -40,8 +40,8 @@ describe Quota do
@user_quota.running_instances = @user_quota.maximum_running_instances
@user_quota.save!
- Quota.can_create_instance?(@instance, @cloud_account).should == false
- Quota.can_start_instance?(@instance, @cloud_account).should == false
+ Quota.can_create_instance?(@instance, @provider_account).should == false
+ Quota.can_start_instance?(@instance, @provider_account).should == false
end
it "should return false when asking if an instance can be created/started when the pool quota is reached" do
@@ -49,17 +49,17 @@ describe Quota do
@pool_quota.running_instances = @pool_quota.maximum_running_instances
@pool_quota.save!
- Quota.can_create_instance?(@instance, @cloud_account).should == false
- Quota.can_start_instance?(@instance, @cloud_account).should == false
+ Quota.can_create_instance?(@instance, @provider_account).should == false
+ Quota.can_start_instance?(@instance, @provider_account).should == false
end
it "should return false when asking if an instance can be created/started when the cloud account quota is reached" do
- @cloud_account_quota.total_instances = @cloud_account_quota.maximum_total_instances
- @cloud_account_quota.running_instances = @cloud_account_quota.maximum_running_instances
- @cloud_account_quota.save!
+ @provider_account_quota.total_instances = @provider_account_quota.maximum_total_instances
+ @provider_account_quota.running_instances = @provider_account_quota.maximum_running_instances
+ @provider_account_quota.save!
- Quota.can_create_instance?(@instance, @cloud_account).should == false
- Quota.can_start_instance?(@instance, @cloud_account).should == false
+ Quota.can_create_instance?(@instance, @provider_account).should == false
+ Quota.can_start_instance?(@instance, @provider_account).should == false
end
it "should return false when asking if an instance can be created/started when the all quotas are reached" do
@@ -71,12 +71,12 @@ describe Quota do
@pool_quota.running_instances = @pool_quota.maximum_running_instances
@pool_quota.save!
- @cloud_account_quota.total_instances = @cloud_account_quota.maximum_total_instances
- @cloud_account_quota.running_instances = @cloud_account_quota.maximum_running_instances
- @cloud_account_quota.save!
+ @provider_account_quota.total_instances = @provider_account_quota.maximum_total_instances
+ @provider_account_quota.running_instances = @provider_account_quota.maximum_running_instances
+ @provider_account_quota.save!
- Quota.can_create_instance?(@instance, @cloud_account).should == false
- Quota.can_start_instance?(@instance, @cloud_account).should == false
+ Quota.can_create_instance?(@instance, @provider_account).should == false
+ Quota.can_start_instance?(@instance, @provider_account).should == false
end
-end
\ No newline at end of file
+end
diff --git a/src/spec/services/data_service_active_record_spec.rb b/src/spec/services/data_service_active_record_spec.rb
index c96024f..9e4fb4e 100644
--- a/src/spec/services/data_service_active_record_spec.rb
+++ b/src/spec/services/data_service_active_record_spec.rb
@@ -2,7 +2,7 @@ require 'spec_helper'
describe DataServiceActiveRecord do
- it "should calculate the total instance quota usage for a provider with a number of cloud accounts" do
+ it "should calculate the total instance quota usage for a provider with a number of provider accounts" do
client = mock('DeltaCloud', :null_object => true)
provider = Factory.build(:mock_provider)
provider.stub!(:connect).and_return(client)
@@ -12,9 +12,9 @@ describe DataServiceActiveRecord do
free = 0
for i in 0..2
quota = Factory(:quota, :maximum_total_instances => data[i][0], :total_instances => data[i][1])
- cloud_account = Factory.build(:cloud_account, :provider => provider, :username => "username" + i.to_s, :quota => quota)
- cloud_account.stub!(:valid_credentials?).and_return(true)
- cloud_account.save!
+ provider_account = Factory.build(:provider_account, :provider => provider, :username => "username" + i.to_s, :quota => quota)
+ provider_account.stub!(:valid_credentials?).and_return(true)
+ provider_account.save!
free += (data[i][0] - data[i][1])
end
@@ -27,29 +27,30 @@ describe DataServiceActiveRecord do
end
- it "should calculate the total number of instances and maximum number of instances of a cloud account" do
+ it "should calculate the total number of instances and maximum number of instances of a provider account" do
client = mock('DeltaCloud', :null_object => true)
provider = Factory.build(:mock_provider)
provider.stub!(:connect).and_return(client)
provider.save!
+
quota = Factory(:quota,
:maximum_running_instances => 40,
:maximum_total_instances => 50,
:running_instances => 20,
:total_instances => 20)
- cloud_account = Factory.build(:cloud_account, :provider => provider, :quota => quota)
- cloud_account.stub!(:valid_credentials?).and_return(true)
- cloud_account.save!
+ provider_account = Factory.build(:provider_account, :provider => provider, :quota => quota)
+ provider_account.stub!(:valid_credentials?).and_return(true)
+ provider_account.save!
- data_point = DataServiceActiveRecord.quota_usage(cloud_account, Quota::RESOURCE_RUNNING_INSTANCES)
+ data_point = DataServiceActiveRecord.quota_usage(provider_account, Quota::RESOURCE_RUNNING_INSTANCES)
data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(20, 40)
- data_point = DataServiceActiveRecord.quota_usage(cloud_account, Quota::RESOURCE_TOTAL_INSTANCES)
+ data_point = DataServiceActiveRecord.quota_usage(provider_account, Quota::RESOURCE_TOTAL_INSTANCES)
data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(20, 50)
- data_point = DataServiceActiveRecord.quota_usage(cloud_account, Quota::RESOURCE_OVERALL)
+ data_point = DataServiceActiveRecord.quota_usage(provider_account, Quota::RESOURCE_OVERALL)
data_point.should == DataServiceActiveRecord::QuotaUsagePoint.new(20, 40)
end
@@ -123,13 +124,13 @@ describe DataServiceActiveRecord do
provider.stub!(:connect).and_return(client)
provider.save!
- cloud_accounts = []
+ provider_accounts = []
expected_averages.each do |expected_average|
- cloud_account = Factory.build(:cloud_account, :provider => provider, :username => "username" + expected_average[0].to_s)
- cloud_account.stub!(:valid_credentials?).and_return(true)
- cloud_account.save!
+ provider_account = Factory.build(:provider_account, :provider => provider, :username => "username" + expected_average[0].to_s)
+ provider_account.stub!(:valid_credentials?).and_return(true)
+ provider_account.save!
- instance = Factory(:instance, :cloud_account_id => cloud_account.id, :pool_id => pool.id)
+ instance = Factory(:instance, :provider_account_id => provider_account.id, :pool_id => pool.id)
generate_tasks(start_time, interval_length, instance, expected_average)
end
@@ -159,11 +160,11 @@ describe DataServiceActiveRecord do
runtimes = [runtime1, runtime2, runtime3]
pool = Factory(:pool)
- cloud_account = Factory :mock_cloud_account
+ provider_account = Factory :mock_provider_account
for i in 0..2 do
runtimes[i].each do |runtime|
- instance = Factory(:instance, :pool => pool, :cloud_account => cloud_account, :state => Instance::STATE_STOPPED)
+ instance = Factory(:instance, :pool => pool, :provider_account => provider_account, :state => Instance::STATE_STOPPED)
instance.save!
instance.time_last_pending = start_times[i] + (interval_length / 2)
@@ -173,21 +174,21 @@ describe DataServiceActiveRecord do
end
end
- stats = DataServiceActiveRecord.qos_instance_runtime_stats(cloud_account, start_time, end_time, interval_length)
+ stats = DataServiceActiveRecord.qos_instance_runtime_stats(provider_account, start_time, end_time, interval_length)
stats[0].should == DataServiceActiveRecord::QoSDataPoint.new(start_times[0], 15, 25, 5)
stats[1].should == DataServiceActiveRecord::QoSDataPoint.new(start_times[1], 30, 50, 10)
stats[2].should == DataServiceActiveRecord::QoSDataPoint.new(start_times[2], 300, 500, 100)
end
- it "should generate the mean max and min instance runtimes of instances for a given cloud account or pool" do
+ it "should generate the mean max and min instance runtimes of instances for a given provider account or pool" do
pool = Factory(:pool)
- cloud_account = Factory :mock_cloud_account
+ provider_account = Factory :mock_provider_account
start_time = Time.utc(2010,"jan",1,20,15,1)
[50, 100, 150, 200, 250].each do |runtime|
- instance = Factory(:new_instance, :pool => pool, :cloud_account => cloud_account)
+ instance = Factory(:new_instance, :pool => pool, :provider_account => provider_account)
instance.time_last_pending = start_time
instance.time_last_running = start_time
instance.acc_running_time = runtime
@@ -201,8 +202,8 @@ describe DataServiceActiveRecord do
it "should calculate the average time it takes a provider to complete a task between two times" do
pool = Factory(:pool)
- cloud_account = Factory(:mock_cloud_account)
- instance = Factory(:instance, :pool => pool, :cloud_account => cloud_account)
+ provider_account = Factory(:mock_provider_account)
+ instance = Factory(:instance, :pool => pool, :provider_account => provider_account)
start_time = Time.utc(2010,"jan",1,20,15,1)
task_completion_times = [10, 20, 30, 40, 50]
@@ -226,21 +227,21 @@ describe DataServiceActiveRecord do
end
expected_average_time = total_time / task_completion_times.length
- average_time = DataServiceActiveRecord.qos_task_completion_mean_max_min(cloud_account.provider, start_time, Time.now, InstanceTask::ACTION_CREATE)
+ average_time = DataServiceActiveRecord.qos_task_completion_mean_max_min(provider_account.provider, start_time, Time.now, InstanceTask::ACTION_CREATE)
average_time[:average].should == expected_average_time
average_time[:min].should == 10
average_time[:max].should == 50
end
- it "should calculate the correct failure rate of instances starts for a particular pool or cloud account" do
+ it "should calculate the correct failure rate of instances starts for a particular pool or provider account" do
start_time = Time.utc(2010,"jan",1,20,15,1)
create_time = start_time + 1
end_time = create_time + 1
pool = Factory(:pool)
- cloud_account = Factory :mock_cloud_account
- instance = Factory(:instance, :pool => pool, :cloud_account => cloud_account)
+ provider_account = Factory :mock_provider_account
+ instance = Factory(:instance, :pool => pool, :provider_account => provider_account)
failures = 5
non_failures = 20
@@ -285,8 +286,8 @@ describe DataServiceActiveRecord do
number_of_instances = 20
pool = Factory(:pool)
- cloud_account = Factory :mock_cloud_account
- instance = Factory(:instance, :pool => pool, :cloud_account => cloud_account)
+ provider_account = Factory :mock_provider_account
+ instance = Factory(:instance, :pool => pool, :provider_account => provider_account)
for i in 0..2
for j in 1..failures[i]
diff --git a/src/test/fixtures/providers.yml b/src/test/fixtures/providers.yml
index 1669919..7e8ee9f 100644
--- a/src/test/fixtures/providers.yml
+++ b/src/test/fixtures/providers.yml
@@ -2,5 +2,5 @@
mock_provider:
name: mock
- cloud_type: Mock
+ provider_type: Mock
url: http://localhost:3001/api
diff --git a/src/test/fixtures/roles.yml b/src/test/fixtures/roles.yml
index 99df4b7..d12fc64 100644
--- a/src/test/fixtures/roles.yml
+++ b/src/test/fixtures/roles.yml
@@ -27,11 +27,11 @@ pool_administrator:
privileges: provider_view, pool_modify, pool_view, quota_modify, quota_view, stats_view, set_perms, view_perms
account_administrator:
name: Account Administrator
- scope: CloudAccount
+ scope: ProviderAccount
privileges: account_modify, account_view, stats_view, set_perms, view_perms
account_viewer:
name: Account User
- scope: CloudAccount
+ scope: ProviderAccount
privileges: account_view
provider_administrator:
name: Provider Administrator
diff --git a/src/test/unit/cloud_account_test.rb b/src/test/unit/cloud_account_test.rb
deleted file mode 100644
index addf6af..0000000
--- a/src/test/unit/cloud_account_test.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-require 'test_helper'
-
-class CloudAccountTest < ActiveSupport::TestCase
- # Replace this with your real tests.
- test "the truth" do
- assert true
- end
-end
diff --git a/src/test/unit/provider_account_test.rb b/src/test/unit/provider_account_test.rb
new file mode 100644
index 0000000..cafbb76
--- /dev/null
+++ b/src/test/unit/provider_account_test.rb
@@ -0,0 +1,8 @@
+require 'test_helper'
+
+class ProviderAccountTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ test "the truth" do
+ assert true
+ end
+end
diff --git a/src/test/unit/provider_test.rb b/src/test/unit/provider_test.rb
index 877fd9c..2181ce6 100644
--- a/src/test/unit/provider_test.rb
+++ b/src/test/unit/provider_test.rb
@@ -5,7 +5,7 @@ class ProviderTest < ActiveSupport::TestCase
def setup
@provider = Provider.new(:name => "my_ec2",
- :cloud_type => "EC2")
+ :provider_type => "EC2")
end
# The following three tests assume you have the deltacloud-framework
# running and configured on localhost:3000
--
1.7.4
13 years, 1 month
[PATCH] Changed deltacloud-configure dependency to be >= 2.0.0.
by Justin Clift
This version of Conductor requires rake db:seed in order to work,
which is only done by version 2 (and above) of deltacloud-configure.
---
deltacloud-aggregator.spec.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/deltacloud-aggregator.spec.in b/deltacloud-aggregator.spec.in
index 0632f79..95c14b6 100644
--- a/deltacloud-aggregator.spec.in
+++ b/deltacloud-aggregator.spec.in
@@ -40,7 +40,7 @@ Requires: ruby-RMagick
Requires: classads >= 1.0
Requires: condor >= 7.5.5-10dcloud
Requires: iwhd
-Requires: deltacloud-configure
+Requires: deltacloud-configure >= 2.0.0
BuildRequires: ruby
BuildRequires: ruby-devel
--
1.7.4
13 years, 1 month
[PATCH configure] build rpms in ~/rpmbuild instead of local project subdir
by Mo Morsi
---
.gitignore | 1 -
Rakefile | 4 ++--
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
index 50fa14f..314808d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
deltacloud
-build/
pkg/
repo/
diff --git a/Rakefile b/Rakefile
index f203717..a116674 100644
--- a/Rakefile
+++ b/Rakefile
@@ -5,10 +5,10 @@ require 'rake/rpmtask'
require 'rake/yumtask'
CURRENT_DIR = File.dirname(__FILE__)
-RPMBUILD_DIR = "#{CURRENT_DIR}/build/rpmbuild"
+RPMBUILD_DIR = "#{File.expand_path('~')}/rpmbuild"
YUM_REPO = "#{CURRENT_DIR}/repo"
-CLEAN.include('pkg', 'build', 'repo')
+CLEAN.include('pkg', 'repo')
CLOBBER.include('deltacloud')
PKG_NAME = "deltacloud-configure"
RPM_SPEC = "contrib/deltacloud-configure.spec"
--
1.7.2.3
13 years, 1 month
[PATCH] Wrap pipe output in a rescue block - updated
by Ian Main
This patch wraps the pipe output in a rescue block so that errors in
this code cannot cause zombie processes as I was seeing in
condor_refreshd.
This update makes it apply to next.
Signed-off-by: Ian Main <imain(a)redhat.com>
---
src/app/util/condormatic.rb | 38 ++++++++++++++++++++++----------------
1 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/app/util/condormatic.rb b/src/app/util/condormatic.rb
index 22b3d64..c8ef075 100644
--- a/src/app/util/condormatic.rb
+++ b/src/app/util/condormatic.rb
@@ -228,22 +228,28 @@ def condormatic_classads_sync
pipe = IO.popen("condor_advertise UPDATE_STARTD_AD 2>&1", "w+")
- pipe.puts "Name=\"provider_combination_#{index}\""
- pipe.puts 'MyType="Machine"'
- pipe.puts 'Requirements=true'
- pipe.puts "\n# Stuff needed to match:"
- pipe.puts "hardwareprofile=\"#{hwp.aggregator_hardware_profiles[0].id}\""
- pipe.puts "image=\"#{provider_image.image.template.id}\""
- pipe.puts "realm=\"#{realm.frontend_realms[0].id}\""
- pipe.puts "\n# Backend info to complete this job:"
- pipe.puts "image_key=\"#{provider_image.provider_image_key}\""
- pipe.puts "hardwareprofile_key=\"#{hwp.external_key}\""
- pipe.puts "realm_key=\"#{realm.external_key}\""
- pipe.puts "provider_url=\"#{account.provider.url}\""
- pipe.puts "username=\"#{account.username}\""
- pipe.puts "password=\"#{account.password}\""
- pipe.puts "cloud_account_id=\"#{account.id}\""
- pipe.puts "keypair=\"#{escape(account.instance_key.name)}\""
+ begin
+ pipe.puts "Name=\"provider_combination_#{index}\""
+ pipe.puts 'MyType="Machine"'
+ pipe.puts 'Requirements=true'
+ pipe.puts "\n# Stuff needed to match:"
+ pipe.puts "hardwareprofile=\"#{hwp.aggregator_hardware_profiles[0].id}\""
+ pipe.puts "image=\"#{provider_image.image.template.id}\""
+ pipe.puts "realm=\"#{realm.frontend_realms[0].id}\""
+ pipe.puts "\n# Backend info to complete this job:"
+ pipe.puts "image_key=\"#{provider_image.provider_image_key}\""
+ pipe.puts "hardwareprofile_key=\"#{hwp.external_key}\""
+ pipe.puts "realm_key=\"#{realm.external_key}\""
+ pipe.puts "provider_url=\"#{account.provider.url}\""
+ pipe.puts "username=\"#{account.username}\""
+ pipe.puts "password=\"#{account.password}\""
+ pipe.puts "cloud_account_id=\"#{account.id}\""
+ pipe.puts "keypair=\"#{escape(account.instance_key.name)}\""
+ rescue Exception => ex
+ Rails.logger.error "Error writing provider classad to condor."
+ Rails.logger.error ex.message
+ Rails.logger.error ex.backtrace
+ end
pipe.close_write
out = pipe.read
--
1.7.4
13 years, 1 month
Fixes
by Jan Provazník
First patch fixes provider account rename, second disables unique instance key
generation when instance is started - as ssh key distribution is not in branch
yet.
13 years, 1 month
[PATCH] Fix REST API mapping - updated.
by Ian Main
This fixes an argument mapping that still references the old
cloud_account_id. This allows the condor quota plugin to work again.
Signed-off-by: Ian Main <imain(a)redhat.com>
---
src/config/routes.rb | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 90d5df7..ee65acb 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -38,8 +38,8 @@ ActionController::Routing::Routes.draw do |map|
r.resources :instances, :collection => {:start => :get, :stop => :get, :select_template => :get, :remove_failed => :get, :can_start => :get, :can_create => :get }, :member => {:key => :get}
end
- map.can_start_instance '/resources/instances/:instance_id/can_start/:cloud_account_id', :controller => 'resources/instances', :action => 'can_start', :conditions => { :method => :get }
- map.can_create_instance '/resources/instances/:instance_id/can_create/:cloud_account_id', :controller => 'resources/instances', :action => 'can_create', :conditions => { :method => :get }
+ map.can_start_instance '/resources/instances/:instance_id/can_start/:provider_account_id', :controller => 'resources/instances', :action => 'can_start', :conditions => { :method => :get }
+ map.can_create_instance '/resources/instances/:instance_id/can_create/:provider_account_id', :controller => 'resources/instances', :action => 'can_create', :conditions => { :method => :get }
map.namespace 'image_factory' do |r|
r.resources :assemblies
--
1.7.4
13 years, 1 month
Known problem? User registration failed: Role can't be blank
by Justin Clift
Hi all,
Is this a known problem or something new?
It's on deltacloud-configure on F14 x64, where it tries to create the initial
admin user:
+ rake 'dc:create_user[admin,password,admin@deltacloud.org,Admin,istrator]'
(in /usr/share/deltacloud-aggregator)
User registration failed: Validation failed: Role can't be blank
+ rake 'dc:site_admin[admin]'
(in /usr/share/deltacloud-aggregator)
Unknown user: admin
So, no web login possible. :(
This occurs (every time) using the repo package rpms for everything except
Conductor. Conductor has been built from source against git head. ('make rpms',
then 'yum upgrade' of the created rpms)
Suspecting some other package might need building from source too, and hoping
someone can point towards what might need trying?
Regards and best wishes,
Justin Clift
13 years, 1 month