diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 0c0101227..5592f0936 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -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. diff --git a/nodepool/driver/openstack/config.py b/nodepool/driver/openstack/config.py index 5c1982cf2..02b47abdd 100644 --- a/nodepool/driver/openstack/config.py +++ b/nodepool/driver/openstack/config.py @@ -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 @@ -162,6 +163,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)) @@ -248,6 +250,7 @@ class OpenStackProviderConfig(ProviderConfig): 'auto-floating-ip': bool, 'max-cores': int, 'max-servers': int, + 'max-ram': int, 'labels': [pool_label], 'availability-zones': [str], } diff --git a/nodepool/driver/openstack/handler.py b/nodepool/driver/openstack/handler.py index 5c2ab9512..27a21712a 100644 --- a/nodepool/driver/openstack/handler.py +++ b/nodepool/driver/openstack/handler.py @@ -357,6 +357,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)) @@ -389,6 +390,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() diff --git a/nodepool/tests/fixtures/node_quota_pool_ram.yaml b/nodepool/tests/fixtures/node_quota_pool_ram.yaml new file mode 100644 index 000000000..608ff8d32 --- /dev/null +++ b/nodepool/tests/fixtures/node_quota_pool_ram.yaml @@ -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 diff --git a/nodepool/tests/test_launcher.py b/nodepool/tests/test_launcher.py index 69327dcb3..ef8784a24 100644 --- a/nodepool/tests/test_launcher.py +++ b/nodepool/tests/test_launcher.py @@ -234,6 +234,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',