P7: Fix pep8 error in cyborg/objects and cyborg/image
Change-Id: If62755aad795319fec9d016d950c9c6d26881522
This commit is contained in:
parent
369abe8dd0
commit
ac4c4ea15c
@ -42,13 +42,12 @@ import six
|
||||
from six.moves import range
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
import cyborg.conf
|
||||
from cyborg.common import exception
|
||||
from cyborg.common import utils
|
||||
import cyborg.conf
|
||||
import cyborg.image.download as image_xfers
|
||||
from cyborg import objects
|
||||
from cyborg.objects import fields
|
||||
from cyborg import service_auth
|
||||
from cyborg.common import utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -18,7 +18,6 @@ from oslo_serialization import jsonutils
|
||||
from oslo_versionedobjects import base as object_base
|
||||
|
||||
from cyborg.db import api as dbapi
|
||||
from cyborg import objects
|
||||
from cyborg.objects import base
|
||||
from cyborg.objects import fields as object_fields
|
||||
|
||||
|
@ -65,7 +65,7 @@ class AttachHandle(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
return obj_ah
|
||||
|
||||
@classmethod
|
||||
def list(cls, context, filters={}):
|
||||
def list(cls, context, filters=None):
|
||||
"""Return a list of AttachHandle objects."""
|
||||
if filters:
|
||||
sort_dir = filters.pop('sort_dir', 'desc')
|
||||
|
@ -41,7 +41,7 @@ class Attribute(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
}
|
||||
|
||||
def create(self, context):
|
||||
"""Create a attribute record in the DB."""
|
||||
"""Create an attribute record in the DB."""
|
||||
if self.deployable_id is None:
|
||||
raise exception.AttributeInvalid()
|
||||
|
||||
@ -59,20 +59,19 @@ class Attribute(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
|
||||
@classmethod
|
||||
def get_by_deployable_id(cls, context, deployable_id):
|
||||
"""Get a attribute by deployable_id"""
|
||||
"""Get an attribute by deployable_id"""
|
||||
db_attr = cls.dbapi.attribute_get_by_deployable_id(context,
|
||||
deployable_id)
|
||||
return cls._from_db_object_list(db_attr, context)
|
||||
|
||||
@classmethod
|
||||
def get_by_filter(cls, context, filters):
|
||||
"""Get a attribute by specified filters"""
|
||||
"""Get an attribute by specified filters"""
|
||||
db_attr = cls.dbapi.attribute_get_by_filter(context, filters)
|
||||
return cls._from_db_object_list(db_attr, context)
|
||||
|
||||
def save(self, context):
|
||||
"""Update a attribute record in the DB."""
|
||||
updates = self.obj_get_changes()
|
||||
"""Update an attribute record in the DB."""
|
||||
db_attr = self.dbapi.attribute_update(context,
|
||||
self.uuid,
|
||||
self.key,
|
||||
@ -80,7 +79,7 @@ class Attribute(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
self._from_db_object(self, db_attr)
|
||||
|
||||
def destroy(self, context):
|
||||
"""Delete a attribute from the DB."""
|
||||
"""Delete an attribute from the DB."""
|
||||
self.dbapi.attribute_delete(context, self.uuid)
|
||||
self.obj_reset_changes()
|
||||
|
||||
|
@ -69,9 +69,8 @@ class CyborgObject(object_base.VersionedObject):
|
||||
attr = attr.as_dict()
|
||||
return attr
|
||||
|
||||
return dict((k, _attr_as_dict(k))
|
||||
for k in self.fields
|
||||
if self.obj_attr_is_set(k))
|
||||
return {k: _attr_as_dict(k)
|
||||
for k in self.fields if self.obj_attr_is_set(k)}
|
||||
|
||||
@staticmethod
|
||||
def _from_db_object(obj, db_obj):
|
||||
|
@ -14,8 +14,8 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
from oslo_versionedobjects import base as object_base
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_versionedobjects import base as object_base
|
||||
|
||||
from cyborg.db import api as dbapi
|
||||
from cyborg.objects import base
|
||||
@ -65,7 +65,7 @@ class ControlpathID(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
return obj_cp
|
||||
|
||||
@classmethod
|
||||
def list(cls, context, filters={}):
|
||||
def list(cls, context, filters=None):
|
||||
"""Return a list of ControlpathID objects."""
|
||||
if filters:
|
||||
sort_dir = filters.pop('sort_dir', 'desc')
|
||||
|
@ -16,11 +16,10 @@
|
||||
from oslo_log import log as logging
|
||||
from oslo_versionedobjects import base as object_base
|
||||
|
||||
from cyborg.common import exception
|
||||
from cyborg.db import api as dbapi
|
||||
from cyborg.objects.attribute import Attribute
|
||||
from cyborg.objects import base
|
||||
from cyborg.objects import fields as object_fields
|
||||
from cyborg.objects.attribute import Attribute
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -100,7 +99,7 @@ class Deployable(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
return obj_dep
|
||||
|
||||
@classmethod
|
||||
def list(cls, context, filters={}):
|
||||
def list(cls, context, filters=None):
|
||||
"""Return a list of Deployable objects."""
|
||||
if filters:
|
||||
sort_dir = filters.pop('sort_dir', 'desc')
|
||||
@ -141,8 +140,8 @@ class Deployable(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
|
||||
def update(self, context, updates):
|
||||
"""Update provided key, value pairs"""
|
||||
db_dep = self.dbapi.deployable_update(context, self.uuid,
|
||||
updates)
|
||||
self.dbapi.deployable_update(context, self.uuid,
|
||||
updates)
|
||||
|
||||
def destroy(self, context):
|
||||
"""Delete a Deployable from the DB."""
|
||||
|
@ -20,7 +20,6 @@ from cyborg.common import constants
|
||||
from cyborg.db import api as dbapi
|
||||
from cyborg.objects import base
|
||||
from cyborg.objects import fields as object_fields
|
||||
from cyborg.objects.control_path import ControlpathID
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -60,7 +59,7 @@ class Device(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
return obj_device
|
||||
|
||||
@classmethod
|
||||
def list(cls, context, filters={}):
|
||||
def list(cls, context, filters=None):
|
||||
"""Return a list of Device objects."""
|
||||
if filters:
|
||||
sort_dir = filters.pop('sort_dir', 'desc')
|
||||
@ -90,7 +89,8 @@ class Device(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
@classmethod
|
||||
def get_list_by_hostname(cls, context, hostname):
|
||||
"""get device object list from the hostname. return [] if not
|
||||
exist."""
|
||||
exist.
|
||||
"""
|
||||
dev_filter = {'hostname': hostname}
|
||||
device_obj_list = Device.list(context, dev_filter)
|
||||
return device_obj_list
|
||||
@ -98,7 +98,8 @@ class Device(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
@classmethod
|
||||
def get_by_device_id(cls, context, device_id):
|
||||
"""get device object list from the device ID. return [] if not
|
||||
exist."""
|
||||
exist.
|
||||
"""
|
||||
dev_filter = {'device_id': device_id}
|
||||
device_obj_list = Device.list(context, dev_filter)
|
||||
return device_obj_list
|
||||
|
@ -51,7 +51,7 @@ class DeviceProfile(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
|
||||
def create(self, context):
|
||||
"""Create a Device Profile record in the DB."""
|
||||
# TODO validate with a JSON schema
|
||||
# TODO() validate with a JSON schema
|
||||
if 'name' not in self:
|
||||
raise exception.ObjectActionError(action='create',
|
||||
reason='name is required')
|
||||
@ -69,7 +69,7 @@ class DeviceProfile(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
obj_devprof = cls._from_db_object(cls(context), db_devprof)
|
||||
return obj_devprof
|
||||
|
||||
# TODO add filters, limits, pagination, etc.
|
||||
# TODO() add filters, limits, pagination, etc.
|
||||
@classmethod
|
||||
def list(cls, context):
|
||||
"""Return a list of Device Profile objects."""
|
||||
|
@ -13,11 +13,12 @@
|
||||
# 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
|
||||
from cyborg.objects.attach_handle import AttachHandle
|
||||
from oslo_log import log as logging
|
||||
from oslo_versionedobjects import base as object_base
|
||||
|
||||
from cyborg.objects.attach_handle import AttachHandle
|
||||
from cyborg.objects import base
|
||||
from cyborg.objects import fields as object_fields
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -37,7 +38,8 @@ class DriverAttachHandle(base.DriverObjectBase,
|
||||
|
||||
def create(self, context, deployable_id, cpid_id):
|
||||
"""Create a driver-side AttachHandle object, call AttachHandle
|
||||
Object to store in DB."""
|
||||
Object to store in DB.
|
||||
"""
|
||||
attach_handle_obj = AttachHandle(context=context,
|
||||
deployable_id=deployable_id,
|
||||
cpid_id=cpid_id,
|
||||
|
@ -14,9 +14,10 @@
|
||||
# under the License.
|
||||
|
||||
from oslo_versionedobjects import base as object_base
|
||||
|
||||
from cyborg.objects.attribute import Attribute
|
||||
from cyborg.objects import base
|
||||
from cyborg.objects import fields as object_fields
|
||||
from cyborg.objects.attribute import Attribute
|
||||
|
||||
|
||||
@base.CyborgObjectRegistry.register
|
||||
@ -32,7 +33,8 @@ class DriverAttribute(base.DriverObjectBase,
|
||||
|
||||
def create(self, context, deployable_id):
|
||||
"""Convert driver-side Attribute into Attribute Object so as to
|
||||
store in DB."""
|
||||
store in DB.
|
||||
"""
|
||||
attr_obj = Attribute()
|
||||
attr_obj.deployable_id = deployable_id
|
||||
attr_obj.set_key_value_pair(self.key, self.value)
|
||||
|
@ -1,60 +1,62 @@
|
||||
# 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
|
||||
from cyborg.objects.control_path import ControlpathID
|
||||
|
||||
|
||||
@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)
|
||||
}
|
||||
|
||||
def create(self, context, device_id):
|
||||
"""Create a driver-side ControlPathID for drivers. Call
|
||||
ControlpathID object to store in DB."""
|
||||
cpid_obj = ControlpathID(context=context,
|
||||
device_id=device_id,
|
||||
cpid_type=self.cpid_type,
|
||||
cpid_info=self.cpid_info)
|
||||
cpid_obj.create(context)
|
||||
return cpid_obj
|
||||
|
||||
def destroy(self, context, device_id):
|
||||
cpid_obj = ControlpathID.get_by_device_id_cpidinfo(context,
|
||||
device_id,
|
||||
self.cpid_info)
|
||||
if cpid_obj is not None:
|
||||
cpid_obj.destroy(context)
|
||||
|
||||
@classmethod
|
||||
def get(cls, context, device_id):
|
||||
# return None when can't found any.
|
||||
cpid_obj = ControlpathID.get_by_device_id(context, device_id)
|
||||
driver_cpid_obj = None
|
||||
if cpid_obj is not None:
|
||||
driver_cpid_obj = cls(context=context,
|
||||
cpid_type=cpid_obj.cpid_type,
|
||||
cpid_info=cpid_obj.cpid_info)
|
||||
return driver_cpid_obj
|
||||
# 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.control_path import ControlpathID
|
||||
from cyborg.objects import fields as object_fields
|
||||
|
||||
|
||||
@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)
|
||||
}
|
||||
|
||||
def create(self, context, device_id):
|
||||
"""Create a driver-side ControlPathID for drivers. Call
|
||||
ControlpathID object to store in DB.
|
||||
"""
|
||||
cpid_obj = ControlpathID(context=context,
|
||||
device_id=device_id,
|
||||
cpid_type=self.cpid_type,
|
||||
cpid_info=self.cpid_info)
|
||||
cpid_obj.create(context)
|
||||
return cpid_obj
|
||||
|
||||
def destroy(self, context, device_id):
|
||||
cpid_obj = ControlpathID.get_by_device_id_cpidinfo(context,
|
||||
device_id,
|
||||
self.cpid_info)
|
||||
if cpid_obj is not None:
|
||||
cpid_obj.destroy(context)
|
||||
|
||||
@classmethod
|
||||
def get(cls, context, device_id):
|
||||
# return None when can't found any.
|
||||
cpid_obj = ControlpathID.get_by_device_id(context, device_id)
|
||||
driver_cpid_obj = None
|
||||
if cpid_obj is not None:
|
||||
driver_cpid_obj = cls(context=context,
|
||||
cpid_type=cpid_obj.cpid_type,
|
||||
cpid_info=cpid_obj.cpid_info)
|
||||
return driver_cpid_obj
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright 2018 Lenovo (Beijing) Co.,LTD.
|
||||
# Copyright 2018 Lenovo (Beijing) Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
@ -14,13 +14,13 @@
|
||||
# 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.deployable import Deployable
|
||||
from cyborg.objects.driver_objects.driver_attach_handle import \
|
||||
DriverAttachHandle
|
||||
from cyborg.objects.deployable import Deployable
|
||||
from cyborg.objects.attach_handle import AttachHandle
|
||||
from cyborg.objects.driver_objects.driver_attribute import DriverAttribute
|
||||
from cyborg.objects import fields as object_fields
|
||||
|
||||
|
||||
@base.CyborgObjectRegistry.register
|
||||
@ -34,7 +34,7 @@ class DriverDeployable(base.DriverObjectBase,
|
||||
'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
|
||||
# TODO() add field related to local_memory or just store in the
|
||||
# attribute list?
|
||||
'attach_handle_list': object_fields.ListOfObjectsField(
|
||||
'DriverAttachHandle', default=[], nullable=True),
|
||||
@ -44,7 +44,8 @@ class DriverDeployable(base.DriverObjectBase,
|
||||
def create(self, context, device_id, cpid_id):
|
||||
"""Create a driver-side Deployable object into DB. This object will be
|
||||
stored in seperate db tables: deployable & attach_handle &
|
||||
attribute table."""
|
||||
attribute table.
|
||||
"""
|
||||
|
||||
# first store in deployable table through Deployable Object.
|
||||
deployable_obj = Deployable(context=context,
|
||||
@ -68,7 +69,8 @@ class DriverDeployable(base.DriverObjectBase,
|
||||
def destroy(self, context, device_id):
|
||||
"""delete one driver-side deployable by calling existing Deployable
|
||||
and AttachHandle Object. Use name&host to identify Deployable and
|
||||
attach_info to identify the AttachHandle"""
|
||||
attach_info to identify the AttachHandle
|
||||
"""
|
||||
|
||||
# get deployable_id by name, get only one value.
|
||||
dep_obj = Deployable.get_by_name_deviceid(context, self.name,
|
||||
|
@ -14,15 +14,14 @@
|
||||
# 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.control_path import ControlpathID
|
||||
from cyborg.objects.device import Device
|
||||
from cyborg.objects.driver_objects.driver_controlpath_id import \
|
||||
DriverControlPathID
|
||||
from cyborg.objects.device import Device
|
||||
from cyborg.objects.deployable import Deployable
|
||||
from cyborg.objects.control_path import ControlpathID
|
||||
from cyborg.objects.attach_handle import AttachHandle
|
||||
from cyborg.objects.driver_objects.driver_deployable import DriverDeployable
|
||||
from cyborg.objects import fields as object_fields
|
||||
|
||||
|
||||
@base.CyborgObjectRegistry.register
|
||||
@ -53,7 +52,8 @@ class DriverDevice(base.DriverObjectBase,
|
||||
def create(self, context, host):
|
||||
"""Create a driver-side Device Object into DB. This object will be
|
||||
stored in many db tables: device, deployable, attach_handle,
|
||||
controlpath_id etc. by calling related Object."""
|
||||
controlpath_id etc. by calling related Object.
|
||||
"""
|
||||
# first store in device table through Device Object.
|
||||
|
||||
device_obj = Device(context=context,
|
||||
@ -77,7 +77,8 @@ class DriverDevice(base.DriverObjectBase,
|
||||
|
||||
def destroy(self, context, host):
|
||||
"""Delete a driver-side Device Object from db. This should
|
||||
delete the internal layer objects."""
|
||||
delete the internal layer objects.
|
||||
"""
|
||||
# get dev_obj_list from hostname
|
||||
device_obj = self.get_device_obj(context, host)
|
||||
# delete deployable_list first.
|
||||
@ -92,7 +93,8 @@ class DriverDevice(base.DriverObjectBase,
|
||||
device_obj.destroy(context)
|
||||
|
||||
def get_device_obj(self, context, host):
|
||||
"""
|
||||
"""Get a driver-side Device Object from db.
|
||||
|
||||
:param context: requested context.
|
||||
:param host: hostname of the node.
|
||||
:return: a device object of current driver device object. It will
|
||||
@ -114,8 +116,8 @@ class DriverDevice(base.DriverObjectBase,
|
||||
"""Form driver-side device object list from DB for one host.
|
||||
A list may contains driver_device_object without controlpath_id.(In
|
||||
the case some of controlpath_id can't store successfully but its
|
||||
devices stores successfully.
|
||||
)"""
|
||||
devices stores successfully.)
|
||||
"""
|
||||
# get dev_obj_list from hostname
|
||||
dev_obj_list = Device.get_list_by_hostname(context, host)
|
||||
driver_dev_obj_list = []
|
||||
@ -136,7 +138,8 @@ class DriverDevice(base.DriverObjectBase,
|
||||
return driver_dev_obj_list
|
||||
|
||||
def get_device_obj_by_device_id(self, context, device_id):
|
||||
"""
|
||||
"""Get device object by device id.
|
||||
|
||||
:param context: requested context.
|
||||
:param host: hostname of the node.
|
||||
:return: a device object of current driver device object. It will
|
||||
@ -146,7 +149,7 @@ class DriverDevice(base.DriverObjectBase,
|
||||
device_obj = Device.get_by_device_id(context, device_id)
|
||||
# use controlpath_id.cpid_info to identiy one Device.
|
||||
# get cpid_obj, could be empty or only one value.
|
||||
cpid_obj = ControlpathID.get_by_device_id_cpidinfo(
|
||||
ControlpathID.get_by_device_id_cpidinfo(
|
||||
context, device_obj.id, self.controlpath_id.cpid_info)
|
||||
# find the one cpid_obj with cpid_info
|
||||
return device_obj
|
||||
|
@ -19,14 +19,15 @@ from oslo_serialization import jsonutils
|
||||
from oslo_versionedobjects import base as object_base
|
||||
|
||||
from cyborg.agent.rpcapi import AgentAPI
|
||||
from cyborg.db import api as dbapi
|
||||
from cyborg.common import constants
|
||||
from cyborg.common import exception
|
||||
from cyborg.common import nova_client
|
||||
from cyborg.common import placement_client
|
||||
from cyborg.conf import CONF
|
||||
from cyborg.db import api as dbapi
|
||||
from cyborg import objects
|
||||
from cyborg.objects import base
|
||||
from cyborg.objects.attach_handle import AttachHandle
|
||||
from cyborg.objects import base
|
||||
from cyborg.objects.deployable import Deployable
|
||||
from cyborg.objects.device_profile import DeviceProfile
|
||||
from cyborg.objects import fields as object_fields
|
||||
@ -36,13 +37,12 @@ LOG = logging.getLogger(__name__)
|
||||
|
||||
@base.CyborgObjectRegistry.register
|
||||
class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
""" ExtARQ is a wrapper around ARQ with Cyborg-private fields.
|
||||
Each ExtARQ object contains exactly one ARQ object as a field.
|
||||
But, in the db layer, ExtARQ and ARQ are represented together
|
||||
as a row in a single table. Both share a single UUID.
|
||||
|
||||
ExtARQ version is bumped up either if any of its fields change
|
||||
or if the ARQ version changes.
|
||||
"""ExtARQ is a wrapper around ARQ with Cyborg-private fields.
|
||||
Each ExtARQ object contains exactly one ARQ object as a field.
|
||||
But, in the db layer, ExtARQ and ARQ are represented together
|
||||
as a row in a single table. Both share a single UUID.
|
||||
ExtARQ version is bumped up either if any of its fields change
|
||||
or if the ARQ version changes.
|
||||
"""
|
||||
# Version 1.0: Initial version
|
||||
# 1.1: v2 API and Nova integration
|
||||
@ -91,7 +91,7 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
@classmethod
|
||||
def get(cls, context, uuid):
|
||||
"""Find a DB ExtARQ and return an Obj ExtARQ."""
|
||||
# TODO Fix warnings that '' is not an UUID
|
||||
# TODO() Fix warnings that '' is not an UUID
|
||||
db_extarq = cls.dbapi.extarq_get(context, uuid)
|
||||
obj_arq = objects.ARQ(context)
|
||||
obj_extarq = ExtARQ(context)
|
||||
@ -121,7 +121,7 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
def delete_by_uuid(cls, context, arq_uuid_list):
|
||||
for uuid in arq_uuid_list:
|
||||
obj_extarq = objects.ExtARQ.get(context, uuid)
|
||||
# TODO Defer deletion to conductor
|
||||
# TODO() Defer deletion to conductor
|
||||
if obj_extarq.arq.state != constants.ARQ_STATE_INITIAL:
|
||||
obj_extarq.unbind(context)
|
||||
obj_extarq.destroy(context)
|
||||
@ -141,7 +141,7 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
default_user = 'devstack-admin'
|
||||
try:
|
||||
auth_user = CONF.image.username or default_user
|
||||
except:
|
||||
except Exception:
|
||||
auth_user = default_user
|
||||
return connection.Connection(cloud=auth_user)
|
||||
|
||||
@ -181,7 +181,7 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
driver_name = deployable.driver_name
|
||||
|
||||
query_filter = {"device_id": deployable.device_id}
|
||||
# TODO We should probably get cpid from objects layer, not db layer
|
||||
# TODO() We should probably get cpid from objects layer, not db layer
|
||||
cpid_list = self.dbapi.control_path_get_by_filters(
|
||||
context, query_filter)
|
||||
count = len(cpid_list)
|
||||
@ -197,14 +197,14 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
'bitstream_id (%s)', hostname,
|
||||
deployable.uuid, bitstream_id)
|
||||
agent = AgentAPI()
|
||||
# TODO do this asynchronously
|
||||
# TODO do this in the conductor
|
||||
# TODO() do this asynchronously
|
||||
# TODO() do this in the conductor
|
||||
agent.fpga_program_v2(context, hostname,
|
||||
controlpath_id, bitstream_id,
|
||||
driver_name)
|
||||
LOG.info('Finished programming for host: (%s) deployable (%s)',
|
||||
hostname, deployable.uuid)
|
||||
# TODO propagate agent errors to caller
|
||||
# TODO() propagate agent errors to caller
|
||||
return True
|
||||
|
||||
def _update_placement(self, devrp_uuid, function_id, bitstream_md):
|
||||
@ -222,8 +222,8 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
placement.add_traits_to_rp(devrp_uuid, trait_names)
|
||||
|
||||
def bind(self, context, hostname, devrp_uuid, instance_uuid):
|
||||
""" Given a device rp UUID, get the deployable UUID and
|
||||
an attach handle.
|
||||
"""Given a device rp UUID, get the deployable UUID and
|
||||
an attach handle.
|
||||
"""
|
||||
LOG.info('[arqs:objs] bind. hostname: %s, devrp_uuid: %s'
|
||||
'instance: %s', hostname, devrp_uuid, instance_uuid)
|
||||
@ -240,7 +240,7 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
|
||||
deployable = Deployable.get_by_device_rp_uuid(context, devrp_uuid)
|
||||
|
||||
# TODO Check that deployable.device.hostname matches param hostname
|
||||
# TODO() Check that deployable.device.hostname matches param hostname
|
||||
|
||||
# Note(Sundar): We associate the ARQ with instance UUID before the
|
||||
# programming starts. So, if programming fails and then Nova calls
|
||||
@ -271,9 +271,9 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
bitstream_id = bitstream_md['id']
|
||||
|
||||
if deployable.bitstream_id == bitstream_id:
|
||||
LOG.info('Deployable %s already has the needed '
|
||||
'bitstream %s. Skipping programming.' %
|
||||
(deployable.uuid, bitstream_id))
|
||||
LOG.info('Deployable %(uuid)s already has the needed '
|
||||
'bitstream %(stream_id)s. Skipping programming.',
|
||||
{"uuid": deployable.uuid, "stream_id": bitstream_id})
|
||||
else:
|
||||
ok = self._do_programming(context, hostname,
|
||||
deployable, bitstream_id)
|
||||
@ -296,9 +296,11 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
try:
|
||||
ah = AttachHandle.allocate(context, deployable.id)
|
||||
self.attach_handle_id = ah.id
|
||||
except:
|
||||
LOG.error("Failed to allocate attach handle for ARQ %s"
|
||||
"from deployable %s" % (arq.uuid, deployable.uuid))
|
||||
except Exception:
|
||||
LOG.error("Failed to allocate attach handle for ARQ "
|
||||
"%(arq_uuid)s from deployable %(deployable_uuid)s",
|
||||
{"arq_uuid": arq.uuid,
|
||||
"deployable_uuid": deployable.uuid})
|
||||
arq.state = constants.ARQ_BIND_FAILED
|
||||
|
||||
self.arq = arq
|
||||
@ -354,8 +356,8 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
|
||||
@classmethod
|
||||
def _fill_obj_extarq_fields(cls, context, db_extarq):
|
||||
""" ExtARQ object has some fields that are not present
|
||||
in db_extarq. We fill them out here.
|
||||
"""ExtARQ object has some fields that are not present
|
||||
in db_extarq. We fill them out here.
|
||||
"""
|
||||
# From the 2 fields in the ExtARQ, we obtain other fields.
|
||||
devprof_id = db_extarq['device_profile_id']
|
||||
@ -366,7 +368,7 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
|
||||
db_extarq['attach_handle_type'] = ''
|
||||
db_extarq['attach_handle_info'] = ''
|
||||
if db_extarq['state'] == 'Bound': # TODO Do proper bind
|
||||
if db_extarq['state'] == 'Bound': # TODO() Do proper bind
|
||||
db_ah = cls.dbapi.attach_handle_get_by_id(
|
||||
context, db_extarq['attach_handle_id'])
|
||||
if db_ah is not None:
|
||||
@ -377,7 +379,7 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
resource='attach handle',
|
||||
msg='')
|
||||
|
||||
# TODO Get the deployable_uuid
|
||||
# TODO() Get the deployable_uuid
|
||||
db_extarq['deployable_uuid'] = ''
|
||||
|
||||
# Get the device profile group
|
||||
@ -390,7 +392,6 @@ class ExtARQ(base.CyborgObject, object_base.VersionedObjectDictCompat):
|
||||
@classmethod
|
||||
def _from_db_object(cls, extarq, db_extarq, context):
|
||||
"""Converts an ExtARQ to a formal object.
|
||||
|
||||
:param extarq: An object of the class ExtARQ
|
||||
:param db_extarq: A DB model of the object
|
||||
:return: The object of the class with the database entity added
|
||||
|
2
tox.ini
2
tox.ini
@ -107,7 +107,7 @@ show-source = True
|
||||
ignore = E123,E125,H405
|
||||
builtins = _
|
||||
enable-extensions = H106,H203,H904
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,*sqlalchemy/alembic/versions/*,demo/,releasenotes,cyborg/hacking/,cyborg/tests/,cyborg/image,cyborg/objects
|
||||
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,*sqlalchemy/alembic/versions/*,demo/,releasenotes,cyborg/hacking/,cyborg/tests/
|
||||
|
||||
[hacking]
|
||||
local-check-factory = cyborg.hacking.checks.factory
|
||||
|
Loading…
x
Reference in New Issue
Block a user