Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map flavor to cluster quota validation against the new big flavor #95

Open
wants to merge 5 commits into
base: stable/queens-m3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nova/compute/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def _check_metadata_properties_quota(self, context, metadata=None):
raise exception.InvalidMetadata(reason=msg)
num_metadata = len(metadata)
try:
objects.Quotas.limit_check(context, metadata_items=num_metadata)
objects.Quotas.limit_check(context,
metadata_items=num_metadata)
except exception.OverQuota as exc:
quota_metadata = exc.kwargs['quotas']['metadata_items']
raise exception.MetadataLimitExceeded(allowed=quota_metadata)
Expand Down Expand Up @@ -1073,7 +1074,6 @@ def _create_instance(self, context, instance_type,
strategy being performed and schedule the instance(s) for
creation.
"""

# Normalize and setup some parameters
if reservation_id is None:
reservation_id = utils.generate_uid('r')
Expand Down
6 changes: 6 additions & 0 deletions nova/conf/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,12 @@

* not to be confused with: ``multi_instance_display_name_template``
"""),
cfg.StrOpt('big_vm_flavor',
default="m1.flavor_2",
help="""
Flavor name for creating "big" virtual machines. The amount of virtual
machines created from this flavor will be counted against the cluster.
"""),
]


Expand Down
1 change: 1 addition & 0 deletions nova/conf/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@
"RetryFilter",
"AvailabilityZoneFilter",
"ComputeFilter",
"BigFlavorFilter",
"ComputeCapabilitiesFilter",
"ImagePropertiesFilter",
"ServerGroupAntiAffinityFilter",
Expand Down
4 changes: 4 additions & 0 deletions nova/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,10 @@ class OverQuota(NovaException):
msg_fmt = _("Quota exceeded for resources: %(overs)s")


class FlavorOverQuota(NovaException):
msg_fmt = _("Quota exceeded for resources: %(overs)s")


class SecurityGroupNotFound(NotFound):
msg_fmt = _("Security group %(security_group_id)s not found.")

Expand Down
7 changes: 6 additions & 1 deletion nova/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ def limit_check(self, context, resources, values, project_id=None,
user_id=user_id,
project_quotas=project_quotas)

quota_data = {
'quotas': quotas,
'user_quotas': user_quotas
}

# Check the quotas and construct a list of the resources that
# would be put over limit by the desired values
overs = [key for key, val in values.items()
Expand All @@ -498,6 +503,7 @@ def limit_check(self, context, resources, values, project_id=None,
)
raise exception.OverQuota(overs=sorted(overs), quotas=quotas,
usages={}, headroom=headroom)
return quota_data

def limit_check_project_and_user(self, context, resources,
project_values=None, user_values=None,
Expand Down Expand Up @@ -1223,7 +1229,6 @@ def limit_check(self, context, project_id=None, user_id=None, **values):
is admin and admin wants to impact on
common user.
"""

return self._driver.limit_check(context,
self.combined_resources(context),
values, project_id=project_id,
Expand Down
87 changes: 87 additions & 0 deletions nova/scheduler/filters/big_flavor_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Copyright (c) 2012 OpenStack Foundation
# 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.

from oslo_log import log as logging
from oslo_config import cfg

from nova.i18n import _LW
from nova import objects
from nova.scheduler import filters
from nova import servicegroup
from nova.context import get_admin_context
from nova.db.api import aggregate_get_by_host

LOG = logging.getLogger(__name__)
CONF = cfg.CONF

class BigFlavorFilter(filters.BaseHostFilter):
"""Filter for specific amount of VM's from a specific custom flavor
Flavor name to check is registered in `nova.conf`
"""

RUN_ON_REBUILD = False

def __init__(self):
self.servicegroup_api = servicegroup.API()
self._context = None

# Host state does not change within a request
run_filter_once_per_request = True

def host_passes(self, host_state, spec_obj):
self._context = self._context or get_admin_context()
flavor_check = self._schedule_big_flavor(self._context, spec_obj,
host_state.host)

if flavor_check == False:
return False

return True

def get_flavor_quota_limit(self, context, host, flavor_extra_specs):

aggregate_list = objects.AggregateList.get_by_host(context, host)
flavor_quota = None

for aggr in aggregate_list:
for aggr_host in aggr.hosts:
if aggr_host == host:
if "support_big_flavor" in aggr.metadata:
if bool(aggr.metadata["support_big_flavor"]):
flavor_quota = aggr.metadata['flavor_quota']
break
return flavor_quota

def _schedule_big_flavor(self, context, spec_obj, host):
instance_list = objects.InstanceList.get_by_host(context, host)
flavor_name = spec_obj.flavor.name
flavor_extra_specs = spec_obj.flavor.extra_specs
big_flavor_quota = 0

flavor_quota_limit = self.get_flavor_quota_limit(context, host,
flavor_extra_specs)

for i in instance_list:
if i.get_flavor().name == CONF.big_vm_flavor:
big_flavor_quota += 1
if flavor_name == CONF.big_vm_flavor:
if big_flavor_quota >= \
int(flavor_quota_limit):
return False
else:
LOG.info("Flavor used is %s. Skipping flavor filtering" %
flavor_name)

return True