Add host operating system info to compute node

Add arch, os type, os name, kernel version to compute node.

Change-Id: Iac4078101308cf5239722211494689d5dfde0655
Partially-Implements: blueprint expose-host-capabilities
This commit is contained in:
ShunliZhou
2017-04-27 09:05:09 +08:00
parent 1ab12584cb
commit 08ace17ac2
8 changed files with 84 additions and 7 deletions

View File

@@ -566,7 +566,12 @@ class DockerDriver(driver.ContainerDriver):
running = info['ContainersRunning']
stopped = info['ContainersStopped']
cpus = info['NCPU']
return total, running, paused, stopped, cpus
architecture = info['Architecture']
os_type = info['OSType']
os = info['OperatingSystem']
kernel_version = info['KernelVersion']
return (total, running, paused, stopped, cpus,
architecture, os_type, os, kernel_version)
def get_cpu_used(self):
cpu_used = 0

View File

@@ -201,11 +201,16 @@ class ContainerDriver(object):
node.mem_free = mem_free // units.Ki
node.mem_available = mem_ava // units.Ki
info = self.get_host_info()
(total, running, paused, stopped, cpus) = info
(total, running, paused, stopped, cpus,
architecture, os_type, os, kernel_version) = info
node.total_containers = total
node.running_containers = running
node.paused_containers = paused
node.stopped_containers = stopped
node.cpus = cpus
node.architecture = architecture
node.os_type = os_type
node.os = os
node.kernel_version = kernel_version
cpu_used = self.get_cpu_used()
node.cpu_used = cpu_used

View File

@@ -0,0 +1,40 @@
# 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 host operating system info
Revision ID: 04ba87af76bb
Revises: 8c3d80e18eb5
Create Date: 2017-04-26 17:37:09.544598
"""
# revision identifiers, used by Alembic.
revision = '04ba87af76bb'
down_revision = '8c3d80e18eb5'
branch_labels = None
depends_on = None
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('compute_node',
sa.Column('architecture', sa.String(32), nullable=True))
op.add_column('compute_node',
sa.Column('os_type', sa.String(32), nullable=True))
op.add_column('compute_node',
sa.Column('os', sa.String(64), nullable=True))
op.add_column('compute_node',
sa.Column('kernel_version',
sa.String(128), nullable=True))

View File

@@ -279,3 +279,7 @@ class ComputeNode(Base):
stopped_containers = Column(Integer, nullable=False, default=0)
cpus = Column(Integer, nullable=False, default=0)
cpu_used = Column(Float, nullable=False, default=0.0)
architecture = Column(String(32), nullable=True)
os_type = Column(String(32), nullable=True)
os = Column(String(64), nullable=True)
kernel_version = Column(String(128), nullable=True)

View File

@@ -23,7 +23,8 @@ class ComputeNode(base.ZunPersistentObject, base.ZunObject):
# Version 1.1: Add mem_total, mem_free, mem_available columns
# Version 1.2: Add total, running, pasued, stopped containers columns
# Version 1.3: Add cpus, cpu_used
VERSION = '1.3'
# Version 1.4: Add host operating system info
VERSION = '1.4'
fields = {
'uuid': fields.UUIDField(read_only=True, nullable=False),
@@ -38,6 +39,10 @@ class ComputeNode(base.ZunPersistentObject, base.ZunObject):
'stopped_containers': fields.IntegerField(nullable=False),
'cpus': fields.IntegerField(nullable=False),
'cpu_used': fields.FloatField(nullable=False),
'architecture': fields.StringField(nullable=True),
'os_type': fields.StringField(nullable=True),
'os': fields.StringField(nullable=True),
'kernel_version': fields.StringField(nullable=True),
}
@staticmethod

View File

@@ -446,13 +446,22 @@ class TestDockerDriver(base.DriverTestCase):
'ContainersPaused': 0,
'ContainersRunning': 8,
'ContainersStopped': 2,
'NCPU': 48}
total, running, paused, stopped, cpus = self.driver.get_host_info()
'NCPU': 48,
'Architecture': 'x86_64',
'OSType': 'linux',
'OperatingSystem': 'CentOS',
'KernelVersion': '3.10.0-123'}
(total, running, paused, stopped, cpus, architecture,
os_type, os, kernel_version) = self.driver.get_host_info()
self.assertEqual(10, total)
self.assertEqual(8, running)
self.assertEqual(0, paused)
self.assertEqual(2, stopped)
self.assertEqual(48, cpus)
self.assertEqual('x86_64', architecture)
self.assertEqual('linux', os_type)
self.assertEqual('CentOS', os)
self.assertEqual('3.10.0-123', kernel_version)
def test_get_cpu_used(self):
self.mock_docker.containers = mock.Mock()
@@ -570,7 +579,8 @@ class TestNovaDockerDriver(base.DriverTestCase):
mock_output.return_value = LSCPU_ON
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)
mock_info.return_value = (10, 8, 0, 2, 48, 'x86_64', 'linux',
'CentOS', '3.10.0-123')
mock_cpu_used.return_value = 1.0
node_obj = objects.ComputeNode()
self.driver.get_available_resources(node_obj)
@@ -584,3 +594,7 @@ class TestNovaDockerDriver(base.DriverTestCase):
self.assertEqual(2, node_obj.stopped_containers)
self.assertEqual(48, node_obj.cpus)
self.assertEqual(1.0, node_obj.cpu_used)
self.assertEqual('x86_64', node_obj.architecture)
self.assertEqual('linux', node_obj.os_type)
self.assertEqual('CentOS', node_obj.os)
self.assertEqual('3.10.0-123', node_obj.kernel_version)

View File

@@ -270,6 +270,10 @@ def get_test_compute_node(**kw):
'stopped_containers': kw.get('stopped_containers', 2),
'cpus': kw.get('cpus', 48),
'cpu_used': kw.get('cpu_used', 6.5),
'architecture': kw.get('architecture', 'x86_64'),
'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'),
'created_at': kw.get('created_at'),
'updated_at': kw.get('updated_at'),
}

View File

@@ -362,7 +362,7 @@ object_data = {
'ResourceClass': '1.1-d661c7675b3cd5b8c3618b68ba64324e',
'ResourceProvider': '1.0-92b427359d5a4cf9ec6c72cbe630ee24',
'ZunService': '1.0-2a19ab9987a746621b2ada02d8aadf22',
'ComputeNode': '1.3-f0b82f7f9593bdbb59b2c2bd07040c5f',
'ComputeNode': '1.4-d73867b95a525c60cbbb5e98c0dc0dd6',
}