# 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.
import enum
import jsonschema
from ironic.common import args
from ironic.common import exception
from ironic.common.i18n import _
from ironic.common.inspection_rules import actions
from ironic.common.inspection_rules import operators
from ironic.common.inspection_rules import utils
_CONDITIONS_SCHEMA = None
_ACTIONS_SCHEMA = None
[docs]
class InspectionPhase(enum.Enum):
MAIN = 'main'
[docs]
def conditions_schema():
global _CONDITIONS_SCHEMA
if _CONDITIONS_SCHEMA is None:
condition_plugins = list(operators.OPERATORS.keys())
condition_plugins.extend(
["!%s" % op for op in list(condition_plugins)])
_CONDITIONS_SCHEMA = {
"title": "Inspection rule conditions schema",
"type": "array",
"minItems": 0,
"items": {
"type": "object",
"required": ["op", "args"],
"properties": {
"op": {
"description": "Condition operator",
"enum": condition_plugins
},
"args": {
"description": "Arguments for the condition",
"type": ["array", "object"]
},
"multiple": {
"description": "How to treat multiple values",
"enum": ["any", "all", "first", "last"]
},
"loop": {
"description": "Loop behavior for conditions",
"type": ["array", "object"]
},
},
# other properties are validated by plugins
"additionalProperties": True
}
}
return _CONDITIONS_SCHEMA
[docs]
def actions_schema():
global _ACTIONS_SCHEMA
if _ACTIONS_SCHEMA is None:
action_plugins = list(actions.ACTIONS.keys())
_ACTIONS_SCHEMA = {
"title": "Inspection rule actions schema",
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"required": ["op", "args"],
"properties": {
"op": {
"description": "action operator",
"enum": action_plugins
},
"args": {
"description": "Arguments for the action",
"type": ["array", "object"]
},
"loop": {
"description": "Loop behavior for actions",
"type": ["array", "object"]
},
},
"additionalProperties": True
}
}
return _ACTIONS_SCHEMA
SCHEMA = {
'type': 'object',
'properties': {
'uuid': {'type': ['string', 'null']},
'priority': {'type': 'integer', "minimum": 0},
'description': {'type': ['string', 'null'], 'maxLength': 255},
'sensitive': {'type':<