Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(storage): config support for generate section #1634

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions rust/agama-lib/share/examples/storage/generate_lvs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"storage": {
"drives": [
{
"partitions": [
{
"alias": "pv1",
"id": "lvm",
"size": { "min": "10 GiB" }
}
]
}
],
"volumeGroups": [
{
"name": "system",
"physicalVolumes": ["pv1"],
"logicalVolumes": [
{ "generate": "default" }
]
}
]
}
}
43 changes: 43 additions & 0 deletions rust/agama-lib/share/examples/storage/generate_lvs_extended.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"storage": {
"drives": [
{
"partitions": [
{
"alias": "pv1",
"id": "lvm",
"size": { "min": "10 GiB" }
}
]
}
],
"volumeGroups": [
{
"name": "system",
"physicalVolumes": ["pv1"],
"logicalVolumes": [
{
"generate": {
"logicalVolumes": "mandatory",
"encryption": {
"luks2": {
"password": "12345"
}
},
"stripes": 10,
"stripeSize": "4 KiB"
}
},
{
"name": "data",
"size": "5 GiB",
"filesystem": {
"path": "/data",
"type": "xfs"
}
}
]
}
]
}
}
13 changes: 13 additions & 0 deletions rust/agama-lib/share/examples/storage/generate_partitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"storage": {
"drives": [
{
"partitions": [
{
"generate": "mandatory"
}
]
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"storage": {
"drives": [
{
"partitions": [
{
"size": "10 GiB",
"filesystem": {
"type": "vfat"
}
},
{
"generate": {
"partitions": "default",
"encryption": {
"luks2": {
"password": "12345"
}
}
}
}
]
}
]
}
}
94 changes: 82 additions & 12 deletions rust/agama-lib/share/profile.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,37 @@
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/$defs/generateVolumes"
},
{
"title": "Generate logical volumes",
"description": "Creates the default or mandatory logical volumes configured by the selected product, allowing to customize some properties.",
"type": "object",
"additionalProperties": false,
"required": ["generate"],
"properties": {
"generate": {
"type": "object",
"additionalProperties": false,
"required": ["logicalVolumes"],
"properties": {
"logicalVolumes": {
"enum": ["default", "mandatory"]
},
"encryption": {
"$ref": "#/$defs/encryption"
},
"stripes": {
"$ref": "#/$defs/lvStripes"
},
"stripeSize": {
"$ref": "#/$defs/lvStripeSize"
}
}
}
}
},
{
"title": "Logical volume",
"type": "object",
Expand All @@ -555,14 +586,10 @@
"$ref": "#/$defs/size"
},
"stripes": {
"title": "Number of stripes",
"type": "integer",
"minimum": 1,
"maximum": 128
"$ref": "#/$defs/lvStripes"
},
"stripeSize": {
"title": "Stripe size",
"$ref": "#/$defs/sizeValue"
"$ref": "#/$defs/lvStripeSize"
},
"encryption": {
"$ref": "#/$defs/encryption"
Expand Down Expand Up @@ -594,14 +621,10 @@
"$ref": "#/$defs/size"
},
"stripes": {
"title": "Number of stripes",
"type": "integer",
"minimum": 1,
"maximum": 128
"$ref": "#/$defs/lvStripes"
},
"stripeSize": {
"title": "Stripe size",
"$ref": "#/$defs/sizeValue"
"$ref": "#/$defs/lvStripeSize"
},
"encryption": {
"$ref": "#/$defs/encryption"
Expand Down Expand Up @@ -1206,11 +1229,48 @@
}
}
},
"generateVolumes": {
"title": "Generate volumes automatically",
"description": "Creates the default or mandatory volumes configured by the selected product.",
"type": "object",
"additionalProperties": false,
"required": ["generate"],
"properties": {
"generate": {
"enum": ["default", "mandatory"]
}
}
},
"partitions": {
"title": "Partitions",
"type": "array",
"items": {
"anyOf": [
{
"$ref": "#/$defs/generateVolumes"
},
{
"title": "Generate partitions",
"description": "Creates the default or mandatory partitions configured by the selected product, allowing to customize some properties.",
"type": "object",
"additionalProperties": false,
"required": ["generate"],
"properties": {
"generate": {
"type": "object",
"additionalProperties": false,
"required": ["partitions"],
"properties": {
"partitions": {
"enum": ["default", "mandatory"]
},
"encryption": {
"$ref": "#/$defs/encryption"
}
}
}
}
},
{
"title": "Partition to create or reuse",
"type": "object",
Expand Down Expand Up @@ -1279,6 +1339,16 @@
}
]
}
},
"lvStripes": {
"title": "Number of stripes",
"type": "integer",
"minimum": 1,
"maximum": 128
},
"lvStripeSize": {
"title": "Stripe size",
"$ref": "#/$defs/sizeValue"
}
}
}
23 changes: 21 additions & 2 deletions service/lib/agama/storage/config_conversions/from_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@
require "agama/config"
require "agama/storage/config_builder"
require "agama/storage/config_conversions/from_json_conversions/config"
require "agama/storage/config_json_solver"

module Agama
module Storage
module ConfigConversions
# Config conversion from JSON hash according to schema.
class FromJSON
# TODO: Replace product_config param by a ProductDefinition.
#
# @param config_json [Hash]
# @param product_config [Agama::Config, nil]
def initialize(config_json, product_config: nil)
# TODO: Replace product_config param by a ProductDefinition.
@config_json = config_json
# Copies the JSON hash to avoid changes in the given parameter, see {ConfigJSONSolver}.
@config_json = json_dup(config_json)
@product_config = product_config || Agama::Config.new
end

Expand All @@ -41,6 +44,14 @@ def initialize(config_json, product_config: nil)
# @return [Storage::Config]
def convert
# TODO: Raise error if config_json does not match the JSON schema.
# Implementation idea: ConfigJSONChecker class which reports issues if:
# * The JSON does not match the schema.
# * The JSON contains more than one "generate" for partitions and logical volumes.
# * The JSON contains invalid aliases (now checked by ConfigChecker).
ConfigJSONSolver
.new(product_config)
.solve(config_json)

FromJSONConversions::Config
.new(config_json, config_builder: config_builder)
.convert
Expand All @@ -54,6 +65,14 @@ def convert
# @return [Agama::Config]
attr_reader :product_config

# Deep dup of the given JSON.
#
# @param json [Hash]
# @return [Hash]
def json_dup(json)
Marshal.load(Marshal.dump(json))
end

# @return [ConfigBuilder]
def config_builder
@config_builder ||= ConfigBuilder.new(product_config)
Expand Down
Loading
Loading