1
# Copyright (c) 2015 OpenStack Foundation.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
19
class BaseResourceFilter(object):
20
"""Encapsulate logic that is specific to the resource type."""
22
def filter_agents(self, plugin, context, resource):
23
"""Return the agents that can host the resource."""
25
def bind(self, context, agents, resource_id):
26
"""Bind the resource to the agents."""
27
with context.session.begin(subtransactions=True):
30
# Load is being incremented here to reflect latest agent load
31
# even within the agent report interval. This will be very
32
# much necessary when bulk resource creation happens within a
33
# agent report interval time.
34
# NOTE: The resource being bound might or might not be of the
35
# same type which is accounted for the load. It isn't a
36
# problem because "+ 1" here does not meant to predict
37
# precisely what the load of the agent will be. The value will
38
# be corrected by the agent on the next report interval.
39
res['load'] = agent.load + 1