Support ram limit per pool

Nodepool supports pretty generic limits on tenant and pool side. Make
the ram limit configurable.

Change-Id: Ie9f1ece75106fa936a737ed2b289188d9a594fb0
This commit is contained in:
Tobias Henkel 2017-09-15 01:04:36 +02:00
parent 4b51ac6f3e
commit 2f183926ca
5 changed files with 52 additions and 0 deletions

View File

@ -432,6 +432,11 @@ Example::
limit the number of servers. If not defined nodepool can create as many
servers the tenant allows.
``max-ram``
Maximum ram usable from this pool. This can be used to limit the amount of
ram allocated by nodepool. If not defined nodepool can use as much ram as
the tenant allows.
``availability-zones`` (list)
A list of availability zones to use.

View File

@ -63,6 +63,7 @@ class ProviderPool(ConfigValue):
if (other.labels != self.labels or
other.max_cores != self.max_cores or
other.max_servers != self.max_servers or
other.max_ram != self.max_ram or
other.azs != self.azs or
other.networks != self.networks):
return False
@ -159,6 +160,7 @@ class OpenStackProviderConfig(ProviderConfig):
self.pools[pp.name] = pp
pp.max_cores = pool.get('max-cores', None)
pp.max_servers = pool.get('max-servers', None)
pp.max_ram = pool.get('max-ram', None)
pp.azs = pool.get('availability-zones')
pp.networks = pool.get('networks', [])
pp.auto_floating_ip = bool(pool.get('auto-floating-ip', True))
@ -242,6 +244,7 @@ class OpenStackProviderConfig(ProviderConfig):
'auto-floating-ip': bool,
'max-cores': int,
'max-servers': int,
'max-ram': int,
'labels': [pool_label],
'availability-zones': [str],
}

View File

@ -356,6 +356,7 @@ class OpenStackNodeRequestHandler(NodeRequestHandler):
# to math.inf representing infinity that can be calculated with.
pool_quota = QuotaInformation(cores=self.pool.max_cores,
instances=self.pool.max_servers,
ram=self.pool.max_ram,
default=math.inf)
pool_quota.subtract(
self.manager.estimatedNodepoolQuotaUsed(self.zk, self.pool))
@ -388,6 +389,7 @@ class OpenStackNodeRequestHandler(NodeRequestHandler):
# to math.inf representing infinity that can be calculated with.
pool_quota = QuotaInformation(cores=self.pool.max_cores,
instances=self.pool.max_servers,
ram=self.pool.max_ram,
default=math.inf)
pool_quota.subtract(needed_quota)
return pool_quota.non_negative()

View File

@ -0,0 +1,39 @@
elements-dir: .
images-dir: '{images_dir}'
zookeeper-servers:
- host: {zookeeper_host}
port: {zookeeper_port}
chroot: {zookeeper_chroot}
labels:
- name: fake-label
min-ready: 0
providers:
- name: fake-provider
cloud: fake
driver: fake
region-name: fake-region
rate: 0.0001
diskimages:
- name: fake-image
pools:
- name: main
max-ram: 16384
labels:
- name: fake-label
diskimage: fake-image
min-ram: 8192
diskimages:
- name: fake-image
elements:
- fedora
- vm
release: 21
env-vars:
TMPDIR: /opt/dib_tmp
DIB_IMAGE_CACHE: /opt/dib_cache
DIB_CLOUD_IMAGES: http://download.fedoraproject.org/pub/fedora/linux/releases/test/21-Beta/Cloud/Images/x86_64/
BASE_IMAGE_FILE: Fedora-Cloud-Base-20141029-21_Beta.x86_64.qcow2

View File

@ -233,6 +233,9 @@ class TestLauncher(tests.DBTestCase):
self._test_node_assignment_at_quota(
config='node_quota_pool_instances.yaml')
def test_node_assignment_at_pool_quota_ram(self):
self._test_node_assignment_at_quota(
config='node_quota_pool_ram.yaml')
def test_node_assignment_at_cloud_cores_quota(self):
self._test_node_assignment_at_quota(config='node_quota_cloud.yaml',