Beispiel #1
0
class AttachHandle(base.CyborgObject, object_base.VersionedObjectDictCompat):
    # Version 1.0: Initial version
    VERSION = '1.0'

    dbapi = dbapi.get_instance()

    fields = {
        'id': object_fields.IntegerField(nullable=False),
        'uuid': object_fields.UUIDField(nullable=False),
        'deployable_id': object_fields.IntegerField(nullable=False),
        'cpid_id': object_fields.IntegerField(nullable=False),
        'attach_type': object_fields.EnumField(valid_values=ATTACH_TYPE,
                                               nullable=False),
        # attach_info should be JSON here.
        'attach_info': object_fields.StringField(nullable=False),
        'in_use': object_fields.BooleanField(nullable=False, default=False)
    }

    def create(self, context):
        """Create a AttachHandle record in the DB."""
        values = self.obj_get_changes()
        db_ah = self.dbapi.attach_handle_create(context, values)
        self._from_db_object(self, db_ah)

    @classmethod
    def get(cls, context, uuid):
        """Find a DB AttachHandle and return an Obj AttachHandle."""
        db_ah = cls.dbapi.attach_handle_get_by_uuid(context, uuid)
        obj_ah = cls._from_db_object(cls(context), db_ah)
        return obj_ah

    @classmethod
    def get_by_id(cls, context, id):
        """Find a DB AttachHandle by ID and return an Obj AttachHandle."""
        db_ah = cls.dbapi.attach_handle_get_by_id(context, id)
        obj_ah = cls._from_db_object(cls(context), db_ah)
        return obj_ah

    @classmethod
    def list(cls, context, filters={}):
        """Return a list of AttachHandle objects."""
        if filters:
            sort_dir = filters.pop('sort_dir', 'desc')
            sort_key = filters.pop('sort_key', 'created_at')
            limit = filters.pop('limit', None)
            marker = filters.pop('marker_obj', None)
            db_ahs = cls.dbapi.attach_handle_get_by_filters(context, filters,
                                                            sort_dir=sort_dir,
                                                            sort_key=sort_key,
                                                            limit=limit,
                                                            marker=marker)
        else:
            db_ahs = cls.dbapi.attach_handle_list(context)
        obj_ah_list = cls._from_db_object_list(db_ahs, context)
        return obj_ah_list

    def save(self, context):
        """Update an AttachHandle record in the DB"""
        updates = self.obj_get_changes()
        db_ahs = self.dbapi.attach_handle_update(context, self.uuid, updates)
        self._from_db_object(self, db_ahs)

    def destroy(self, context):
        """Delete a AttachHandle from the DB."""
        self.dbapi.attach_handle_delete(context, self.uuid)
        self.obj_reset_changes()

    @classmethod
    def get_ah_list_by_deployable_id(cls, context, deployable_id):
        ah_filter = {'deployable_id': deployable_id}
        ah_obj_list = AttachHandle.list(context, ah_filter)
        return ah_obj_list

    @classmethod
    def get_ah_by_depid_attachinfo(cls, context, deployable_id, attach_info):
        ah_filter = {'deployable_id': deployable_id,
                     'attach_info': attach_info}
        ah_obj_list = AttachHandle.list(context, ah_filter)
        if len(ah_obj_list) != 0:
            return ah_obj_list[0]
        else:
            return None
Beispiel #2
0
class ControlpathID(base.CyborgObject, object_base.VersionedObjectDictCompat):
    # Version 1.0: Initial version
    # Version 1.1: Add cpid_info_obj
    VERSION = '1.1'

    dbapi = dbapi.get_instance()

    fields = {
        'id':
        object_fields.IntegerField(nullable=False),
        'uuid':
        object_fields.UUIDField(nullable=False),
        'device_id':
        object_fields.IntegerField(nullable=False),
        'cpid_type':
        object_fields.EnumField(valid_values=constants.CPID_TYPE,
                                nullable=False),
        'cpid_info':
        object_fields.StringField(nullable=False)
    }

    @property
    def cpid_info_obj(self):
        return jsonutils.loads(self.cpid_info)

    @cpid_info_obj.setter
    def cpid_info_obj(self, cpid_info_obj):
        self.cpid_info = jsonutils.dumps(cpid_info_obj)

    def create(self, context):
        """Create a ControlPathID record in the DB."""
        values = self.obj_get_changes()
        db_cp = self.dbapi.control_path_create(context, values)
        self._from_db_object(self, db_cp)

    @classmethod
    def get(cls, context, uuid):
        """Find a DB ControlpathID and return an Obj ControlpathID."""
        db_cp = cls.dbapi.control_path_get_by_uuid(context, uuid)
        obj_cp = cls._from_db_object(cls(context), db_cp)
        return obj_cp

    @classmethod
    def list(cls, context, filters=None):
        """Return a list of ControlpathID objects."""
        if filters:
            sort_dir = filters.pop('sort_dir', 'desc')
            sort_key = filters.pop('sort_key', 'created_at')
            limit = filters.pop('limit', None)
            marker = filters.pop('marker_obj', None)
            db_cps = cls.dbapi.control_path_get_by_filters(context,
                                                           filters,
                                                           sort_dir=sort_dir,
                                                           sort_key=sort_key,
                                                           limit=limit,
                                                           marker=marker)
        else:
            db_cps = cls.dbapi.control_path_list(context)
        obj_cp_list = cls._from_db_object_list(db_cps, context)
        return obj_cp_list

    def save(self, context):
        """Update an ControlpathID record in the DB"""
        updates = self.obj_get_changes()
        db_cps = self.dbapi.control_path_update(context, self.uuid, updates)
        self._from_db_object(self, db_cps)

    def destroy(self, context):
        """Delete a ControlpathID from the DB."""
        self.dbapi.control_path_delete(context, self.uuid)
        self.obj_reset_changes()

    @classmethod
    def get_by_device_id(cls, context, device_id):
        # control_path is unique for one device.
        cpid_filter = {'device_id': device_id}
        cpid_obj_list = ControlpathID.list(context, cpid_filter)
        if len(cpid_obj_list) != 0:
            return cpid_obj_list[0]
        else:
            return None

    @classmethod
    def get_by_device_id_cpidinfo(cls, context, device_id, cpid_info):
        cpid_filter = {'device_id': device_id, 'cpid_info': cpid_info}
        # the list could have one value or is empty.
        cpid_obj_list = ControlpathID.list(context, cpid_filter)
        if len(cpid_obj_list) != 0:
            return cpid_obj_list[0]
        else:
            return None
Beispiel #3
0
class Device(base.CyborgObject, object_base.VersionedObjectDictCompat):
    # Version 1.0: Initial version
    # Version 1.1: Add AICHIP, GENERIC type
    VERSION = '1.1'

    dbapi = dbapi.get_instance()

    fields = {
        'id': object_fields.IntegerField(nullable=False),
        'uuid': object_fields.UUIDField(nullable=False),
        'type': object_fields.EnumField(valid_values=constants.DEVICE_TYPE,
                                        nullable=False),
        'vendor': object_fields.StringField(nullable=False),
        'model': object_fields.StringField(nullable=False),
        'std_board_info': object_fields.StringField(nullable=True),
        'vendor_board_info': object_fields.StringField(nullable=True),
        'hostname': object_fields.StringField(nullable=False),
    }

    def create(self, context):
        """Create a device record in the DB."""
        values = self.obj_get_changes()
        db_device = self.dbapi.device_create(context, values)
        self._from_db_object(self, db_device)

    @classmethod
    def get(cls, context, uuid):
        """Find a DB Device and return an Obj Device."""
        db_device = cls.dbapi.device_get(context, uuid)
        obj_device = cls._from_db_object(cls(context), db_device)
        return obj_device

    @classmethod
    def list(cls, context, filters=None):
        """Return a list of Device objects."""
        if filters:
            sort_dir = filters.pop('sort_dir', 'desc')
            sort_key = filters.pop('sort_key', 'created_at')
            limit = filters.pop('limit', None)
            marker = filters.pop('marker_obj', None)
            db_devices = cls.dbapi.device_list_by_filters(
                context, filters, sort_dir=sort_dir, sort_key=sort_key,
                limit=limit, marker=marker)
        else:
            db_devices = cls.dbapi.device_list(context)
        return cls._from_db_object_list(db_devices, context)

    def save(self, context):
        """Update a Device record in the DB."""
        updates = self.obj_get_changes()
        db_device = self.dbapi.device_update(context, self.uuid, updates)
        self._from_db_object(self, db_device)

    def destroy(self, context):
        """Delete the Device from the DB."""
        self.dbapi.device_delete(context, self.uuid)
        self.obj_reset_changes()

    @classmethod
    def get_list_by_hostname(cls, context, hostname):
        """get device object list from the hostname. return [] if not
        exist.
        """
        dev_filter = {'hostname': hostname}
        device_obj_list = Device.list(context, dev_filter)
        return device_obj_list

    @classmethod
    def get_by_device_id(cls, context, device_id):
        """get device object by the device ID."""
        db_device = cls.dbapi.device_get_by_id(context, device_id)
        obj_device = cls._from_db_object(cls(context), db_device)
        return obj_device