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
d0221951
authored
Jan 20, 2015
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix flake8 warnings
parent
67650b8d
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
34 deletions
+22
-34
agent.py
+1
-1
context.py
+0
-0
freebsd/_freebsdcontext.py
+9
-7
freebsd/network.py
+12
-22
utils.py
+0
-4
No files found.
agent.py
View file @
d0221951
...
...
@@ -9,7 +9,7 @@ import sys
system
=
platform
.
system
()
if
system
==
"Linux"
or
system
==
"FreeBSD"
:
if
system
==
"Linux"
or
system
==
"FreeBSD"
:
try
:
chdir
(
sys
.
path
[
0
])
subprocess
.
call
((
'pip'
,
'install'
,
'-r'
,
'requirements.txt'
))
...
...
context.py
View file @
d0221951
freebsd/_freebsdcontext.py
View file @
d0221951
...
...
@@ -15,7 +15,8 @@ try:
subprocess
.
call
((
'/sbin/kldload'
,
'-n'
,
'virtio_console'
))
subprocess
.
call
((
'/sbin/kldload'
,
'-n'
,
'smbfs'
))
chdir
(
working_directory
)
subprocess
.
call
((
'/usr/local/bin/pip'
,
'install'
,
'-r'
,
'requirements.txt'
))
subprocess
.
call
(
(
'/usr/local/bin/pip'
,
'install'
,
'-r'
,
'requirements.txt'
))
copy
(
"/root/agent/misc/vm_renewal"
,
"/usr/local/bin/"
)
except
:
pass
# hope it works
...
...
@@ -61,6 +62,7 @@ nsmbrc_template_freebsd = (
'addr=
%(host)
s
\n
'
'password=
%(password)
s
\n
'
)
class
Context
(
BaseContext
):
# http://stackoverflow.com/questions/12081310/
...
...
@@ -85,19 +87,18 @@ class Context(BaseContext):
@staticmethod
def
change_password
(
password
):
proc0
=
subprocess
.
Popen
([
'/usr/sbin/pw'
,
'user'
,
'mod'
,
'cloud'
,
'-h'
,
'0'
],
proc0
=
subprocess
.
Popen
(
[
'/usr/sbin/pw'
,
'user'
,
'mod'
,
'cloud'
,
'-h'
,
'0'
],
stdin
=
subprocess
.
PIPE
)
proc0
.
communicate
(
'
%
s
\n
'
%
password
)
proc1
=
subprocess
.
Popen
([
'/usr/sbin/pw'
,
'user'
,
'mod'
,
'root'
,
'-h'
,
'0'
],
proc1
=
subprocess
.
Popen
(
[
'/usr/sbin/pw'
,
'user'
,
'mod'
,
'root'
,
'-h'
,
'0'
],
stdin
=
subprocess
.
PIPE
)
proc1
.
communicate
(
'
%
s
\n
'
%
password
)
@staticmethod
def
restart_networking
():
logger
.
debug
(
"restart_networking"
)
#logger.debug("XXX restart_networking disabled")
pass
#subprocess.call(['/usr/sbin/service', 'netif', 'restart'])
@staticmethod
def
change_ip
(
interfaces
,
dns
):
...
...
@@ -124,7 +125,8 @@ class Context(BaseContext):
@staticmethod
def
mount_store
(
host
,
username
,
password
):
data
=
{
'host'
:
host
,
'username'
:
username
,
'password'
:
password
,
'USERNAME'
:
username
.
upper
()}
data
=
{
'host'
:
host
,
'username'
:
username
,
'password'
:
password
,
'USERNAME'
:
username
.
upper
()}
data
[
'dir'
]
=
STORE_DIR
if
not
exists
(
STORE_DIR
):
mkdir
(
STORE_DIR
)
...
...
freebsd/network.py
View file @
d0221951
import
netifaces
from
netaddr
import
IPNetwork
import
fileinput
import
logging
import
subprocess
import
os
...
...
@@ -10,6 +9,7 @@ logger = logging.getLogger()
rcconf_dir
=
'/etc/rc.conf.d/'
def
get_interfaces_freebsd
(
interfaces
):
for
ifname
in
netifaces
.
interfaces
():
if
ifname
==
'lo0'
:
...
...
@@ -23,60 +23,51 @@ def get_interfaces_freebsd(interfaces):
def
remove_interfaces_freebsd
(
devices
):
delete_device
=
False
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
:
logger
.
debug
(
"unable to remove interface configuration: "
+
if_file
)
logger
.
debug
(
"unable to remove interface configuration: "
+
if_file
)
def
change_ip_freebsd
(
interfaces
,
dns
):
data
=
list
(
get_interfaces_freebsd
(
interfaces
))
for
ifname
,
conf
in
data
:
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'stop'
,
ifname
))
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'stop'
,
ifname
))
remove_interfaces_freebsd
(
dict
(
data
)
.
keys
())
for
device
,
conf
in
data
:
if_file
=
rcconf_dir
+
"ifconfig_"
+
device
with
open
(
if_file
,
'w'
)
as
f
:
ipv4_alias_counter
=
ipv6_alias_counter
=
0
#route6 = "ipv6_static_routes=\""
#route4 = "static_routes=\""
for
i
in
conf
[
'addresses'
]:
alias
=
""
alias
=
""
ip_with_prefix
=
IPNetwork
(
i
)
ip
=
ip_with_prefix
.
ip
prefixlen
=
ip_with_prefix
.
prefixlen
if
ip
.
version
==
6
:
alias
=
"_ipv6"
alias
=
"_ipv6"
if
ipv6_alias_counter
>
0
:
alias
=
'_alias
%
d'
%
(
ipv6_alias_counter
-
1
)
ipv6_alias_counter
+=
1
f
.
write
(
"ifconfig_"
+
device
+
alias
+
"="
+
"
\"
inet6
%(ip)
s prefixlen
%(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)s -gateway %(gw)s\"\n" % { 'netw' : ip_with_prefix.network, 'gw' : conf['gw6']})
"
\"
inet6
%(ip)
s prefixlen
%(pref)
s
\"\n
"
%
{
'ip'
:
ip
,
'pref'
:
prefixlen
})
f
.
write
(
"ipv6_defaultrouter=
\"
"
+
str
(
conf
[
'gw6'
])
+
"
\"\n
"
)
else
:
if
ipv4_alias_counter
>
0
:
# az aliasok szamanak folytonosnak kell lennie
ipv4_alias_counter
=
ipv6_alias_counter
+
1
ipv4_alias_counter
=
ipv6_alias_counter
+
1
alias
=
'_alias
%
d'
%
(
ipv4_alias_counter
)
ipv4_alias_counter
+=
1
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
(
"ifconfig_"
+
device
+
alias
+
"="
+
"
\"
inet
%(ip)
s/
%(pref)
s
\"\n
"
%
{
'ip'
:
ip
,
'pref'
:
prefixlen
})
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
)
...
...
@@ -95,4 +86,3 @@ def change_ip_freebsd(interfaces, dns):
# u'02:00:00:02:A3:E9': {
# u'gw4': u'10.255.255.1', u'addresses': [u'10.255.255.9']}},
# '8.8.8.8')
utils.py
View file @
d0221951
...
...
@@ -23,10 +23,6 @@ class SerialLineReceiverBase(LineReceiver, object):
def
handle_response
(
self
,
response
,
args
):
raise
NotImplementedError
(
"Subclass must implement abstract method"
)
def
dataReceivedd
(
self
,
data
):
#print data
pass
def
lineReceived
(
self
,
data
):
try
:
data
=
json
.
loads
(
data
)
...
...
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