pmcf 1.36.1 → 1.37.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 +1 -1
- package/src/model.mjs +48 -33
- package/src/owner.mjs +24 -3
- package/src/utils.mjs +19 -0
- package/types/model.d.mts +8 -7
- package/types/owner.d.mts +3 -2
- package/types/utils.d.mts +1 -0
package/package.json
CHANGED
package/src/model.mjs
CHANGED
|
@@ -12,7 +12,29 @@ import { Service } from "./service.mjs";
|
|
|
12
12
|
import { Cluster } from "./cluster.mjs";
|
|
13
13
|
import { DNSService } from "./dns.mjs";
|
|
14
14
|
|
|
15
|
-
export class
|
|
15
|
+
export class Location extends Owner {
|
|
16
|
+
static get typeName() {
|
|
17
|
+
return "location";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get location() {
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
locationNamed(name) {
|
|
25
|
+
if (this.fullName === name) {
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return super.locationNamed(name);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get network() {
|
|
33
|
+
return [...this.typeList("network")][0] || super.network;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class Root extends Location {
|
|
16
38
|
static get types() {
|
|
17
39
|
return _typesByName;
|
|
18
40
|
}
|
|
@@ -27,8 +49,7 @@ export class Root extends Owner {
|
|
|
27
49
|
this.addObject(this);
|
|
28
50
|
}
|
|
29
51
|
|
|
30
|
-
get types()
|
|
31
|
-
{
|
|
52
|
+
get types() {
|
|
32
53
|
return this.constructor.types;
|
|
33
54
|
}
|
|
34
55
|
|
|
@@ -109,24 +130,6 @@ export class Root extends Owner {
|
|
|
109
130
|
}
|
|
110
131
|
}
|
|
111
132
|
|
|
112
|
-
export class Location extends Owner {
|
|
113
|
-
static get typeName() {
|
|
114
|
-
return "location";
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
get location() {
|
|
118
|
-
return this;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
locationNamed(name) {
|
|
122
|
-
if (this.fullName === name) {
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return super.locationNamed(name);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
133
|
export class Host extends Base {
|
|
131
134
|
postinstall = [];
|
|
132
135
|
#services = [];
|
|
@@ -326,6 +329,10 @@ export class Host extends Base {
|
|
|
326
329
|
return this;
|
|
327
330
|
}
|
|
328
331
|
|
|
332
|
+
get network() {
|
|
333
|
+
return this.owner.network;
|
|
334
|
+
}
|
|
335
|
+
|
|
329
336
|
addService(service) {
|
|
330
337
|
this.#services.push(service);
|
|
331
338
|
}
|
|
@@ -347,7 +354,7 @@ export class Host extends Base {
|
|
|
347
354
|
return this.#networkInterfaces;
|
|
348
355
|
}
|
|
349
356
|
|
|
350
|
-
|
|
357
|
+
networkInterfaceNamed(name) {
|
|
351
358
|
return this.#networkInterfaces.get(name);
|
|
352
359
|
}
|
|
353
360
|
|
|
@@ -477,11 +484,20 @@ export class NetworkInterface extends Base {
|
|
|
477
484
|
//this.arpbridge = owner.addARPBridge(this, data.arpbridge);
|
|
478
485
|
}
|
|
479
486
|
|
|
487
|
+
addSubnet(address) {
|
|
488
|
+
if (!this.network) {
|
|
489
|
+
this.error("Missing network", address);
|
|
490
|
+
} else {
|
|
491
|
+
return this.network.addSubnet(address);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
480
495
|
set ipAddresses(value) {
|
|
481
|
-
const networkOwner = this.owner.owner;
|
|
482
496
|
for (const address of asArray(value)) {
|
|
483
|
-
|
|
484
|
-
|
|
497
|
+
this.#ipAddresses.set(
|
|
498
|
+
normalizeIPAddress(address),
|
|
499
|
+
this.addSubnet(address)
|
|
500
|
+
);
|
|
485
501
|
}
|
|
486
502
|
}
|
|
487
503
|
|
|
@@ -501,7 +517,6 @@ export class NetworkInterface extends Base {
|
|
|
501
517
|
}
|
|
502
518
|
|
|
503
519
|
get gatewayAddress() {
|
|
504
|
-
console.log(typeof this.gateway);
|
|
505
520
|
for (const a of this.gateway.networkAddresses()) {
|
|
506
521
|
if (a.networkInterface.network === this.network) {
|
|
507
522
|
return a.address;
|
|
@@ -510,7 +525,7 @@ export class NetworkInterface extends Base {
|
|
|
510
525
|
}
|
|
511
526
|
|
|
512
527
|
get ipAddresses() {
|
|
513
|
-
return this.#ipAddresses.keys();
|
|
528
|
+
return [...this.#ipAddresses.keys()];
|
|
514
529
|
}
|
|
515
530
|
|
|
516
531
|
get ipAddressesWithPrefixLength() {
|
|
@@ -531,13 +546,17 @@ export class NetworkInterface extends Base {
|
|
|
531
546
|
return this.network?.prefixLength;
|
|
532
547
|
}
|
|
533
548
|
|
|
549
|
+
get host() {
|
|
550
|
+
return this.owner;
|
|
551
|
+
}
|
|
552
|
+
|
|
534
553
|
get network() {
|
|
535
|
-
return this.#network;
|
|
554
|
+
return this.#network || this.host.network;
|
|
536
555
|
}
|
|
537
556
|
|
|
538
557
|
set network(networkOrName) {
|
|
539
558
|
if (!(networkOrName instanceof Network)) {
|
|
540
|
-
let network = this.
|
|
559
|
+
let network = this.host.owner.networkNamed(networkOrName);
|
|
541
560
|
|
|
542
561
|
if (network) {
|
|
543
562
|
this.#network = network;
|
|
@@ -550,10 +569,6 @@ export class NetworkInterface extends Base {
|
|
|
550
569
|
this.#network = networkOrName;
|
|
551
570
|
}
|
|
552
571
|
|
|
553
|
-
get host() {
|
|
554
|
-
return this.owner;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
572
|
get scope() {
|
|
558
573
|
return this.#scope || this.network?.scope || "global";
|
|
559
574
|
}
|
package/src/owner.mjs
CHANGED
|
@@ -166,10 +166,18 @@ export class Owner extends Base {
|
|
|
166
166
|
}
|
|
167
167
|
|
|
168
168
|
subnetNamed(name) {
|
|
169
|
+
if (this !== this.location) {
|
|
170
|
+
return this.location.subnetNamed(name);
|
|
171
|
+
}
|
|
172
|
+
|
|
169
173
|
return this.typeNamed("subnet", name);
|
|
170
174
|
}
|
|
171
175
|
|
|
172
176
|
subnets() {
|
|
177
|
+
if (this !== this.location) {
|
|
178
|
+
return this.location.subnets();
|
|
179
|
+
}
|
|
180
|
+
|
|
173
181
|
return this.typeList("subnet");
|
|
174
182
|
}
|
|
175
183
|
|
|
@@ -181,18 +189,28 @@ export class Owner extends Base {
|
|
|
181
189
|
}
|
|
182
190
|
}
|
|
183
191
|
|
|
184
|
-
|
|
192
|
+
addSubnet(address) {
|
|
193
|
+
if (this !== this.location) {
|
|
194
|
+
return this.location.addSubnet(address);
|
|
195
|
+
}
|
|
196
|
+
|
|
185
197
|
if (address instanceof Subnet) {
|
|
186
198
|
return address;
|
|
187
199
|
}
|
|
188
200
|
|
|
189
201
|
const { cidr } = normalizeCIDR(address);
|
|
190
202
|
|
|
203
|
+
//console.log("ADD SUBNET", this.toString(), address, cidr);
|
|
204
|
+
|
|
191
205
|
if (cidr) {
|
|
192
206
|
let subnet = this.subnetNamed(cidr);
|
|
193
207
|
|
|
194
208
|
if (!subnet) {
|
|
195
209
|
subnet = new Subnet(this, { name: cidr });
|
|
210
|
+
|
|
211
|
+
/*if(this.owner) {
|
|
212
|
+
this.owner.addSubnet(subnet);
|
|
213
|
+
}*/
|
|
196
214
|
}
|
|
197
215
|
|
|
198
216
|
return subnet;
|
|
@@ -331,6 +349,10 @@ export class Network extends Owner {
|
|
|
331
349
|
this.bridge = owner.addBridge(this, bridge);
|
|
332
350
|
}
|
|
333
351
|
|
|
352
|
+
get network() {
|
|
353
|
+
return this;
|
|
354
|
+
}
|
|
355
|
+
|
|
334
356
|
networkNamed(name) {
|
|
335
357
|
if (this.fullName === name) {
|
|
336
358
|
return this;
|
|
@@ -340,8 +362,7 @@ export class Network extends Owner {
|
|
|
340
362
|
|
|
341
363
|
addSubnets(value) {
|
|
342
364
|
for (const address of asArray(value)) {
|
|
343
|
-
const subnet = this.
|
|
344
|
-
this.addObject(subnet);
|
|
365
|
+
const subnet = this.addSubnet(address);
|
|
345
366
|
subnet.networks.add(this);
|
|
346
367
|
}
|
|
347
368
|
}
|
package/src/utils.mjs
CHANGED
|
@@ -81,6 +81,25 @@ function decodeIPv4(address, length = 32) {
|
|
|
81
81
|
return octets.join(".");
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
+
export function encodeIPv6(address) {
|
|
85
|
+
const words = [0, 0, 0, 0, 0, 0, 0, 0];
|
|
86
|
+
|
|
87
|
+
let i = 0;
|
|
88
|
+
for (const a of normalizeIPAddress(address).split(/\:/)) {
|
|
89
|
+
words[i++] = parseInt(a,16);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let res = 0n;
|
|
93
|
+
let shift = 128n;
|
|
94
|
+
|
|
95
|
+
for(const word of words) {
|
|
96
|
+
shift -= 16n;
|
|
97
|
+
res += BigInt(word) << shift;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return res;
|
|
101
|
+
}
|
|
102
|
+
|
|
84
103
|
export function normalizeCIDR(address) {
|
|
85
104
|
let [prefix, prefixLength] = address.split(/\//);
|
|
86
105
|
|
package/types/model.d.mts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class Location extends Owner {
|
|
2
|
+
get location(): this;
|
|
3
|
+
}
|
|
4
|
+
export class Root extends Location {
|
|
2
5
|
static get types(): {
|
|
3
6
|
[k: string]: typeof DNSService | typeof Owner | typeof Subnet | typeof Service | typeof Host | typeof NetworkInterface;
|
|
4
7
|
};
|
|
@@ -9,9 +12,6 @@ export class Root extends Owner {
|
|
|
9
12
|
load(name: any, options: any): any;
|
|
10
13
|
loadAll(): Promise<void>;
|
|
11
14
|
}
|
|
12
|
-
export class Location extends Owner {
|
|
13
|
-
get location(): this;
|
|
14
|
-
}
|
|
15
15
|
export class Host extends Base {
|
|
16
16
|
static prepareData(root: any, data: any): Promise<typeof Host>;
|
|
17
17
|
postinstall: any[];
|
|
@@ -37,7 +37,7 @@ export class Host extends Base {
|
|
|
37
37
|
addService(service: any): void;
|
|
38
38
|
services(filter: any): Generator<any, void, unknown>;
|
|
39
39
|
get networkInterfaces(): Map<any, any>;
|
|
40
|
-
|
|
40
|
+
networkInterfaceNamed(name: any): any;
|
|
41
41
|
addNetworkInterface(networkInterface: any): void;
|
|
42
42
|
networkAddresses(): Generator<{
|
|
43
43
|
networkInterface: any;
|
|
@@ -60,8 +60,9 @@ export class NetworkInterface extends Base {
|
|
|
60
60
|
hwaddr: any;
|
|
61
61
|
set network(networkOrName: any);
|
|
62
62
|
get network(): any;
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
addSubnet(address: any): any;
|
|
64
|
+
set ipAddresses(value: any[]);
|
|
65
|
+
get ipAddresses(): any[];
|
|
65
66
|
subnetForAddress(address: any): any;
|
|
66
67
|
addressWithPrefixLength(address: any): string;
|
|
67
68
|
get gateway(): any;
|
package/types/owner.d.mts
CHANGED
|
@@ -20,9 +20,9 @@ export class Owner extends Base {
|
|
|
20
20
|
networkNamed(name: any): any;
|
|
21
21
|
networks(): Generator<any, void, unknown>;
|
|
22
22
|
subnetNamed(name: any): any;
|
|
23
|
-
subnets():
|
|
23
|
+
subnets(): any;
|
|
24
24
|
subnetForAddress(address: any): any;
|
|
25
|
-
|
|
25
|
+
addSubnet(address: any): any;
|
|
26
26
|
clusterNamed(name: any): any;
|
|
27
27
|
clusters(): Generator<any, void, unknown>;
|
|
28
28
|
addBridge(network: any, destinationNetworks: any): any;
|
|
@@ -38,6 +38,7 @@ export class Network extends Owner {
|
|
|
38
38
|
metric: any;
|
|
39
39
|
bridge: any;
|
|
40
40
|
gateway: any;
|
|
41
|
+
get network(): this;
|
|
41
42
|
addSubnets(value: any): void;
|
|
42
43
|
}
|
|
43
44
|
export class Subnet extends Base {
|
package/types/utils.d.mts
CHANGED
|
@@ -6,6 +6,7 @@ export function isIPv4Address(address: any): boolean;
|
|
|
6
6
|
export function isIPv6Address(address: any): boolean;
|
|
7
7
|
export function isLinkLocal(address: any): any;
|
|
8
8
|
export function normalizeIPAddress(address: any): any;
|
|
9
|
+
export function encodeIPv6(address: any): bigint;
|
|
9
10
|
export function normalizeCIDR(address: any): {
|
|
10
11
|
prefix?: undefined;
|
|
11
12
|
prefixLength?: undefined;
|