class Prof::EnvironmentManager

Attributes

pcf_environment[R]

Public Class Methods

new(pcf_environment) click to toggle source
# File lib/prof/environment_manager.rb, line 15
def initialize(pcf_environment)
  @pcf_environment = pcf_environment
end

Public Instance Methods

destroy_orphan_deployments() click to toggle source
# File lib/prof/environment_manager.rb, line 37
def destroy_orphan_deployments
  orphans = orphan_deployments
  return unless orphans.any?

  puts "Removing orphaned deployment(s) '#{orphans.join(', ')}'"
  orphans.each do |deployment_name|
    bosh_director.delete_deployment(deployment_name, force: true)
  end
end
destroy_orphan_tiles() click to toggle source
# File lib/prof/environment_manager.rb, line 29
def destroy_orphan_tiles
  orphans = orphan_tiles
  return unless orphans.any?

  puts "Removing orphaned tile(s) #{orphans.map(&:name).join(', ')}"
  ops_manager.uninstall_tiles(orphans)
end
isolate_cloud_foundry() { || ... } click to toggle source
# File lib/prof/environment_manager.rb, line 19
def isolate_cloud_foundry(&_block)
  cloud_foundry.create_and_target_org(cf_org_name)
  cloud_foundry.create_and_target_space(cf_space_name)
  cloud_foundry.setup_permissive_security_group(cf_org_name, cf_space_name)

  yield

  cloud_foundry.delete_org(cf_org_name)
end
reset() click to toggle source
# File lib/prof/environment_manager.rb, line 51
def reset
  raise OpsManagerNotConfigured, "Please configure #{ops_manager.url}" unless ops_manager.cf_installed?

  destroy_orphan_tiles
  destroy_orphan_deployments
  uninstall_tiles
end
uninstall_tiles() click to toggle source
# File lib/prof/environment_manager.rb, line 47
def uninstall_tiles
  ops_manager.uninstall_tiles(ops_manager.product_tiles)
end

Private Instance Methods

bosh_director() click to toggle source
# File lib/prof/environment_manager.rb, line 89
def bosh_director
  pcf_environment.bosh_director
end
cf_org_name() click to toggle source
# File lib/prof/environment_manager.rb, line 63
def cf_org_name
  @cf_org_name ||= "cf-org-#{SecureRandom.hex(4)}"
end
cf_space_name() click to toggle source
# File lib/prof/environment_manager.rb, line 67
def cf_space_name
  @cf_space_name ||= "cf-space-#{SecureRandom.hex(4)}"
end
cloud_foundry() click to toggle source
# File lib/prof/environment_manager.rb, line 71
def cloud_foundry
  pcf_environment.cloud_foundry
end
ops_manager() click to toggle source
# File lib/prof/environment_manager.rb, line 75
def ops_manager
  pcf_environment.ops_manager
end
orphan_deployments() click to toggle source
# File lib/prof/environment_manager.rb, line 79
def orphan_deployments
  tile_guids = pcf_environment.ops_manager.tiles.map(&:guid)
  pcf_environment.bosh_director.deployment_names.reject { |deployment_name| tile_guids.include?(deployment_name) }
end
orphan_tiles() click to toggle source
# File lib/prof/environment_manager.rb, line 84
def orphan_tiles
  bosh_deployment_names = pcf_environment.bosh_director.deployment_names
  pcf_environment.ops_manager.product_tiles.reject { |tile| bosh_deployment_names.include?(tile.guid) }
end