[PATCH conductor] bug 798516: prevent last admin deletion
by Scott Seago
https://bugzilla.redhat.com/show_bug.cgi?id=798516
Don't allow deletion of admin permissions if there is only one admin left.
Upon permission removal, redirect user to /account if the user's
own permissions to that page have been revoked.
---
src/app/controllers/application_controller.rb | 5 +++++
src/app/controllers/permissions_controller.rb | 6 ++++--
src/app/models/base_permission_object.rb | 13 +++++++++++++
src/app/views/permissions/_permissions.html.haml | 6 ++++--
src/spec/controllers/permissions_controller_spec.rb | 2 +-
5 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/src/app/controllers/application_controller.rb b/src/app/controllers/application_controller.rb
index 2d7f325..64f3498 100644
--- a/src/app/controllers/application_controller.rb
+++ b/src/app/controllers/application_controller.rb
@@ -44,6 +44,11 @@ class ApplicationController < ActionController::Base
# permissions checking
def handle_perm_error(error)
+ if params[:return_from_permission_change]
+ flash.now
+ redirect_to account_url
+ return
+ end
handle_error(:error => error, :status => :forbidden,
:title => t('application_controller.access_denied'))
end
diff --git a/src/app/controllers/permissions_controller.rb b/src/app/controllers/permissions_controller.rb
index 33c2a7e..0bc90cb 100644
--- a/src/app/controllers/permissions_controller.rb
+++ b/src/app/controllers/permissions_controller.rb
@@ -220,7 +220,7 @@ class PermissionsController < ApplicationController
raise RuntimeError, "invalid permission object" if @permission_object.nil?
unless @return_path
if @permission_object == BasePermissionObject.general_permission_scope
- @return_path = permissions_path
+ @return_path = permissions_path(:return_from_permission_change => true)
set_admin_users_tabs 'permissions'
else
@return_path = send("#{@path_prefix}polymorphic_path",
@@ -230,7 +230,9 @@ class PermissionsController < ApplicationController
@polymorphic_path_extras) :
@permission_object,
@use_tabs == "yes" ? {:details_tab => :permissions,
- :only_tab => true} : {})
+ :only_tab => true,
+ :return_from_permission_change => true} :
+ {:return_from_permission_change => true})
end
end
require_privilege(required_role, @permission_object)
diff --git a/src/app/models/base_permission_object.rb b/src/app/models/base_permission_object.rb
index c5d525a..faf5e53 100644
--- a/src/app/models/base_permission_object.rb
+++ b/src/app/models/base_permission_object.rb
@@ -56,4 +56,17 @@ class BasePermissionObject < ActiveRecord::Base
[HardwareProfile, Catalog, Deployable, PoolFamily, Pool,
Deployment, Instance, Provider, ProviderAccount]
end
+
+ def self.global_admin_permission_count
+ self.general_permission_scope.permissions.includes(:role => :privileges).
+ where("privileges.target_type" => "BasePermissionObject",
+ "privileges.action" => Privilege::PERM_SET).size
+ end
+
+ def self.is_global_admin_perm(permission)
+ permission.role.privileges.where("privileges.target_type" =>
+ "BasePermissionObject",
+ "privileges.action" =>
+ Privilege::PERM_SET).size > 0
+ end
end
diff --git a/src/app/views/permissions/_permissions.html.haml b/src/app/views/permissions/_permissions.html.haml
index 4f2818d..6d8ab32 100644
--- a/src/app/views/permissions/_permissions.html.haml
+++ b/src/app/views/permissions/_permissions.html.haml
@@ -1,3 +1,5 @@
+- has_admin_perms = check_privilege(Privilege::PERM_SET)
+- prevent_admin_deletion = has_admin_perms && !(@show_inherited || @show_global) && (@permission_object == BasePermissionObject.general_permission_scope) && (BasePermissionObject.global_admin_permission_count == 1)
- content_for :permissions_form_header do
- if not(@show_inherited or @show_global) && check_privilege(Privilege::PERM_SET)
%li= link_to t('permissions.form.grant_access'), new_permission_path(:permission_object_type => @permission_object.class.name, :permission_object_id => @permission_object.id, :path_prefix => @path_prefix, :use_tabs => @use_tabs ? @use_tabs : (@tabs ? 'yes' : 'no')), { :class => 'button primary', :id => 'new_permission_button'}
@@ -51,11 +53,11 @@
%tr{:class => cycle('nostripe','stripe')}
- if not(@show_inherited or @show_global)
%td{:class => 'checkbox'}
- - if check_privilege(Privilege::PERM_SET)
+ - if has_admin_perms && !(prevent_admin_deletion && BasePermissionObject.is_global_admin_perm(permission))
- selected = params[:select] == 'all'
= check_box_tag "permission_selected[]", permission.id, selected, :id => "permission_checkbox_#{permission.id}"
%td= link_to permission.entity.name, ((permission.entity.entity_target_type == "User") ? user_path(permission.entity.user) : user_group_path(permission.entity.user_group))
- - if not(@show_inherited or @show_global) && check_privilege(Privilege::PERM_SET)
+ - if not(@show_inherited or @show_global) && has_admin_perms && !(prevent_admin_deletion && BasePermissionObject.is_global_admin_perm(permission))
%td= select_tag "permission_role_selected[]", options_for_select((a)roles.map {|r| [ t(r.name, :scope=> :role_defs, :default => r.name), "#{permission.id},#{r.id}" ] }, :selected => "#{permission.id},#{permission.role.id}", :disabled => @permission_object.permissions.where(["entity_id = ? and role_id != ?", permission.entity_id, permission.role_id]).collect {|p| "#{permission.id},#{p.role.id}"}), :id => "permission_role_selected_#{permission.id}"
:javascript
$("#permission_role_selected_#{permission.id}").change(function () { $("#perm_edit_button").click(); } );
diff --git a/src/spec/controllers/permissions_controller_spec.rb b/src/spec/controllers/permissions_controller_spec.rb
index a27d669..4538dc9 100644
--- a/src/spec/controllers/permissions_controller_spec.rb
+++ b/src/spec/controllers/permissions_controller_spec.rb
@@ -36,7 +36,7 @@ describe PermissionsController do
post :multi_update, :permission_object_id => @deployable.id, :permission_object_type => @deployable.class.to_s,
:permission_role_selected => ["#{@permission.id},#{(a)new_role.id}"], :polymorphic_path_extras => { 'catalog_id' => @catalog.id}
- response.should redirect_to catalog_deployable_path(@catalog, @deployable)
+ response.should redirect_to catalog_deployable_path(@catalog, @deployable, :return_from_permission_change => true)
end
it "should work for global role grants" do
--
1.7.11.4
11 years, 6 months
[PATCH 0/1 conductor] BZ 853939 - Error on click of "logs" button
by Tzu-Mainn Chen
This bz was due to the introduction of a new source_type for events. Since the logs page was intended to show a history of deployments and instances, I'm just filtering out non-deployment/instance events for now. The eventual notifications page will likely be more inclusive.
Mainn
11 years, 6 months
[PATCH conductor] Bug 852866 - aeolus-upgrade hits "aeolus-services: unrecognized service"
by steve linabery
aeolus-upgrade script previously called 'service aeolus-services stop'
to stop services, but aeolus-services is not a system service. This was
silently failing to stop services on f16/f17, but rhel more sensibly
reports the failure which uncovered the issue. This patch
changes the stop method to call aeolus-services directly.
---
src/script/aeolus-upgrade | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/script/aeolus-upgrade b/src/script/aeolus-upgrade
index df89c31..2fe8d13 100755
--- a/src/script/aeolus-upgrade
+++ b/src/script/aeolus-upgrade
@@ -296,7 +296,7 @@ class UpgradeProcess
else
puts "This script can be run in auto-stop mode with the -a / --auto-stop option to"
puts "disable services automatically."
- puts "You may always use `service aeolus-services stop` to stop all the services"
+ puts "You may always use `aeolus-services stop` to stop all the services"
puts ""
exit_service_stop
end
@@ -419,7 +419,7 @@ end
# system call fails. non catastrophic errors, such as the service
# already being off
def stop(service)
- return system('/sbin/service %s stop' % service)
+ return system('%s stop' % service)
end
# Parse and return script options
--
1.7.7.6
11 years, 6 months
[PATCH conductor] bug 839474: extraneous group name text in edit form
by Scott Seago
https://bugzilla.redhat.com/show_bug.cgi?id=839474
Remove extra group name h2 text from haml.
---
src/app/views/user_groups/edit.html.haml | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/app/views/user_groups/edit.html.haml b/src/app/views/user_groups/edit.html.haml
index 62d4be9..f51bb04 100644
--- a/src/app/views/user_groups/edit.html.haml
+++ b/src/app/views/user_groups/edit.html.haml
@@ -9,6 +9,5 @@
%section.content-section.user_groups
.content
.align-center
- %h2.user_groups= @user_group.name
= form_for @user_group, :url => user_group_path(@user_group), :html => {:class => 'generic horizontal'} do |f|
= render :partial => "form", :locals => { :form => f }
--
1.7.11.4
11 years, 6 months
[PATCH conductor] bug 807752: appropriate error message for permission denied on HWP deletion
by Scott Seago
https://bugzilla.redhat.com/show_bug.cgi?id=807752
---
src/app/controllers/hardware_profiles_controller.rb | 2 +-
src/config/locales/en.yml | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/app/controllers/hardware_profiles_controller.rb b/src/app/controllers/hardware_profiles_controller.rb
index 52532dc..1c530d8 100644
--- a/src/app/controllers/hardware_profiles_controller.rb
+++ b/src/app/controllers/hardware_profiles_controller.rb
@@ -180,7 +180,7 @@ class HardwareProfilesController < ApplicationController
flash[:notice] = t('hardware_profiles.flash.notice.more_deleted', :count => deleted.count, :deleted => deleted.join(', '))
end
unless not_deleted.empty?
- flash[:error] = t('hardware_profiles.flash.error.more_not_deleted', :count => not_deleted.count, :not_deleted => not_deleted.join(', '))
+ flash[:error] = t('hardware_profiles.flash.error.not_deleted_perms', :count => not_deleted.count, :not_deleted => not_deleted.join(', '))
end
redirect_to hardware_profiles_path
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index b1093c6..8c966c0 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -713,6 +713,9 @@ en:
more_not_deleted:
one: "%{not_deleted} could not be deleted"
other: "Could not delete the following hardware profiles: %{not_deleted}"
+ not_deleted_perms:
+ one: "Insufficient permissions to delete hardware profile %{not_deleted}"
+ other: "Insufficient permissions to remove %{count} hardware profiles %{not_deleted}"
warning:
cannot_edit_backend_hwp: "Cannot modify Provider Hardware Profiles"
cannot_delete_backend_hwp: "Cannot delete Provider Hardware Profiles"
--
1.7.11.4
11 years, 6 months
[PATCH conductor] bug 805134: Fix quota usage message on pools page.
by Scott Seago
https://bugzilla.redhat.com/show_bug.cgi?id=805134
Quota was showing up as 'x of y' where x is instances in use, and y was available instances.
This was incorrect, since "of y" implies that y is the total quota, not the free space.
---
src/app/views/pools/_scoreboard_show.html.haml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/app/views/pools/_scoreboard_show.html.haml b/src/app/views/pools/_scoreboard_show.html.haml
index 3693eeb..f858c0c 100644
--- a/src/app/views/pools/_scoreboard_show.html.haml
+++ b/src/app/views/pools/_scoreboard_show.html.haml
@@ -29,5 +29,5 @@
%dd.fraction.instance
%span.part{:title => t('pools.scoreboard.running_instances_quota')}= @statistics[:used_quota]
%span.divider.label.small.caps of
- %span.total{:title => t('pools.scoreboard.total_available_instances')}= @statistics[:available_quota] or '∞'.html_safe
+ %span.total{:title => t('pools.scoreboard.total_available_instances')}= @pool.quota.maximum_running_instances or '∞'.html_safe
-# TODO: Implement alerts and updates
--
1.7.11.4
11 years, 6 months
[PATCH conductor] bug 784108: Hide additional links for non-privileged users.
by Scott Seago
https://bugzilla.redhat.com/show_bug.cgi?id=784108
"Images Valid"/"Repair Images" links are disabled if the user doesn't have edit permission on the deployable
On the deployables list, the "add catalog" form filters the dropdown by catalogs that the user has permission to add to, and the form is hidden entirely if the user doesn't have edit rights on the deployable
On the Environments index page, the add image links and edit pool links are hidden for users without permission to perform those actions
---
src/app/controllers/deployables_controller.rb | 2 +-
src/app/helpers/deployables_helper.rb | 17 ++++++++++++-----
src/app/views/deployables/show.html.haml | 16 +++++++++-------
src/app/views/pool_families/_list.html.haml | 9 ++++++---
4 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/src/app/controllers/deployables_controller.rb b/src/app/controllers/deployables_controller.rb
index e07a603..947f578 100644
--- a/src/app/controllers/deployables_controller.rb
+++ b/src/app/controllers/deployables_controller.rb
@@ -68,7 +68,7 @@ class DeployablesController < ApplicationController
save_breadcrumb(polymorphic_path([@catalog, @deployable]), @deployable.name)
@providers = Provider.all
@catalogs_options = Catalog.list_for_user(current_session, current_user,
- Privilege::VIEW).select do |c|
+ Privilege::MODIFY).select do |c|
!(a)deployable.catalogs.include?(c) and
@deployable.catalogs.first.pool_family == c.pool_family
end
diff --git a/src/app/helpers/deployables_helper.rb b/src/app/helpers/deployables_helper.rb
index d97eaef..51a8fee 100644
--- a/src/app/helpers/deployables_helper.rb
+++ b/src/app/helpers/deployables_helper.rb
@@ -1,15 +1,22 @@
module DeployablesHelper
- def image_valid?(assembly)
+ def image_valid?(assembly, modify_perm)
edit_xml_path = edit_polymorphic_path([@catalog, @deployable], :edit_xml => true)
if @missing_images.empty? && assembly[:hwp_name].present?
- link_to t('.images_valid'), edit_xml_path, :class => 'images_valid', :id => 'edit_xml_button'
+ link_hash = {:label => '.images_valid', :class => 'images_valid'}
elsif assembly[:hwp_name].nil?
- link_to t('.repair_images'), edit_xml_path, :class => 'repair_images', :id => 'edit_xml_button'
+ link_hash = {:label => '.repair_images', :class => 'repair_images'}
elsif @missing_images.include?(assembly[:image_uuid])
- link_to t('.repair_images'), edit_xml_path, :class => 'repair_images', :id => 'edit_xml_button'
+ link_hash = {:label => '.repair_images', :class => 'repair_images'}
else
- link_to t('.images_valid'), edit_xml_path, :class => 'images_valid', :id => 'edit_xml_button'
+ link_hash = {:label => '.images_valid', :class => 'images_valid'}
+ end
+ if modify_perm
+ link_to(t(link_hash[:label]), edit_xml_path,
+ :class => link_hash[:class], :id => 'edit_xml_button')
+ else
+ content_tag(:a, t(link_hash[:label]), :class => link_hash[:class],
+ :id => 'edit_xml_button')
end
end
diff --git a/src/app/views/deployables/show.html.haml b/src/app/views/deployables/show.html.haml
index a7ee021..ade679d 100644
--- a/src/app/views/deployables/show.html.haml
+++ b/src/app/views/deployables/show.html.haml
@@ -1,8 +1,9 @@
= render :partial => 'layouts/admin_nav'
+- modify_perm = check_privilege(Privilege::MODIFY, @deployable)
%header.page-header
.obj_actions
.button-group
- - if check_privilege(Privilege::MODIFY, @deployable)
+ - if modify_perm
= link_to t('.edit'), edit_polymorphic_path([@catalog, @deployable]), :class => 'button', :id => 'edit_button'
= link_to t('.edit_xml'), edit_polymorphic_path([@catalog, @deployable], :edit_xml => true), :class => 'button', :id => 'edit_xml_button'
= button_to t('.delete'), polymorphic_path([@catalog, @deployable]), :method => 'delete', :confirm => "#{t'catalog_entries.show.confirm_delete'}", :class => 'button danger', :id => 'delete'
@@ -33,7 +34,7 @@
%tbody
- @images_details.each do |assembly|
%tr
- %td.status= image_valid?(assembly)
+ %td.status= image_valid?(assembly, modify_perm)
%td
%strong=assembly[:name]
%td.align-center=assembly[:images_count]
@@ -77,11 +78,12 @@
%section.content-section
%header
.section-controls
- = form_for(:catalog_entry, :url => catalog_entries_path) do |f|
- = f.label :catalog_id, t('.choose_catalog')
- = f.select :catalog_id, options_for_select((a)catalogs_options.map {|c| [c.name, c.id]})
- = f.hidden_field(:deployable_id, :value => @deployable.id)
- = f.submit t('.add_catalog'), :id => :add_catalog, :class => 'button pill', :disabled => @catalogs_options.empty?
+ -if modify_perm
+ = form_for(:catalog_entry, :url => catalog_entries_path) do |f|
+ = f.label :catalog_id, t('.choose_catalog')
+ = f.select :catalog_id, options_for_select((a)catalogs_options.map {|c| [c.name, c.id]})
+ = f.hidden_field(:deployable_id, :value => @deployable.id)
+ = f.submit t('.add_catalog'), :id => :add_catalog, :class => 'button pill', :disabled => @catalogs_options.empty?
%h2.catalogs= t('.catalogs')
.content
.centered
diff --git a/src/app/views/pool_families/_list.html.haml b/src/app/views/pool_families/_list.html.haml
index 0a6515d..962b8cc 100644
--- a/src/app/views/pool_families/_list.html.haml
+++ b/src/app/views/pool_families/_list.html.haml
@@ -14,8 +14,9 @@
%h2
= link_to pool_family.name, pool_family
.section-controls
- = link_to t("pools.new_pool"), new_pool_path(:pool_family_id => pool_family.id), :class => 'pool_family_button'
- - if pool_family.pools.any?
+ - if check_privilege(Privilege::CREATE, Pool, pool_family)
+ = link_to t("pools.new_pool"), new_pool_path(:pool_family_id => pool_family.id), :class => 'pool_family_button'
+ - if pool_family.pools.any? && check_privilege(Privilege::USE, pool_family)
= link_to t("images.import.import_image"), new_image_path(:environment => pool_family.id, :tab => 'import'), :class => 'new_image_button'
= link_to t("images.new.new_image"), new_image_path( :environment => pool_family.id), :class => 'new_image_button'
- unless pool_family.pools.blank?
@@ -47,7 +48,9 @@
%td= pool_stats[:available_quota].nil? ? raw('∞') : pool_stats[:available_quota]
%td= pool.enabled? ? t("pool_families.index.answer_yes") : t("pool_families.index.answer_no")
%td= link_to pool.catalogs.first.name, catalog_path(pool.catalogs.first) if pool.catalogs.any?
- %td= link_to t(:edit), edit_pool_path(pool), :class => 'pool_family_button'
+ %td
+ - if check_privilege(Privilege::MODIFY, pool)
+ = link_to t(:edit), edit_pool_path(pool), :class => 'pool_family_button'
%td= link_to t('pool_families.index.provider_selection'), pool_provider_selection_path(pool), :class => 'pool_family_button'
%tr
%td= t("pool_families.index.total_statistics")
--
1.7.11.4
11 years, 6 months
[PATCH conductor] BZ 847798 - prevent editting provider name
by jzigmund@redhat.com
From: Jozef Zigmund <jzigmund(a)redhat.com>
This is short-term fix. It prevents setting of provider name,
that causes failing image push in imagefactory.
https://bugzilla.redhat.com/show_bug.cgi?id=847798
---
src/app/controllers/providers_controller.rb | 86 +++++++++++++++++++----------
src/app/models/provider.rb | 40 ++++++++++++++
src/config/locales/activerecord/en.yml | 4 ++
src/config/locales/en.yml | 1 +
4 files changed, 101 insertions(+), 30 deletions(-)
diff --git a/src/app/controllers/providers_controller.rb b/src/app/controllers/providers_controller.rb
index f3a9302..80474de 100644
--- a/src/app/controllers/providers_controller.rb
+++ b/src/app/controllers/providers_controller.rb
@@ -121,24 +121,38 @@ class ProvidersController < ApplicationController
@provider = Provider.new(params[:provider])
- if @provider.save
+ begin
+ if @provider.save
+ @provider.assign_owner_roles(current_user)
+ respond_to do |format|
+ format.html do
+ flash[:notice] = t"providers.flash.notice.added"
+ redirect_to edit_provider_path(@provider)
+ end
+ format.xml { render :partial => 'detail', :locals => { :provider => @provider } }
+ end
+ else
+ respond_to do |format|
+ format.html do
+ flash[:warning] = t"providers.flash.error.not_added"
+ render :action => "new"
+ end
+ format.xml { render :template => 'api/validation_error', :locals => { :errors => @provider.errors }, :status => :bad_request }
+ end
+ end
+ rescue Errno::EACCES
+ Provider.skip_callback :save, :check_name
+ @provider.save
@provider.assign_owner_roles(current_user)
respond_to do |format|
format.html do
flash[:notice] = t"providers.flash.notice.added"
+ flash[:warning] = t"providers.flash.warning.check_config_file"
redirect_to edit_provider_path(@provider)
end
- format.xml { render :partial => 'detail', :locals => { :provider => @provider } }
- end
- else
- respond_to do |format|
- format.html do
- flash[:warning] = t"providers.flash.error.not_added"
- render :action => "new"
- end
- format.xml { render :template => 'api/validation_error', :locals => { :errors => @provider.errors }, :status => :bad_request }
end
end
+
end
def update
@@ -152,31 +166,43 @@ class ProvidersController < ApplicationController
return
end
- if @provider.save
- @provider.update_availability
- respond_to do |format|
- format.html do
- flash[:notice] = t"providers.flash.notice.updated"
- redirect_to edit_provider_path(@provider)
+ begin
+ if @provider.save
+ @provider.update_availability
+ respond_to do |format|
+ format.html do
+ flash[:notice] = t"providers.flash.notice.updated"
+ redirect_to edit_provider_path(@provider)
+ end
+ format.xml { render :partial => 'detail', :locals => { :provider => @provider } }
+ end
+ else
+ # we reset 'enabled' attribute to real state
+ # if save failed
+ @provider.reset_enabled!
+ respond_to do |format|
+ format.html do
+ unless @provider.connect
+ flash.now[:warning] = t"providers.flash.warning.connect_failed"
+ else
+ flash[:error] = t"providers.flash.error.not_updated"
+ end
+ load_provider_tabs
+ @alerts = provider_alerts(@provider)
+ render :action => "edit"
+ end
+ format.xml { render :template => 'api/validation_error', :locals => { :errors => @provider.errors }, :status => :bad_request }
end
- format.xml { render :partial => 'detail', :locals => { :provider => @provider } }
end
- else
- # we reset 'enabled' attribute to real state
- # if save failed
- @provider.reset_enabled!
+ rescue Errno::EACCES
+ Provider.skip_callback :save, :check_name
+ @provider.save
respond_to do |format|
format.html do
- unless @provider.connect
- flash.now[:warning] = t"providers.flash.warning.connect_failed"
- else
- flash[:error] = t"providers.flash.error.not_updated"
- end
- load_provider_tabs
- @alerts = provider_alerts(@provider)
- render :action => "edit"
+ flash[:notice] = t"providers.flash.notice.updated"
+ flash[:warning] = t"providers.flash.warning.check_config_file"
+ redirect_to edit_provider_path(@provider)
end
- format.xml { render :template => 'api/validation_error', :locals => { :errors => @provider.errors }, :status => :bad_request }
end
end
end
diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb
index 64ddb33..80f57fc 100644
--- a/src/app/models/provider.rb
+++ b/src/app/models/provider.rb
@@ -63,6 +63,28 @@ class Provider < ActiveRecord::Base
has_many :provider_priority_groups, :through => :provider_priority_group_elements
before_destroy :destroyable?
+ before_save :check_name
+
+ def check_name
+ case provider_type.name
+ when "Mock"
+ if name.starts_with?("mock")
+ true
+ else
+ errors.add(:name, :start_with_mock)
+ false
+ end
+ when "RHEV-M"
+ load_rhevm_json(name)
+ when "Amazon EC2"
+ if name.starts_with?("ec2-")
+ true
+ else
+ errors.add(:name, :start_with_ec2)
+ false
+ end
+ end
+ end
def derived_subtree(role = nil)
subtree = super(role)
@@ -144,6 +166,7 @@ class Provider < ActiveRecord::Base
end
end
if res[:failed_to_stop].blank? and res[:failed_to_terminate].blank?
+ Provider.skip_callback :save, :check_name
update_attribute(:enabled, false)
end
res
@@ -277,4 +300,21 @@ class Provider < ActiveRecord::Base
end
true
end
+
+ def load_rhevm_json(provider_name)
+ path_to_json = "/etc/imagefactory/rhevm.json"
+ if File.exists?(path_to_json)
+ json = File.read(path_to_json)
+ json_hash = ActiveSupport::JSON.decode(json)
+ if json_hash.key?(provider_name)
+ true
+ else
+ errors.add(:name, :not_found_in_config)
+ false
+ end
+ else
+ errors.add(:name, :config_not_exist)
+ false
+ end
+ end
end
diff --git a/src/config/locales/activerecord/en.yml b/src/config/locales/activerecord/en.yml
index ae2514d..9d2242e 100644
--- a/src/config/locales/activerecord/en.yml
+++ b/src/config/locales/activerecord/en.yml
@@ -360,6 +360,10 @@ en:
attributes:
name:
invalid: "must only contain: numbers, letters, spaces, '_' and '-'"
+ not_found_in_config: "was not found in configuration file"
+ config_not_exist: "cannot be verified, configuration file does not exist"
+ start_with_mock: "must start with 'mock'"
+ start_with_ec2: "must start with 'ec2-'"
url:
invalid_framework: "Must be a valid provider uri"
deltacloud_provider:
diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml
index c8fd262..2652dd5 100644
--- a/src/config/locales/en.yml
+++ b/src/config/locales/en.yml
@@ -1201,6 +1201,7 @@ en:
connect_failed: "Failed to connect to Provider"
not_stopped_instances: "Provider was not disabled. Failed to stop following instances:"
not_terminated_instances: "Provider was not disabled. Failed to change status to 'stopped' for following instances:"
+ check_config_file: Cannot check if provider name is right. Please check config file
alerts:
type:
critical: Critical
--
1.7.11.4
11 years, 6 months