forked from openstack/nova
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rough implementation of mixed filter-weigher for feedback
- Loading branch information
1 parent
0b35204
commit 27311c3
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright (c) 2025 SAP SE | ||
# All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
""" | ||
""" | ||
import requests | ||
from oslo_log import log as logging | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def call_external_scheduler_api(host_objs, spec_obj, url): | ||
"""Reorder and filter hosts using an external scheduler service.""" | ||
if not url or not host_objs: | ||
return host_objs | ||
# TODO: Check utils.request_is_rebuild(spec) here? | ||
json_data = { | ||
"hosts": [ o.obj_to_primitive() for o in host_objs ], | ||
"request_spec": spec_obj.obj_to_primitive(), | ||
} | ||
try: | ||
response = requests.post(url, json=json_data, timeout=10) | ||
response.raise_for_status() | ||
except requests.RequestException as e: | ||
LOG.error("Failed to call external scheduler API: %s", e) | ||
return host_objs | ||
response_json = response.json() | ||
# We expect the service to return an ordered list | ||
# of host names. This list can also be empty. | ||
host_names = response_json.get("hosts", []) | ||
return [ o for o in host_objs if o.host in host_names ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters