pmcf 2.22.0 → 2.22.1

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.22.0",
3
+ "version": "2.22.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/src/cluster.mjs CHANGED
@@ -4,6 +4,7 @@ import { Owner } from "./owner.mjs";
4
4
  import { Host } from "./host.mjs";
5
5
  import { addType } from "./types.mjs";
6
6
  import { writeLines } from "./utils.mjs";
7
+ import { cidrAddresses } from "./network-support.mjs";
7
8
 
8
9
  const ClusterTypeDefinition = {
9
10
  name: "cluster",
@@ -102,10 +103,15 @@ export class Cluster extends Host {
102
103
  cfg.push(`vrrp_instance ${cluster.name} {`);
103
104
  cfg.push(` state ${cluster.masters.has(ni) ? "MASTER" : "BACKUP"}`);
104
105
  cfg.push(` interface ${ni.name}`);
106
+
105
107
  cfg.push(" virtual_ipaddress {");
106
- cfg.push(
107
- ` ${cluster.cidrAddress} dev ${ni.name} label ${cluster.name}`
108
- );
108
+ for (const na of cluster.networkAddresses(
109
+ na => na.networkInterface.kind !== "loopback"
110
+ )) {
111
+ cfg.push(
112
+ ` ${na.cidrAddress} dev ${ni.name} label ${cluster.name}`
113
+ );
114
+ }
109
115
  cfg.push(" }");
110
116
  cfg.push(` virtual_router_id ${cluster.routerId}`);
111
117
  cfg.push(
@@ -141,9 +147,7 @@ export class Cluster extends Host {
141
147
  for (const member of this.members) {
142
148
  const memberService = member.findService({ type: service.type });
143
149
 
144
- cfg.push(
145
- ` real_server ${member.address} ${memberService.port} {`
146
- );
150
+ cfg.push(` real_server ${member.address} ${memberService.port} {`);
147
151
  cfg.push(` weight ${memberService.weight}`);
148
152
 
149
153
  switch (service.type) {
@@ -1,4 +1,9 @@
1
- import { hasWellKnownSubnet, normalizeIP, familyIP } from "ip-utilties";
1
+ import {
2
+ hasWellKnownSubnet,
3
+ normalizeIP,
4
+ familyIP,
5
+ formatCIDR
6
+ } from "ip-utilties";
2
7
  import { Base } from "./base.mjs";
3
8
  import { Subnet } from "./subnet.mjs";
4
9
  import {
@@ -9,13 +14,35 @@ import { asArray } from "./utils.mjs";
9
14
  import { addType } from "./types.mjs";
10
15
 
11
16
  /**
12
- * @typedef {object} NetworkAddress
13
17
  * @property {NetworkInterface} networkInterface
14
18
  * @property {string|Uint8Array|Uint16Array} address
15
19
  * @property {string} family
16
20
  * @property {Subnet} subnet
17
21
  * @property {Set<string>} domainNames
18
22
  */
23
+ export class NetworkAddress {
24
+ /** @type {Subnet} */ subnet;
25
+ /** @type {NetworkInterface} */ networkInterface;
26
+ /** @type {string|Uint8Array|Uint16Array} */ address;
27
+
28
+ constructor(networkInterface, address, subnet) {
29
+ this.networkInterface = networkInterface;
30
+ this.address = address;
31
+ this.subnet = subnet;
32
+ }
33
+
34
+ get domainNames() {
35
+ this.networkInterface.domainNames;
36
+ }
37
+
38
+ get family() {
39
+ return familyIP(this.address);
40
+ }
41
+
42
+ get cidrAddress() {
43
+ return formatCIDR(this.address, this.subnet.prefixLength);
44
+ }
45
+ }
19
46
 
20
47
  class SkeletonNetworkInterface extends Base {
21
48
  _extends = [];
@@ -73,13 +100,7 @@ class SkeletonNetworkInterface extends Base {
73
100
  */
74
101
  *networkAddresses(filter = n => true) {
75
102
  for (const [address, subnet] of this.ipAddresses) {
76
- const networkAddress = {
77
- networkInterface: this,
78
- domainNames: this.domainNames,
79
- address,
80
- family: familyIP(address),
81
- subnet
82
- };
103
+ const networkAddress = new NetworkAddress(this, address, subnet);
83
104
 
84
105
  if (filter(networkAddress)) {
85
106
  yield networkAddress;
@@ -1,5 +1,3 @@
1
- import { formatCIDR } from "ip-utilties";
2
-
3
1
  export const networkProperties = {
4
2
  scope: {
5
3
  type: "string",
@@ -46,7 +44,5 @@ export function addresses(networkAddresses) {
46
44
  }
47
45
 
48
46
  export function cidrAddresses(networkAddresses) {
49
- return [...networkAddresses].map(na =>
50
- formatCIDR(na.address, na.subnet.prefixLength)
51
- );
47
+ return [...networkAddresses].map(na => na.cidrAddress);
52
48
  }
@@ -1,3 +1,19 @@
1
+ /**
2
+ * @property {NetworkInterface} networkInterface
3
+ * @property {string|Uint8Array|Uint16Array} address
4
+ * @property {string} family
5
+ * @property {Subnet} subnet
6
+ * @property {Set<string>} domainNames
7
+ */
8
+ export class NetworkAddress {
9
+ constructor(networkInterface: any, address: any, subnet: any);
10
+ /** @type {Subnet} */ subnet: Subnet;
11
+ /** @type {NetworkInterface} */ networkInterface: NetworkInterface;
12
+ /** @type {string|Uint8Array|Uint16Array} */ address: string | Uint8Array | Uint16Array;
13
+ get domainNames(): void;
14
+ get family(): any;
15
+ get cidrAddress(): any;
16
+ }
1
17
  export namespace NetworkInterfaceTypeDefinition {
2
18
  export let name: string;
3
19
  export let priority: number;
@@ -685,21 +701,7 @@ export class LoopbackNetworkInterface extends SkeletonNetworkInterface {
685
701
  prefixLength: number;
686
702
  }>;
687
703
  }
688
- export type NetworkAddress = {
689
- networkInterface: NetworkInterface;
690
- address: string | Uint8Array | Uint16Array;
691
- family: string;
692
- subnet: Subnet;
693
- domainNames: Set<string>;
694
- };
695
- /**
696
- * @typedef {object} NetworkAddress
697
- * @property {NetworkInterface} networkInterface
698
- * @property {string|Uint8Array|Uint16Array} address
699
- * @property {string} family
700
- * @property {Subnet} subnet
701
- * @property {Set<string>} domainNames
702
- */
704
+ import { Subnet } from "./subnet.mjs";
703
705
  declare class SkeletonNetworkInterface extends Base {
704
706
  _extends: any[];
705
707
  _network: any;
@@ -721,6 +723,5 @@ declare class SkeletonNetworkInterface extends Base {
721
723
  get address(): any;
722
724
  get addresses(): any[];
723
725
  }
724
- import { Subnet } from "./subnet.mjs";
725
726
  import { Base } from "./base.mjs";
726
727
  export {};