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
f647f5aa
authored
Jan 15, 2015
by
Oliver Pinter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
workiing ipv4 networking
parent
43614758
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
15 deletions
+20
-15
freebsd/network.py
+20
-15
No files found.
freebsd/network.py
View file @
f647f5aa
...
@@ -45,6 +45,8 @@ def change_ip_freebsd(interfaces, dns):
...
@@ -45,6 +45,8 @@ def change_ip_freebsd(interfaces, dns):
if_file
=
rcconf_dir
+
"ifconfig_"
+
device
if_file
=
rcconf_dir
+
"ifconfig_"
+
device
with
open
(
if_file
,
'w'
)
as
f
:
with
open
(
if_file
,
'w'
)
as
f
:
ipv4_alias_counter
=
ipv6_alias_counter
=
0
ipv4_alias_counter
=
ipv6_alias_counter
=
0
route6
=
"ipv6_static_routes=
\"
"
route4
=
"static_routes=
\"
"
for
i
in
conf
[
'addresses'
]:
for
i
in
conf
[
'addresses'
]:
alias
=
""
alias
=
""
ip_with_prefix
=
IPNetwork
(
i
)
ip_with_prefix
=
IPNetwork
(
i
)
...
@@ -57,30 +59,33 @@ def change_ip_freebsd(interfaces, dns):
...
@@ -57,30 +59,33 @@ def change_ip_freebsd(interfaces, dns):
ipv6_alias_counter
+=
1
ipv6_alias_counter
+=
1
f
.
write
(
"ifconfig_"
+
device
+
alias
+
"="
+
f
.
write
(
"ifconfig_"
+
device
+
alias
+
"="
+
"
\"
inet6
%(ip)
s prefix
%(pref)
s
\"\n
"
%
{
'ip'
:
ip
,
'pref'
:
prefixlen
})
"
\"
inet6
%(ip)
s prefix
%(pref)
s
\"\n
"
%
{
'ip'
:
ip
,
'pref'
:
prefixlen
})
route6_name
=
device
+
"R"
+
str
(
ipv6_alias_counter
)
+
"v6"
route6
+=
route6_name
+
":"
+
device
+
" "
f
.
write
(
"route_"
+
route6_name
+
"=
\"
-net
%(netw)
s0 -gateway
%(gw)
s
\"\n
"
%
{
'netw'
:
ip_with_prefix
.
network
,
'gw'
:
conf
[
'gw6'
]})
else
:
else
:
if
ipv4_alias_counter
>
0
:
if
ipv4_alias_counter
>
0
:
alias
=
'_alias
%
d'
%
(
ipv4_alias_counter
-
1
)
# az aliasok szamanak folytonosnak kell lennie
ipv4_alias_counter
=
ipv6_alias_counter
+
1
alias
=
'_alias
%
d'
%
(
ipv4_alias_counter
)
ipv4_alias_counter
+=
1
ipv4_alias_counter
+=
1
f
.
write
(
"ifconfig_"
+
device
+
alias
+
"="
+
"
\"
inet
%(ip)
s/
%(pref)
s
\"\n
"
%
{
'ip'
:
ip
,
'pref'
:
prefixlen
})
f
.
write
(
"ifconfig_"
+
device
+
alias
+
"="
+
"
\"
inet
%(ip)
s/
%(pref)
s
\"\n
"
%
{
'ip'
:
ip
,
'pref'
:
prefixlen
})
route4_name
=
device
+
"R"
+
str
(
ipv4_alias_counter
)
+
"v4"
route4
+=
route4_name
+
":"
+
device
+
" "
f
.
write
(
"route_"
+
route4_name
+
"=
\"
-net
%(netw)
s -gateway
%(gw)
s
\"\n
"
%
{
'netw'
:
ip_with_prefix
.
network
,
'gw'
:
conf
[
'gw4'
]})
f
.
write
(
"defaultrouter=
\"
"
+
str
(
conf
[
'gw4'
])
+
"
\"\n
"
)
route4
+=
"
\"\n
"
route6
+=
"
\"\n
"
f
.
write
(
route4
)
f
.
write
(
route6
)
'''
with
open
(
"/etc/resolv.conf"
,
"w"
)
as
f
:
f
.
write
(
"nameserver "
+
dns
)
f.write(
'iface
%(ifname)
s
%(proto)
s static
\n
'
' address
%(ip)
s
\n
'
' netmask
%(prefixlen)
d
\n
'
' gateway
%(gw)
s
\n
'
' dns-nameservers
%(dns)
s
\n
'
%
{
'ifname': alias,
'proto': 'inet6' if ip.version == 6 else 'inet',
'ip': ip,
'prefixlen': prefixlen,
'gw': conf['gw6' if ip.version == 6 else 'gw4'],
'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
))
subprocess
.
call
((
'/usr/sbin/service'
,
'routing'
,
'start'
))
# example:
# example:
# change_ip_ubuntu({
# change_ip_ubuntu({
...
...
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