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
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):
...
@@ -225,7 +225,7 @@ class Context(BaseContext):
args
=
{}
args
=
{}
interfaces
=
netifaces
.
interfaces
()
interfaces
=
netifaces
.
interfaces
()
for
i
in
interfaces
:
for
i
in
interfaces
:
if
i
==
'lo'
:
if
i
==
'lo
0
'
:
continue
continue
args
[
i
]
=
[]
args
[
i
]
=
[]
addresses
=
netifaces
.
ifaddresses
(
i
)
addresses
=
netifaces
.
ifaddresses
(
i
)
...
...
freebsd/network.py
View file @
5a056e25
...
@@ -3,60 +3,49 @@ from netaddr import IPNetwork
...
@@ -3,60 +3,49 @@ from netaddr import IPNetwork
import
fileinput
import
fileinput
import
logging
import
logging
import
subprocess
import
subprocess
import
os
import
os.path
logger
=
logging
.
getLogger
()
logger
=
logging
.
getLogger
()
interfaces_file
=
'/etc/rc.conf.d/ifconfig_
'
rcconf_dir
=
'/etc/rc.conf.d/
'
def
get_interfaces_freebsd
(
interfaces
):
def
get_interfaces_freebsd
(
interfaces
):
for
ifname
in
netifaces
.
interfaces
():
for
ifname
in
netifaces
.
interfaces
():
if
ifname
==
'lo0'
:
continue
# XXXOP: ?
logger
.
debug
(
"get_interfaces: "
+
ifname
)
mac
=
netifaces
.
ifaddresses
(
ifname
)[
18
][
0
][
'addr'
]
mac
=
netifaces
.
ifaddresses
(
ifname
)[
18
][
0
][
'addr'
]
logger
.
debug
(
"get_interfaces: "
+
mac
)
conf
=
interfaces
.
get
(
mac
.
upper
())
conf
=
interfaces
.
get
(
mac
.
upper
())
if
conf
:
if
conf
:
yield
ifname
,
conf
yield
ifname
,
conf
def
remove_interfaces_
ubuntu
(
devices
):
def
remove_interfaces_
freebsd
(
devices
):
delete_device
=
False
delete_device
=
False
for
device
in
devices
:
for
line
in
fileinput
.
input
(
interfaces_file
,
inplace
=
True
):
if_file
=
rcconf_dir
+
device
line
=
line
.
rstrip
()
if
os
.
path
.
isfile
(
if_file
):
words
=
line
.
split
()
logger
.
debug
(
"remove interface configuration: "
+
if_file
)
os
.
unlink
(
if_file
)
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
else
:
else
:
delete_device
=
False
logger
.
debug
(
"unable to remove interface configuration: "
+
if_file
)
if
line
[
0
]
in
(
' '
,
'
\t
'
)
and
delete_device
:
# remove line
continue
# keep line
print
line
def
change_ip_freebsd
(
interfaces
,
dns
):
def
change_ip_freebsd
(
interfaces
,
dns
):
data
=
list
(
get_interfaces_freebsd
(
interfaces
))
data
=
list
(
get_interfaces_freebsd
(
interfaces
))
print
data
for
ifname
,
conf
in
data
:
for
ifname
,
conf
in
data
:
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'stop'
,
ifname
))
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:
with open(interfaces_file, 'a') as f:
for ifname, conf in data:
for ifname, conf in data:
ipv4_alias_counter = ipv6_alias_counter = 0
ipv4_alias_counter = ipv6_alias_counter = 0
...
@@ -87,6 +76,7 @@ def change_ip_freebsd(interfaces, dns):
...
@@ -87,6 +76,7 @@ def change_ip_freebsd(interfaces, dns):
'prefixlen': prefixlen,
'prefixlen': prefixlen,
'gw': conf['gw6' if ip.version == 6 else 'gw4'],
'gw': conf['gw6' if ip.version == 6 else 'gw4'],
'dns': dns})
'dns': dns})
'''
for
ifname
,
conf
in
data
:
for
ifname
,
conf
in
data
:
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'start'
,
ifname
))
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