metal/inventory/inventory/inventory/objects/pci_device.py
John Kung bd998017d5 SysInv Decoupling: Create Inventory Service
Create host inventory services (api, conductor and agent) and
python-inventoryclient.

The inventory service collects the host resources and provides a
REST API and client to expose the host resources.

Create plugin for integration with system configuration (sysinv)
service.

This is the initial inventory service infratructure commit.
Puppet configuration, SM integration and host integration with
sysinv(systemconfig) changes are pending and planned to be
delivered in future commits.

Tests Performed:
 Verify the changes are inert on config_controller installation
 and provisioning.
     Puppet and spec changes are required in order to create keystone,
     database and activate inventory services.

 Unit tests performed (when puppet configuration for keystone, database
 is applied):
     Trigger host configure_check, configure signals into
         systemconfig(sysinv).

     Verify python-inventoryclient and api service:
         Disks and related storage resources are pending.
         inventory host-cpu-list/show
         inventory host-device-list/show/modify
         inventory host-ethernetport-list/show
         inventory host-lldp-neighbor-list
         inventory host-lldp-agent-list/show
         inventory host-memory-list/show
         inventory host-node-list/show
         inventory host-port-list/show

     Tox Unit tests:
         inventory: pep8
         python-inventoryclient: py27, pep8, cover, pylint

Change-Id: I744ac0de098608c55b9356abf180cc36601cfb8d
Story: 2002950
Task: 22952
Signed-off-by: John Kung <john.kung@windriver.com>
2018-12-06 13:17:35 -05:00

100 lines
3.7 KiB
Python

#
# Copyright (c) 2016 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# coding=utf-8
#
from inventory.db import api as db_api
from inventory.objects import base
from inventory.objects import fields as object_fields
from oslo_versionedobjects import base as object_base
@base.InventoryObjectRegistry.register
class PCIDevice(base.InventoryObject,
object_base.VersionedObjectDictCompat):
dbapi = db_api.get_instance()
fields = {
'id': object_fields.IntegerField(nullable=True),
'uuid': object_fields.UUIDField(nullable=True),
'host_id': object_fields.IntegerField(nullable=True),
'host_uuid': object_fields.UUIDField(nullable=True),
'name': object_fields.StringField(nullable=True),
'pciaddr': object_fields.StringField(nullable=True),
'pclass_id': object_fields.StringField(nullable=True),
'pvendor_id': object_fields.StringField(nullable=True),
'pdevice_id': object_fields.StringField(nullable=True),
'pclass': object_fields.StringField(nullable=True),
'pvendor': object_fields.StringField(nullable=True),
'pdevice': object_fields.StringField(nullable=True),
'psvendor': object_fields.StringField(nullable=True),
'psdevice': object_fields.StringField(nullable=True),
'numa_node': object_fields.IntegerField(nullable=True),
'sriov_totalvfs': object_fields.IntegerField(nullable=True),
'sriov_numvfs': object_fields.IntegerField(nullable=True),
'sriov_vfs_pci_address': object_fields.StringField(nullable=True),
'driver': object_fields.StringField(nullable=True),
'enabled': object_fields.BooleanField(nullable=True),
'extra_info': object_fields.StringField(nullable=True),
}
_foreign_fields = {
'host_uuid': 'host:uuid'
}
@classmethod
def get_by_uuid(cls, context, uuid):
db_pci_device = cls.dbapi.pci_device_get(uuid)
return cls._from_db_object(context, cls(), db_pci_device)
def save_changes(self, context, updates):
self.dbapi.pci_device_update(self.uuid, updates)
@classmethod
def list(cls, context, limit=None, marker=None, sort_key=None,
sort_dir=None):
"""Return a list of CPU objects.
:param cls: the :class:`CPU`
:param context: Security context.
:param limit: maximum number of resources to return in a single result.
:param marker: pagination marker for large data sets.
:param sort_key: column to sort results by.
:param sort_dir: direction to sort. "asc" or "desc".
:returns: a list of :class:`CPU` object.
"""
db_pci_devices = cls.dbapi.pci_device_get_list(
limit=limit, marker=marker, sort_key=sort_key, sort_dir=sort_dir)
return cls._from_db_object_list(context, db_pci_devices)
@classmethod
def get_by_host(cls, context, host_uuid,
limit=None, marker=None,
sort_key=None, sort_dir=None):
db_pci_devices = cls.dbapi.pci_device_get_by_host(
host_uuid,
limit=limit,
marker=marker,
sort_key=sort_key,
sort_dir=sort_dir)
return cls._from_db_object_list(context, db_pci_devices)
def create(self, context=None):
"""Create a CPU record in the DB.
Column-wise updates will be made based on the result of
self.what_changed().
:param context: Security context.
"""
values = self.do_version_changes_for_db()
db_pci_device = self.dbapi.pci_device_create(values)
return self._from_db_object(self._context, self, db_pci_device)