pmcf 2.9.2 → 2.10.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "2.9.2",
3
+ "version": "2.10.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/service.mjs CHANGED
@@ -152,6 +152,10 @@ export class Service extends Base {
152
152
  return this.rawAddresses.map(a => `${a}:${this.port}`);
153
153
  }
154
154
 
155
+ get networks() {
156
+ return this.server.networks;
157
+ }
158
+
155
159
  get endpoints() {
156
160
  if (!ServiceTypes[this.type]) {
157
161
  return [{ address: this.rawAddress, port: this._port, tls: false }];
@@ -147,17 +147,14 @@ export class DHCPService extends Service {
147
147
  }
148
148
  };
149
149
 
150
- // console.log(this.owner.name,this.owner.networks());
151
- /*
152
150
  const subnets = new Set();
153
151
 
154
- for (const network of this.owner.networks()) {
152
+ for (const network of this.networks) {
155
153
  for (const subnet of network.subnets()) {
156
154
  subnets.add(subnet);
157
155
  }
158
156
  }
159
- console.log([...subnets].map(s => s.address));
160
- */
157
+ //console.log([...subnets].filter(s => s.isIPv4).map(s => s.address));
161
158
 
162
159
  const hwmap = new Map();
163
160
  const hostNames = new Set();
@@ -199,24 +196,22 @@ export class DHCPService extends Service {
199
196
  data: [...this.domains].join(",")
200
197
  }
201
198
  ],
202
- subnet4: [
203
- {
204
- id: 1,
205
- subnet: "192.168.1.0/24",
206
- pools: [
207
- {
208
- pool: "192.168.1.100 - 192.168.1.200"
209
- }
210
- ],
211
- "option-data": [
212
- {
213
- name: "routers",
214
- data: network.gateway.rawAddress
215
- }
216
- ],
217
- reservations
218
- }
219
- ],
199
+ subnet4: [...subnets]
200
+ .filter(s => s.isIPv4)
201
+ .map((subnet, index) => {
202
+ return {
203
+ id: index + 1,
204
+ subnet: subnet.address,
205
+ pools: [{ pool: subnet.addressRange.join(" - ") }],
206
+ "option-data": [
207
+ {
208
+ name: "routers",
209
+ data: network.gateway.rawAddress
210
+ }
211
+ ],
212
+ reservations
213
+ };
214
+ }),
220
215
  loggers
221
216
  }
222
217
  };
package/src/subnet.mjs CHANGED
@@ -1,4 +1,9 @@
1
- import { normalizeCIDR, isLinkLocal } from "./utils.mjs";
1
+ import {
2
+ normalizeCIDR,
3
+ isLinkLocal,
4
+ isIPv4Address,
5
+ isIPv6Address
6
+ } from "./utils.mjs";
2
7
  import { Base } from "./base.mjs";
3
8
  import { addType } from "./types.mjs";
4
9
 
@@ -48,6 +53,20 @@ export class Subnet extends Base {
48
53
  return isLinkLocal(this.address);
49
54
  }
50
55
 
56
+ get isIPv4() {
57
+ return isIPv4Address(this.address);
58
+ }
59
+
60
+ get isIPv6() {
61
+ return isIPv6Address(this.address);
62
+ }
63
+
64
+ get addressRange()
65
+ {
66
+ const l = this.prefixLength;
67
+ return l === 24 ? [this.prefix + '.0', this.prefix + '.255'] : [this.prefix + '.0.0', this.prefix + '.255.255']
68
+ }
69
+
51
70
  get prefix() {
52
71
  const [prefix] = this.name.split("/");
53
72
  return prefix;
@@ -76,7 +95,6 @@ export class Subnet extends Base {
76
95
  }
77
96
  }
78
97
 
79
-
80
98
  export function subnets(sources) {
81
99
  const all = new Set();
82
100
 
@@ -88,4 +106,3 @@ export function subnets(sources) {
88
106
 
89
107
  return all;
90
108
  }
91
-
@@ -262,6 +262,7 @@ export class Service extends Base {
262
262
  get rawAddress(): any;
263
263
  set ipAddresses(value: any);
264
264
  get addresses(): any;
265
+ get networks(): any;
265
266
  get endpoints(): any;
266
267
  set port(value: any);
267
268
  get port(): any;
@@ -28,6 +28,9 @@ export class Subnet extends Base {
28
28
  get fullName(): string;
29
29
  matchesAddress(address: any): any;
30
30
  get isLinkLocal(): boolean;
31
+ get isIPv4(): boolean;
32
+ get isIPv6(): boolean;
33
+ get addressRange(): string[];
31
34
  get prefix(): string;
32
35
  get prefixLength(): number;
33
36
  get address(): string;