summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKashyap Kopparam <kashyapk@thoughtworks.com>2014-11-12 15:32:00 +0530
committerKashyap Kopparam <kashyapk@thoughtworks.com>2014-11-12 15:32:00 +0530
commit6e806639043bab3cf4df64a86c066075227cec98 (patch)
tree73ef269ced7e58e02a87b66364f85f6821ca1cdf
parent33ba46398cb8ff60f5333190e4b6e7c438de7656 (diff)
Venu & kashyap | added the filter used for cloud bursting
-rw-r--r--cloud_burst_filter.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/cloud_burst_filter.py b/cloud_burst_filter.py
new file mode 100644
index 0000000..610e5fe
--- /dev/null
+++ b/cloud_burst_filter.py
@@ -0,0 +1,46 @@
1# Copyright (c) 2014 ThoughtWorks
2# All Rights Reserved.
3#
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
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
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
14# under the License.
15
16from oslo.config import cfg
17from nova import db
18from nova.openstack.common import log as logging
19from nova.scheduler import filters
20
21opts = [
22 cfg.BoolOpt('cloud_burst',
23 help='Switch to enable could bursting'),
24 cfg.StrOpt('cloud_burst_availability_zone',
25 help='The availability zone of only compute hosts with the public cloud driver'),
26]
27CONF = cfg.CONF
28CONF.register_opts(opts)
29
30LOG = logging.getLogger(__name__)
31
32class CloudBurstFilter(filters.BaseHostFilter):
33 """Filter for cloud burst availability zone"""
34
35 run_filter_once_per_request = True
36
37 def host_passes(self, host_state, filter_properties):
38 context = filter_properties['context'].elevated()
39 metadata = db.aggregate_metadata_get_by_host(context, host_state.host, key='availability_zone')
40
41 if CONF.cloud_burst:
42 return CONF.cloud_burst_availability_zone in metadata['availability_zone']
43 else:
44 return CONF.cloud_burst_availability_zone not in metadata['availability_zone']
45
46 return True