-
Notifications
You must be signed in to change notification settings - Fork 5
/
smoke.py
56 lines (49 loc) · 1.38 KB
/
smoke.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Example file for testing
This creates a smallt testnet with ipaddresses from 192.168.0.0/24,
one switch, and three hosts.
"""
import sys, os
sys.path.insert(0, os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
import virtnet
def run(vnet):
"Main functionality"
network = vnet.Network("192.168.0.0/24")
switch = vnet.Switch("sw")
hosts = []
for i in range(3):
host = vnet.Host("host{}".format(i))
host.connect(vnet.VirtualLink, switch, "eth0")
host["eth0"].add_ip(network)
hosts.append(host)
vnet.update_hosts()
with hosts[0].Popen(["ip", "addr"]):
pass
print("-"*80)
with hosts[0].Popen(["cat", "/etc/hosts"]):
pass
print("-"*80)
with hosts[0].Popen(["ls", "/sys/class/net"]):
pass
print("-"*80)
with hosts[0].Popen(["cat", "/proc/net/dev"]):
pass
print("-"*80)
for i in range(3):
with hosts[i].Popen(["ls", "-al", "/proc/self/ns"]):
pass
print("-"*80)
with hosts[0].Popen(["cat", "/etc/hosts"]):
pass
print("-"*80)
with hosts[0].Popen(["mount"]):
pass
print("-"*80)
for i in range(3):
with hosts[i].Popen(["uname", "-a"]):
pass
print("-"*80)
with hosts[0].Popen(["ping", "-c", "1", "host2"]):
pass
input("Done")
with virtnet.Manager() as context:
run(context)