pmcf 1.24.0 → 1.25.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/bin/pmcf-host-defs +4 -2
- package/package.json +1 -1
- package/src/base.mjs +24 -1
- package/src/model.mjs +33 -20
- package/types/base.d.mts +3 -0
- package/types/model.d.mts +2 -0
package/bin/pmcf-host-defs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { writeFile, mkdir, copyFile, glob } from "node:fs/promises";
|
|
3
|
+
import { writeFile, mkdir, copyFile, glob, chmod } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { Host } from "pmcf";
|
|
6
6
|
import { writeLines, sectionLines } from "../src/utils.mjs";
|
|
@@ -151,7 +151,9 @@ async function copySshKeys(host, dir) {
|
|
|
151
151
|
await mkdir(sshDir, { recursive: true });
|
|
152
152
|
|
|
153
153
|
for await (const file of glob("ssh_host_*", { cwd: host.directory })) {
|
|
154
|
-
|
|
154
|
+
const destinationFileName = join(sshDir, file);
|
|
155
|
+
await copyFile(join(host.directory, file), destinationFileName);
|
|
156
|
+
await chmod(destinationFileName, destinationFileName.endsWith('.pub') ? 0o0644 : 0o0600);
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
159
|
|
package/package.json
CHANGED
package/src/base.mjs
CHANGED
|
@@ -122,8 +122,14 @@ export class Base {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
execFinalize() {
|
|
125
|
+
this.traverse(object => {
|
|
126
|
+
//console.log(object.toString());
|
|
127
|
+
object._finalize();
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
_finalize() {
|
|
125
132
|
if (this.#finalize) {
|
|
126
|
-
//this.info("finalize");
|
|
127
133
|
let i = 0;
|
|
128
134
|
for (const action of this.#finalize) {
|
|
129
135
|
if (action) {
|
|
@@ -135,6 +141,23 @@ export class Base {
|
|
|
135
141
|
}
|
|
136
142
|
}
|
|
137
143
|
|
|
144
|
+
traverse(visitor, ...args) {
|
|
145
|
+
const visited = new Set();
|
|
146
|
+
this._traverse(visited, visitor, ...args);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
_traverse(visited, visitor, ...args) {
|
|
150
|
+
if (visited.has(this)) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
visited.add(this);
|
|
155
|
+
|
|
156
|
+
visitor(this, ...args);
|
|
157
|
+
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
|
|
138
161
|
error(...args) {
|
|
139
162
|
console.error(`${this.toString()}:`, ...args);
|
|
140
163
|
}
|
package/src/model.mjs
CHANGED
|
@@ -41,18 +41,22 @@ export class Owner extends Base {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
Object.assign(this, data);
|
|
44
|
+
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
_traverse(...args) {
|
|
47
|
+
if (super._traverse(...args)) {
|
|
46
48
|
for (const network of this.#networks.values()) {
|
|
47
|
-
network.
|
|
49
|
+
network._traverse(...args);
|
|
48
50
|
}
|
|
49
|
-
});
|
|
50
51
|
|
|
51
|
-
this.finalize(() => {
|
|
52
52
|
for (const host of this.#hosts.values()) {
|
|
53
|
-
host.
|
|
53
|
+
host._traverse(...args);
|
|
54
54
|
}
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return false;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
get dns() {
|
|
@@ -219,6 +223,18 @@ export class World extends Owner {
|
|
|
219
223
|
this.addObject(this);
|
|
220
224
|
}
|
|
221
225
|
|
|
226
|
+
_traverse(...args) {
|
|
227
|
+
if (super._traverse(...args)) {
|
|
228
|
+
for (const object of this.#byName.values()) {
|
|
229
|
+
object._traverse(...args);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
|
|
222
238
|
get fullName() {
|
|
223
239
|
return "";
|
|
224
240
|
}
|
|
@@ -429,7 +445,6 @@ export class Host extends Base {
|
|
|
429
445
|
#deployment;
|
|
430
446
|
#chassis;
|
|
431
447
|
#vendor;
|
|
432
|
-
#location;
|
|
433
448
|
|
|
434
449
|
static get typeName() {
|
|
435
450
|
return "host";
|
|
@@ -452,11 +467,6 @@ export class Host extends Base {
|
|
|
452
467
|
constructor(owner, data) {
|
|
453
468
|
super(owner, data);
|
|
454
469
|
|
|
455
|
-
if (data.location !== undefined) {
|
|
456
|
-
this.#location = data.location;
|
|
457
|
-
delete data.location;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
470
|
if (data.deployment !== undefined) {
|
|
461
471
|
this.#deployment = data.deployment;
|
|
462
472
|
delete data.deployment;
|
|
@@ -520,12 +530,20 @@ export class Host extends Base {
|
|
|
520
530
|
}
|
|
521
531
|
|
|
522
532
|
owner.addHost(this);
|
|
533
|
+
}
|
|
523
534
|
|
|
524
|
-
|
|
535
|
+
_traverse(...args) {
|
|
536
|
+
if (super._traverse(...args)) {
|
|
525
537
|
for (const ni of Object.values(this.networkInterfaces)) {
|
|
526
|
-
ni.
|
|
538
|
+
ni._traverse(...args);
|
|
527
539
|
}
|
|
528
|
-
|
|
540
|
+
for (const service of this.services()) {
|
|
541
|
+
service._traverse(...args);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
return true;
|
|
545
|
+
}
|
|
546
|
+
return false;
|
|
529
547
|
}
|
|
530
548
|
|
|
531
549
|
get deployment() {
|
|
@@ -552,10 +570,6 @@ export class Host extends Base {
|
|
|
552
570
|
return this.#extends.map(e => this.expand(e));
|
|
553
571
|
}
|
|
554
572
|
|
|
555
|
-
get location() {
|
|
556
|
-
return this.#location || super.location;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
573
|
get provides() {
|
|
560
574
|
let provides = new Set(this.#provides);
|
|
561
575
|
this.extends.forEach(h => (provides = provides.union(h.provides)));
|
|
@@ -857,6 +871,5 @@ export class Subnet extends Base {
|
|
|
857
871
|
}
|
|
858
872
|
}
|
|
859
873
|
|
|
860
|
-
|
|
861
874
|
const _types = [Location, Network, Subnet, Host, Service, DNSService];
|
|
862
875
|
const _typesByName = Object.fromEntries(_types.map(t => [t.typeName, t]));
|
package/types/base.d.mts
CHANGED
|
@@ -22,6 +22,9 @@ export class Base {
|
|
|
22
22
|
expand(object: any): any;
|
|
23
23
|
finalize(action: any): void;
|
|
24
24
|
execFinalize(): void;
|
|
25
|
+
_finalize(): void;
|
|
26
|
+
traverse(visitor: any, ...args: any[]): void;
|
|
27
|
+
_traverse(visited: any, visitor: any, ...args: any[]): boolean;
|
|
25
28
|
error(...args: any[]): void;
|
|
26
29
|
info(...args: any[]): void;
|
|
27
30
|
toString(): string;
|
package/types/model.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ export class Owner extends Base {
|
|
|
3
3
|
ntp: {
|
|
4
4
|
servers: any[];
|
|
5
5
|
};
|
|
6
|
+
_traverse(...args: any[]): boolean;
|
|
6
7
|
get dns(): DNSService;
|
|
7
8
|
hosts(): AsyncGenerator<any, void, unknown>;
|
|
8
9
|
addObject(object: any): void;
|
|
@@ -58,6 +59,7 @@ export class Host extends Base {
|
|
|
58
59
|
static prepareData(world: any, data: any): Promise<typeof Host>;
|
|
59
60
|
networkInterfaces: {};
|
|
60
61
|
postinstall: any[];
|
|
62
|
+
_traverse(...args: any[]): boolean;
|
|
61
63
|
get deployment(): any;
|
|
62
64
|
get chassis(): any;
|
|
63
65
|
get vendor(): any;
|