class Oneds::Mrproper::Cleaners::SystemCleaner

Attributes

datastore_manager[R]
vm_manager[R]

Public Class Methods

new(client, dry_run) click to toggle source
Calls superclass method Oneds::Mrproper::Cleaners::Cleaner::new
# File lib/oneds/mrproper/cleaners/system_cleaner.rb, line 7
def initialize(client, dry_run)
  super(dry_run)

  @datastore_manager = Oneds::Mrproper::One::Managers::DatastoreManager.new client
  @vm_manager = Oneds::Mrproper::One::Managers::VirtualMachineManager.new client
end

Public Instance Methods

clean() click to toggle source
# File lib/oneds/mrproper/cleaners/system_cleaner.rb, line 14
def clean
  logger.info 'Cleaning system datastores'
  datastores = datastore_manager.system_datastores
  datastores.each { |datastore| clean_datastore datastore }
end
clean_datastore(datastore) click to toggle source
# File lib/oneds/mrproper/cleaners/system_cleaner.rb, line 20
def clean_datastore(datastore)
  ds_path = datastore['BASE_PATH']
  logger.info "Cleaning datastore #{datastore.name.inspect} with path #{ds_path.inspect}"

  unless File.exist? ds_path
    logger.warn "Path #{ds_path.inspect} not found on headnode, skipping"
    return
  end

  fs_vm_ids = Dir.entries(ds_path).select { |dir| dir =~ /^[0-9]*$/ }.sort
  logger.debug "Directories available on filesystem: #{fs_vm_ids.inspect}"

  remove_vm_directories fs_vm_ids, ds_path
end

Private Instance Methods

remove_vm_directories(directories, ds_path) click to toggle source
# File lib/oneds/mrproper/cleaners/system_cleaner.rb, line 37
def remove_vm_directories(directories, ds_path)
  directories.each do |vm_id|
    vm = vm_manager.virtual_machine(vm_id)
    if vm && vm_manager.done?(vm)
      logger.info "Removing virtual machine directory with id #{vm.id.inspect}"
      FileUtils.rm_r File.join(ds_path, vm_id) unless dry_run
    end
  end
end