Add labels info to compute node
Add labels info to compute node Change-Id: If7cdc25c40d695fc87c7fbe9a5ada185893b07f3 Partially-Implements: blueprint expose-host-capabilities
This commit is contained in:
@@ -606,8 +606,15 @@ class DockerDriver(driver.ContainerDriver):
|
||||
os_type = info['OSType']
|
||||
os = info['OperatingSystem']
|
||||
kernel_version = info['KernelVersion']
|
||||
labels = {}
|
||||
slabels = info['Labels']
|
||||
if slabels:
|
||||
for l in slabels:
|
||||
kv = l.split("=")
|
||||
label = {kv[0]: kv[1]}
|
||||
labels.update(label)
|
||||
return (total, running, paused, stopped, cpus,
|
||||
architecture, os_type, os, kernel_version)
|
||||
architecture, os_type, os, kernel_version, labels)
|
||||
|
||||
def get_cpu_used(self):
|
||||
cpu_used = 0
|
||||
|
||||
@@ -202,7 +202,7 @@ class ContainerDriver(object):
|
||||
node.mem_available = mem_ava // units.Ki
|
||||
info = self.get_host_info()
|
||||
(total, running, paused, stopped, cpus,
|
||||
architecture, os_type, os, kernel_version) = info
|
||||
architecture, os_type, os, kernel_version, labels) = info
|
||||
node.total_containers = total
|
||||
node.running_containers = running
|
||||
node.paused_containers = paused
|
||||
@@ -214,3 +214,4 @@ class ContainerDriver(object):
|
||||
node.kernel_version = kernel_version
|
||||
cpu_used = self.get_cpu_used()
|
||||
node.cpu_used = cpu_used
|
||||
node.labels = labels
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# 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.
|
||||
|
||||
"""Add container hosts label info
|
||||
|
||||
Revision ID: 17ab8b533cc8
|
||||
Revises: 04ba87af76bb
|
||||
Create Date: 2017-05-03 14:00:06.170629
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '17ab8b533cc8'
|
||||
down_revision = '04ba87af76bb'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
import zun
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column('compute_node',
|
||||
sa.Column('labels',
|
||||
zun.db.sqlalchemy.models.JSONEncodedDict(),
|
||||
nullable=True))
|
||||
@@ -283,3 +283,4 @@ class ComputeNode(Base):
|
||||
os_type = Column(String(32), nullable=True)
|
||||
os = Column(String(64), nullable=True)
|
||||
kernel_version = Column(String(128), nullable=True)
|
||||
labels = Column(JSONEncodedDict)
|
||||
|
||||
@@ -24,7 +24,8 @@ class ComputeNode(base.ZunPersistentObject, base.ZunObject):
|
||||
# Version 1.2: Add total, running, pasued, stopped containers columns
|
||||
# Version 1.3: Add cpus, cpu_used
|
||||
# Version 1.4: Add host operating system info
|
||||
VERSION = '1.4'
|
||||
# Version 1.5: Add host labels info
|
||||
VERSION = '1.5'
|
||||
|
||||
fields = {
|
||||
'uuid': fields.UUIDField(read_only=True, nullable=False),
|
||||
@@ -43,6 +44,7 @@ class ComputeNode(base.ZunPersistentObject, base.ZunObject):
|
||||
'os_type': fields.StringField(nullable=True),
|
||||
'os': fields.StringField(nullable=True),
|
||||
'kernel_version': fields.StringField(nullable=True),
|
||||
'labels': fields.DictOfStringsField(nullable=True),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -459,9 +459,10 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
'Architecture': 'x86_64',
|
||||
'OSType': 'linux',
|
||||
'OperatingSystem': 'CentOS',
|
||||
'KernelVersion': '3.10.0-123'}
|
||||
'KernelVersion': '3.10.0-123',
|
||||
'Labels': ['dev.type=product']}
|
||||
(total, running, paused, stopped, cpus, architecture,
|
||||
os_type, os, kernel_version) = self.driver.get_host_info()
|
||||
os_type, os, kernel_version, labels) = self.driver.get_host_info()
|
||||
self.assertEqual(10, total)
|
||||
self.assertEqual(8, running)
|
||||
self.assertEqual(0, paused)
|
||||
@@ -471,6 +472,7 @@ class TestDockerDriver(base.DriverTestCase):
|
||||
self.assertEqual('linux', os_type)
|
||||
self.assertEqual('CentOS', os)
|
||||
self.assertEqual('3.10.0-123', kernel_version)
|
||||
self.assertEqual({"dev.type": "product"}, labels)
|
||||
|
||||
def test_get_cpu_used(self):
|
||||
self.mock_docker.containers = mock.Mock()
|
||||
@@ -589,7 +591,8 @@ class TestNovaDockerDriver(base.DriverTestCase):
|
||||
conf.CONF.set_override('floating_cpu_set', "0")
|
||||
mock_mem.return_value = (100 * units.Ki, 50 * units.Ki, 50 * units.Ki)
|
||||
mock_info.return_value = (10, 8, 0, 2, 48, 'x86_64', 'linux',
|
||||
'CentOS', '3.10.0-123')
|
||||
'CentOS', '3.10.0-123',
|
||||
{'dev.type': 'product'})
|
||||
mock_cpu_used.return_value = 1.0
|
||||
node_obj = objects.ComputeNode()
|
||||
self.driver.get_available_resources(node_obj)
|
||||
@@ -607,3 +610,4 @@ class TestNovaDockerDriver(base.DriverTestCase):
|
||||
self.assertEqual('linux', node_obj.os_type)
|
||||
self.assertEqual('CentOS', node_obj.os)
|
||||
self.assertEqual('3.10.0-123', node_obj.kernel_version)
|
||||
self.assertEqual({'dev.type': 'product'}, node_obj.labels)
|
||||
|
||||
@@ -274,6 +274,7 @@ def get_test_compute_node(**kw):
|
||||
'os_type': kw.get('os_type', 'linux'),
|
||||
'os': kw.get('os', 'Centos'),
|
||||
'kernel_version': kw.get('kernel_version', '3.10.0-123.el7.x86_64'),
|
||||
'labels': kw.get('labels', {"dev.type": "product"}),
|
||||
'created_at': kw.get('created_at'),
|
||||
'updated_at': kw.get('updated_at'),
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ object_data = {
|
||||
'ResourceClass': '1.1-d661c7675b3cd5b8c3618b68ba64324e',
|
||||
'ResourceProvider': '1.0-92b427359d5a4cf9ec6c72cbe630ee24',
|
||||
'ZunService': '1.0-2a19ab9987a746621b2ada02d8aadf22',
|
||||
'ComputeNode': '1.4-d73867b95a525c60cbbb5e98c0dc0dd6',
|
||||
'ComputeNode': '1.5-0d6ff86fbdc03859b77f1092e785ce10',
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user