Browse Source

Venu & kashyap | added the filter used for cloud bursting

changes/85/139985/1
Kashyap Kopparam 4 years ago
parent
commit
6e80663904
1 changed files with 46 additions and 0 deletions
  1. 46
    0
      cloud_burst_filter.py

+ 46
- 0
cloud_burst_filter.py View File

@@ -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
+
16
+from oslo.config import cfg
17
+from nova import db
18
+from nova.openstack.common import log as logging
19
+from nova.scheduler import filters
20
+
21
+opts = [
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
+]
27
+CONF = cfg.CONF
28
+CONF.register_opts(opts)
29
+
30
+LOG = logging.getLogger(__name__)
31
+
32
+class 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

Loading…
Cancel
Save