-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add evm_owner, tenant, group to orch stacks
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
db/migrate/20181010134649_add_evm_owner_to_orchestration_stacks.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddEvmOwnerToOrchestrationStacks < ActiveRecord::Migration[5.0] | ||
def change | ||
add_reference :orchestration_stacks, :evm_owner, :type => :bigint, :index => true | ||
add_reference :orchestration_stacks, :miq_group, :type => :bigint, :index => true | ||
add_reference :orchestration_stacks, :tenant, :type => :bigint, :index => true | ||
end | ||
end |
39 changes: 39 additions & 0 deletions
39
db/migrate/20181016140921_migrate_orch_stacks_to_have_ownership_concept.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class MigrateOrchStacksToHaveOwnershipConcept < ActiveRecord::Migration[5.0] | ||
class ExtManagementSystem < ApplicationRecord | ||
def tenant_identity | ||
User.super_admin.tap { |u| u.current_group = tenant.default_miq_group } | ||
end | ||
end | ||
|
||
class Service < ApplicationRecord | ||
end | ||
|
||
class OrchestrationStack < ApplicationRecord | ||
end | ||
|
||
def up | ||
say_with_time("Migrating existing orchestration stacks to have direct owners, groups, tenant") do | ||
OrchestrationStack.select { |orch_stack| orch_stack.service.present? }.each do |stack| | ||
$log.info("Setting orchestration stack #{stack.id} owner to #{stack.service.tenant_identity.id}, the owner of service #{stack.service.id}") | ||
stack.evm_owner_id = stack.service.tenant_identity.id | ||
stack.tenant_id = stack.service.tenant_identity.current_tenant.id | ||
stack.miq_group_id = stack.service.tenant_identity.current_group.id | ||
stack.save | ||
end | ||
OrchestrationStack.where.not(:ems_id => nil).find_each do |stack| | ||
$log.info("Setting orchestration stack #{stack.id} owner to #{stack.ext_management_system.tenant_identity.id}, the owner of ems #{stack.ext_management_system.id}") | ||
stack.evm_owner_id = stack.ext_management_system.tenant_identity.id | ||
stack.tenant_id = stack.ext_management_system.tenant_identity.current_tenant.id | ||
stack.miq_group_id = stack.ext_management_system.tenant_identity.current_group.id | ||
stack.save | ||
end | ||
OrchestrationStack.where(:ems_id => nil).find_each do |stack| | ||
$log.info("Orchestration stack #{stack.id} has neither an associated service nor an ems to set ownership") | ||
end | ||
end | ||
end | ||
|
||
def down | ||
OrchestrationStack.update_all(:evm_owner_id => nil, :tenant_id => nil, :miq_group_id => nil) | ||
end | ||
end |