Change to use node resource_class

Currently, we use node_type property to link with the flavors, but
ironic node's resource_class field just want to do such thing, so
we can just change to use it instead of adding a new node property.

Change-Id: I535606ce05299037a7bd5aacdcd7869ca5f855c4
Closes-Bug: #1695819
This commit is contained in:
Zhenguo Niu 2017-06-05 14:51:37 +08:00
parent 1eadb8e248
commit deb70c7a63
9 changed files with 15 additions and 15 deletions

View File

@ -173,10 +173,10 @@ function create_flavor {
}
function update_ironic_node_type {
function update_ironic_node_resource_class {
ironic_nodes=$(openstack baremetal node list -c UUID -f value)
for node in ${ironic_nodes};do
openstack baremetal node set --property node_type=${MOGAN_DEFAULT_FLAVOR} ${node}
openstack --os-baremetal-api-version latest baremetal node set --resource-class ${MOGAN_DEFAULT_FLAVOR} ${node}
done
}
@ -200,8 +200,8 @@ if is_service_enabled mogan; then
start_mogan
echo_summary "Creating flavor"
create_flavor
echo_summary "Updating ironic node properties"
update_ironic_node_type
echo_summary "Updating ironic node resource class"
update_ironic_node_resource_class
fi
if [[ "$1" == "unstack" ]]; then

View File

@ -156,7 +156,7 @@ def upgrade():
sa.Column('cpus', sa.Integer(), nullable=False),
sa.Column('memory_mb', sa.Integer(), nullable=False),
sa.Column('hypervisor_type', sa.String(length=255), nullable=False),
sa.Column('node_type', sa.String(length=255), nullable=False),
sa.Column('resource_class', sa.String(length=80), nullable=False),
sa.Column('availability_zone', sa.String(length=255), nullable=True),
sa.Column('node_uuid', sa.String(length=36), nullable=False),
sa.Column('extra_specs', sa.Text(), nullable=True),

View File

@ -102,7 +102,7 @@ class ComputeNode(Base):
cpus = Column(Integer, nullable=False)
memory_mb = Column(Integer, nullable=False)
hypervisor_type = Column(String(255), nullable=False)
node_type = Column(String(255), nullable=False)
resource_class = Column(String(80), nullable=False)
availability_zone = Column(String(255), nullable=True)
node_uuid = Column(String(36), nullable=False)
extra_specs = Column(db_types.JsonEncodedDict)

View File

@ -115,7 +115,6 @@ class IronicDriver(base_driver.BaseEngineDriver):
properties['capabilities'] = node.properties.get('capabilities')
properties['availability_zone'] = \
node.properties.get('availability_zone')
properties['node_type'] = node.properties.get('node_type')
return properties
def _node_resource(self, node):
@ -125,7 +124,6 @@ class IronicDriver(base_driver.BaseEngineDriver):
cpus = properties['cpus']
memory_mb = properties['memory_mb']
availability_zone = properties['availability_zone']
node_type = properties['node_type']
nodes_extra_specs = {}
@ -148,7 +146,7 @@ class IronicDriver(base_driver.BaseEngineDriver):
'cpus': cpus,
'memory_mb': memory_mb,
'hypervisor_type': self._get_hypervisor_type(),
'node_type': str(node_type),
'resource_class': str(node.resource_class),
'extra_specs': nodes_extra_specs,
'node_uuid': str(node.uuid),
'ports': node.ports,

View File

@ -158,6 +158,8 @@ class EngineManager(base_manager.BaseEngineManager):
# Record compute nodes to db
for uuid, node in nodes.items():
if node.get('resource_class') is None:
continue
# initialize the compute node object, creating it
# if it does not already exist.
self._init_compute_node(context, node)

View File

@ -34,7 +34,7 @@ class ComputeNode(base.MoganObject, object_base.VersionedObjectDictCompat):
'cpus': object_fields.IntegerField(),
'memory_mb': object_fields.IntegerField(),
'hypervisor_type': object_fields.StringField(),
'node_type': object_fields.StringField(),
'resource_class': object_fields.StringField(),
'availability_zone': object_fields.StringField(nullable=True),
'node_uuid': object_fields.UUIDField(read_only=True),
'ports': object_fields.ObjectField('ComputePortList', nullable=True),
@ -81,7 +81,7 @@ class ComputeNode(base.MoganObject, object_base.VersionedObjectDictCompat):
self.obj_reset_changes()
def update_from_driver(self, node):
keys = ["cpus", "memory_mb", "hypervisor_type", "node_type",
keys = ["cpus", "memory_mb", "hypervisor_type", "resource_class",
"availability_zone", "node_uuid", "extra_specs"]
for key in keys:
if key in node:

View File

@ -38,7 +38,7 @@ class NodeState(object):
self.capabilities = node.extra_specs
self.availability_zone = node.availability_zone \
or CONF.engine.default_availability_zone
self.flavor = node.node_type
self.flavor = node.resource_class
self.ports = node.ports
def consume_from_request(self, context):
@ -46,7 +46,7 @@ class NodeState(object):
objects.ComputeNode.consume_node(context, self.node_uuid)
def __repr__(self):
return "<Node:%s node_type:%s>" % (self.node_uuid, self.flavor)
return "<Node:%s resource_class:%s>" % (self.node_uuid, self.flavor)
class NodeManager(object):

View File

@ -91,7 +91,7 @@ def get_test_compute_node(**kw):
'cpus': kw.get('cpus', 16),
'memory_mb': kw.get('memory_mb', 10240),
'hypervisor_type': kw.get('hypervisor_type', 'ironic'),
'node_type': kw.get('node_type', 'gold'),
'resource_class': kw.get('resource_class', 'gold'),
'availability_zone': kw.get('availability_zone', 'test_az'),
'node_uuid': kw.get('node_uuid',
'f978ef48-d4af-4dad-beec-e6174309bc71'),

View File

@ -383,7 +383,7 @@ class _TestObject(object):
# The fingerprint values should only be changed if there is a version bump.
expected_object_fingerprints = {
'Server': '1.0-f3ef6866ef8072b063014a2c49060c6d',
'ComputeNode': '1.0-36221253681d9acb88efe2a9113071c7',
'ComputeNode': '1.0-586e7eaadd4ec88a0506c4238ebdd7a5',
'ComputeNodeList': '1.0-33a2e1bb91ad4082f9f63429b77c1244',
'ComputePort': '1.0-ca4c1817ad7324286813f2cfcdcf802e',
'ComputePortList': '1.0-33a2e1bb91ad4082f9f63429b77c1244',