pmcf 1.95.1 → 1.97.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/dhcp.mjs +276 -0
- package/src/module.mjs +1 -0
- package/src/owner.mjs +16 -4
- package/src/utils.mjs +14 -13
- package/types/cluster.d.mts +10 -0
- package/types/dhcp.d.mts +20 -0
- package/types/location.d.mts +20 -0
- package/types/module.d.mts +1 -0
- package/types/network.d.mts +10 -0
- package/types/owner.d.mts +10 -0
- package/types/root.d.mts +20 -0
package/package.json
CHANGED
package/src/dhcp.mjs
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { FileContentProvider } from "npm-pkgbuild";
|
|
3
|
+
import { Base } from "./base.mjs";
|
|
4
|
+
import { addType } from "./types.mjs";
|
|
5
|
+
import { writeLines } from "./utils.mjs";
|
|
6
|
+
import { serviceAddresses } from "./service.mjs";
|
|
7
|
+
|
|
8
|
+
const DHCPServiceTypeDefinition = {
|
|
9
|
+
name: "dhcp",
|
|
10
|
+
owners: ["location", "owner", "network", "cluster", "root"],
|
|
11
|
+
priority: 0.1,
|
|
12
|
+
properties: {}
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export class DHCPService extends Base {
|
|
16
|
+
static {
|
|
17
|
+
addType(this);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static get typeDefinition() {
|
|
21
|
+
return DHCPServiceTypeDefinition;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
constructor(owner, data) {
|
|
25
|
+
if (!data.name) {
|
|
26
|
+
data.name = DHCPServiceTypeDefinition.name; // TODO
|
|
27
|
+
}
|
|
28
|
+
super(owner, data);
|
|
29
|
+
this.read(data, DHCPServiceTypeDefinition);
|
|
30
|
+
|
|
31
|
+
owner.addObject(this);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async *preparePackages(dir) {
|
|
35
|
+
const name = this.owner.name;
|
|
36
|
+
const packageData = {
|
|
37
|
+
dir,
|
|
38
|
+
sources: [new FileContentProvider(dir + "/")[Symbol.asyncIterator]()],
|
|
39
|
+
outputs: this.outputs,
|
|
40
|
+
properties: {
|
|
41
|
+
name: `kea-${name}`,
|
|
42
|
+
description: `kea definitions for ${this.fullName}`,
|
|
43
|
+
access: "private",
|
|
44
|
+
dependencies: ["kea"]
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const loggers = [
|
|
49
|
+
{
|
|
50
|
+
"output-options": [
|
|
51
|
+
{
|
|
52
|
+
output: "systlog"
|
|
53
|
+
}
|
|
54
|
+
],
|
|
55
|
+
severity: "INFO",
|
|
56
|
+
debuglevel: 0
|
|
57
|
+
}
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
const ctrlAgent = {
|
|
61
|
+
"Control-agent": {
|
|
62
|
+
"http-host": "127.0.0.1",
|
|
63
|
+
"http-port": 8000,
|
|
64
|
+
"control-sockets": {
|
|
65
|
+
dhcp4: {
|
|
66
|
+
"socket-type": "unix",
|
|
67
|
+
"socket-name": "/run/kea/4-ctrl-socket"
|
|
68
|
+
},
|
|
69
|
+
dhcp6: {
|
|
70
|
+
"socket-type": "unix",
|
|
71
|
+
"socket-name": "/run/kea/6-ctrl-socket"
|
|
72
|
+
},
|
|
73
|
+
d2: {
|
|
74
|
+
"socket-type": "unix",
|
|
75
|
+
"socket-name": "/run/kea/ddns-ctrl-socket"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
loggers
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const ddns = {
|
|
83
|
+
DhcpDdns: {
|
|
84
|
+
"ip-address": "127.0.0.1",
|
|
85
|
+
port: 53001,
|
|
86
|
+
"control-socket": {
|
|
87
|
+
"socket-type": "unix",
|
|
88
|
+
"socket-name": "/run/kea/ddns-ctrl-socket"
|
|
89
|
+
},
|
|
90
|
+
"tsig-keys": [],
|
|
91
|
+
"forward-ddns": {},
|
|
92
|
+
"reverse-ddns": {},
|
|
93
|
+
loggers
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// console.log(this.owner.name,this.owner.networks());
|
|
98
|
+
/*
|
|
99
|
+
const subnets = new Set();
|
|
100
|
+
|
|
101
|
+
for (const network of this.owner.networks()) {
|
|
102
|
+
for (const subnet of network.subnets()) {
|
|
103
|
+
subnets.add(subnet);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log([...subnets].map(s => s.address));
|
|
108
|
+
*/
|
|
109
|
+
const reservations = [];
|
|
110
|
+
|
|
111
|
+
for await (const {
|
|
112
|
+
networkInterface,
|
|
113
|
+
address,
|
|
114
|
+
subnet,
|
|
115
|
+
domainNames
|
|
116
|
+
} of this.owner.networkAddresses()) {
|
|
117
|
+
if (networkInterface.hwaddr) {
|
|
118
|
+
reservations.push({
|
|
119
|
+
"hw-address": networkInterface.hwaddr,
|
|
120
|
+
"ip-address": networkInterface.rawAddress,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const dhcp4 = {
|
|
126
|
+
Dhcp4: {
|
|
127
|
+
"interfaces-config": {
|
|
128
|
+
interfaces: ["end0"]
|
|
129
|
+
},
|
|
130
|
+
"control-socket": {
|
|
131
|
+
"socket-type": "unix",
|
|
132
|
+
"socket-name": "/run/kea/4-ctrl-socket"
|
|
133
|
+
},
|
|
134
|
+
"lease-database": {
|
|
135
|
+
type: "memfile",
|
|
136
|
+
"lfc-interval": 3600
|
|
137
|
+
},
|
|
138
|
+
"expired-leases-processing": {
|
|
139
|
+
"reclaim-timer-wait-time": 10,
|
|
140
|
+
"flush-reclaimed-timer-wait-time": 25,
|
|
141
|
+
"hold-reclaimed-time": 3600,
|
|
142
|
+
"max-reclaim-leases": 100,
|
|
143
|
+
"max-reclaim-time": 250,
|
|
144
|
+
"unwarned-reclaim-cycles": 5
|
|
145
|
+
},
|
|
146
|
+
"renew-timer": 900,
|
|
147
|
+
"rebind-timer": 1800,
|
|
148
|
+
"valid-lifetime": 3600,
|
|
149
|
+
"option-data": [
|
|
150
|
+
{
|
|
151
|
+
name: "domain-name-servers",
|
|
152
|
+
data: serviceAddresses(this, {
|
|
153
|
+
type: "dns",
|
|
154
|
+
priority: "<10"
|
|
155
|
+
}).join(",")
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "domain-search",
|
|
159
|
+
data: [...this.domains].join(",")
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
subnet4: [
|
|
163
|
+
{
|
|
164
|
+
id: 1,
|
|
165
|
+
subnet: "192.168.1.0/24",
|
|
166
|
+
pools: [
|
|
167
|
+
{
|
|
168
|
+
pool: "192.168.1.100 - 192.168.1.200"
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
"option-data": [
|
|
172
|
+
{
|
|
173
|
+
name: "routers",
|
|
174
|
+
data: "192.168.1.254"
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
reservations /*: [
|
|
178
|
+
{
|
|
179
|
+
"hw-address": "1a:1b:1c:1d:1e:1f",
|
|
180
|
+
"ip-address": "192.168.1.199"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
"client-id": "01:11:22:33:44:55:66",
|
|
184
|
+
"ip-address": "192.168.1.198",
|
|
185
|
+
hostname: "special-snowflake"
|
|
186
|
+
}
|
|
187
|
+
]*/
|
|
188
|
+
}
|
|
189
|
+
],
|
|
190
|
+
loggers
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const dhcp6 = {
|
|
194
|
+
Dhcp6: {
|
|
195
|
+
"interfaces-config": {
|
|
196
|
+
interfaces: []
|
|
197
|
+
},
|
|
198
|
+
"control-socket": {
|
|
199
|
+
"socket-type": "unix",
|
|
200
|
+
"socket-name": "/run/kea/6-ctrl-socket"
|
|
201
|
+
},
|
|
202
|
+
"lease-database": {
|
|
203
|
+
type: "memfile",
|
|
204
|
+
"lfc-interval": 3600
|
|
205
|
+
},
|
|
206
|
+
"expired-leases-processing": {
|
|
207
|
+
"reclaim-timer-wait-time": 10,
|
|
208
|
+
"flush-reclaimed-timer-wait-time": 25,
|
|
209
|
+
"hold-reclaimed-time": 3600,
|
|
210
|
+
"max-reclaim-leases": 100,
|
|
211
|
+
"max-reclaim-time": 250,
|
|
212
|
+
"unwarned-reclaim-cycles": 5
|
|
213
|
+
},
|
|
214
|
+
"renew-timer": 1000,
|
|
215
|
+
"rebind-timer": 2000,
|
|
216
|
+
"preferred-lifetime": 3000,
|
|
217
|
+
"valid-lifetime": 4000,
|
|
218
|
+
"option-data": [
|
|
219
|
+
{
|
|
220
|
+
name: "dns-servers",
|
|
221
|
+
data: "2001:db8:2::45, 2001:db8:2::100"
|
|
222
|
+
}
|
|
223
|
+
],
|
|
224
|
+
subnet6: [
|
|
225
|
+
{
|
|
226
|
+
id: 1,
|
|
227
|
+
subnet: "2001:db8:1::/64",
|
|
228
|
+
pools: [
|
|
229
|
+
{
|
|
230
|
+
pool: "2001:db8:1::/80"
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
"pd-pools": [
|
|
234
|
+
{
|
|
235
|
+
prefix: "2001:db8:8::",
|
|
236
|
+
"prefix-len": 56,
|
|
237
|
+
"delegated-len": 64
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
"option-data": [
|
|
241
|
+
{
|
|
242
|
+
name: "dns-servers",
|
|
243
|
+
data: "2001:db8:2::dead:beef, 2001:db8:2::cafe:babe"
|
|
244
|
+
}
|
|
245
|
+
],
|
|
246
|
+
reservations: [
|
|
247
|
+
{
|
|
248
|
+
duid: "01:02:03:04:05:0A:0B:0C:0D:0E",
|
|
249
|
+
"ip-addresses": ["2001:db8:1::100"]
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
}
|
|
253
|
+
],
|
|
254
|
+
loggers
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const files = {
|
|
259
|
+
"kea-ctrl-agent": ctrlAgent,
|
|
260
|
+
"kea-dhcp-ddns": ddns,
|
|
261
|
+
"kea-dhcp4": dhcp4,
|
|
262
|
+
"kea-dhcp6": dhcp6
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
for (const [name, data] of Object.entries(files)) {
|
|
266
|
+
loggers[0].name = name;
|
|
267
|
+
await writeLines(
|
|
268
|
+
join(packageData.dir, "etc/kea"),
|
|
269
|
+
`${name}.conf`,
|
|
270
|
+
JSON.stringify(data, undefined, 2)
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
yield packageData;
|
|
275
|
+
}
|
|
276
|
+
}
|
package/src/module.mjs
CHANGED
package/src/owner.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { Subnet } from "./subnet.mjs";
|
|
|
4
4
|
import { addType, types } from "./types.mjs";
|
|
5
5
|
import { DNSService } from "./dns.mjs";
|
|
6
6
|
import { NTPService } from "./ntp.mjs";
|
|
7
|
+
import { DHCPService } from "./dhcp.mjs";
|
|
7
8
|
|
|
8
9
|
const OwnerTypeDefinition = {
|
|
9
10
|
name: "owner",
|
|
@@ -25,6 +26,11 @@ const OwnerTypeDefinition = {
|
|
|
25
26
|
collection: false,
|
|
26
27
|
writeable: true
|
|
27
28
|
},
|
|
29
|
+
dhcp: {
|
|
30
|
+
type: DHCPService.typeDefinition,
|
|
31
|
+
collection: false,
|
|
32
|
+
writeable: true
|
|
33
|
+
},
|
|
28
34
|
|
|
29
35
|
country: { type: "string", collection: false, writeable: true },
|
|
30
36
|
domain: { type: "string", collection: false, writeable: true },
|
|
@@ -65,6 +71,7 @@ export class Owner extends Base {
|
|
|
65
71
|
|
|
66
72
|
this.dns?._traverse(...args);
|
|
67
73
|
this.ntp?._traverse(...args);
|
|
74
|
+
this.dhcp?._traverse(...args);
|
|
68
75
|
|
|
69
76
|
return true;
|
|
70
77
|
}
|
|
@@ -193,6 +200,10 @@ export class Owner extends Base {
|
|
|
193
200
|
yield* this.owner.subnets();
|
|
194
201
|
}
|
|
195
202
|
yield* this.typeList("subnet");
|
|
203
|
+
|
|
204
|
+
/* for (const network of this.networks()) {
|
|
205
|
+
yield* network.subnets();
|
|
206
|
+
}*/
|
|
196
207
|
}
|
|
197
208
|
|
|
198
209
|
addSubnet(address) {
|
|
@@ -409,17 +420,18 @@ export class Owner extends Base {
|
|
|
409
420
|
|
|
410
421
|
#architectures;
|
|
411
422
|
|
|
412
|
-
set architectures(value)
|
|
413
|
-
{
|
|
423
|
+
set architectures(value) {
|
|
414
424
|
if (value instanceof Set) {
|
|
415
|
-
this.#architectures = this.#architectures
|
|
425
|
+
this.#architectures = this.#architectures
|
|
426
|
+
? this.#architectures.union(value)
|
|
427
|
+
: value;
|
|
416
428
|
} else {
|
|
417
429
|
this.#architectures = new Set(value);
|
|
418
430
|
}
|
|
419
431
|
}
|
|
420
432
|
|
|
421
433
|
get architectures() {
|
|
422
|
-
if(this.#architectures) {
|
|
434
|
+
if (this.#architectures) {
|
|
423
435
|
return this.#architectures;
|
|
424
436
|
}
|
|
425
437
|
|
package/src/utils.mjs
CHANGED
|
@@ -20,11 +20,21 @@ export function domainFromDominName(domainName, defaultDomain) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export async function writeLines(dir, name, lines) {
|
|
23
|
+
let data;
|
|
24
|
+
|
|
23
25
|
switch (typeof lines) {
|
|
24
26
|
case "undefined":
|
|
25
27
|
return;
|
|
26
28
|
case "string":
|
|
27
|
-
|
|
29
|
+
data = lines;
|
|
30
|
+
break;
|
|
31
|
+
|
|
32
|
+
default:
|
|
33
|
+
data = [...lines]
|
|
34
|
+
.flat()
|
|
35
|
+
.filter(line => line !== undefined)
|
|
36
|
+
.map(l => l + "\n")
|
|
37
|
+
.join("");
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
const full = join(dir, name);
|
|
@@ -32,15 +42,7 @@ export async function writeLines(dir, name, lines) {
|
|
|
32
42
|
name = basename(full);
|
|
33
43
|
await mkdir(dir, { recursive: true });
|
|
34
44
|
|
|
35
|
-
return writeFile(
|
|
36
|
-
join(dir, name),
|
|
37
|
-
[...lines]
|
|
38
|
-
.flat()
|
|
39
|
-
.filter(line => line !== undefined)
|
|
40
|
-
.map(l => l + "\n")
|
|
41
|
-
.join(""),
|
|
42
|
-
"utf8"
|
|
43
|
-
);
|
|
45
|
+
return writeFile(join(dir, name), data, "utf8");
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export function sectionLines(sectionName, values) {
|
|
@@ -80,9 +82,8 @@ export function isIPv4Address(address) {
|
|
|
80
82
|
return address.indexOf(".") >= 0;
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
export function generateEU64(mac)
|
|
84
|
-
|
|
85
|
-
//TODO
|
|
85
|
+
export function generateEU64(mac) {
|
|
86
|
+
//TODO
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
export function isIPv6Address(address) {
|
package/types/cluster.d.mts
CHANGED
|
@@ -193,6 +193,16 @@ export class Cluster extends Host {
|
|
|
193
193
|
collection: boolean;
|
|
194
194
|
writeable: boolean;
|
|
195
195
|
};
|
|
196
|
+
dhcp: {
|
|
197
|
+
type: {
|
|
198
|
+
name: string;
|
|
199
|
+
owners: string[];
|
|
200
|
+
priority: number;
|
|
201
|
+
properties: {};
|
|
202
|
+
};
|
|
203
|
+
collection: boolean;
|
|
204
|
+
writeable: boolean;
|
|
205
|
+
};
|
|
196
206
|
country: {
|
|
197
207
|
type: string;
|
|
198
208
|
collection: boolean;
|
package/types/dhcp.d.mts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class DHCPService extends Base {
|
|
2
|
+
static get typeDefinition(): {
|
|
3
|
+
name: string;
|
|
4
|
+
owners: string[];
|
|
5
|
+
priority: number;
|
|
6
|
+
properties: {};
|
|
7
|
+
};
|
|
8
|
+
preparePackages(dir: any): AsyncGenerator<{
|
|
9
|
+
dir: any;
|
|
10
|
+
sources: AsyncIterable<import("content-entry").ContentEntry>[];
|
|
11
|
+
outputs: Set<typeof import("npm-pkgbuild").ARCH | typeof import("npm-pkgbuild").DOCKER>;
|
|
12
|
+
properties: {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
access: string;
|
|
16
|
+
dependencies: string[];
|
|
17
|
+
};
|
|
18
|
+
}, void, unknown>;
|
|
19
|
+
}
|
|
20
|
+
import { Base } from "./base.mjs";
|
package/types/location.d.mts
CHANGED
|
@@ -193,6 +193,16 @@ export class Location extends Owner {
|
|
|
193
193
|
collection: boolean;
|
|
194
194
|
writeable: boolean;
|
|
195
195
|
};
|
|
196
|
+
dhcp: {
|
|
197
|
+
type: {
|
|
198
|
+
name: string;
|
|
199
|
+
owners: string[];
|
|
200
|
+
priority: number;
|
|
201
|
+
properties: {};
|
|
202
|
+
};
|
|
203
|
+
collection: boolean;
|
|
204
|
+
writeable: boolean;
|
|
205
|
+
};
|
|
196
206
|
country: {
|
|
197
207
|
type: string;
|
|
198
208
|
collection: boolean;
|
|
@@ -423,6 +433,16 @@ export class Location extends Owner {
|
|
|
423
433
|
collection: boolean;
|
|
424
434
|
writeable: boolean;
|
|
425
435
|
};
|
|
436
|
+
dhcp: {
|
|
437
|
+
type: {
|
|
438
|
+
name: string;
|
|
439
|
+
owners: string[];
|
|
440
|
+
priority: number;
|
|
441
|
+
properties: {};
|
|
442
|
+
};
|
|
443
|
+
collection: boolean;
|
|
444
|
+
writeable: boolean;
|
|
445
|
+
};
|
|
426
446
|
country: {
|
|
427
447
|
type: string;
|
|
428
448
|
collection: boolean;
|
package/types/module.d.mts
CHANGED
package/types/network.d.mts
CHANGED
|
@@ -195,6 +195,16 @@ export class Network extends Owner {
|
|
|
195
195
|
collection: boolean;
|
|
196
196
|
writeable: boolean;
|
|
197
197
|
};
|
|
198
|
+
dhcp: {
|
|
199
|
+
type: {
|
|
200
|
+
name: string;
|
|
201
|
+
owners: string[];
|
|
202
|
+
priority: number;
|
|
203
|
+
properties: {};
|
|
204
|
+
};
|
|
205
|
+
collection: boolean;
|
|
206
|
+
writeable: boolean;
|
|
207
|
+
};
|
|
198
208
|
country: {
|
|
199
209
|
type: string;
|
|
200
210
|
collection: boolean;
|
package/types/owner.d.mts
CHANGED
|
@@ -191,6 +191,16 @@ export class Owner extends Base {
|
|
|
191
191
|
collection: boolean;
|
|
192
192
|
writeable: boolean;
|
|
193
193
|
};
|
|
194
|
+
dhcp: {
|
|
195
|
+
type: {
|
|
196
|
+
name: string;
|
|
197
|
+
owners: string[];
|
|
198
|
+
priority: number;
|
|
199
|
+
properties: {};
|
|
200
|
+
};
|
|
201
|
+
collection: boolean;
|
|
202
|
+
writeable: boolean;
|
|
203
|
+
};
|
|
194
204
|
country: {
|
|
195
205
|
type: string;
|
|
196
206
|
collection: boolean;
|
package/types/root.d.mts
CHANGED
|
@@ -197,6 +197,16 @@ export class Root extends Location {
|
|
|
197
197
|
collection: boolean;
|
|
198
198
|
writeable: boolean;
|
|
199
199
|
};
|
|
200
|
+
dhcp: {
|
|
201
|
+
type: {
|
|
202
|
+
name: string;
|
|
203
|
+
owners: string[];
|
|
204
|
+
priority: number;
|
|
205
|
+
properties: {};
|
|
206
|
+
};
|
|
207
|
+
collection: boolean;
|
|
208
|
+
writeable: boolean;
|
|
209
|
+
};
|
|
200
210
|
country: {
|
|
201
211
|
type: string;
|
|
202
212
|
collection: boolean;
|
|
@@ -427,6 +437,16 @@ export class Root extends Location {
|
|
|
427
437
|
collection: boolean;
|
|
428
438
|
writeable: boolean;
|
|
429
439
|
};
|
|
440
|
+
dhcp: {
|
|
441
|
+
type: {
|
|
442
|
+
name: string;
|
|
443
|
+
owners: string[];
|
|
444
|
+
priority: number;
|
|
445
|
+
properties: {};
|
|
446
|
+
};
|
|
447
|
+
collection: boolean;
|
|
448
|
+
writeable: boolean;
|
|
449
|
+
};
|
|
430
450
|
country: {
|
|
431
451
|
type: string;
|
|
432
452
|
collection: boolean;
|