pmcf 1.95.0 → 1.96.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.95.0",
3
+ "version": "1.96.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/dhcp.mjs ADDED
@@ -0,0 +1,248 @@
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
+ const dhcp4 = {
98
+ Dhcp4: {
99
+ "interfaces-config": {
100
+ interfaces: ["end0"]
101
+ },
102
+ "control-socket": {
103
+ "socket-type": "unix",
104
+ "socket-name": "/run/kea/4-ctrl-socket"
105
+ },
106
+ "lease-database": {
107
+ type: "memfile",
108
+ "lfc-interval": 3600
109
+ },
110
+ "expired-leases-processing": {
111
+ "reclaim-timer-wait-time": 10,
112
+ "flush-reclaimed-timer-wait-time": 25,
113
+ "hold-reclaimed-time": 3600,
114
+ "max-reclaim-leases": 100,
115
+ "max-reclaim-time": 250,
116
+ "unwarned-reclaim-cycles": 5
117
+ },
118
+ "renew-timer": 900,
119
+ "rebind-timer": 1800,
120
+ "valid-lifetime": 3600,
121
+ "option-data": [
122
+ {
123
+ name: "domain-name-servers",
124
+ data: serviceAddresses(this, {
125
+ type: "dns",
126
+ priority: "<10"
127
+ }).join(",")
128
+ },
129
+ {
130
+ name: "domain-search",
131
+ data: [...this.domains].join(",")
132
+ }
133
+ ],
134
+ subnet4: [
135
+ {
136
+ id: 1,
137
+ subnet: "192.168.1.0/24",
138
+ pools: [
139
+ {
140
+ pool: "192.168.1.100 - 192.168.1.200"
141
+ }
142
+ ],
143
+ "option-data": [
144
+ {
145
+ name: "routers",
146
+ data: "192.168.1.254"
147
+ }
148
+ ],
149
+ reservations: [
150
+ {
151
+ "hw-address": "1a:1b:1c:1d:1e:1f",
152
+ "ip-address": "192.168.1.199"
153
+ },
154
+ {
155
+ "client-id": "01:11:22:33:44:55:66",
156
+ "ip-address": "192.168.1.198",
157
+ hostname: "special-snowflake"
158
+ }
159
+ ]
160
+ }
161
+ ],
162
+ loggers
163
+ }
164
+ };
165
+ const dhcp6 = {
166
+ Dhcp6: {
167
+ "interfaces-config": {
168
+ interfaces: []
169
+ },
170
+ "control-socket": {
171
+ "socket-type": "unix",
172
+ "socket-name": "/run/kea/6-ctrl-socket"
173
+ },
174
+ "lease-database": {
175
+ type: "memfile",
176
+ "lfc-interval": 3600
177
+ },
178
+ "expired-leases-processing": {
179
+ "reclaim-timer-wait-time": 10,
180
+ "flush-reclaimed-timer-wait-time": 25,
181
+ "hold-reclaimed-time": 3600,
182
+ "max-reclaim-leases": 100,
183
+ "max-reclaim-time": 250,
184
+ "unwarned-reclaim-cycles": 5
185
+ },
186
+ "renew-timer": 1000,
187
+ "rebind-timer": 2000,
188
+ "preferred-lifetime": 3000,
189
+ "valid-lifetime": 4000,
190
+ "option-data": [
191
+ {
192
+ name: "dns-servers",
193
+ data: "2001:db8:2::45, 2001:db8:2::100"
194
+ }
195
+ ],
196
+ subnet6: [
197
+ {
198
+ id: 1,
199
+ subnet: "2001:db8:1::/64",
200
+ pools: [
201
+ {
202
+ pool: "2001:db8:1::/80"
203
+ }
204
+ ],
205
+ "pd-pools": [
206
+ {
207
+ prefix: "2001:db8:8::",
208
+ "prefix-len": 56,
209
+ "delegated-len": 64
210
+ }
211
+ ],
212
+ "option-data": [
213
+ {
214
+ name: "dns-servers",
215
+ data: "2001:db8:2::dead:beef, 2001:db8:2::cafe:babe"
216
+ }
217
+ ],
218
+ reservations: [
219
+ {
220
+ duid: "01:02:03:04:05:0A:0B:0C:0D:0E",
221
+ "ip-addresses": ["2001:db8:1::100"]
222
+ }
223
+ ]
224
+ }
225
+ ],
226
+ loggers
227
+ }
228
+ };
229
+
230
+ const files = {
231
+ "kea-ctrl-agent": ctrlAgent,
232
+ "kea-dhcp-ddns": ddns,
233
+ "kea-dhcp4": dhcp4,
234
+ "kea-dhcp6": dhcp6
235
+ };
236
+
237
+ for (const [name, data] of Object.entries(files)) {
238
+ loggers[0].name = name;
239
+ await writeLines(
240
+ join(packageData.dir, "etc/kea"),
241
+ `${name}.conf`,
242
+ JSON.stringify(data, undefined, 2)
243
+ );
244
+ }
245
+
246
+ yield packageData;
247
+ }
248
+ }
package/src/dns.mjs CHANGED
@@ -378,14 +378,14 @@ async function generateZoneDefs(dns, packageData) {
378
378
  }
379
379
 
380
380
  for (const service of host.findServices()) {
381
- for (const domainName of domainNames) {
381
+ //for (const domainName of domainNames) {
382
382
  for (const record of service.dnsRecordsForDomainName(
383
- domainName,
383
+ host.domainName,
384
384
  dns.hasSVRRecords
385
385
  )) {
386
386
  zone.records.add(record);
387
387
  }
388
- }
388
+ //}
389
389
  }
390
390
  }
391
391
  }
package/src/module.mjs CHANGED
@@ -2,6 +2,7 @@ export * from "./base.mjs";
2
2
  export * from "./service.mjs";
3
3
  export * from "./dns.mjs";
4
4
  export * from "./ntp.mjs";
5
+ export * from "./dhcp.mjs";
5
6
  export * from "./cluster.mjs";
6
7
  export * from "./owner.mjs";
7
8
  export * from "./location.mjs";
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
  }
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
- lines = [lines];
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) {
@@ -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;
@@ -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";
@@ -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;
@@ -2,6 +2,7 @@ export * from "./base.mjs";
2
2
  export * from "./service.mjs";
3
3
  export * from "./dns.mjs";
4
4
  export * from "./ntp.mjs";
5
+ export * from "./dhcp.mjs";
5
6
  export * from "./cluster.mjs";
6
7
  export * from "./owner.mjs";
7
8
  export * from "./location.mjs";
@@ -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;