コード例 #1
0
 class TestObj(base.IronicObjectListBase, base.IronicObject):
     fields = {'objects': fields.ListOfObjectsField('MyObj')}
コード例 #2
0
class TraitList(base.IronicObjectListBase, base.IronicObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    dbapi = db_api.get_instance()

    fields = {
        'objects': object_fields.ListOfObjectsField('Trait'),
    }

    # NOTE(mgoddard): We don't want to enable RPC on this call just yet.
    # Remotable methods can be used in the future to replace current explicit
    # RPC calls.  Implications of calling new remote procedures should be
    # thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_node_id(cls, context, node_id):
        """Return all traits for the specified node.

        :param context: security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Trait(context).
        :param node_id: The id of a node.
        :raises: NodeNotFound if the node no longer appears in the database.
        """
        db_traits = cls.dbapi.get_node_traits_by_node_id(node_id)
        return object_base.obj_make_list(context, cls(), Trait, db_traits)

    # NOTE(mgoddard): We don't want to enable RPC on this call just yet.
    # Remotable methods can be used in the future to replace current explicit
    # RPC calls.  Implications of calling new remote procedures should be
    # thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def create(cls, context, node_id, traits):
        """Replace all existing traits with the specified list.

        :param context: security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Trait(context).
        :param node_id: The id of a node.
        :param traits: List of Strings; traits to set.
        :raises: InvalidParameterValue if adding the trait would exceed the
            per-node traits limit.
        :raises: NodeNotFound if the node no longer appears in the database.
        """
        version = Trait.get_target_version()
        db_traits = cls.dbapi.set_node_traits(node_id, traits, version)
        return object_base.obj_make_list(context, cls(), Trait, db_traits)

    # NOTE(mgoddard): We don't want to enable RPC on this call just yet.
    # Remotable methods can be used in the future to replace current explicit
    # RPC calls.  Implications of calling new remote procedures should be
    # thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def destroy(cls, context, node_id):
        """Delete all traits for the specified node.

        :param context: security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: Trait(context).
        :param node_id: The id of a node.
        :raises: NodeNotFound if the node no longer appears in the database.
        """
        cls.dbapi.unset_node_traits(node_id)

    def get_trait_names(self):
        """Return a list of names of the traits in this list."""
        return [t.trait for t in self.objects]
コード例 #3
0
ファイル: bios.py プロジェクト: olliewalsh/ironic
class BIOSSettingList(base.IronicObjectListBase, base.IronicObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    dbapi = dbapi.get_instance()

    fields = {
        'objects': object_fields.ListOfObjectsField('BIOSSetting'),
    }

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def create(cls, context, node_id, settings):
        """Create a list of BIOS Setting records in DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: BIOSSetting(context)
        :param node_id: The node id.
        :param settings: A list of bios settings.
        :raises: NodeNotFound if the node id is not found.
        :raises: BIOSSettingAlreadyExists if any of the setting records
            already exists.
        :return: A list of BIOSSetting objects.
        """
        version = BIOSSetting.get_target_version()
        db_setting_list = cls.dbapi.create_bios_setting_list(
            node_id, settings, version)
        return object_base.obj_make_list(context, cls(), BIOSSetting,
                                         db_setting_list)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def save(cls, context, node_id, settings):
        """Save a list of BIOS Setting updates in DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: BIOSSetting(context)
        :param node_id: The node id.
        :param settings: A list of bios settings.
        :raises: NodeNotFound if the node id is not found.
        :raises: BIOSSettingNotFound if any of the bios setting names
            is not found.
        :return: A list of BIOSSetting objects.
        """
        version = BIOSSetting.get_target_version()
        updated_setting_list = cls.dbapi.update_bios_setting_list(
            node_id, settings, version)
        return object_base.obj_make_list(context, cls(), BIOSSetting,
                                         updated_setting_list)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_node_id(cls, context, node_id):
        """Get BIOS Setting based on node_id.

        :param context: Security context.
        :param node_id: The node id.
        :raises: NodeNotFound if the node id is not found.
        :return: A list of BIOSSetting objects.
        """
        node_bios_setting = cls.dbapi.get_bios_setting_list(node_id)
        return object_base.obj_make_list(context, cls(), BIOSSetting,
                                         node_bios_setting)
コード例 #4
0
ファイル: bios.py プロジェクト: ajya/ironic-fork
class BIOSSettingList(base.IronicObjectListBase, base.IronicObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    dbapi = dbapi.get_instance()

    fields = {
        'objects': object_fields.ListOfObjectsField('BIOSSetting'),
    }

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def create(cls, context, node_id, settings):
        """Create a list of BIOS Setting records in DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: BIOSSetting(context)
        :param node_id: The node id.
        :param settings: A list of bios settings.
        :raises: NodeNotFound if the node id is not found.
        :raises: BIOSSettingAlreadyExists if any of the setting records
            already exists.
        :return: A list of BIOSSetting objects.
        """
        version = BIOSSetting.get_target_version()
        db_setting_list = cls.dbapi.create_bios_setting_list(
            node_id, settings, version)
        return object_base.obj_make_list(context, cls(), BIOSSetting,
                                         db_setting_list)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def save(cls, context, node_id, settings):
        """Save a list of BIOS Setting updates in DB.

        :param context: Security context. NOTE: This should only
                        be used internally by the indirection_api.
                        Unfortunately, RPC requires context as the first
                        argument, even though we don't use it.
                        A context should be set when instantiating the
                        object, e.g.: BIOSSetting(context)
        :param node_id: The node id.
        :param settings: A list of bios settings.
        :raises: NodeNotFound if the node id is not found.
        :raises: BIOSSettingNotFound if any of the bios setting names
            is not found.
        :return: A list of BIOSSetting objects.
        """
        version = BIOSSetting.get_target_version()
        updated_setting_list = cls.dbapi.update_bios_setting_list(
            node_id, settings, version)
        return object_base.obj_make_list(context, cls(), BIOSSetting,
                                         updated_setting_list)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def delete(cls, context, node_id, names):
        """Delete BIOS Settings based on node_id and names.

        :param context: Security context.
        :param node_id: The node id.
        :param names: List of BIOS setting names to be deleted.
        :raises: NodeNotFound if the node id is not found.
        :raises: BIOSSettingNotFound if any of BIOS setting fails to delete.
        """
        cls.dbapi.delete_bios_setting_list(node_id, names)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def get_by_node_id(cls, context, node_id):
        """Get BIOS Setting based on node_id.

        :param context: Security context.
        :param node_id: The node id.
        :raises: NodeNotFound if the node id is not found.
        :return: A list of BIOSSetting objects.
        """
        node_bios_setting = cls.dbapi.get_bios_setting_list(node_id)
        return object_base.obj_make_list(context, cls(), BIOSSetting,
                                         node_bios_setting)

    # NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
    # methods can be used in the future to replace current explicit RPC calls.
    # Implications of calling new remote procedures should be thought through.
    # @object_base.remotable_classmethod
    @classmethod
    def sync_node_setting(cls, context, node_id, settings):
        """Returns lists of create/update/delete/unchanged settings.

        This method sync with 'bios_settings' database table and sorts
        out four lists of create/update/delete/unchanged settings.

        :param context: Security context.
        :param node_id: The node id.
        :param settings: BIOS settings to be synced.
        :returns: A 4-tuple of lists of BIOS settings to be created,
            updated, deleted and unchanged.
        """
        create_list = []
        update_list = []
        delete_list = []
        nochange_list = []
        current_settings_dict = {}

        given_setting_names = [setting['name'] for setting in settings]
        current_settings = cls.get_by_node_id(context, node_id)

        for setting in current_settings:
            current_settings_dict[setting.name] = setting.value

        for setting in settings:
            if setting['name'] in current_settings_dict:
                if setting['value'] != current_settings_dict[setting['name']]:
                    update_list.append(setting)
                else:
                    nochange_list.append(setting)
            else:
                create_list.append(setting)

        for setting in current_settings:
            if setting.name not in given_setting_names:
                delete_list.append({
                    'name': setting.name,
                    'value': setting.value
                })

        return (create_list, update_list, delete_list, nochange_list)