Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
tun
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
tun
Commits
5fed9a8c
Commit
5fed9a8c
authored
Dec 14, 2020
by
nanahira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add gateway group
parent
748e53ae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
6 deletions
+60
-6
ansible/bird.conf.j2
ansible/bird.conf.j2
+2
-0
ansible/configure.yaml
ansible/configure.yaml
+2
-2
src/inventory.ts
src/inventory.ts
+56
-4
No files found.
ansible/bird.conf.j2
View file @
5fed9a8c
...
...
@@ -32,11 +32,13 @@ protocol kernel {
{% for plan in routePlans %}
ipv4 table {{plan.name}};
{% if plan.addressesString %}
protocol pipe {
table master4;
peer table {{plan.name}};
export where ospf_router_id ~ {{plan.addressesString}};
}
{% endif %}
protocol kernel {
ipv4 {
table {{plan.name}};
...
...
ansible/configure.yaml
View file @
5fed9a8c
...
...
@@ -56,13 +56,13 @@
vars
:
conn
:
'
{{item}}'
with_items
:
'
{{
connections
}}'
when
:
"
item.protocol
==
'null'"
when
:
"
not
noUpdateLinks
and
item.protocol
==
'null'"
-
name
:
'
loop
through
list
from
a
variable'
include_tasks
:
'
protocols/{{item.protocol}}/configure.yaml'
vars
:
conn
:
'
{{item}}'
with_items
:
'
{{
connections
}}'
when
:
"
item.protocol
!=
'null'"
when
:
"
not
noUpdateLinks
and
item.protocol
!=
'null'"
# end
-
name
:
services conf
copy
:
...
...
src/inventory.ts
View file @
5fed9a8c
...
...
@@ -3,15 +3,26 @@ import util from 'util';
import
fs
from
'
fs
'
;
import
path
from
'
path
'
;
import
YAML
from
'
yaml
'
;
import
_
from
'
lodash
'
;
import
_
,
{
add
}
from
'
lodash
'
;
import
child_process
from
'
child_process
'
;
import
assert
from
'
assert
'
;
import
ip
from
"
ip
"
;
import
{
promises
as
dns
}
from
"
dns
"
;
interface
GatewayGroup
{
id
:
number
;
name
:
string
;
locationPrefix
:
string
;
includeRouters
:
string
;
excludeRouters
:
string
;
children
:
string
;
destMark
:
number
;
}
class
InventoryBuilder
{
hosts
:
{
[
key
:
string
]:
any
};
gateways
:
any
;
gatewayGroups
:
GatewayGroup
[];
connections
:
string
[];
routeLists
:
any
;
resolveCache
:
Map
<
string
,
string
>
;
...
...
@@ -45,7 +56,7 @@ class InventoryBuilder {
constructor
()
{
this
.
resolveCache
=
new
Map
();
this
.
resolver
=
new
dns
.
Resolver
();
this
.
resolver
.
setServers
([
'
114.114.114.114
'
,
'
223.5.5.5
'
]);
this
.
resolver
.
setServers
(
process
.
env
.
DNS
?
[
process
.
env
.
DNS
]
:
[
'
114.114.114.114
'
,
'
223.5.5.5
'
]);
}
async
load
(
sheetName
)
{
...
...
@@ -71,6 +82,7 @@ class InventoryBuilder {
async
main
()
{
this
.
hosts
=
_
.
keyBy
(
await
this
.
load
(
'
nextgen2
'
),
'
name
'
);
this
.
gateways
=
_
.
mapValues
(
_
.
groupBy
(
await
this
.
loadGateways
(),
'
router
'
),
g
=>
_
.
keyBy
(
g
,
'
isp
'
));
this
.
gatewayGroups
=
await
this
.
load
(
'
gateway groups
'
);
//console.log(this.gateways);
this
.
connections
=
_
.
intersection
(
Object
.
keys
(
this
.
hosts
),
Object
.
keys
(
_
.
find
(
this
.
hosts
)));
...
...
@@ -111,6 +123,7 @@ class InventoryBuilder {
const
vars
=
{
routeLists
:
this
.
routeLists
,
routeListNames
:
Object
.
keys
(
this
.
routeLists
),
noUpdateLinks
:
!!
process
.
env
.
NO_LINKS
};
for
(
let
col
in
raw_utility
)
{
vars
[
col
]
=
raw_utility
[
col
].
value
;
...
...
@@ -119,8 +132,45 @@ class InventoryBuilder {
return
vars
;
}
getRoutePlanAddressesString
(
addresses
:
string
[])
{
if
(
!
addresses
.
length
)
{
return
null
;
}
return
`[
${
addresses
.
join
(
"
,
"
)}
]`
;
}
getAddressesFromGatewayGroup
(
gatewayGroup
:
GatewayGroup
,
hosts
:
any
[])
{
const
locationPrefixes
=
gatewayGroup
.
locationPrefix
.
split
(
"
,
"
);
const
excludeRouters
=
gatewayGroup
.
excludeRouters
.
split
(
"
,
"
);
const
includeRouters
=
gatewayGroup
.
includeRouters
.
split
(
"
,
"
);
const
children
=
gatewayGroup
.
children
.
split
(
"
,
"
);
const
suitableHosts
=
hosts
.
filter
(
host
=>
{
if
(
excludeRouters
.
includes
(
host
.
name
))
{
return
false
;
}
return
locationPrefixes
.
some
(
prefix
=>
prefix
!==
""
&&
(
host
.
location
as
string
).
startsWith
(
prefix
))
||
includeRouters
.
includes
(
host
.
name
);
});
let
addresses
=
suitableHosts
.
map
(
host
=>
host
.
address
);
for
(
let
childName
of
children
)
{
const
targetGatewayGroup
=
this
.
gatewayGroups
.
find
(
g
=>
g
.
name
===
childName
);
if
(
!
targetGatewayGroup
)
{
continue
;
}
addresses
=
addresses
.
concat
(
this
.
getAddressesFromGatewayGroup
(
targetGatewayGroup
,
hosts
));
}
return
addresses
;
}
getRoutePlansFromGatewayGroups
(
host
:
any
)
{
const
allOtherHosts
=
this
.
connections
.
filter
(
h
=>
h
!==
host
.
name
).
map
(
h
=>
this
.
hosts
[
h
]);
const
routePlans
=
this
.
gatewayGroups
.
map
(
group
=>
{
const
addresses
=
this
.
getAddressesFromGatewayGroup
(
group
,
allOtherHosts
);
return
{
name
:
group
.
name
.
replace
(
/-/g
,
"
_
"
),
destMark
:
group
.
destMark
,
addresses
,
addressesString
:
this
.
getRoutePlanAddressesString
(
addresses
)
}
});
return
routePlans
;
}
async
host_vars
(
host
)
{
const
connections
=
[];
host
.
dockerServices
=
{
...
...
@@ -138,7 +188,7 @@ class InventoryBuilder {
host
.
frpsNeeded
=
false
;
const
null_connection
=
"
10000,null
"
;
const
lanInterfaces
=
host
.
lanInterfaces
.
length
>
0
?
host
.
lanInterfaces
.
split
(
"
,
"
)
:
[];
const
routePlans
=
[]
;
const
routePlans
=
this
.
getRoutePlansFromGatewayGroups
(
host
)
;
for
(
const
h
of
this
.
connections
)
{
if
(
h
!=
host
.
name
)
{
const
to
=
host
[
h
];
// 当前主机的条目
...
...
@@ -161,11 +211,13 @@ class InventoryBuilder {
routePlans
.
push
({
name
:
h
.
replace
(
/-/g
,
"
_
"
),
destMark
:
targetHost
.
destMark
,
addresses
:
targetHost
.
address
,
addresses
:
[
targetHost
.
address
]
,
addressesString
:
this
.
getRoutePlanAddressesString
([
targetHost
.
address
])
});
}
}
return
{
ansible_ssh_host
:
host
.
host
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment