Add New Driver OVO.

Driver OVO is used for drivers to report to agent. It contains the
layered objects as well as the functions in order to operate the
DB. The design of driver OVO is reference to:
https://docs.google.com/document/d/
1XLQtvyGJeEgo3ztBQiufWLF-E7S7yGLaYrme8iUPtA0/edit

Change-Id: I997a251673e1b7cfdb035d58889781c6943b3db7
This commit is contained in:
Coco 2018-12-10 12:31:29 -05:00
parent e6028de00f
commit 620bf0ca31
10 changed files with 206 additions and 0 deletions

View File

@ -16,6 +16,12 @@
CONDUCTOR_TOPIC = 'cyborg-conductor'
AGENT_TOPIC = 'cyborg-agent'
DEVICE_GPU = 'GPU'
DEVICE_FPGA = 'FPGA'
ARQ_STATES = (ARQINITIAL, ARQBOUND, ARQUNBOUND, ARQBINDFAILED) = \
('Initial', 'Bound', 'Unbound', 'BindFailed')
# Device type
DEVICE_TYPE = (DEVICE_GPU, DEVICE_FPGA)

View File

@ -33,3 +33,4 @@ def register_all():
__import__('cyborg.objects.control_path')
__import__('cyborg.objects.device')
__import__('cyborg.objects.device_profile')
__import__('cyborg.objects.driver_objects')

View File

@ -176,3 +176,16 @@ def obj_equal_prims(obj_1, obj_2, ignore=None):
prim_1 = _strip(obj_1.obj_to_primitive(), keys)
prim_2 = _strip(obj_2.obj_to_primitive(), keys)
return prim_1 == prim_2
class DriverObjectBase(CyborgObject):
@staticmethod
def _from_db_object(obj, db_obj):
fields = obj.fields
fields.pop("updated_at")
fields.pop("created_at")
for field in fields:
obj[field] = db_obj[field]
obj.obj_reset_changes()
return obj

View File

@ -0,0 +1,5 @@
__import__('cyborg.objects.driver_objects.driver_device')
__import__('cyborg.objects.driver_objects.driver_attribute')
__import__('cyborg.objects.driver_objects.driver_attach_handle')
__import__('cyborg.objects.driver_objects.driver_deployable')
__import__('cyborg.objects.driver_objects.driver_controlpath_id')

View File

@ -0,0 +1,31 @@
# Copyright 2018 Lenovo (Beijing) Co.,LTD.
# All Rights Reserved.
#
# 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.
from oslo_versionedobjects import base as object_base
from cyborg.objects import fields as object_fields
from cyborg.objects import base
@base.CyborgObjectRegistry.register
class DriverAttachHandle(base.DriverObjectBase,
object_base.VersionedObjectDictCompat):
# Version 1.0: Initial version
VERSION = '1.0'
fields = {
'attach_type': object_fields.StringField(nullable=False),
# PCI BDF or mediated device ID...
'attach_info': object_fields.StringField(nullable=False),
}

View File

@ -0,0 +1,30 @@
# Copyright 2018 Lenovo (Beijing) Co.,LTD.
# All Rights Reserved.
#
# 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.
from oslo_versionedobjects import base as object_base
from cyborg.objects import base
from cyborg.objects import fields as object_fields
@base.CyborgObjectRegistry.register
class DriverAttribute(base.DriverObjectBase,
object_base.VersionedObjectDictCompat):
# Version 1.0: Initial version
VERSION = '1.0'
fields = {
'key': object_fields.StringField(nullable=False),
'value': object_fields.StringField(nullable=False)
}

View File

@ -0,0 +1,31 @@
# Copyright 2018 Lenovo (Beijing) Co.,LTD.
# All Rights Reserved.
#
# 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.
from oslo_versionedobjects import base as object_base
from cyborg.objects import fields as object_fields
from cyborg.objects import base
@base.CyborgObjectRegistry.register
class DriverControlPathID(base.DriverObjectBase,
object_base.VersionedObjectDictCompat):
# Version 1.0: Initial version
VERSION = '1.0'
fields = {
'cpid_type': object_fields.StringField(nullable=False),
# PCI BDF, PowerVM device, etc.
'cpid_info': object_fields.StringField(nullable=False),
}

View File

@ -0,0 +1,38 @@
# Copyright 2018 Lenovo (Beijing) Co.,LTD.
# All Rights Reserved.
#
# 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.
from oslo_versionedobjects import base as object_base
from cyborg.objects import base
from cyborg.objects import fields as object_fields
from cyborg.objects.driver_objects.driver_attribute import DriverAttribute
from cyborg.objects.driver_objects.driver_attach_handle import \
DriverAttachHandle
@base.CyborgObjectRegistry.register
class DriverDeployable(base.DriverObjectBase,
object_base.VersionedObjectDictCompat):
# Version 1.0: Initial version
VERSION = '1.0'
fields = {
'num_accelerators': object_fields.IntegerField(nullable=False),
'attribute_list': object_fields.ListOfObjectsField(
'DriverAttribute', default=[], nullable=True),
# TODO: add field related to local_memory or just store in the
# attribute list?
'attach_handle_list': object_fields.ListOfObjectsField(
'DriverAttachHandle', default=[], nullable=True)
}

View File

@ -0,0 +1,47 @@
# Copyright 2018 Lenovo (Beijing) Co.,LTD.
# All Rights Reserved.
#
# 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.
from oslo_versionedobjects import base as object_base
from cyborg.objects import base
from cyborg.objects import fields as object_fields
from cyborg.objects.driver_objects.driver_deployable import DriverDeployable
from cyborg.objects.driver_objects.driver_controlpath_id import \
DriverControlPathID
@base.CyborgObjectRegistry.register
class DriverDevice(base.DriverObjectBase,
object_base.VersionedObjectDictCompat):
# Version 1.0: Initial version
VERSION = '1.0'
fields = {
# standard borad info: vendor_id, product_id, remotable?
'vendor': object_fields.StringField(nullable=False),
'model': object_fields.StringField(nullable=False),
'type': object_fields.DeviceTypeField(nullable=False),
'std_board_info': object_fields.StringField(nullable=True),
# vendor board info should be a dict: like acc_topology which is used
# for driver-specific resource provider.
'vendor_board_info': object_fields.StringField(nullable=True),
'hostname': object_fields.StringField(nullable=False),
# Each controlpath_id corresponds to a different PF. For now
# we are sticking with a single cpid.
'controlpath_id': object_fields.ObjectField('DriverControlPathID',
nullable=False),
'deployable_list': object_fields.ListOfObjectsField('DriverDeployable',
default=[],
nullable=False)
}

View File

@ -42,3 +42,7 @@ class ARQState(object_fields.Enum):
class ARQStateField(object_fields.BaseEnumField):
AUTO_TYPE = ARQState()
class DeviceTypeField(object_fields.AutoTypedField):
AUTO_TYPE = object_fields.Enum(valid_values=constants.DEVICE_TYPE)