diff --git a/zun/db/sqlalchemy/alembic/versions/d0c606fdec3c_add_disk_info_to_compute_node.py b/zun/db/sqlalchemy/alembic/versions/d0c606fdec3c_add_disk_info_to_compute_node.py new file mode 100644 index 000000000..3fbba4877 --- /dev/null +++ b/zun/db/sqlalchemy/alembic/versions/d0c606fdec3c_add_disk_info_to_compute_node.py @@ -0,0 +1,36 @@ +# 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 disk total and used to compute node + +Revision ID: d0c606fdec3c +Revises: 3f49fa520409 +Create Date: 2018-03-06 18:44:27.630273 + +""" + +# revision identifiers, used by Alembic. +revision = 'd0c606fdec3c' +down_revision = '3f49fa520409' +branch_labels = None +depends_on = None + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + with op.batch_alter_table('compute_node', schema=None) as batch_op: + batch_op.add_column(sa.Column('disk_total', + sa.Integer(), nullable=False)) + batch_op.add_column(sa.Column('disk_used', + sa.Integer(), nullable=False)) diff --git a/zun/db/sqlalchemy/models.py b/zun/db/sqlalchemy/models.py index 21c96bd80..3b9f3d227 100644 --- a/zun/db/sqlalchemy/models.py +++ b/zun/db/sqlalchemy/models.py @@ -326,6 +326,8 @@ class ComputeNode(Base): # Json string PCI Stats # '[{"vendor_id":"8086", "product_id":"1234", "count":3 }, ...]' pci_stats = Column(Text) + disk_total = Column(Integer, nullable=False, default=0) + disk_used = Column(Integer, nullable=False, default=0) class Capsule(Base): diff --git a/zun/objects/compute_node.py b/zun/objects/compute_node.py index 99f9129f0..8ebe3fcae 100644 --- a/zun/objects/compute_node.py +++ b/zun/objects/compute_node.py @@ -31,7 +31,8 @@ class ComputeNode(base.ZunPersistentObject, base.ZunObject): # Version 1.7: Change get_by_hostname to get_by_name # Version 1.8: Add pci_device_pools to compute node # Version 1.9: Change PciDevicePoolList to ObjectField - VERSION = '1.9' + # Version 1.10: Add disk_total, disk_used columns + VERSION = '1.10' fields = { 'uuid': fields.UUIDField(read_only=True, nullable=False), @@ -56,6 +57,8 @@ class ComputeNode(base.ZunPersistentObject, base.ZunObject): # pci_stats field in the database 'pci_device_pools': fields.ObjectField('PciDevicePoolList', nullable=True), + 'disk_total': fields.IntegerField(nullable=False), + 'disk_used': fields.IntegerField(nullable=False), } @staticmethod diff --git a/zun/tests/unit/db/utils.py b/zun/tests/unit/db/utils.py index 6c0549f5e..9872defb9 100644 --- a/zun/tests/unit/db/utils.py +++ b/zun/tests/unit/db/utils.py @@ -346,6 +346,8 @@ def get_test_compute_node(**kwargs): 'labels': kwargs.get('labels', {"dev.type": "product"}), 'created_at': kwargs.get('created_at'), 'updated_at': kwargs.get('updated_at'), + 'disk_total': kwargs.get('disk_total', 80), + 'disk_used': kwargs.get('disk_used', 20), } diff --git a/zun/tests/unit/objects/test_objects.py b/zun/tests/unit/objects/test_objects.py index d91521ee1..24d305031 100644 --- a/zun/tests/unit/objects/test_objects.py +++ b/zun/tests/unit/objects/test_objects.py @@ -355,7 +355,7 @@ object_data = { 'ZunService': '1.2-deff2a74a9ce23baa231ae12f39a6189', 'Capsule': '1.6-7238a80b4ef34e219c135fa72d0adc06', 'PciDevice': '1.1-6e3f0851ad1cf12583e6af4df1883979', - 'ComputeNode': '1.9-e8536102d3b28cb3378e9e26f508cd72', + 'ComputeNode': '1.10-707fc7af76adf27f967eebeb6e4dd3ba', 'PciDevicePool': '1.0-3f5ddc3ff7bfa14da7f6c7e9904cc000', 'PciDevicePoolList': '1.0-15ecf022a68ddbb8c2a6739cfc9f8f5e', 'ContainerPCIRequest': '1.0-b060f9f9f734bedde79a71a4d3112ee0',