pmcf 1.42.1 → 1.43.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.
@@ -15,7 +15,7 @@ const host = await root.load(hostName, { type: Host });
15
15
  await generateNetworkDefs(host, options.output);
16
16
  await generateMachineInfo(host, options.output);
17
17
  await copySshKeys(host, options.output);
18
- await generateKnownHosts(root.hosts(), join(options.output, "root", ".ssh"));
18
+ await generateKnownHosts(host.owner.hosts(), join(options.output, "root", ".ssh"));
19
19
 
20
20
  console.log("provides", "host", ...host.provides);
21
21
  console.log("depends", `location-${host.location.name}`, ...host.depends);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.42.1",
3
+ "version": "1.43.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -43,7 +43,7 @@
43
43
  "pacc": "^3.3.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@types/node": "^22.13.2",
46
+ "@types/node": "^22.13.4",
47
47
  "ava": "^6.2.0",
48
48
  "c8": "^10.1.3",
49
49
  "documentation": "^14.0.3",
package/src/base.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { join } from "node:path";
2
2
  import { getAttribute } from "pacc";
3
3
  import { typesByName } from "./types.mjs";
4
+ import { asArray } from "./utils.mjs";
4
5
 
5
6
  export class Base {
6
7
  owner;
@@ -8,19 +9,21 @@ export class Base {
8
9
  description;
9
10
 
10
11
  static get typeName() {
11
- return "base";
12
+ return this.typeDefinition.name;
12
13
  }
13
14
 
14
15
  static get typeDefinition() {
15
16
  return {
16
- // name: { type: "string", collection: false }
17
+ name: "base",
18
+ properties: {
19
+ /* name: { type: "string" },
20
+ description: { type: "string" },
21
+ directory: { type: "string" },
22
+ owner: {}*/
23
+ }
17
24
  };
18
25
  }
19
26
 
20
- static get pluralTypeName() {
21
- return this.typeName + "s";
22
- }
23
-
24
27
  static get nameLookupName() {
25
28
  return this.typeName + "Named";
26
29
  }
@@ -46,28 +49,41 @@ export class Base {
46
49
  constructor(owner, data) {
47
50
  this.owner = owner;
48
51
 
49
- if (data) {
50
- this.name = data.name;
51
- if (data.description) {
52
- this.description = data.description;
52
+ switch (typeof data) {
53
+ case "string":
54
+ this.name = data;
55
+ break;
56
+ case "object": {
57
+ this.name = data.name;
58
+ if (data.description) {
59
+ this.description = data.description;
60
+ }
53
61
  }
54
62
  }
55
63
  }
56
64
 
57
65
  read(data) {
58
66
  for (const [slotName, typeDef] of Object.entries(
59
- this.constructor.typeDefinition
67
+ this.constructor.typeDefinition.properties
60
68
  )) {
61
69
  const slot = data[slotName];
62
70
  if (slot) {
63
71
  delete data[slotName];
64
72
  if (typeDef.collection) {
65
- for (const [objectName, objectData] of Object.entries(slot)) {
66
- objectData.name = objectName;
67
- new typesByName[typeDef.type](this, objectData);
73
+ if (Array.isArray(slot) || typeof slot === "string") {
74
+ for (const item of asArray(slot)) {
75
+ new typesByName[typeDef.type](this, item);
76
+ }
77
+ } else {
78
+ for (const [objectName, objectData] of Object.entries(slot)) {
79
+ objectData.name = objectName;
80
+ new typesByName[typeDef.type](this, objectData);
81
+ }
68
82
  }
69
83
  } else {
70
- this[typeDef.type] = new typesByName[typeDef.type](this, slot);
84
+ // if (typeDef.type) {
85
+ this[typeDef.type] = new typesByName[typeDef.type](this, slot);
86
+ // }
71
87
  }
72
88
  }
73
89
  }
package/src/cluster.mjs CHANGED
@@ -6,8 +6,12 @@ export class Cluster extends Owner {
6
6
  addType(this);
7
7
  }
8
8
 
9
- static get typeName() {
10
- return "cluster";
9
+ static get typeDefinition() {
10
+ return {
11
+ name: "cluster",
12
+ extends: "owner",
13
+ properties: {}
14
+ };
11
15
  }
12
16
 
13
17
  constructor(owner, data) {
package/src/dns.mjs CHANGED
@@ -14,9 +14,19 @@ export class DNSService extends Base {
14
14
  static {
15
15
  addType(this);
16
16
  }
17
-
18
- static get typeName() {
19
- return "dns";
17
+
18
+ static get typeDefinition() {
19
+ return {
20
+ name: "dns",
21
+ properties: {
22
+ /*recordTTL: {},
23
+ soaUpdates: {},
24
+ hasSVRRecords: {},
25
+ hasCatalog: {},
26
+ forwardsTo: {},
27
+ allowedUpdates: {}*/
28
+ }
29
+ };
20
30
  }
21
31
 
22
32
  constructor(owner, data) {
package/src/host.mjs CHANGED
@@ -27,14 +27,21 @@ export class Host extends Base {
27
27
  addType(this);
28
28
  }
29
29
 
30
- static get typeName() {
31
- return "host";
32
- }
33
-
34
30
  static get typeDefinition() {
35
31
  return {
36
- networkInterfaces: { type: "network_interface", collection: true },
37
- services: { type: "service", collection: true }
32
+ name: "host",
33
+ extends: "base",
34
+ properties: {
35
+ networkInterfaces: { type: "network_interface", collection: true },
36
+ services: { type: "service", collection: true }
37
+ /*os: {},
38
+ distribution: {},
39
+ deployment: {},
40
+ master: { },
41
+ model: {},
42
+ replaces: { },
43
+ depends: { }*/
44
+ }
38
45
  };
39
46
  }
40
47
 
@@ -299,8 +306,24 @@ export class NetworkInterface extends Base {
299
306
  addType(this);
300
307
  }
301
308
 
302
- static get typeName() {
303
- return "network_interface";
309
+ static get typeDefinition() {
310
+ return {
311
+ name: "network_interface",
312
+ extends: "base",
313
+ properties: {
314
+ /*
315
+ arpbridge: {},
316
+ hwaddr: {},
317
+ network: {},
318
+ gateway: {},
319
+ ssid: {},
320
+ psk: {},
321
+ scope: {},
322
+ metric: {},
323
+ kind: {},
324
+ ipAddresses: {}*/
325
+ }
326
+ };
304
327
  }
305
328
 
306
329
  #ipAddresses = new Map();
package/src/location.mjs CHANGED
@@ -6,8 +6,18 @@ export class Location extends Owner {
6
6
  addType(this);
7
7
  }
8
8
 
9
- static get typeName() {
10
- return "location";
9
+ static get typeDefinition() {
10
+ return {
11
+ name: "location",
12
+ extends: "owner",
13
+ properties: {
14
+ networks: { type: "network", collection: true },
15
+ hosts: { type: "host", collection: true },
16
+ clusters: { type: "cluster", collection: true },
17
+ subnets: { type: "subnet", collection: true },
18
+ dns: { type: "dns", collection: false }
19
+ }
20
+ };
11
21
  }
12
22
 
13
23
  get location() {
package/src/network.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Owner } from "./owner.mjs";
2
- import { asArray } from "./utils.mjs";
2
+ import { Subnet } from "./subnet.mjs";
3
3
  import { addType } from "./types.mjs";
4
4
 
5
5
  export class Network extends Owner {
@@ -13,18 +13,29 @@ export class Network extends Owner {
13
13
  addType(this);
14
14
  }
15
15
 
16
- static get typeName() {
17
- return "network";
16
+ static get typeDefinition() {
17
+ return {
18
+ name: "network",
19
+ extends: "owner",
20
+ properties: {
21
+ networks: { type: "network", collection: true },
22
+ hosts: { type: "host", collection: true },
23
+ clusters: { type: "cluster", collection: true },
24
+ subnets: { type: "subnet", collection: true },
25
+ dns: { type: "dns", collection: false }
26
+
27
+ /* kind: {},
28
+ scope: {},
29
+ metric: {},
30
+ bridge: {},
31
+ gateway: {}*/
32
+ }
33
+ };
18
34
  }
19
35
 
20
36
  constructor(owner, data) {
21
37
  super(owner, data);
22
38
 
23
- if (data.subnets) {
24
- this.addSubnets(data.subnets);
25
- delete data.subnets;
26
- }
27
-
28
39
  if (data.bridge) {
29
40
  this.bridge = owner.addBridge(this, data.bridge);
30
41
  delete data.bridge;
@@ -48,10 +59,10 @@ export class Network extends Owner {
48
59
  return super.networkNamed(name);
49
60
  }
50
61
 
51
- addSubnets(value) {
52
- for (const address of asArray(value)) {
53
- const subnet = this.addSubnet(address);
54
- subnet.networks.add(this);
62
+ addObject(object) {
63
+ super.addObject(object);
64
+ if (object instanceof Subnet) {
65
+ object.networks.add(this);
55
66
  }
56
67
  }
57
68
 
@@ -60,32 +71,6 @@ export class Network extends Owner {
60
71
  }
61
72
 
62
73
  set bridge(bridge) {
63
- for (const network of bridge) {
64
- if (network instanceof Network && network !== this) {
65
- for (const subnet of this.subnets()) {
66
- for (const otherSubnet of network.subnets()) {
67
- if (
68
- subnet !== otherSubnet &&
69
- subnet.address === otherSubnet.address
70
- ) {
71
- /*console.log(
72
- "SHARE SUBNETS",
73
- subnet.owner.toString(),
74
- otherSubnet.owner.toString()
75
- );*/
76
-
77
- otherSubnet.owner.addObject(subnet);
78
- for (const n of otherSubnet.networks) {
79
- subnet.networks.add(n);
80
- }
81
-
82
- //console.log(subnet.toString(),[...subnet.networks].map(n=>n.toString()));
83
- }
84
- }
85
- }
86
- }
87
- }
88
-
89
74
  this.#bridge = bridge;
90
75
  }
91
76
 
package/src/owner.mjs CHANGED
@@ -14,17 +14,17 @@ export class Owner extends Base {
14
14
  addType(this);
15
15
  }
16
16
 
17
- static get typeName() {
18
- return "owner";
19
- }
20
-
21
17
  static get typeDefinition() {
22
18
  return {
23
- networks: { type: "network", collection: true },
24
- hosts: { type: "host", collection: true },
25
- clusters: { type: "cluster", collection: true },
26
- /* subnets: { type: "subnet", collection: true },*/
27
- dns: { type: "dns", collection: false }
19
+ name: "owner",
20
+ extends: "base",
21
+ properties: {
22
+ networks: { type: "network", collection: true },
23
+ hosts: { type: "host", collection: true },
24
+ clusters: { type: "cluster", collection: true },
25
+ subnets: { type: "subnet", collection: true },
26
+ dns: { type: "dns", collection: false }
27
+ }
28
28
  };
29
29
  }
30
30
 
@@ -66,7 +66,6 @@ export class Owner extends Base {
66
66
  }
67
67
 
68
68
  named(name) {
69
- //console.log("NAMED", this.#membersByType.keys());
70
69
  for (const slot of this.#membersByType.values()) {
71
70
  const object = slot.get(name);
72
71
  if (object) {
@@ -164,13 +163,7 @@ export class Owner extends Base {
164
163
  const { cidr } = normalizeCIDR(address);
165
164
 
166
165
  if (cidr) {
167
- let subnet = this.subnetNamed(cidr);
168
-
169
- if (!subnet) {
170
- subnet = new Subnet(this, { name: cidr });
171
- }
172
-
173
- return subnet;
166
+ return this.subnetNamed(cidr) || new Subnet(this, cidr);
174
167
  }
175
168
  }
176
169
 
@@ -229,7 +222,10 @@ export class Owner extends Base {
229
222
  _resolveBridges() {
230
223
  for (const bridge of this.#bridges) {
231
224
  //this.info(bridgeToJSON(bridge));
232
- for (const network of bridge) {
225
+
226
+ const subnets = new Map();
227
+
228
+ for (let network of bridge) {
233
229
  if (typeof network === "string") {
234
230
  const other = this.networkNamed(network);
235
231
 
@@ -237,10 +233,25 @@ export class Owner extends Base {
237
233
  bridge.delete(network);
238
234
  bridge.add(other);
239
235
  other.bridge = bridge;
236
+ network = other;
240
237
  } else {
241
238
  this.error(`Unresolvabale bridge network`, network);
242
239
  }
243
240
  }
241
+
242
+ // enshure only one subnet address in the bridge
243
+ for (const subnet of network.subnets()) {
244
+ const present = subnets.get(subnet.address);
245
+ if (present) {
246
+ subnet.owner.addObject(present);
247
+
248
+ for (const n of subnet.networks) {
249
+ present.networks.add(n);
250
+ }
251
+ } else {
252
+ subnets.set(subnet.address, subnet);
253
+ }
254
+ }
244
255
  }
245
256
  }
246
257
  }
package/src/root.mjs CHANGED
@@ -10,8 +10,13 @@ export class Root extends Location {
10
10
  addType(this);
11
11
  }
12
12
 
13
- static get typeName() {
14
- return "root";
13
+ static get typeDefinition() {
14
+ return {
15
+ name: "root",
16
+ extends: "location",
17
+ properties: {
18
+ }
19
+ };
15
20
  }
16
21
 
17
22
  constructor(directory) {
package/src/service.mjs CHANGED
@@ -26,8 +26,22 @@ export class Service extends Base {
26
26
  addType(this);
27
27
  }
28
28
 
29
- static get typeName() {
30
- return "service";
29
+ static get typeDefinition() {
30
+ return {
31
+ name: "service",
32
+ extends: "base",
33
+ properties: {
34
+ /*ipAddresses: {},
35
+ addresses: {},
36
+ port: {},
37
+ protocol: {},
38
+ alias: {},
39
+ type: {},
40
+ master: {},
41
+ priority: {},
42
+ weight: {}*/
43
+ }
44
+ };
31
45
  }
32
46
 
33
47
  constructor(owner, data) {
package/src/subnet.mjs CHANGED
@@ -9,24 +9,26 @@ export class Subnet extends Base {
9
9
  addType(this);
10
10
  }
11
11
 
12
- static get typeName() {
13
- return "subnet";
12
+ static get typeDefinition() {
13
+ return {
14
+ name: "subnet",
15
+ extends: "base",
16
+ properties: {
17
+ // address: {}
18
+ }
19
+ };
14
20
  }
15
21
 
16
- constructor(owner, data) {
17
- const { cidr } = normalizeCIDR(data.name);
22
+ constructor(owner, address) {
23
+ const { cidr } = normalizeCIDR(address);
18
24
 
19
25
  if (!cidr) {
20
26
  const error = Error(`Invalid address`);
21
- error.address = data.name;
27
+ error.address = address;
22
28
  throw error;
23
29
  }
24
30
 
25
- data.name = cidr;
26
-
27
- super(owner, data);
28
-
29
- Object.assign(this, data);
31
+ super(owner, cidr);
30
32
 
31
33
  owner.addObject(this);
32
34
  }
package/src/types.mjs CHANGED
@@ -1,6 +1,10 @@
1
1
  export function addType(clazz) {
2
2
  types.push(clazz);
3
- typesByName[clazz.typeName] = clazz;
3
+
4
+ const typeDefinition = clazz.typeDefinition;
5
+ typeDefinition.clazz = clazz;
6
+
7
+ typesByName[typeDefinition.name] = clazz;
4
8
  }
5
9
 
6
10
  export const types = [];
package/types/base.d.mts CHANGED
@@ -1,8 +1,10 @@
1
1
  export function extractFrom(object: any): {};
2
2
  export class Base {
3
3
  static get typeName(): string;
4
- static get typeDefinition(): {};
5
- static get pluralTypeName(): string;
4
+ static get typeDefinition(): {
5
+ name: string;
6
+ properties: {};
7
+ };
6
8
  static get nameLookupName(): string;
7
9
  static get typeFileName(): string;
8
10
  static get fileNameGlob(): string;
@@ -1,4 +1,9 @@
1
1
  export class Cluster extends Owner {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: string;
5
+ properties: {};
6
+ };
2
7
  constructor(owner: any, data: any);
3
8
  }
4
9
  import { Owner } from "./owner.mjs";
package/types/host.d.mts CHANGED
@@ -1,12 +1,16 @@
1
1
  export class Host extends Base {
2
2
  static get typeDefinition(): {
3
- networkInterfaces: {
4
- type: string;
5
- collection: boolean;
6
- };
7
- services: {
8
- type: string;
9
- collection: boolean;
3
+ name: string;
4
+ extends: string;
5
+ properties: {
6
+ networkInterfaces: {
7
+ type: string;
8
+ collection: boolean;
9
+ };
10
+ services: {
11
+ type: string;
12
+ collection: boolean;
13
+ };
10
14
  };
11
15
  };
12
16
  static prepareData(root: any, data: any): Promise<typeof Host>;
@@ -52,6 +56,11 @@ export class Host extends Base {
52
56
  #private;
53
57
  }
54
58
  export class NetworkInterface extends Base {
59
+ static get typeDefinition(): {
60
+ name: string;
61
+ extends: string;
62
+ properties: {};
63
+ };
55
64
  arpbridge: any;
56
65
  hwaddr: any;
57
66
  set network(networkOrName: any);
@@ -7,7 +7,6 @@ export class Network extends Owner {
7
7
  set bridge(bridge: any);
8
8
  get bridge(): any;
9
9
  get network(): this;
10
- addSubnets(value: any): void;
11
10
  #private;
12
11
  }
13
12
  import { Owner } from "./owner.mjs";
package/types/owner.d.mts CHANGED
@@ -1,20 +1,28 @@
1
1
  export class Owner extends Base {
2
2
  static get typeDefinition(): {
3
- networks: {
4
- type: string;
5
- collection: boolean;
6
- };
7
- hosts: {
8
- type: string;
9
- collection: boolean;
10
- };
11
- clusters: {
12
- type: string;
13
- collection: boolean;
14
- };
15
- dns: {
16
- type: string;
17
- collection: boolean;
3
+ name: string;
4
+ extends: string;
5
+ properties: {
6
+ networks: {
7
+ type: string;
8
+ collection: boolean;
9
+ };
10
+ hosts: {
11
+ type: string;
12
+ collection: boolean;
13
+ };
14
+ clusters: {
15
+ type: string;
16
+ collection: boolean;
17
+ };
18
+ subnets: {
19
+ type: string;
20
+ collection: boolean;
21
+ };
22
+ dns: {
23
+ type: string;
24
+ collection: boolean;
25
+ };
18
26
  };
19
27
  };
20
28
  constructor(owner: any, data?: {});
package/types/root.d.mts CHANGED
@@ -1,4 +1,9 @@
1
1
  export class Root extends Location {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: string;
5
+ properties: {};
6
+ };
2
7
  constructor(directory: any);
3
8
  get fullName(): string;
4
9
  get root(): this;
@@ -1,4 +1,9 @@
1
1
  export class Service extends Base {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: string;
5
+ properties: {};
6
+ };
2
7
  alias: any;
3
8
  get protocol(): any;
4
9
  get srvPrefix(): string;
@@ -1,4 +1,9 @@
1
1
  export class Subnet extends Base {
2
+ static get typeDefinition(): {
3
+ name: string;
4
+ extends: string;
5
+ properties: {};
6
+ };
2
7
  networks: Set<any>;
3
8
  matchesAddress(address: any): any;
4
9
  get isLinkLocal(): any;