Skip to content

Commit

Permalink
Add evm_owner, tenant, group to orch stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Oct 30, 2018
1 parent af11356 commit 2751fb1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
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
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

0 comments on commit 2751fb1

Please sign in to comment.