Class: Berta::Utils::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/berta/utils/filter.rb

Overview

Base Filter class, filters out invalid states

Direct Known Subclasses

ExcludeFilter, IncludeFilter

Constant Summary collapse

IGNORED_STATES =

VM states to ignore

%w[PENDING HOLD].freeze

Instance Method Summary collapse

Constructor Details

#initialize(ids, users, groups, clusters) ⇒ Filter

Constructs Filter object.

Parameters:

  • ids (Array<Numeric>)

    Ids of VM to filter

  • users (Array<String>)

    User names to filter

  • groups (Array<String>)

    Group names to filter

  • clusters (Array<OpenNebula::Cluster>)

    Clusters to filter



14
15
16
17
18
19
20
21
# File 'lib/berta/utils/filter.rb', line 14

def initialize(ids, users, groups, clusters)
  @ids = ids || []
  @users = users || []
  @groups = groups || []
  @clusters = clusters || []
  logger.debug "Filter type: #{self.class}"
  log_filter
end

Instance Method Details

#run(vmhs) ⇒ Array<Berta::VirtualMachineHandler>

Execute this filter

Parameters:

Returns:



27
28
29
30
31
32
33
# File 'lib/berta/utils/filter.rb', line 27

def run(vmhs)
  fvmhs = vmhs.select { |vmh| takes_resources?(vmh) }
  logger.debug "Filtered based on RESOURCE: #{(vmhs - fvmhs).map { |vmh| vmh.handle.id }}"
  fvmhs = filter(fvmhs)
  logger.debug "VMS after filter : #{fvmhs.map { |vmh| vmh.handle.id }}"
  fvmhs
end