pmcf 1.35.4 → 1.36.1
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/bin/pmcf-diagram +6 -7
- package/bin/pmcf-host-defs +2 -2
- package/package.json +1 -1
- package/src/base.mjs +14 -7
- package/src/model.mjs +48 -10
- package/src/owner.mjs +21 -3
- package/src/service.mjs +1 -1
- package/types/base.d.mts +1 -1
- package/types/model.d.mts +6 -1
package/bin/pmcf-diagram
CHANGED
|
@@ -17,10 +17,9 @@ console.log("graph G {");
|
|
|
17
17
|
console.log(" node [shape=record];");
|
|
18
18
|
for await (const host of location.hosts()) {
|
|
19
19
|
console.log(
|
|
20
|
-
` ${id(host.name)} [label="${host.name}|{${
|
|
21
|
-
host.networkInterfaces
|
|
22
|
-
|
|
23
|
-
.map(([n, i]) => `<${id(n)}> ${n}`)
|
|
20
|
+
` ${id(host.name)} [label="${host.name}|{${
|
|
21
|
+
host.networkInterfaces.values()
|
|
22
|
+
.map((ni) => `<${id(ni.name)}> ${ni.name}`)
|
|
24
23
|
.join("|")}}"];`
|
|
25
24
|
);
|
|
26
25
|
}
|
|
@@ -33,9 +32,9 @@ for await (const network of location.networks()) {
|
|
|
33
32
|
);
|
|
34
33
|
|
|
35
34
|
for await (const host of network.hosts()) {
|
|
36
|
-
for (const
|
|
37
|
-
if (
|
|
38
|
-
console.log(` ${id(network.name)} -- ${id(host.name)}:${id(
|
|
35
|
+
for (const ni of host.networkInterfaces.values()) {
|
|
36
|
+
if (ni.network === network) {
|
|
37
|
+
console.log(` ${id(network.name)} -- ${id(host.name)}:${id(ni.name)};`);
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
}
|
package/bin/pmcf-host-defs
CHANGED
|
@@ -44,7 +44,7 @@ async function generateMachineInfo(host, dir) {
|
|
|
44
44
|
async function generateNetworkDefs(host, dir) {
|
|
45
45
|
const networkDir = join(dir, "etc/systemd/network");
|
|
46
46
|
|
|
47
|
-
for (const ni of
|
|
47
|
+
for (const ni of host.networkInterfaces.values()) {
|
|
48
48
|
if (ni.name !== "eth0" && ni.hwaddr) {
|
|
49
49
|
await writeLines(networkDir, `${ni.name}.link`, [
|
|
50
50
|
sectionLines("Match", { MACAddress: ni.hwaddr }),
|
|
@@ -69,7 +69,7 @@ async function generateNetworkDefs(host, dir) {
|
|
|
69
69
|
case "wifi":
|
|
70
70
|
const routeSectionExtra = ni.destination
|
|
71
71
|
? { Destination: ni.destination }
|
|
72
|
-
: { Gateway:
|
|
72
|
+
: { Gateway: ni.gatewayAddress };
|
|
73
73
|
|
|
74
74
|
const networkSectionExtra = ni.arpbridge
|
|
75
75
|
? {
|
package/package.json
CHANGED
package/src/base.mjs
CHANGED
|
@@ -47,10 +47,10 @@ export class Base {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
forOwner(owner) {
|
|
51
51
|
if (this.owner !== owner) {
|
|
52
52
|
// @ts-ignore
|
|
53
|
-
return new this.constructor(owner, this);
|
|
53
|
+
return new this.constructor(owner, this.toJSON());
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
return this;
|
|
@@ -87,11 +87,14 @@ export class Base {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
get directory() {
|
|
90
|
-
return
|
|
90
|
+
return (
|
|
91
|
+
this.#directory ||
|
|
92
|
+
(this.owner ? join(this.owner.directory, this.name) : this.name)
|
|
93
|
+
);
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
get fullName() {
|
|
94
|
-
return this.owner && this.name
|
|
97
|
+
return this.owner?.fullName && this.name
|
|
95
98
|
? join(this.owner.fullName, this.name)
|
|
96
99
|
: this.name;
|
|
97
100
|
}
|
|
@@ -200,9 +203,13 @@ export function extractFrom(object) {
|
|
|
200
203
|
json[p].name = value.name;
|
|
201
204
|
}
|
|
202
205
|
} else {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
+
if (Array.isArray(value)) {
|
|
207
|
+
json[p] = value;
|
|
208
|
+
} else {
|
|
209
|
+
json[p] = Object.fromEntries(
|
|
210
|
+
Object.entries(value).map(([k, v]) => [k, extractFrom(v)])
|
|
211
|
+
);
|
|
212
|
+
}
|
|
206
213
|
}
|
|
207
214
|
break;
|
|
208
215
|
default:
|
package/src/model.mjs
CHANGED
|
@@ -27,6 +27,11 @@ export class Root extends Owner {
|
|
|
27
27
|
this.addObject(this);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
get types()
|
|
31
|
+
{
|
|
32
|
+
return this.constructor.types;
|
|
33
|
+
}
|
|
34
|
+
|
|
30
35
|
get fullName() {
|
|
31
36
|
return "";
|
|
32
37
|
}
|
|
@@ -123,10 +128,10 @@ export class Location extends Owner {
|
|
|
123
128
|
}
|
|
124
129
|
|
|
125
130
|
export class Host extends Base {
|
|
126
|
-
networkInterfaces = {};
|
|
127
131
|
postinstall = [];
|
|
128
132
|
#services = [];
|
|
129
133
|
#extends = [];
|
|
134
|
+
#networkInterfaces = new Map();
|
|
130
135
|
#provides = new Set();
|
|
131
136
|
#replaces = new Set();
|
|
132
137
|
#depends = new Set();
|
|
@@ -203,25 +208,32 @@ export class Host extends Base {
|
|
|
203
208
|
delete data.services;
|
|
204
209
|
}
|
|
205
210
|
|
|
211
|
+
if (data.networkInterfaces) {
|
|
212
|
+
for (const [name, iface] of Object.entries(data.networkInterfaces)) {
|
|
213
|
+
iface.name = name;
|
|
214
|
+
new NetworkInterface(this, iface);
|
|
215
|
+
}
|
|
216
|
+
delete data.networkInterfaces;
|
|
217
|
+
}
|
|
218
|
+
|
|
206
219
|
for (const host of this.extends) {
|
|
207
220
|
for (const service of host.services()) {
|
|
208
|
-
service.
|
|
221
|
+
service.forOwner(this);
|
|
209
222
|
}
|
|
223
|
+
|
|
224
|
+
/*for (const ni of host.networkInterfaces.values()) {
|
|
225
|
+
ni.forOwner(this);
|
|
226
|
+
}*/
|
|
210
227
|
}
|
|
211
228
|
|
|
212
229
|
Object.assign(this, data);
|
|
213
230
|
|
|
214
|
-
for (const [name, iface] of Object.entries(this.networkInterfaces)) {
|
|
215
|
-
iface.name = name;
|
|
216
|
-
new NetworkInterface(this, iface);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
231
|
owner.addObject(this);
|
|
220
232
|
}
|
|
221
233
|
|
|
222
234
|
_traverse(...args) {
|
|
223
235
|
if (super._traverse(...args)) {
|
|
224
|
-
for (const ni of
|
|
236
|
+
for (const ni of this.networkInterfaces.values()) {
|
|
225
237
|
ni._traverse(...args);
|
|
226
238
|
}
|
|
227
239
|
for (const service of this.services()) {
|
|
@@ -331,8 +343,16 @@ export class Host extends Base {
|
|
|
331
343
|
}
|
|
332
344
|
}
|
|
333
345
|
|
|
346
|
+
get networkInterfaces() {
|
|
347
|
+
return this.#networkInterfaces;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
networkInterfacesNamed(name) {
|
|
351
|
+
return this.#networkInterfaces.get(name);
|
|
352
|
+
}
|
|
353
|
+
|
|
334
354
|
addNetworkInterface(networkInterface) {
|
|
335
|
-
this.
|
|
355
|
+
this.#networkInterfaces.set(networkInterface.name, networkInterface);
|
|
336
356
|
|
|
337
357
|
if (networkInterface.network) {
|
|
338
358
|
networkInterface.network.addObject(this);
|
|
@@ -340,7 +360,7 @@ export class Host extends Base {
|
|
|
340
360
|
}
|
|
341
361
|
|
|
342
362
|
*networkAddresses() {
|
|
343
|
-
for (const networkInterface of
|
|
363
|
+
for (const networkInterface of this.networkInterfaces.values()) {
|
|
344
364
|
for (const address of networkInterface.ipAddresses) {
|
|
345
365
|
yield {
|
|
346
366
|
networkInterface,
|
|
@@ -355,6 +375,7 @@ export class Host extends Base {
|
|
|
355
375
|
get ipAddresses() {
|
|
356
376
|
return [...this.networkAddresses()].map(na => na.address);
|
|
357
377
|
}
|
|
378
|
+
|
|
358
379
|
get ipAddressesWithPrefixLength() {
|
|
359
380
|
return [...this.networkAddresses()].map(na => na.addressWithPrefixLength);
|
|
360
381
|
}
|
|
@@ -385,6 +406,9 @@ export class Host extends Base {
|
|
|
385
406
|
return {
|
|
386
407
|
...super.toJSON(),
|
|
387
408
|
extends: this.extends.map(host => host.name),
|
|
409
|
+
networkInterfaces: Object.fromEntries(
|
|
410
|
+
[...this.networkInterfaces.values()].map(ni => [ni.name, ni.toJSON()])
|
|
411
|
+
),
|
|
388
412
|
services: Object.fromEntries(
|
|
389
413
|
[...this.services()].map(s => [s.name, s.toJSON()])
|
|
390
414
|
)
|
|
@@ -472,6 +496,19 @@ export class NetworkInterface extends Base {
|
|
|
472
496
|
return `${address}/${this.subnetForAddress(address)?.prefixLength}`;
|
|
473
497
|
}
|
|
474
498
|
|
|
499
|
+
get gateway() {
|
|
500
|
+
return this.network?.gateway;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
get gatewayAddress() {
|
|
504
|
+
console.log(typeof this.gateway);
|
|
505
|
+
for (const a of this.gateway.networkAddresses()) {
|
|
506
|
+
if (a.networkInterface.network === this.network) {
|
|
507
|
+
return a.address;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
475
512
|
get ipAddresses() {
|
|
476
513
|
return this.#ipAddresses.keys();
|
|
477
514
|
}
|
|
@@ -543,6 +580,7 @@ export class NetworkInterface extends Base {
|
|
|
543
580
|
"arpbridge",
|
|
544
581
|
"hwaddr",
|
|
545
582
|
"network",
|
|
583
|
+
"gateway",
|
|
546
584
|
"ssid",
|
|
547
585
|
"psk",
|
|
548
586
|
"scope",
|
package/src/owner.mjs
CHANGED
|
@@ -14,6 +14,19 @@ export class Owner extends Base {
|
|
|
14
14
|
return "owner";
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/*static async prepareData(root, data) {
|
|
18
|
+
if (data.networks) {
|
|
19
|
+
for (const [name, networkData] of Object.entries(data.networks)) {
|
|
20
|
+
if(networkData.gateway) {
|
|
21
|
+
networkData.gateway = await root.load(networkData.gateway, { type: root.types.host });
|
|
22
|
+
console.log("GATEWAY", networkData.gateway);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return this;
|
|
28
|
+
}*/
|
|
29
|
+
|
|
17
30
|
constructor(owner, data = {}) {
|
|
18
31
|
super(owner, data);
|
|
19
32
|
|
|
@@ -309,6 +322,12 @@ export class Network extends Owner {
|
|
|
309
322
|
|
|
310
323
|
Object.assign(this, data);
|
|
311
324
|
|
|
325
|
+
if (typeof this.gateway === "string") {
|
|
326
|
+
this.finalize(() => {
|
|
327
|
+
this.gateway = this.owner.hostNamed(this.gateway);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
312
331
|
this.bridge = owner.addBridge(this, bridge);
|
|
313
332
|
}
|
|
314
333
|
|
|
@@ -349,7 +368,7 @@ export class Subnet extends Base {
|
|
|
349
368
|
constructor(owner, data) {
|
|
350
369
|
const { cidr } = normalizeCIDR(data.name);
|
|
351
370
|
|
|
352
|
-
if(!cidr) {
|
|
371
|
+
if (!cidr) {
|
|
353
372
|
const error = Error(`Invalid address`);
|
|
354
373
|
error.address = data.name;
|
|
355
374
|
throw error;
|
|
@@ -368,8 +387,7 @@ export class Subnet extends Base {
|
|
|
368
387
|
return address.startsWith(this.prefix);
|
|
369
388
|
}
|
|
370
389
|
|
|
371
|
-
get isLinkLocal()
|
|
372
|
-
{
|
|
390
|
+
get isLinkLocal() {
|
|
373
391
|
return isLinkLocal(this.address);
|
|
374
392
|
}
|
|
375
393
|
|
package/src/service.mjs
CHANGED
package/types/base.d.mts
CHANGED
package/types/model.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ export class Root extends Owner {
|
|
|
3
3
|
[k: string]: typeof DNSService | typeof Owner | typeof Subnet | typeof Service | typeof Host | typeof NetworkInterface;
|
|
4
4
|
};
|
|
5
5
|
constructor(directory: any);
|
|
6
|
+
get types(): any;
|
|
6
7
|
get fullName(): string;
|
|
7
8
|
get root(): this;
|
|
8
9
|
load(name: any, options: any): any;
|
|
@@ -13,7 +14,6 @@ export class Location extends Owner {
|
|
|
13
14
|
}
|
|
14
15
|
export class Host extends Base {
|
|
15
16
|
static prepareData(root: any, data: any): Promise<typeof Host>;
|
|
16
|
-
networkInterfaces: {};
|
|
17
17
|
postinstall: any[];
|
|
18
18
|
_traverse(...args: any[]): boolean;
|
|
19
19
|
get deployment(): any;
|
|
@@ -36,6 +36,8 @@ export class Host extends Base {
|
|
|
36
36
|
get host(): this;
|
|
37
37
|
addService(service: any): void;
|
|
38
38
|
services(filter: any): Generator<any, void, unknown>;
|
|
39
|
+
get networkInterfaces(): Map<any, any>;
|
|
40
|
+
networkInterfacesNamed(name: any): any;
|
|
39
41
|
addNetworkInterface(networkInterface: any): void;
|
|
40
42
|
networkAddresses(): Generator<{
|
|
41
43
|
networkInterface: any;
|
|
@@ -48,6 +50,7 @@ export class Host extends Base {
|
|
|
48
50
|
publicKey(type?: string): Promise<string>;
|
|
49
51
|
toJSON(): {
|
|
50
52
|
extends: any[];
|
|
53
|
+
networkInterfaces: any;
|
|
51
54
|
services: any;
|
|
52
55
|
};
|
|
53
56
|
#private;
|
|
@@ -61,6 +64,8 @@ export class NetworkInterface extends Base {
|
|
|
61
64
|
get ipAddresses(): MapIterator<any>;
|
|
62
65
|
subnetForAddress(address: any): any;
|
|
63
66
|
addressWithPrefixLength(address: any): string;
|
|
67
|
+
get gateway(): any;
|
|
68
|
+
get gatewayAddress(): any;
|
|
64
69
|
get ipAddressesWithPrefixLength(): string[];
|
|
65
70
|
get ipv4Addresses(): any[];
|
|
66
71
|
get ipv6Addresses(): any[];
|