Skip to content

Commit

Permalink
allow setting cloud_discovery timeouts
Browse files Browse the repository at this point in the history
Signed-off-by: John Crispin <john@phrozen.org>
  • Loading branch information
blogic committed Nov 13, 2024
1 parent 7ac7ed5 commit 5c7ba8a
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 0 deletions.
9 changes: 9 additions & 0 deletions renderer/templates/timeout.uc
Original file line number Diff line number Diff line change
@@ -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 %}
%}
3 changes: 3 additions & 0 deletions renderer/templates/toplevel.uc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down
18 changes: 18 additions & 0 deletions schema/timeouts.yml
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions schema/ucentral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
50 changes: 50 additions & 0 deletions schemareader.uc
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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 };
Expand Down
18 changes: 18 additions & 0 deletions ucentral.schema.full.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions ucentral.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"config-raw": {
"$ref": "#/$defs/config-raw"
},
"timeouts": {
"$ref": "#/$defs/timeouts"
},
"third-party": {
"type": "object",
"additionalProperties": true
Expand Down Expand Up @@ -3667,6 +3670,20 @@
]
]
}
},
"timeouts": {
"type": "object",
"properties": {
"offline": {
"type": "integer"
},
"orphaned": {
"type": "integer"
},
"validate": {
"type": "integer"
}
}
}
}
}
21 changes: 21 additions & 0 deletions ucentral.schema.pretty.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
"config-raw": {
"$ref": "#/$defs/config-raw"
},
"timeouts": {
"$ref": "#/$defs/timeouts"
},
"third-party": {
"type": "object",
"additionalProperties": true
Expand Down Expand Up @@ -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"
}
}
}
}
}

0 comments on commit 5c7ba8a

Please sign in to comment.