-
Notifications
You must be signed in to change notification settings - Fork 27
Provider Selection Algorithms
Provider selection algorithms allow administrators to define complex provider selection for each pool. This article is about how to write a custom algorithm.
Since the administrator can enable multiple strategies, these strategies should be written in a chainable manner. To allow chaining of the strategies you just have to include the following modules in your strategy class:
<code class="ruby">
include ProviderSelection::ChainableStrategy::InstanceMethods
extend ProviderSelection::ChainableStrategy::ClassMethods
</code>
The first module handles the chaining of the strategies. The second module adds some common methods to the class, e.g. properties which may contain the edit path for the strategy.
Next, you should define the calculate method:
<code class="ruby">
def calculate
rank = @strategies.calculate
# Modify the rank object
rank
end
</code>
This code will first make a call to the strategy chain before the current strategy to calculate the rank. To alter the ranking you should modify the rank object and it should be returned from method.
The rank contains all the priority groups. The priority groups are
ordered by their score from low to high. It also has special priority
group: the default_priority_group
which contains all the valid
matches. Your algorithm should use the matches from this group to
avoid the duplication of the filtering logic. Also worth noting that
the default_priority_group
has a score of 10000, way much higher than
the user defined priority groups whose score can be from the [–100, 100]
interval. For now, a match has a provider_account
,
hardware_profile
, instance_hwp
and a score
attributes. In the
future it can be extended with provider realm, provider image and more.
You can put your strategy class in
vendor/provider_selection/strategies/strategy_name/strategy_name.rb
and it will be automatically loaded.
To define the translated name for the strategy just create a new entry
in the config/locales/strategies
directory:
<code class="yaml">
en:
strategies:
strategy_name:
name: 'Strategy Name'
</code>
http://www.aeolusproject.org/docs/presentations/2012-nov-conference/ProviderSelection.pdf