Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
5a056e25
authored
Dec 17, 2014
by
Oliver Pinter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
basic networking
parent
04fcde02
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
33 deletions
+23
-33
freebsd/_freebsdcontext.py
+1
-1
freebsd/network.py
+22
-32
No files found.
freebsd/_freebsdcontext.py
View file @
5a056e25
...
...
@@ -225,7 +225,7 @@ class Context(BaseContext):
args
=
{}
interfaces
=
netifaces
.
interfaces
()
for
i
in
interfaces
:
if
i
==
'lo'
:
if
i
==
'lo
0
'
:
continue
args
[
i
]
=
[]
addresses
=
netifaces
.
ifaddresses
(
i
)
...
...
freebsd/network.py
View file @
5a056e25
...
...
@@ -3,60 +3,49 @@ from netaddr import IPNetwork
import
fileinput
import
logging
import
subprocess
import
os
import
os.path
logger
=
logging
.
getLogger
()
interfaces_file
=
'/etc/rc.conf.d/ifconfig_
'
rcconf_dir
=
'/etc/rc.conf.d/
'
def
get_interfaces_freebsd
(
interfaces
):
for
ifname
in
netifaces
.
interfaces
():
if
ifname
==
'lo0'
:
continue
# XXXOP: ?
logger
.
debug
(
"get_interfaces: "
+
ifname
)
mac
=
netifaces
.
ifaddresses
(
ifname
)[
18
][
0
][
'addr'
]
logger
.
debug
(
"get_interfaces: "
+
mac
)
conf
=
interfaces
.
get
(
mac
.
upper
())
if
conf
:
yield
ifname
,
conf
def
remove_interfaces_
ubuntu
(
devices
):
def
remove_interfaces_
freebsd
(
devices
):
delete_device
=
False
for
line
in
fileinput
.
input
(
interfaces_file
,
inplace
=
True
):
line
=
line
.
rstrip
()
words
=
line
.
split
()
if
line
.
startswith
(
'#'
)
or
line
==
''
or
line
.
isspace
()
or
not
words
:
# keep line
print
line
continue
if
(
words
[
0
]
in
(
'auto'
,
'allow-hotplug'
)
and
words
[
1
]
.
split
(
':'
)[
0
]
in
devices
):
# remove line
continue
if
words
[
0
]
==
'iface'
:
ifname
=
words
[
1
]
.
split
(
':'
)[
0
]
if
ifname
in
devices
:
# remove line
delete_device
=
True
continue
for
device
in
devices
:
if_file
=
rcconf_dir
+
device
if
os
.
path
.
isfile
(
if_file
):
logger
.
debug
(
"remove interface configuration: "
+
if_file
)
os
.
unlink
(
if_file
)
else
:
delete_device
=
False
if
line
[
0
]
in
(
' '
,
'
\t
'
)
and
delete_device
:
# remove line
continue
# keep line
print
line
logger
.
debug
(
"unable to remove interface configuration: "
+
if_file
)
def
change_ip_freebsd
(
interfaces
,
dns
):
data
=
list
(
get_interfaces_freebsd
(
interfaces
))
print
data
for
ifname
,
conf
in
data
:
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'stop'
,
ifname
))
#remove_interfaces_ubuntu
(dict(data).keys())
remove_interfaces_freebsd
(
dict
(
data
)
.
keys
())
for
device
,
conf
in
data
:
if_file
=
rcconf_dir
+
device
with
open
(
if_file
,
'w'
)
as
f
:
f
.
write
(
'ifconfig_'
+
device
+
'="DHCP"'
)
#XXXOP - hardcoded
'''
with open(interfaces_file, 'a') as f:
for ifname, conf in data:
ipv4_alias_counter = ipv6_alias_counter = 0
...
...
@@ -87,6 +76,7 @@ def change_ip_freebsd(interfaces, dns):
'prefixlen': prefixlen,
'gw': conf['gw6' if ip.version == 6 else 'gw4'],
'dns': dns})
'''
for
ifname
,
conf
in
data
:
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'start'
,
ifname
))
...
...
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