pmcf 1.5.3 → 1.6.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.
@@ -74,7 +74,7 @@ async function generateNamedDefs(location, targetDir) {
74
74
  };
75
75
  zones.push(zone);
76
76
 
77
- for await (const subnet of location.subnets()) {
77
+ for (const subnet of location.subnets()) {
78
78
  if (subnet.address) {
79
79
  const reverse = reverseAddress(subnet.address);
80
80
  const reverseArpa = reverseArpaAddress(subnet.address);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.5.3",
3
+ "version": "1.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/model.mjs CHANGED
@@ -101,7 +101,7 @@ export class Base {
101
101
  }
102
102
 
103
103
  toString() {
104
- return this.typeName + ":" + this.owner.name + "/" + this.name;
104
+ return this.typeName + ":" + (this.owner?.name || "") + "/" + this.name;
105
105
  }
106
106
 
107
107
  get propertyNames() {
@@ -114,9 +114,54 @@ export class Base {
114
114
  }
115
115
 
116
116
  export class Owner extends Base {
117
- addHost(host) {}
118
- addNetwork(network) {}
119
- async network(name) {}
117
+ #hosts = new Map();
118
+ #networks = new Map();
119
+ #subnets = new Map();
120
+
121
+ async *hosts() {
122
+ for (const host of this.#hosts.values()) {
123
+ yield host;
124
+ }
125
+ }
126
+
127
+ addHost(host) {
128
+ this.#hosts.set(host.name, host);
129
+ }
130
+
131
+ network(name) {
132
+ return this.#networks.get(name);
133
+ }
134
+
135
+ async *networks() {
136
+ for (const network of this.#networks.values()) {
137
+ yield network;
138
+ }
139
+ }
140
+
141
+ addNetwork(network) {
142
+ this.#networks.set(network.name, network);
143
+ }
144
+
145
+ addSubnet(subnet) {
146
+ this.#subnets.set(subnet.name, subnet);
147
+ }
148
+
149
+ subnet(name) {
150
+ return this.#subnets.get(name);
151
+ }
152
+
153
+ subnets() {
154
+ return this.#subnets.values();
155
+ }
156
+
157
+ toJSON() {
158
+ return {
159
+ ...super.toJSON(),
160
+ networks: [...this.#networks.keys()].sort(),
161
+ subnets: [...this.#subnets.keys()].sort(),
162
+ hosts: [...this.#hosts.keys()].sort()
163
+ };
164
+ }
120
165
  }
121
166
 
122
167
  export class World extends Owner {
@@ -237,9 +282,6 @@ export class Location extends Owner {
237
282
  domain;
238
283
  dns;
239
284
  #administratorEmail;
240
- #hosts = new Map();
241
- #networks = new Map();
242
- #subnets = new Map();
243
285
 
244
286
  static get typeName() {
245
287
  return "location";
@@ -253,11 +295,12 @@ export class Location extends Owner {
253
295
  Object.assign(this, data);
254
296
 
255
297
  if (networks) {
256
- for (const [name, network] of Object.entries(networks)) {
257
- network.name = name;
258
- this.addNetwork(network);
298
+ for (const [name, data] of Object.entries(networks)) {
299
+ data.name = name;
300
+ new Network(this, data);
259
301
  }
260
302
 
303
+ /*
261
304
  for (const network of this.#networks.values()) {
262
305
  if (network.bridges) {
263
306
  network.bridges = new Set(
@@ -271,6 +314,7 @@ export class Location extends Owner {
271
314
  );
272
315
  }
273
316
  }
317
+ */
274
318
  }
275
319
  }
276
320
 
@@ -316,67 +360,6 @@ export class Location extends Owner {
316
360
  }
317
361
  }
318
362
 
319
- async network(name) {
320
- return this.#networks.get(name);
321
- }
322
-
323
- async *networks() {
324
- for (const network of this.#networks.values()) {
325
- yield network;
326
- }
327
- }
328
-
329
- async *subnets() {
330
- for (const subnet of this.#subnets.values()) {
331
- yield subnet;
332
- }
333
- }
334
-
335
- addNetwork(data) {
336
- if (!data?.name) {
337
- return undefined;
338
- }
339
-
340
- let network = this.#networks.get(data.name);
341
- if (network) {
342
- return network;
343
- }
344
-
345
- if (data instanceof Network) {
346
- this.#networks.set(data.name, data);
347
- return data;
348
- }
349
-
350
- network = new Network(this, data);
351
- this.#networks.set(data.name, network);
352
-
353
- const subnetAddress = network.subnetAddress;
354
-
355
- if (subnetAddress) {
356
- let subnet = this.#subnets.get(subnetAddress);
357
- if (!subnet) {
358
- subnet = new Subnet(this, subnetAddress);
359
- this.#subnets.set(subnetAddress, subnet);
360
- }
361
- network.subnet = subnet;
362
- subnet.networks.add(network);
363
- }
364
- return network;
365
- }
366
-
367
- addHost(host) {
368
- this.#hosts.set(host.name, host);
369
-
370
- for (const [name, iface] of Object.entries(host.networkInterfaces)) {
371
- const network = this.addNetwork({ name: iface.network });
372
- if (!network) {
373
- console.error("Missing network", host.name, name);
374
- } else {
375
- network.addHost(host);
376
- }
377
- }
378
- }
379
-
380
363
  get dnsAllowedUpdates() {
381
364
  return this.dns?.allowedUpdates || [];
382
365
  }
@@ -392,22 +375,13 @@ export class Location extends Owner {
392
375
  get propertyNames() {
393
376
  return [...super.propertyNames, "domain" /*, "hosts"*/];
394
377
  }
395
-
396
- toJSON() {
397
- return {
398
- ...super.toJSON(),
399
- hosts: [...this.#hosts.keys()].sort()
400
- };
401
- }
402
378
  }
403
379
 
404
- export class Network extends Base {
405
- #hosts = new Map();
380
+ export class Network extends Owner {
406
381
  kind;
407
382
  scope;
408
383
  metric;
409
384
  ipv4;
410
- ipv4_netmask;
411
385
  subnet;
412
386
 
413
387
  static get typeName() {
@@ -419,16 +393,28 @@ export class Network extends Base {
419
393
 
420
394
  Object.assign(this, data);
421
395
 
422
- if (this.ipv4) {
423
- const m = this.ipv4.match(/\/(\d+)$/);
424
- if (m) {
425
- this.ipv4_netmask = m[1];
396
+ const subnetAddress = this.subnetAddress;
397
+
398
+ if (subnetAddress) {
399
+ let subnet = owner.subnet(subnetAddress);
400
+ if (!subnet) {
401
+ subnet = new Subnet(owner, { name: subnetAddress });
426
402
  }
403
+
404
+ this.subnet = subnet;
405
+ subnet.networks.add(this);
427
406
  }
428
407
 
429
408
  owner.addNetwork(this);
430
409
  }
431
410
 
411
+ get ipv4_netmask() {
412
+ const m = this.ipv4?.match(/\/(\d+)$/);
413
+ if (m) {
414
+ return m[1];
415
+ }
416
+ }
417
+
432
418
  get subnetAddress() {
433
419
  if (this.ipv4) {
434
420
  const [addr, bits] = this.ipv4.split(/\//);
@@ -437,16 +423,6 @@ export class Network extends Base {
437
423
  }
438
424
  }
439
425
 
440
- async *hosts() {
441
- for (const host of this.#hosts.values()) {
442
- yield host;
443
- }
444
- }
445
-
446
- addHost(host) {
447
- this.#hosts.set(host.name, host);
448
- }
449
-
450
426
  get propertyNames() {
451
427
  return [...super.propertyNames, "kind", "ipv4", "scope", "metric"];
452
428
  }
@@ -535,7 +511,14 @@ export class Host extends Base {
535
511
  iface.host = this;
536
512
  iface.name = name;
537
513
  if (iface.network) {
538
- iface.network = this.network(iface.network);
514
+ const network = owner.network(iface.network);
515
+
516
+ if (!network) {
517
+ console.error(`${this.toString()}: Missing network`, iface.network);
518
+ } else {
519
+ iface.network = network;
520
+ network.addHost(this);
521
+ }
539
522
  }
540
523
  }
541
524
 
@@ -664,7 +647,6 @@ export class Host extends Base {
664
647
 
665
648
  export class Model extends Host {}
666
649
 
667
-
668
650
  export class Subnet extends Base {
669
651
  networks = new Set();
670
652
 
@@ -672,8 +654,12 @@ export class Subnet extends Base {
672
654
  return "subnet";
673
655
  }
674
656
 
675
- constructor(owner, address) {
676
- super(owner, { name: address });
657
+ constructor(owner, data) {
658
+ super(owner, data);
659
+
660
+ Object.assign(this, data);
661
+
662
+ owner.addSubnet(this);
677
663
  }
678
664
 
679
665
  get address() {
package/types/model.d.mts CHANGED
@@ -24,9 +24,20 @@ export class Base {
24
24
  #private;
25
25
  }
26
26
  export class Owner extends Base {
27
+ hosts(): AsyncGenerator<any, void, unknown>;
27
28
  addHost(host: any): void;
29
+ network(name: any): any;
30
+ networks(): AsyncGenerator<any, void, unknown>;
28
31
  addNetwork(network: any): void;
29
- network(name: any): Promise<void>;
32
+ addSubnet(subnet: any): void;
33
+ subnet(name: any): any;
34
+ subnets(): MapIterator<any>;
35
+ toJSON(): {
36
+ networks: any[];
37
+ subnets: any[];
38
+ hosts: any[];
39
+ };
40
+ #private;
30
41
  }
31
42
  export class World extends Owner {
32
43
  static get types(): {
@@ -52,33 +63,22 @@ export class World extends Owner {
52
63
  export class Location extends Owner {
53
64
  domain: any;
54
65
  dns: any;
55
- hosts(): AsyncGenerator<any, void, unknown>;
56
66
  service(filter: any): Promise<any>;
57
67
  services(filter: any): AsyncGenerator<any, void, unknown>;
58
68
  networkAddresses(): AsyncGenerator<any, void, unknown>;
59
- network(name: any): Promise<any>;
60
- networks(): AsyncGenerator<any, void, unknown>;
61
- subnets(): AsyncGenerator<any, void, unknown>;
62
- addNetwork(data: any): any;
63
69
  get dnsAllowedUpdates(): any;
64
70
  get dnsRecordTTL(): any;
65
71
  get administratorEmail(): any;
66
- toJSON(): {
67
- hosts: any[];
68
- };
69
72
  #private;
70
73
  }
71
- export class Network extends Base {
74
+ export class Network extends Owner {
72
75
  kind: any;
73
76
  scope: any;
74
77
  metric: any;
75
78
  ipv4: any;
76
- ipv4_netmask: any;
77
79
  subnet: any;
80
+ get ipv4_netmask(): any;
78
81
  get subnetAddress(): any;
79
- hosts(): AsyncGenerator<any, void, unknown>;
80
- addHost(host: any): void;
81
- #private;
82
82
  }
83
83
  export class Host extends Base {
84
84
  static prepareData(world: any, data: any): Promise<typeof Host>;