Commit 38c18c5e authored by nanahira's avatar nanahira

support no-update link

parent 1831a824
...@@ -89,13 +89,13 @@ ...@@ -89,13 +89,13 @@
vars: vars:
conn: '{{item}}' conn: '{{item}}'
with_items: '{{ connections }}' with_items: '{{ connections }}'
when: "not noUpdateLinks and (not onlyUpdateLink or item.name == onlyUpdateLink) and item.protocol == 'null'" when: "not noUpdateLinks and item.protocol == 'null' and not item.noUpdate"
- name: 'loop through list from a variable' - name: 'loop through list from a variable'
include_tasks: 'protocols/{{item.protocol}}/configure.yaml' include_tasks: 'protocols/{{item.protocol}}/configure.yaml'
vars: vars:
conn: '{{item}}' conn: '{{item}}'
with_items: '{{ connections }}' with_items: '{{ connections }}'
when: "not noUpdateLinks and (not onlyUpdateLink or item.name == onlyUpdateLink) and item.protocol != 'null'" when: "not noUpdateLinks and item.protocol != 'null' and not item.noUpdate"
# end # end
- name: disable bug self-link - name: disable bug self-link
become: true become: true
......
...@@ -25,6 +25,7 @@ class InventoryBuilder { ...@@ -25,6 +25,7 @@ class InventoryBuilder {
resolveCache: Map<string, string>; resolveCache: Map<string, string>;
resolver: dns.Resolver; resolver: dns.Resolver;
vars: any; vars: any;
linksOnly: string[];
constructor() { constructor() {
this.resolveCache = new Map(); this.resolveCache = new Map();
...@@ -95,6 +96,9 @@ class InventoryBuilder { ...@@ -95,6 +96,9 @@ class InventoryBuilder {
for (const host of Object.values(this.hosts)) { for (const host of Object.values(this.hosts)) {
host.wgPublickey = await this.wgPublickey(host.wgPrivateKey); host.wgPublickey = await this.wgPublickey(host.wgPrivateKey);
} }
if (process.env.ONLY_LINKS) {
this.linksOnly = process.env.ONLY_LINKS.split(",");
}
this.vars = await this.loadUtilities(); this.vars = await this.loadUtilities();
const inventoryValue = { wg: {hosts: Object.fromEntries(Object.values(this.hosts).map(host => [host.name, this.getHostConnectionInfo(host)]))} }; const inventoryValue = { wg: {hosts: Object.fromEntries(Object.values(this.hosts).map(host => [host.name, this.getHostConnectionInfo(host)]))} };
await fs.promises.writeFile('result/inventory.yaml', YAML.stringify(inventoryValue)); await fs.promises.writeFile('result/inventory.yaml', YAML.stringify(inventoryValue));
...@@ -128,8 +132,7 @@ class InventoryBuilder { ...@@ -128,8 +132,7 @@ class InventoryBuilder {
const vars = { const vars = {
routeLists: this.routeLists, routeLists: this.routeLists,
routeListNames: Object.keys(this.routeLists), routeListNames: Object.keys(this.routeLists),
noUpdateLinks: !!process.env.NO_LINK, noUpdateLinks: !!process.env.NO_LINK
onlyUpdateLink: process.env.ONLY_LINK || null
}; };
for (let col in raw_utility) { for (let col in raw_utility) {
vars[col] = raw_utility[col].value; vars[col] = raw_utility[col].value;
...@@ -346,6 +349,8 @@ class InventoryBuilder { ...@@ -346,6 +349,8 @@ class InventoryBuilder {
console.log(`${local.name} GW ${localGateway.isp} ${inbound ? '<' : '='}=${frpType === 'frps' ? 's' : '='}=[${protocol}]=${frpType === 'frpc' ? 's' : '='}=> ${remote.name} GW ${remoteGateway.isp}`); console.log(`${local.name} GW ${localGateway.isp} ${inbound ? '<' : '='}=${frpType === 'frps' ? 's' : '='}=[${protocol}]=${frpType === 'frpc' ? 's' : '='}=> ${remote.name} GW ${remoteGateway.isp}`);
} }
const noUpdate = this.linksOnly && !this.linksOnly.includes(remote.name) && !this.linksOnly.includes(local.name)
return { return {
name, name,
metric, metric,
...@@ -370,7 +375,8 @@ class InventoryBuilder { ...@@ -370,7 +375,8 @@ class InventoryBuilder {
ocType, ocType,
inbound, inbound,
outbound, outbound,
mtu mtu,
noUpdate,
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment