Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mininet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Olaf Bergmann
mininet
Commits
af2f67d9
Commit
af2f67d9
authored
10 years ago
by
Cody Burkard
Browse files
Options
Downloads
Patches
Plain Diff
added documentation for HostWithPrivateDirs
parent
752c2d6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/bind.py
+53
-12
53 additions, 12 deletions
examples/bind.py
mininet/node.py
+10
-3
10 additions, 3 deletions
mininet/node.py
with
63 additions
and
15 deletions
examples/bind.py
+
53
−
12
View file @
af2f67d9
#!/usr/bin/python
"""
bind.py: Bind mount
prototyp
e
bind.py: Bind mount
exampl
e
This creates hosts with private directories as desired.
This creates hosts with private directories that the user specifies.
These hosts may have persistent directories that will be available
across multiple mininet session, or temporary directories that will
only last for one mininet session. To specify a persistent
directory, add a tuple to a list of private directories:
[ (
'
directory to be mounted on
'
,
'
directory to be mounted
'
) ]
String expansion may be used to create a directory template for
each host. To do this, add a %(name)s in place of the host name
when creating your list of directories:
[ (
'
/var/run
'
,
'
/tmp/%(name)s/var/run
'
) ]
If no persistent directory is specified, the directories will default
to temporary private directories. To do this, simply create a list of
directories to be made private. A tmpfs will then be mounted on them.
You may use both temporary and persistent directories at the same
time. In the following privateDirs string, each host will have a
persistent directory in the root filesystem at
"
/tmp/(hostname)/var/run
"
mounted on
"
/var/run
"
. Each host will also
have a temporary private directory mounted on
"
/var/log
"
.
[ (
'
/var/run
'
,
'
/tmp/%(name)s/var/run
'
),
'
/var/log
'
]
This example runs TWO mininet instances, one after the other.
The first mounts persistent private directories on /var/log and
/var/run. The second mounts temporary private directories on the same
directories.
"""
from
mininet.net
import
Mininet
...
...
@@ -15,33 +44,45 @@
from
functools
import
partial
#
S
ample usage
#
Persistent directory s
ample usage
def
test
HostWith
PrivateDirs
():
def
test
Persistent
PrivateDirs
():
"
Test bind mounts
"
topo
=
SingleSwitchTopo
(
10
)
privateDirs
=
[
(
'
/var/log
'
,
'
/onos/%(name)s/var/log
'
),
(
'
/var/run
'
,
'
/ovx/%(name)s/var/run
'
),
'
/mn
'
]
privateDirs
=
[
(
'
/var/log
'
,
'
/tmp/%(name)s/var/log
'
),
(
'
/var/run
'
,
'
/tmp/%(name)s/var/run
'
)
]
host
=
partial
(
HostWithPrivateDirs
,
privateDirs
=
privateDirs
)
net
=
Mininet
(
topo
=
topo
,
host
=
host
)
net
.
start
()
info
(
'
p
rivate Directories: [
'
)
info
(
'
P
rivate Directories: [
'
)
for
directory
in
privateDirs
:
if
isinstance
(
directory
,
tuple
):
info
(
'
%s,
'
%
directory
[
0
]
)
info
(
'
%s,
'
%
directory
[
0
]
)
else
:
info
(
'
%s,
'
%
directory
)
info
(
'
]
\n
'
)
CLI
(
net
)
net
.
stop
()
# Temporary directory sample usage
def
testTempPrivateDirs
():
"
test bind mounts with temporary directories
"
topo
=
SingleSwitchTopo
(
10
)
privateDirs
=
[
'
/var/log
'
,
'
/var/run
'
]
host
=
partial
(
HostWithPrivateDirs
,
privateDirs
=
privateDirs
)
net
=
Mininet
(
topo
=
topo
,
host
=
host
)
net
.
start
()
info
(
'
Private Directories:
'
,
privateDirs
,
'
\n
'
)
CLI
(
net
)
net
.
stop
()
if
__name__
==
'
__main__
'
:
setLogLevel
(
'
info
'
)
test
HostWith
PrivateDirs
()
info
(
'
Done.
\n
'
)
test
Persistent
PrivateDirs
()
testTempPrivateDirs
(
)
info
(
'
Done.
\n
'
)
This diff is collapsed.
Click to expand it.
mininet/node.py
+
10
−
3
View file @
af2f67d9
...
...
@@ -16,6 +16,11 @@
CPULimitedHost: a virtual host whose CPU bandwidth is limited by
RT or CFS bandwidth limiting.
HostWithPrivateDirs: a virtual host that has user-specified private
directories. These may be temporary directories stored as a tmpfs,
or persistent directories that are mounted from another directory in
the root filesystem.
Switch: superclass for switch nodes.
UserSwitch: a switch using the user-space switch from the OpenFlow
...
...
@@ -728,23 +733,25 @@ def init( cls ):
class
HostWithPrivateDirs
(
Host
):
"
Host with private directories
"
def
__init__
(
self
,
name
,
*
args
,
**
kwargs
):
""
"
privateDirs: list of private director
i
es
"
""
def
__init__
(
self
,
name
,
*
args
,
**
kwargs
):
"
privateDirs: list of private director
y strings or tupl
es
"
self
.
name
=
name
self
.
privateDirs
=
kwargs
.
pop
(
'
privateDirs
'
,
[]
)
Host
.
__init__
(
self
,
name
,
*
args
,
**
kwargs
)
self
.
mountPrivateDirs
()
def
mountPrivateDirs
(
self
):
"
mount t
h
e directories
that have specified mountpoints
"
"
mount
priva
te directories
"
for
directory
in
self
.
privateDirs
:
if
isinstance
(
directory
,
tuple
):
# mount given private directory
privateDir
=
directory
[
1
]
%
self
.
__dict__
mountPoint
=
directory
[
0
]
self
.
cmd
(
'
mkdir -p %s
'
%
privateDir
)
self
.
cmd
(
'
mkdir -p %s
'
%
mountPoint
)
self
.
cmd
(
'
mount --bind %s %s
'
%
(
privateDir
,
mountPoint
)
)
else
:
# mount temporary filesystem on directory
self
.
cmd
(
'
mkdir -p %s
'
%
directory
)
self
.
cmd
(
'
mount -n -t tmpfs tmpfs %s
'
%
directory
)
...
...
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