diff --git a/cyborg/common/constants.py b/cyborg/common/constants.py index aa5aaaea..bd41db42 100644 --- a/cyborg/common/constants.py +++ b/cyborg/common/constants.py @@ -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) diff --git a/cyborg/objects/__init__.py b/cyborg/objects/__init__.py index 0b1bac2b..ef7f1dd0 100644 --- a/cyborg/objects/__init__.py +++ b/cyborg/objects/__init__.py @@ -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') diff --git a/cyborg/objects/base.py b/cyborg/objects/base.py index 74afede4..b8a6de6b 100644 --- a/cyborg/objects/base.py +++ b/cyborg/objects/base.py @@ -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 diff --git a/cyborg/objects/driver_objects/__init__.py b/cyborg/objects/driver_objects/__init__.py new file mode 100644 index 00000000..9de19710 --- /dev/null +++ b/cyborg/objects/driver_objects/__init__.py @@ -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') diff --git a/cyborg/objects/driver_objects/driver_attach_handle.py b/cyborg/objects/driver_objects/driver_attach_handle.py new file mode 100644 index 00000000..196b59b4 --- /dev/null +++ b/cyborg/objects/driver_objects/driver_attach_handle.py @@ -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), + } diff --git a/cyborg/objects/driver_objects/driver_attribute.py b/cyborg/objects/driver_objects/driver_attribute.py new file mode 100644 index 00000000..7def8ed3 --- /dev/null +++ b/cyborg/objects/driver_objects/driver_attribute.py @@ -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) + } diff --git a/cyborg/objects/driver_objects/driver_controlpath_id.py b/cyborg/objects/driver_objects/driver_controlpath_id.py new file mode 100644 index 00000000..ce2585da --- /dev/null +++ b/cyborg/objects/driver_objects/driver_controlpath_id.py @@ -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), + } diff --git a/cyborg/objects/driver_objects/driver_deployable.py b/cyborg/objects/driver_objects/driver_deployable.py new file mode 100644 index 00000000..4d1842e6 --- /dev/null +++ b/cyborg/objects/driver_objects/driver_deployable.py @@ -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) + } diff --git a/cyborg/objects/driver_objects/driver_device.py b/cyborg/objects/driver_objects/driver_device.py new file mode 100644 index 00000000..8372c7bb --- /dev/null +++ b/cyborg/objects/driver_objects/driver_device.py @@ -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) + } diff --git a/cyborg/objects/fields.py b/cyborg/objects/fields.py index 2fbd9fb5..1e12032f 100644 --- a/cyborg/objects/fields.py +++ b/cyborg/objects/fields.py @@ -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)