pmcf 1.6.1 → 1.6.3
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/model.mjs +38 -45
- package/types/model.d.mts +3 -2
package/package.json
CHANGED
package/src/model.mjs
CHANGED
|
@@ -100,6 +100,10 @@ export class Base {
|
|
|
100
100
|
return object;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
error(...args) {
|
|
104
|
+
console.error(`${this.toString()}:`, ...args);
|
|
105
|
+
}
|
|
106
|
+
|
|
103
107
|
toString() {
|
|
104
108
|
return this.typeName + ":" + (this.owner?.name || "") + "/" + this.name;
|
|
105
109
|
}
|
|
@@ -144,43 +148,32 @@ export class Owner extends Base {
|
|
|
144
148
|
}
|
|
145
149
|
|
|
146
150
|
addBridge(network, destinationNetworks) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
bridge.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
console.log(
|
|
161
|
-
"REPLACE",
|
|
162
|
-
network.name,
|
|
163
|
-
[...bridge].map(n => n.name||`(${n})`)
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
break;
|
|
151
|
+
if (destinationNetworks) {
|
|
152
|
+
let bridge;
|
|
153
|
+
|
|
154
|
+
for (bridge of this.#bridges) {
|
|
155
|
+
if (bridge.has(network.name)) {
|
|
156
|
+
bridge.delete(network.name);
|
|
157
|
+
bridge.add(network);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (bridge.has(network)) {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
167
164
|
}
|
|
168
165
|
|
|
169
|
-
if (bridge
|
|
170
|
-
|
|
166
|
+
if (!bridge) {
|
|
167
|
+
bridge = new Set([network]);
|
|
168
|
+
this.#bridges.add(bridge);
|
|
171
169
|
}
|
|
172
|
-
}
|
|
173
170
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
171
|
+
for (const name of destinationNetworks) {
|
|
172
|
+
bridge.add(this.network(name) || name);
|
|
173
|
+
}
|
|
178
174
|
|
|
179
|
-
|
|
180
|
-
bridge.add(this.network(name) || name);
|
|
175
|
+
return bridge;
|
|
181
176
|
}
|
|
182
|
-
|
|
183
|
-
return bridge;
|
|
184
177
|
}
|
|
185
178
|
|
|
186
179
|
addSubnet(subnet) {
|
|
@@ -200,7 +193,7 @@ export class Owner extends Base {
|
|
|
200
193
|
...super.toJSON(),
|
|
201
194
|
networks: [...this.#networks.keys()].sort(),
|
|
202
195
|
subnets: [...this.#subnets.keys()].sort(),
|
|
203
|
-
bridges: [...this.#bridges
|
|
196
|
+
bridges: [...this.#bridges].map(b => bridgeToJSON(b)),
|
|
204
197
|
hosts: [...this.#hosts.keys()].sort()
|
|
205
198
|
};
|
|
206
199
|
}
|
|
@@ -250,7 +243,7 @@ export class World extends Owner {
|
|
|
250
243
|
|
|
251
244
|
type = await type.prepareData(this, data);
|
|
252
245
|
object = new type(owner, data);
|
|
253
|
-
this
|
|
246
|
+
this.addObject(object);
|
|
254
247
|
}
|
|
255
248
|
|
|
256
249
|
return object;
|
|
@@ -266,6 +259,10 @@ export class World extends Owner {
|
|
|
266
259
|
}
|
|
267
260
|
}
|
|
268
261
|
|
|
262
|
+
addObject(object) {
|
|
263
|
+
this.#byName.set(object.name, object);
|
|
264
|
+
}
|
|
265
|
+
|
|
269
266
|
async named(name) {
|
|
270
267
|
await this.load();
|
|
271
268
|
return this.#byName.get(name);
|
|
@@ -305,12 +302,6 @@ export class World extends Owner {
|
|
|
305
302
|
return this._loadType(name, Host);
|
|
306
303
|
}
|
|
307
304
|
|
|
308
|
-
async *subnets() {
|
|
309
|
-
for await (const location of this.locations()) {
|
|
310
|
-
yield* location.subnets();
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
305
|
async *networkAddresses() {
|
|
315
306
|
for await (const host of this.hosts()) {
|
|
316
307
|
for (const networkAddresses of host.networkAddresses()) {
|
|
@@ -440,9 +431,7 @@ export class Network extends Owner {
|
|
|
440
431
|
|
|
441
432
|
owner.addNetwork(this);
|
|
442
433
|
|
|
443
|
-
|
|
444
|
-
this.bridge = owner.addBridge(this, bridges);
|
|
445
|
-
}
|
|
434
|
+
this.bridge = owner.addBridge(this, bridges);
|
|
446
435
|
}
|
|
447
436
|
|
|
448
437
|
get ipv4_netmask() {
|
|
@@ -557,11 +546,11 @@ export class Host extends Base {
|
|
|
557
546
|
if (iface.network) {
|
|
558
547
|
const network = owner.network(iface.network);
|
|
559
548
|
|
|
560
|
-
if (
|
|
561
|
-
console.error(`${this.toString()}: Missing network`, iface.network);
|
|
562
|
-
} else {
|
|
549
|
+
if (network) {
|
|
563
550
|
iface.network = network;
|
|
564
551
|
network.addHost(this);
|
|
552
|
+
} else {
|
|
553
|
+
this.error("Missing network", iface.network);
|
|
565
554
|
}
|
|
566
555
|
}
|
|
567
556
|
}
|
|
@@ -849,3 +838,7 @@ function extractFrom(object, propertyNames) {
|
|
|
849
838
|
}
|
|
850
839
|
return json;
|
|
851
840
|
}
|
|
841
|
+
|
|
842
|
+
function bridgeToJSON(bridge) {
|
|
843
|
+
return [...bridge].map(n => n.name || `(${n})`).sort();
|
|
844
|
+
}
|
package/types/model.d.mts
CHANGED
|
@@ -18,6 +18,7 @@ export class Base {
|
|
|
18
18
|
set directory(directory: any);
|
|
19
19
|
get directory(): any;
|
|
20
20
|
expand(object: any): any;
|
|
21
|
+
error(...args: any[]): void;
|
|
21
22
|
toString(): string;
|
|
22
23
|
get propertyNames(): string[];
|
|
23
24
|
toJSON(): {};
|
|
@@ -36,7 +37,7 @@ export class Owner extends Base {
|
|
|
36
37
|
toJSON(): {
|
|
37
38
|
networks: any[];
|
|
38
39
|
subnets: any[];
|
|
39
|
-
bridges: any[];
|
|
40
|
+
bridges: any[][];
|
|
40
41
|
hosts: any[];
|
|
41
42
|
};
|
|
42
43
|
#private;
|
|
@@ -49,13 +50,13 @@ export class World extends Owner {
|
|
|
49
50
|
get world(): this;
|
|
50
51
|
_loadType(name: any, type: any): Promise<any>;
|
|
51
52
|
load(): Promise<void>;
|
|
53
|
+
addObject(object: any): void;
|
|
52
54
|
named(name: any): Promise<any>;
|
|
53
55
|
locations(): AsyncGenerator<Location, void, unknown>;
|
|
54
56
|
hosts(): AsyncGenerator<Host, void, unknown>;
|
|
55
57
|
domains(): AsyncGenerator<any, void, unknown>;
|
|
56
58
|
location(name: any): Promise<any>;
|
|
57
59
|
host(name: any): Promise<any>;
|
|
58
|
-
subnets(): AsyncGenerator<any, void, unknown>;
|
|
59
60
|
networkAddresses(): AsyncGenerator<{
|
|
60
61
|
address: any;
|
|
61
62
|
networkInterface: any;
|