From 5c7ba8a2c846e1a6e3af2573312437ac414197d4 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Tue, 12 Nov 2024 17:04:09 +0100 Subject: [PATCH] allow setting cloud_discovery timeouts Signed-off-by: John Crispin --- renderer/templates/timeout.uc | 9 ++++++ renderer/templates/toplevel.uc | 3 ++ schema/timeouts.yml | 18 ++++++++++++ schema/ucentral.yml | 2 ++ schemareader.uc | 50 ++++++++++++++++++++++++++++++++++ ucentral.schema.full.json | 18 ++++++++++++ ucentral.schema.json | 17 ++++++++++++ ucentral.schema.pretty.json | 21 ++++++++++++++ 8 files changed, 138 insertions(+) create mode 100644 renderer/templates/timeout.uc create mode 100644 schema/timeouts.yml diff --git a/renderer/templates/timeout.uc b/renderer/templates/timeout.uc new file mode 100644 index 00000000..b12100ec --- /dev/null +++ b/renderer/templates/timeout.uc @@ -0,0 +1,9 @@ + +# Basic unit configuration +{% for (let t in [ 'offline', 'orphan', 'validate' ]): + if (timeout[t]): +%} +set ucentral.timeouts.{{ t }}={{ timeout[t] }} +{% endif + endfor %} +%} diff --git a/renderer/templates/toplevel.uc b/renderer/templates/toplevel.uc index 604307ad..f3eec76d 100644 --- a/renderer/templates/toplevel.uc +++ b/renderer/templates/toplevel.uc @@ -118,6 +118,9 @@ if (state.unit) include('unit.uc', { location: '/unit', unit: state.unit }); + if (state.timeouts) + include('timeout.uc', { location: '/timeout', timeout: state.timeouts }); + if (!state.services) state.services = {}; diff --git a/schema/timeouts.yml b/schema/timeouts.yml new file mode 100644 index 00000000..490c548f --- /dev/null +++ b/schema/timeouts.yml @@ -0,0 +1,18 @@ +description: + A device has certain properties that describe its identity and location. + These properties are described inside this object. +type: object +properties: + offline: + description: + How long can the device be offline before it enters orphan state. + type: integer + orphaned: + description: + The interval at which an orphaned device will try to discover the cloud. + type: integer + validate: + description: + How long the client has time to connect to the cloud before discovery is restarted. + type: integer + diff --git a/schema/ucentral.yml b/schema/ucentral.yml index f2252368..9609b37c 100644 --- a/schema/ucentral.yml +++ b/schema/ucentral.yml @@ -38,6 +38,8 @@ properties: $ref: "https://ucentral.io/schema/v1/metrics/" config-raw: $ref: "https://ucentral.io/schema/v1/config-raw/" + timeouts: + $ref: "https://ucentral.io/schema/v1/timeouts/" third-party: type: object additionalProperties: true diff --git a/schemareader.uc b/schemareader.uc index 35081de5..b36c40d0 100644 --- a/schemareader.uc +++ b/schemareader.uc @@ -10043,6 +10043,52 @@ function instantiateConfigRaw(location, value, errors) { return value; } +function instantiateTimeouts(location, value, errors) { + if (type(value) == "object") { + let obj = {}; + + function parseOffline(location, value, errors) { + if (type(value) != "int") + push(errors, [ location, "must be of type integer" ]); + + return value; + } + + if (exists(value, "offline")) { + obj.offline = parseOffline(location + "/offline", value["offline"], errors); + } + + function parseOrphaned(location, value, errors) { + if (type(value) != "int") + push(errors, [ location, "must be of type integer" ]); + + return value; + } + + if (exists(value, "orphaned")) { + obj.orphaned = parseOrphaned(location + "/orphaned", value["orphaned"], errors); + } + + function parseValidate(location, value, errors) { + if (type(value) != "int") + push(errors, [ location, "must be of type integer" ]); + + return value; + } + + if (exists(value, "validate")) { + obj.validate = parseValidate(location + "/validate", value["validate"], errors); + } + + return obj; + } + + if (type(value) != "object") + push(errors, [ location, "must be of type object" ]); + + return value; +} + function newUCentralState(location, value, errors) { if (type(value) == "object") { let obj = {}; @@ -10145,6 +10191,10 @@ function newUCentralState(location, value, errors) { obj.config_raw = instantiateConfigRaw(location + "/config-raw", value["config-raw"], errors); } + if (exists(value, "timeouts")) { + obj.timeouts = instantiateTimeouts(location + "/timeouts", value["timeouts"], errors); + } + function parseThirdParty(location, value, errors) { if (type(value) == "object") { let obj = { ...value }; diff --git a/ucentral.schema.full.json b/ucentral.schema.full.json index 42ef9fda..93ee17bb 100644 --- a/ucentral.schema.full.json +++ b/ucentral.schema.full.json @@ -4656,6 +4656,24 @@ ] } }, + "timeouts": { + "description": "A device has certain properties that describe its identity and location. These properties are described inside this object.", + "type": "object", + "properties": { + "offline": { + "description": "How long can the device be offline before it enters orphan state.", + "type": "integer" + }, + "orphaned": { + "description": "The interval at which an orphaned device will try to discover the cloud.", + "type": "integer" + }, + "validate": { + "description": "How long the client has time to connect to the cloud before discovery is restarted.", + "type": "integer" + } + } + }, "third-party": { "type": "object", "additionalProperties": true diff --git a/ucentral.schema.json b/ucentral.schema.json index 79ba7f3f..fb517132 100644 --- a/ucentral.schema.json +++ b/ucentral.schema.json @@ -49,6 +49,9 @@ "config-raw": { "$ref": "#/$defs/config-raw" }, + "timeouts": { + "$ref": "#/$defs/timeouts" + }, "third-party": { "type": "object", "additionalProperties": true @@ -3667,6 +3670,20 @@ ] ] } + }, + "timeouts": { + "type": "object", + "properties": { + "offline": { + "type": "integer" + }, + "orphaned": { + "type": "integer" + }, + "validate": { + "type": "integer" + } + } } } } \ No newline at end of file diff --git a/ucentral.schema.pretty.json b/ucentral.schema.pretty.json index 3b948d6a..ac3b8655 100644 --- a/ucentral.schema.pretty.json +++ b/ucentral.schema.pretty.json @@ -52,6 +52,9 @@ "config-raw": { "$ref": "#/$defs/config-raw" }, + "timeouts": { + "$ref": "#/$defs/timeouts" + }, "third-party": { "type": "object", "additionalProperties": true @@ -4190,6 +4193,24 @@ ] ] } + }, + "timeouts": { + "description": "A device has certain properties that describe its identity and location. These properties are described inside this object.", + "type": "object", + "properties": { + "offline": { + "description": "How long can the device be offline before it enters orphan state.", + "type": "integer" + }, + "orphaned": { + "description": "The interval at which an orphaned device will try to discover the cloud.", + "type": "integer" + }, + "validate": { + "description": "How long the client has time to connect to the cloud before discovery is restarted.", + "type": "integer" + } + } } } } \ No newline at end of file