Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bird-tools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
labs
bird-tools
Commits
6df72b5c
Commit
6df72b5c
authored
Feb 22, 2016
by
Maria Matejka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more features just put in how it came under my hands
parent
9de005b7
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
810 additions
and
251 deletions
+810
-251
.gitignore
.gitignore
+5
-0
bin/mpls
bin/mpls
+129
-0
bin/restart
bin/restart
+12
-0
bin/serial
bin/serial
+11
-0
bin/serial-mikrotik-fix.pl
bin/serial-mikrotik-fix.pl
+83
-0
bin/ssh
bin/ssh
+6
-1
bin/start
bin/start
+96
-15
bin/status
bin/status
+32
-6
bin/stop
bin/stop
+45
-15
bin/virt-lib
bin/virt-lib
+123
-8
etc/virtlist
etc/virtlist
+131
-96
nfs/net/rc.local.network
nfs/net/rc.local.network
+117
-38
nfs/rc.local
nfs/rc.local
+20
-72
No files found.
.gitignore
View file @
6df72b5c
...
...
@@ -3,5 +3,10 @@ iso/*
run/*
nfs/bird*
nfs/net/vl-*
nfs/net/rc-*
nfs/net/gr-*
nfs/net/hostname-*
nfs/net/misc-*
nfs/tmp
bin/socat
savelog
bin/mpls
0 → 100755
View file @
6df72b5c
#!/bin/bash
.
$(
dirname
$(
readlink
-f
$0
))
/virt-lib
set
-e
EVENT
=
$1
shift
idtoip
()
{
echo
10.255.
$((
$1
/
254
))
.
$((
$1
%
254
))
}
idtolink
()
{
echo
10.254.
$((
$1
/
254
))
.
$((
$1
%
254
))
}
if
!
brctl show |
grep
-q
br-mpls
;
then
brctl addbr br-mpls
;
ip
link set
br-mpls up
;
fi
case
$EVENT
in
add-rr|add-p|add-pe
)
T
=
${
EVENT
##add-
}
id
=
$1
ip
=
$(
idtoip
$id
)
vctl start
-t
mpls-auto
$T
-
$id
gethost mpls-auto-
$T
-
$id
vctl serial-mikrotik-fix.pl mpls-auto-
$T
-
$id
vctl ssh mpls-auto-
$T
-
$id
-t
<<
EOF
/interface bridge add name=lo
/ip address add address=
$ip
/32 interface=lo
/routing ospf instance set distribute-default=never redistribute-connected=as-type-1 router-id=
$ip
0
/routing ospf network add network=
$ip
/32 area=backbone
EOF
if
[
"
$EVENT
"
!=
"add-rr"
]
;
then
echo
"/mpls ldp set enabled=yes lsr-id=
$ip
transport-address=
$ip
"
| vctl ssh mpls-auto-
$T
-
$id
-t
fi
;;
add-c
)
id
=
$1
vpn
=
$2
pe
=
$3
ip
=
$(
idtoip
$id
)
peip
=
$(
idtoip
$pe
)
linkip
=
$(
idtolink
$id
)
linkpeip
=
$(
idtolink
$pe
)
vctl start
-t
mpls-auto c-
$id
gethost mpls-auto-c-
$id
cip
=
$HOSTIP4
gethost mpls-auto-pe-
$pe
cpeip
=
$HOSTIP4
vctl serial-mikrotik-fix.pl mpls-auto-c-
$id
vctl ssh mpls-auto-c-
$id
-t
<<
EOF
/interface bridge add name=lo
/ip address add address=
$ip
/32 interface=lo
/interface gre add remote-address=
$cpeip
name=pe-
$pe
/ip address add address=
$linkip
/32 network=
$linkpeip
interface=pe-
$pe
/routing ospf instance set distribute-default=never redistribute-connected=as-type-1 router-id=
$ip
0
/routing ospf network add network=
$ip
/32 area=backbone
/routing ospf network add network=
$linkpeip
/32 area=backbone
EOF
vctl ssh mpls-auto-pe-
$pe
-t
<<
EOF
/interface gre add remote-address=
$cip
name=c-
$id
/ip address add address=
$linkpeip
/32 network=
$linkip
interface=c-
$id
/ip route vrf add routing-mark=
$vpn
interfaces=c-
$id
route-distinguisher=
$vpn
import-route-targets=
$vpn
export-route-targets=
$vpn
/routing bgp instance vrf add instance=default routing-mark=
$vpn
redistribute-connected=yes redistribute-ospf=yes
/routing ospf instance add name=c-
$id
routing-table=
$vpn
redistribute-bgp=as-type-1
/routing ospf area add instance=c-
$id
name=c-
$id
/routing ospf network add network=
$linkip
/32 area=c-
$id
EOF
;;
add-link
)
from
=
$1
to
=
$2
fip
=
$(
idtolink
${
from
##*-
}
)
tip
=
$(
idtolink
${
to
##*-
}
)
gethost mpls-auto-
$from
cfip
=
$HOSTIP4
gethost mpls-auto-
$to
ctip
=
$HOSTIP4
vctl ssh mpls-auto-
$from
-t
<<
EOF
/interface gre add remote-address=
$ctip
name=
$to
/ip address add address=
$fip
/32 network=
$tip
interface=
$to
/routing ospf network add network=
$tip
/32 area=backbone
EOF
vctl ssh mpls-auto-
$to
-t
<<
EOF
/interface gre add remote-address=
$cfip
name=
$from
/ip address add address=
$tip
/32 network=
$fip
interface=
$from
/routing ospf network add network=
$fip
/32 area=backbone
EOF
case
"
$from$to
"
in
*
rr
*
)
:
;;
*
)
echo
"/mpls ldp interface add interface=
$to
"
| vctl ssh mpls-auto-
$from
-t
echo
"/mpls ldp interface add interface=
$from
"
| vctl ssh mpls-auto-
$to
-t
;;
esac
;;
bgp-rr
)
pe
=
$1
rr
=
$2
peip
=
$(
idtoip
$pe
)
rrip
=
$(
idtoip
$rr
)
echo
"/routing bgp peer add remote-address=
$rrip
remote-as=65530 address-families=vpnv4 update-source=lo"
| vctl ssh mpls-auto-pe-
$pe
-t
echo
"/routing bgp peer add remote-address=
$peip
remote-as=65530 address-families=vpnv4 update-source=lo route-reflect=yes"
| vctl ssh mpls-auto-rr-
$rr
-t
;;
bgp-link
)
from
=
$1
to
=
$2
fip
=
$(
idtoip
${
from
}
)
tip
=
$(
idtoip
${
to
}
)
echo
"/routing bgp peer add remote-address=
$tip
remote-as=65530 address-families=vpnv4 update-source=lo"
| vctl ssh mpls-auto-rr-
$from
-t
echo
"/routing bgp peer add remote-address=
$fip
remote-as=65530 address-families=vpnv4 update-source=lo"
| vctl ssh mpls-auto-rr-
$to
-t
;;
*
)
echo
"Commands: add-rr ID, add-p ID, add-pe ID, add-c ID VPN PE, add-link FROM TO, bgp-rr PE RR"
exit
2
;;
esac
bin/restart
0 → 100755
View file @
6df72b5c
#!/bin/bash
.
$(
dirname
$(
readlink
-f
$0
))
/virt-lib
NAME
=
$1
if
[
-z
"
$NAME
"
]
;
then
echo
-e
"Usage:
$0
name [custom options for qemu]
\n
or
$0
-m list of names"
exit
2
fi
vctl stop
"
$@
"
vctl start
"
$@
"
bin/serial
0 → 100755
View file @
6df72b5c
#!/bin/bash
.
$(
dirname
$(
readlink
-f
$0
))
/virt-lib
NAME
=
$1
if
[
-z
"
$NAME
"
]
;
then
echo
"Usage:
$0
NAME"
exit
2
fi
minicom
-D
unix
\#
$ROOT
/run/
$1
.serial
bin/serial-mikrotik-fix.pl
0 → 100755
View file @
6df72b5c
#!/usr/bin/perl -CL
use
common::
sense
;
use
Data::
Dumper
;
use
IO::Socket::
UNIX
;
my
$client
=
IO::Socket::
UNIX
->
new
(
Type
=>
SOCK_STREAM
(),
Peer
=>
"
/var/lib/virt/run/
$ARGV
[0].serial
");
my
$data
;
$/
=
"";
my
$state
=
"
login
";
say
"
init client
";
syswrite
$client
,
"
\r
";
while
(
1
)
{
say
"";
sleep
1
;
sysread
$client
,
$data
,
65536
;
$data
=~
s/[^ -~]/?/g
;
print
Dumper
\
$data
;
if
(
$data
=~
/MikroTik Login: $/
)
{
say
"
sending login
";
syswrite
$client
,
"
root
\r
";
$state
=
"
login
";
next
;
}
if
(
$data
=~
/assword: $/
)
{
say
"
sending password
";
syswrite
$client
,
"
root
\r
";
next
;
}
if
(
$data
=~
/tinue!/
)
{
say
"
continue boilerplate
";
syswrite
$client
,
"
\r
";
# $state = "export";
$state
=
"
macreset
";
next
;
}
if
(
$data
=~
/\[root\@MikroTik\] > $/
&&
$state
eq
"
export
")
{
say
"
export
";
syswrite
$client
,
"
export
\r
";
$state
=
"
macreset
";
next
;
}
if
(
$data
=~
/\[root\@MikroTik\] > $/
&&
$state
eq
"
macreset
")
{
say
"
interface ethernet reset-mac-address numbers=0
";
syswrite
$client
,
"
interface ethernet reset-mac-address numbers=0
\r
";
$state
=
"
dhcp
";
next
;
}
if
(
$data
=~
/\[root\@MikroTik\] > $/
&&
$state
eq
"
dhcp
")
{
say
"
ip dhcp-client renew numbers=0
";
syswrite
$client
,
"
ip dhcp-client renew numbers=0
\r
";
$state
=
"
quit
";
next
;
}
if
(
$data
=~
/\[root\@MikroTik\] > $/
&&
$state
eq
"
quit
")
{
say
"
quit
";
syswrite
$client
,
"
quit
\r
";
sleep
1
;
sysread
$client
,
$data
,
65536
;
$data
=~
s/[^ -~]/?/g
;
print
Dumper
\
$data
;
exit
0
;
}
if
(
$data
=~
/\[root\@MikroTik\] > $/
)
{
say
"
Logged in, noop now
";
syswrite
$client
,
"
\r
";
$state
=
"
macreset
";
next
;
}
say
"
NOP, strange input
";
}
bin/ssh
View file @
6df72b5c
...
...
@@ -11,4 +11,9 @@ fi
shift
gethost
$NAME
ssh
-i
/root/.ssh/virt-rsa root@
$HOSTIP4
"
$@
"
if
[
"
${#
@
}
"
==
"0"
]
;
then
TERM
=
rxvt-256color ssh
-i
/root/.ssh/virt-rsa
-t
root@
$HOSTIP4
bash
else
TERM
=
rxvt-256color ssh
-i
/root/.ssh/virt-rsa root@
$HOSTIP4
"
$@
"
fi
bin/start
View file @
6df72b5c
...
...
@@ -4,10 +4,25 @@
NAME
=
$1
shift
if
[
-z
"
$NAME
"
]
;
then
echo
"Usage:
$0
name
[custom options for qemu]"
usage
()
{
echo
-e
"Usage:
$0
name [custom options for qemu]
\n
or
$0
-m list of names
\n
or
$0
-t name suffix
[custom options for qemu]"
exit
2
fi
}
check_stale
()
{
local
NAME
=
$1
if
[
-e
$ROOT
/run/
$NAME
.pid
]
;
then
echo
-n
"Host
$NAME
pidfile found"
if
[
-d
/proc/
$(
<
$ROOT
/run/
$NAME
.pid
)
]
;
then
echo
" running with PID
$(
<
$ROOT
/run/
$NAME
.pid
)
"
exit
1
else
echo
" stale ... removing"
rm
$ROOT
/run/
$NAME
.pid
fi
fi
}
[
-z
"
$NAME
"
]
&&
usage
if
[
"
$NAME
"
=
"-m"
]
;
then
set
-e
...
...
@@ -18,17 +33,30 @@ if [ "$NAME" = "-m" ]; then
exit
0
fi
if
[
-e
$ROOT
/run/
$NAME
.pid
]
;
then
echo
-n
"Host
$NAME
pidfile found"
if
[
-d
/proc/
$(
<
$ROOT
/run/
$NAME
.pid
)
]
;
then
echo
" running with PID
$(
<
$ROOT
/run/
$NAME
.pid
)
"
exit
1
else
echo
" stale ... removing"
rm
$ROOT
/run/
$NAME
.pid
fi
if
[
"
$NAME
"
=
"-t"
]
;
then
NAME
=
$1
SUFFIX
=
$2
([
-z
"
$SUFFIX
"
]
||
[
-z
"
$NAME
"
])
&&
usage
ID
=
0
if
[
-e
$ROOT
/run/tmp-
$NAME
-
$SUFFIX
]
;
then
echo
"Host
$NAME
tmpfile found."
check_stale
$NAME
-
$SUFFIX
rm
$(
readlink
-f
$ROOT
/run/tmp-
$NAME
-
$SUFFIX
)
$ROOT
/run/tmp-
$NAME
-
$SUFFIX
fi
while
[
-e
$ROOT
/run/tmp-
$ID
]
;
do
ID
=
$((
ID+1
))
done
HEXID
=
$(
printf
"%02x"
$ID
)
echo
"
$SUFFIX
"
>
$ROOT
/run/tmp-
$ID
ln
-s
tmp-
$ID
$ROOT
/run/tmp-
$NAME
-
$SUFFIX
shift
2
else
check_stale
$NAME
fi
NAME
=
$NAME
${
SUFFIX
:+-
$SUFFIX
}
gethost
$NAME
if
[
"
$?
"
!=
0
]
;
then
...
...
@@ -41,8 +69,8 @@ if [ "$1" = "--install" ]; then
shift
2
fi
declare
-a
HOSTNICVLAN
if
[
-n
"
$HOSTNIC
"
]
;
then
declare
-a
HOSTNICVLAN
declare
-a
HOSTNIC
=(
$HOSTNIC
)
for
N
in
${
HOSTNIC
[@]
}
;
do
IFS
=
';'
read
NETNAME MAC TAG IP4 IP4PEER
<<<
"
$N
"
...
...
@@ -56,16 +84,69 @@ if [ -n "$HOSTNIC" ]; then
done
fi
GREFILE
=
$ROOT
/nfs/net/gr-
${
HOSTMAC
//
:
}
truncate
-s0
$GREFILE
if
[
-n
"
$HOSTVARS
"
]
;
then
declare
-a
HOSTVARS
=(
$HOSTVARS
)
for
V
in
${
HOSTVARS
[@]
}
;
do
echo
"export
$V
"
>>
$GREFILE
done
declare
-a
HOSTVARNAMES
for
V
in
${
HOSTVARS
[@]
}
;
do
HOSTVARNAMES+
=(
${
V
%%=*
}
)
done
echo
"declare -a VARNAMES=(
${
HOSTVARNAMES
[@]
}
)"
>>
$GREFILE
fi
if
[
-n
"
$HOSTDUMMY
"
]
;
then
declare
-a
HOSTDUMMY
=(
$HOSTDUMMY
)
for
D
in
${
HOSTDUMMY
[@]
}
;
do
IFS
=
';'
read
DNAME IP4 IP6
<<<
"
$D
"
echo
dummy
$DNAME
$IP4
$IP6
>>
$GREFILE
done
fi
if
[
-n
"
$HOSTGRE
"
]
;
then
declare
-a
HOSTGRE
=(
$HOSTGRE
)
for
G
in
${
HOSTGRE
[@]
}
;
do
IFS
=
';'
read
GRENAME PEER IP4 IP4PEER
<<<
"
$G
"
echo
gre
$GRENAME
$HOSTIP4
${
CONF
[
$PEER
;IP4]
}
$IP4
$IP4PEER
>>
$GREFILE
done
fi
if
[
-n
"
$HOSTSOCK
"
]
;
then
declare
-a
HOSTSOCK
=(
$HOSTSOCK
)
for
S
in
${
HOSTSOCK
[@]
}
;
do
IFS
=
';'
read
SOCKNAME APPEND MAC IP4
<<<
"
$S
"
TAPID
=
$(
mactotap
$MAC
)
HOSTNICDEV
=
"
$HOSTNICDEV
-netdev socket,
$APPEND
,id=
$SOCKNAME
-device e1000,netdev=
$SOCKNAME
,mac=
$MAC
"
TAPFILE
=
$ROOT
/nfs/net/
$TAPID
echo
"NAME
$NETNAME
"
>
$TAPFILE
echo
"IP4
$IP4
"
>>
$TAPFILE
if
[
-n
"
$IP4PEER
"
]
;
then
echo
"IP4PEER
$IP4PEER
"
>>
$TAPFILE
;
fi
done
fi
echo
-e
"hostname
$HOSTNAME
\n
export HOSTNAME=
$HOSTNAME
"
>
$ROOT
/nfs/net/hostname-
${
HOSTMAC
//
:
}
$ROOT
/bin/omapi add
$NAME
$HOSTMAC
$HOSTIP4
qemu-system-
$HOSTARCH
-enable-kvm
-m
$HOSTMEMORY
-hda
$ROOT
/img/
$HOSTIMAGE
$HOSTCOW
-display
none
${
HOSTVNCID
:+-vnc
10.0.0.11
:
$HOSTVNCID
}
-netdev
tap,id
=
ctl,ifname
=
$HOSTTAP
,script
=
no
-device
e1000,netdev
=
ctl,mac
=
$HOSTMAC
$HOSTNICDEV
-pidfile
$ROOT
/run/
$NAME
.pid
-monitor
unix:
$ROOT
/run/
$NAME
.sock,server,nowait
-daemonize
$INSTALL
"
$@
"
qemu-system-
$HOSTARCH
-enable-kvm
-m
$HOSTMEMORY
-hda
$ROOT
/img/
$HOSTIMAGE
$HOSTCOW
-display
none
${
HOSTVNCID
:+-vnc
10.0.0.11
:
$HOSTVNCID
}
-netdev
tap,id
=
ctl,ifname
=
$HOSTTAP
,script
=
no
-device
e1000,netdev
=
ctl,mac
=
$HOSTMAC
$HOSTNICDEV
-pidfile
$ROOT
/run/
$NAME
.pid
-monitor
unix:
$ROOT
/run/
$NAME
.sock,server,nowait
-
serial
unix:
$ROOT
/run/
$NAME
.serial,server,nowait
-
daemonize
$INSTALL
"
$@
"
#-runas $VIRTUSER
ip
link set
$HOSTTAP
up
vsctl add-port
$VIRTBR
$HOSTTAP
tag
=
1
echo
vsctl add-port
$VIRTBR
$HOSTTAP
tag
=
1
for
T
in
${
HOSTNICVLAN
[@]
}
;
do
IFS
=
,
read
TAPID TAG
<<<
"
$T
"
ip
link set
$TAPID
up
vsctl add-port
$VIRTBR
$TAPID
tag
=
$TAG
if
ip
link
show br-
$TAG
2>/dev/null
>
/dev/null
;
then
:
;
else
brctl addbr br-
$TAG
ip
link set
br-
$TAG
up
fi
echo
"brctl addif br-
$TAG
$TAPID
"
brctl addif br-
$TAG
$TAPID
# vsctl add-port $VIRTBR $TAPID tag=$TAG
done
bin/status
View file @
6df72b5c
#!/bin/bash
.
$(
dirname
$(
readlink
-f
$0
))
/virt-lib
if
[
"
$1
"
==
"-n"
]
;
then
shift
DO_PING
=
false
else
DO_PING
=
true
fi
if
[
"
$1
"
==
"-v"
]
;
then
for
C
in
$(
echo
${
!CONF[@]
}
|
tr
' '
'\n'
|
sort
)
;
do
echo
$C
:
${
CONF
[
$C
]
}
done
exit
0
fi
declare
-A
seen
seen[dhcpd]
=
1
for
H
in
$(
hostlist
)
;
do
if
[
-S
$ROOT
/run/
$H
.sock
]
;
then
if
ping
-nc1
${
CONF
[
$H
;IP4]
}
>
/dev/null
;
then
PING
=
"(ping ok)"
else
PING
=
"(ping FAIL)"
fi
if
[
-e
$ROOT
/run/tmp-
$H
]
;
then
ID
=
$(
basename
$(
readlink
-f
$ROOT
/run/tmp-
$H
))
ID
=
${
ID
##tmp-
}
HOSTIP4
=
192.168.255.
$((
$ID
%
254
))
else
HOSTIP4
=
${
CONF
[
$H
;IP4]
}
fi
if
$DO_PING
;
then
if
ping
-nc1
$HOSTIP4
>
/dev/null
;
then
PING
=
"(ping ok)"
else
PING
=
"(ping FAIL)"
fi
else
PING
=
""
fi
echo
"
$H
running, IPv4
$
{
CONF
[
$H
;IP4]
}
$PING
, monitor
$ROOT
/run/
$H
.sock"
echo
"
$H
running, IPv4
$
HOSTIP4
$PING
, monitor
$ROOT
/run/
$H
.sock"
elif
[
-f
$ROOT
/run/
$H
.pid
]
;
then
if
ps
-p
$(
<
$ROOT
/run/
$H
.pid
)
>
/dev/null
;
then
echo
"
$H
probably running at PID
$(
<
$ROOT
/run/
$H
.pid
)
, no socket, IPv4
${
CONF
[
$H
;IP4]
}
"
...
...
bin/stop
View file @
6df72b5c
...
...
@@ -5,65 +5,95 @@ NAME=$1
shift
if
[
-z
"
$NAME
"
]
;
then
echo
"Usage:
$0
name [custom options for qemu]
"
echo
-e
"Usage:
$0
name
\n
or
$0
-m list of names
"
exit
2
fi
if
[
"
$NAME
"
=
"-m"
]
;
then
set
-e
declare
-a
PIDS
for
N
in
"
$@
"
;
do
echo
Stopping
"
$N
"
$0
"
$N
"
$0
-q
"
$N
"
&
PIDS+
=(
$!
)
done
exit
0
echo
${
PIDS
[@]
}
while
true
;
do
declare
-a
NEWPIDS
NEWPIDS
=()
for
P
in
${
PIDS
[@]
}
;
do
if
[
-d
/proc/
$P
]
;
then
NEWPIDS+
=(
$P
)
fi
done
PIDS
=(
${
NEWPIDS
[@]
}
)
if
[
"
${#
PIDS
[@]
}
"
-eq
0
]
;
then
break
;
fi
echo
-e
"Still
${#
PIDS
[@]
}
machine(s) running ...
\r
"
sleep
1
done
echo
"Everything OK. "
exit
0
fi
QUIET
=
false
if
[
"
$NAME
"
=
"-q"
]
;
then
QUIET
=
true
NAME
=
$1
shift
fi
function
ok
()
{
echo
E
rm
-f
$ROOT
/run/
$NAME
.sock
$ROOT
/run/
$NAME
.pid
if
gethost
$NAME
;
then
echo
"
$NAME
"
if
[
-e
$ROOT
/run/tmp-
$NAME
]
;
then
rm
$(
readlink
-f
$ROOT
/run/tmp-
$NAME
)
$ROOT
/run/tmp-
$NAME
;
fi
$ROOT
/bin/omapi del
$HOSTMAC
vsctl del-port
$HOSTTAP
if
[
-n
"
$HOSTNIC
"
]
;
then
for
N
in
${
HOSTNIC
[@]
}
;
do
IFS
=
';'
read
_ MAC _
<<<
"
$N
"
IFS
=
';'
read
_ MAC
TAG
_
<<<
"
$N
"
TAPID
=
$(
mactotap
$MAC
)
echo
$TAPID
vsctl del-port
$TAPID
E
$TAPID
brctl delif br-
$TAG
$TAPID
# vsctl del-port $TAPID
done
fi
else
echo
"Warning: Config not found for this host"
E
"Warning: Config not found for this host"
fi
echo
"OK"
E
"OK"
exit
0
}
if
[
-e
$ROOT
/run/
$NAME
.sock
]
;
then
echo
-n
"Graceful powerdown "
E
-n
"Graceful powerdown "
echo
"system_powerdown"
| socat - UNIX-CONNECT:
$ROOT
/run/
$NAME
.sock
>
/dev/null
if
wait_pidfile
$ROOT
/run/
$NAME
.pid 30
;
then
ok
;
fi
else
echo
"No monitor socket found."
E
"No monitor socket found."
fi
if
[
-e
$ROOT
/run/
$NAME
.pid
]
;
then
if
[
!
-d
/proc/
$(
<
$ROOT
/run/
$NAME
.pid
)
]
;
then
echo
"Stale pidfile found, cleaning up"
E
"Stale pidfile found, cleaning up"
rm
$ROOT
/run/
$NAME
.pid
return
0
fi
echo
-n
"Sending TERM "
E
-n
"Sending TERM "
kill
-15
$(
<
$ROOT
/run/
$NAME
.pid
)
if
wait_pidfile
$ROOT
/run/
$NAME
.pid 30
;
then
ok
;
fi
echo
-n
"Sending KILL "
E
-n
"Sending KILL "
kill
-9
$(
<
$ROOT
/run/
$NAME
.pid
)
if
wait_pidfile
$ROOT
/run/
$NAME
.pid 30
;
then
ok
;
fi
echo
"Did not stop even after KILL, strange."
E
"Did not stop even after KILL, strange."
exit
1
fi
bin/virt-lib
View file @
6df72b5c
...
...
@@ -7,6 +7,10 @@ VIRTUPLINK=virtuplink
VIRTUALS
=
$ROOT
/etc/virtlist
VIRTUSER
=
virt-qemu
function
E
()
{
$QUIET
||
echo
"
$@
"
}
function
virtns
()
{
"
$@
"
}
...
...
@@ -19,17 +23,35 @@ function mactotap() {
echo
vl-
$(
tr
-d
':'
<<<
"
$1
"
)
}
function
wait_pidfiles
()
{
local
-A
PIDS
while
[
-r
$1
]
;
do
${
PIDS
[
$(
<
$1
)
]
}
=
1
shift
done
TIMEOUT
=
${
1
:-
30
}
while
[
!
-z
"
${
!PIDS[@]
}
"
]
;
do
E
-n
"."
for
pid
in
"
${
!PIDS[@]
}
"
;
do
if
[
!
-d
/proc/
$pid
]
;
then
unset
PIDS[
$pid
]
fi
done
done
}
function
wait_pidfile
()
{
CNT
=
0
FILE
=
$1
TIMEOUT
=
${
2
:-
30
}
while
[
-d
/proc/
$(
<
$FILE
)
]
;
do
echo
-n
"."
E
-n
"."
sleep
1
CNT
=
$((
CNT+1
))
if
[
$CNT
-eq
$TIMEOUT
]
;
then
echo
echo
"Timeout
${
TIMEOUT
}
s reached."
E
E
"Timeout
${
TIMEOUT
}
s reached."
return
1
fi
done
...
...
@@ -48,9 +70,9 @@ function getmac() {
function
hostctlnet
()
{
if
[
-z
"
${
CONF
[
$1
;NETWORK]
}
"
]
;
then
local
SHA
=
$(
sha1sum
<<<
"
$1
"
|
head
-c
12
)
CONF[
$1
;
TAP]
=
vc-
$SHA
CONF[
$1
;
MAC]
=
$(
getmac
$SHA
)
CONF[
$1
;
IP4]
=
192.168.
$((
193
+((
0
x
$SHA
/
254
)
%
63
))
)
.
$((
0
x
$SHA
%
254
))
CONF[
$1
;
TAP]
=
$(
mactotap
${
CONF
[
$1
;MAC]
}
|
sed
's/vl-/vc-/'
)
CONF[
$1
;
IP4]
=
192.168.
$((
193
+((
0
x
$SHA
/
254
)
%
62
))
)
.
$((
0
x
$SHA
%
254
))
else
read
CONF[
$1
;
TAP] CONF[
$1
;
MAC] CONF[
$1
;
IP4]
<<<
"
${
CONF
[
$1
;NETWORK]
}
"
fi
...
...
@@ -130,6 +152,79 @@ function nethosts() {
done
}
function
grehosts
()
{
local
NAME
=
$1
local
an
=
$2
local
ai
=
$3
local
bn
=
$4
local
bi
=
$5
if
[
-z
"
$an
"
]
||
[
-z
"
$ai
"
]
||
[
-z
"
$bn
"
]
||
[
-z
"
$bi
"
]
;
then
echo
"Link usage: 'Link host IP host IP' in config."
exit
2
fi
CONF[
$an
;
GRE]
=
"
${
CONF
[
$an
;GRE]
}
$NAME
;
$bn
;
$ai
;
$bi
"
CONF[
$bn
;
GRE]
=
"
${
CONF
[
$bn
;GRE]
}
$NAME
;
$an
;
$bi
;
$ai
"
}
function
sockethosts
()
{