Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
defaultgw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cloud
charms
defaultgw
Commits
aebb2fb0
Commit
aebb2fb0
authored
6 years ago
by
Claudio Pisa
Committed by
Alberto Colla
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
2019-02-04: CP;AC; update to bionic (which is not using ifupdown)
parent
568dfc4b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hooks/install
+54
-33
54 additions, 33 deletions
hooks/install
metadata.yaml
+1
-0
1 addition, 0 deletions
metadata.yaml
with
55 additions
and
33 deletions
hooks/install
+
54
−
33
View file @
aebb2fb0
...
...
@@ -3,6 +3,7 @@
# e.g. apt install -y foo
# Make sure this hook exits cleanly and is idempotent.
set
-e
set
-x
status-set maintenance
"Setting the default gateway"
GATEWAY
=
"
$(
config-get gateway
)
"
...
...
@@ -14,44 +15,64 @@ if [ -z "$GATEWAY" ]; then
fi
GATEWAY_IP
=
`
echo
"
$GATEWAY
"
|
awk
-F
"/"
'{print $1}'
`
OLD_GATEWAY_IP
=
`
grep
-s
gateway /etc/network/interfaces /etc/network/interfaces.d/
*
.cfg |
head
-1
|
awk
'{print $NF}'
`
if
[
"
$GATEWAY_IP
"
==
"
$OLD_GATEWAY_IP
"
]
;
then
juju-log
"Default gateway is already set. Exiting..."
status-set active
"Unit is ready."
exit
0
fi
source
/etc/lsb-release
RELEASE_MAJOR
=
"
$(
echo
$DISTRIB_RELEASE
|
awk
-F
'.'
'{print $1}'
)
"
if
[
"
$RELEASE_MAJOR
"
-le
"16"
]
;
then
OLD_GATEWAY_IP
=
`
grep
-s
gateway /etc/network/interfaces /etc/network/interfaces.d/
*
.cfg |
head
-1
|
awk
'{print $NF}'
`
if
[
"
$GATEWAY_IP
"
==
"
$OLD_GATEWAY_IP
"
]
;
then
juju-log
"Default gateway is already set. Exiting..."
status-set active
"Unit is ready."
exit
0
fi
apt
install
-y
sipcalc
apt
install
-y
sipcalc
GATEWAY_NET
=
`
sipcalc
$GATEWAY
|
grep
"Network address"
|
awk
'{print $NF}'
`
GATEWAY_NET
=
`
sipcalc
$GATEWAY
|
grep
"Network address"
|
awk
'{print $NF}'
`
IFS
=
$'
\n
'
FOUND
=
0
for
LINE
in
$(
grep
-s
address /etc/network/interfaces /etc/network/interfaces.d/
*
.cfg
)
;
do
FILE
=
`
echo
$LINE
|
awk
'{print substr($1, 0, length($1)-1)}'
`
# drop ':'
ADDRESS
=
`
echo
$LINE
|
awk
'{print $NF}'
`
ADDRESS_NET
=
`
sipcalc
$ADDRESS
|
grep
"Network address"
|
awk
'{print $NF}'
`
if
[
"
$ADDRESS_NET
"
==
"
$GATEWAY_NET
"
]
;
then
FOUND
=
1
fi
done
unset
IFS
IFS
=
$'
\n
'
FOUND
=
0
for
LINE
in
$(
grep
-s
address /etc/network/interfaces /etc/network/interfaces.d/
*
.cfg
)
;
do
FILE
=
`
echo
$LINE
|
awk
'{print substr($1, 0, length($1)-1)}'
`
# drop ':'
ADDRESS
=
`
echo
$LINE
|
awk
'{print $NF}'
`
ADDRESS_NET
=
`
sipcalc
$ADDRESS
|
grep
"Network address"
|
awk
'{print $NF}'
`
if
[
"
$ADDRESS_NET
"
==
"
$GATEWAY_NET
"
]
;
then
FOUND
=
1
if
[
"
$FOUND
"
-gt
0
]
;
then
juju-log
"Setting default gateway:
$GATEWAY_IP
..."
sed
-i
"/
${
GATEWAY_IP
}
/a
\
gateway
$GATEWAY_IP
"
$FILE
if
[
!
-z
"
$OLD_GATEWAY_IP
"
]
;
then
juju-log
"Removing old default gateway
$OLD_GATEWAY_IP
..."
sed
-i
"/
${
OLD_GATEWAY_IP
}
/d"
$FILE
fi
ip route del default
ip route add default via
$GATEWAY_IP
juju-log
"Default gateway changed"
status-set active
"Unit is ready"
else
juju-log
"Network not found. Exiting..."
status-set blocked
"Incorrect gateway IP."
fi
done
unset
IFS
if
[
"
$FOUND
"
-gt
0
]
;
then
juju-log
"Setting default gateway:
$GATEWAY_IP
..."
sed
-i
"/
${
GATEWAY_IP
}
/a
\
gateway
$GATEWAY_IP
"
$FILE
if
[
!
-z
"
$OLD_GATEWAY_IP
"
]
;
then
juju-log
"Removing old default gateway
$OLD_GATEWAY_IP
..."
sed
-i
"/
${
OLD_GATEWAY_IP
}
/d"
$FILE
else
# release is not less or equal than trusty
# copy metric 0 routes to routes with metric 1
ip route show default metric 0 |
while
read
line
;
do
ip route append
$line
metric 1
||
true
;
done
# delete metric 0 routes
ip route show default metric 0 |
while
read
line
;
do
ip route del
$line
metric 0
;
done
# add our route
if
ip route replace default via
$GATEWAY_IP
metric 0
;
then
juju-log
"Default gateway set"
status-set active
"Unit is ready"
else
juju-log
"Route change failed. Exiting..."
status-set blocked
"Incorrect gateway IP."
fi
ip route del default
ip route add default via
$GATEWAY_IP
juju-log
"Default gateway changed"
status-set active
"Unit is ready"
else
juju-log
"Network not found. Exiting..."
status-set blocked
"Incorrect gateway IP."
fi
This diff is collapsed.
Click to expand it.
metadata.yaml
+
1
−
0
View file @
aebb2fb0
...
...
@@ -7,6 +7,7 @@ description: |
tags
:
-
network
series
:
-
bionic
-
xenial
-
trusty
requires
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment