Commit d0221951 by Bach Dániel

fix flake8 warnings

parent 67650b8d
...@@ -9,7 +9,7 @@ import sys ...@@ -9,7 +9,7 @@ import sys
system = platform.system() system = platform.system()
if system == "Linux" or system == "FreeBSD" : if system == "Linux" or system == "FreeBSD":
try: try:
chdir(sys.path[0]) chdir(sys.path[0])
subprocess.call(('pip', 'install', '-r', 'requirements.txt')) subprocess.call(('pip', 'install', '-r', 'requirements.txt'))
......
...@@ -28,7 +28,7 @@ def get_context(): ...@@ -28,7 +28,7 @@ def get_context():
elif system == "Linux": elif system == "Linux":
from linux._linuxcontext import Context from linux._linuxcontext import Context
elif system == "FreeBSD": elif system == "FreeBSD":
from freebsd._freebsdcontext import Context from freebsd._freebsdcontext import Context
else: else:
raise NotImplementedError("Platform %s is not supported.", system) raise NotImplementedError("Platform %s is not supported.", system)
return Context return Context
......
...@@ -15,7 +15,8 @@ try: ...@@ -15,7 +15,8 @@ try:
subprocess.call(('/sbin/kldload', '-n', 'virtio_console')) subprocess.call(('/sbin/kldload', '-n', 'virtio_console'))
subprocess.call(('/sbin/kldload', '-n', 'smbfs')) subprocess.call(('/sbin/kldload', '-n', 'smbfs'))
chdir(working_directory) 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/") copy("/root/agent/misc/vm_renewal", "/usr/local/bin/")
except: except:
pass # hope it works pass # hope it works
...@@ -61,6 +62,7 @@ nsmbrc_template_freebsd = ( ...@@ -61,6 +62,7 @@ nsmbrc_template_freebsd = (
'addr=%(host)s\n' 'addr=%(host)s\n'
'password=%(password)s\n') 'password=%(password)s\n')
class Context(BaseContext): class Context(BaseContext):
# http://stackoverflow.com/questions/12081310/ # http://stackoverflow.com/questions/12081310/
...@@ -85,19 +87,18 @@ class Context(BaseContext): ...@@ -85,19 +87,18 @@ class Context(BaseContext):
@staticmethod @staticmethod
def change_password(password): def change_password(password):
proc0 = subprocess.Popen(['/usr/sbin/pw', 'user', 'mod', 'cloud', '-h', '0'], proc0 = subprocess.Popen(
stdin=subprocess.PIPE) ['/usr/sbin/pw', 'user', 'mod', 'cloud', '-h', '0'],
stdin=subprocess.PIPE)
proc0.communicate('%s\n' % password) proc0.communicate('%s\n' % password)
proc1 = subprocess.Popen(['/usr/sbin/pw', 'user', 'mod', 'root', '-h', '0'], proc1 = subprocess.Popen(
stdin=subprocess.PIPE) ['/usr/sbin/pw', 'user', 'mod', 'root', '-h', '0'],
stdin=subprocess.PIPE)
proc1.communicate('%s\n' % password) proc1.communicate('%s\n' % password)
@staticmethod @staticmethod
def restart_networking(): def restart_networking():
logger.debug("restart_networking") logger.debug("restart_networking")
#logger.debug("XXX restart_networking disabled")
pass
#subprocess.call(['/usr/sbin/service', 'netif', 'restart'])
@staticmethod @staticmethod
def change_ip(interfaces, dns): def change_ip(interfaces, dns):
...@@ -124,7 +125,8 @@ class Context(BaseContext): ...@@ -124,7 +125,8 @@ class Context(BaseContext):
@staticmethod @staticmethod
def mount_store(host, username, password): 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 data['dir'] = STORE_DIR
if not exists(STORE_DIR): if not exists(STORE_DIR):
mkdir(STORE_DIR) mkdir(STORE_DIR)
...@@ -133,7 +135,7 @@ class Context(BaseContext): ...@@ -133,7 +135,7 @@ class Context(BaseContext):
if not (line.startswith('//') and ' smbfs ' in line): if not (line.startswith('//') and ' smbfs ' in line):
print line.rstrip() print line.rstrip()
with open(NSMBRC, 'w') as f: with open(NSMBRC, 'w') as f:
chmod(NSMBRC, 0600) chmod(NSMBRC, 0600)
f.write(nsmbrc_template_freebsd % data) f.write(nsmbrc_template_freebsd % data)
...@@ -209,7 +211,7 @@ class Context(BaseContext): ...@@ -209,7 +211,7 @@ class Context(BaseContext):
'/etc/nsmb.conf' '/etc/nsmb.conf'
'/root/.nsmbrc.conf' '/root/.nsmbrc.conf'
'/home/cloud/.nsmbrc.conf' '/home/cloud/.nsmbrc.conf'
] ]
+ glob('/etc/ssh/ssh_host_*')) + glob('/etc/ssh/ssh_host_*'))
for f in filelist: for f in filelist:
rmtree(f, ignore_errors=True) rmtree(f, ignore_errors=True)
......
import netifaces import netifaces
from netaddr import IPNetwork from netaddr import IPNetwork
import fileinput
import logging import logging
import subprocess import subprocess
import os import os
...@@ -10,10 +9,11 @@ logger = logging.getLogger() ...@@ -10,10 +9,11 @@ logger = logging.getLogger()
rcconf_dir = '/etc/rc.conf.d/' 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': if ifname == 'lo0':
continue # XXXOP: ? continue # XXXOP: ?
logger.debug("get_interfaces: " + ifname) logger.debug("get_interfaces: " + ifname)
mac = netifaces.ifaddresses(ifname)[18][0]['addr'] mac = netifaces.ifaddresses(ifname)[18][0]['addr']
logger.debug("get_interfaces: " + mac) logger.debug("get_interfaces: " + mac)
...@@ -23,60 +23,51 @@ def get_interfaces_freebsd(interfaces): ...@@ -23,60 +23,51 @@ def get_interfaces_freebsd(interfaces):
def remove_interfaces_freebsd(devices): def remove_interfaces_freebsd(devices):
delete_device = False
for device in devices: for device in devices:
if_file = rcconf_dir + device if_file = rcconf_dir + device
if os.path.isfile(if_file): if os.path.isfile(if_file):
logger.debug("remove interface configuration: " + if_file) logger.debug("remove interface configuration: " + if_file)
os.unlink(if_file) os.unlink(if_file)
else: 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): def change_ip_freebsd(interfaces, dns):
data = list(get_interfaces_freebsd(interfaces)) data = list(get_interfaces_freebsd(interfaces))
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_freebsd(dict(data).keys()) remove_interfaces_freebsd(dict(data).keys())
for device, conf in data: for device, conf in data:
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)
ip = ip_with_prefix.ip ip = ip_with_prefix.ip
prefixlen = ip_with_prefix.prefixlen prefixlen = ip_with_prefix.prefixlen
if ip.version == 6: if ip.version == 6:
alias="_ipv6" alias = "_ipv6"
if ipv6_alias_counter > 0: if ipv6_alias_counter > 0:
alias = '_alias%d' % (ipv6_alias_counter-1) alias = '_alias%d' % (ipv6_alias_counter-1)
ipv6_alias_counter += 1 ipv6_alias_counter += 1
f.write("ifconfig_" + device + alias + "=" + f.write("ifconfig_" + device + alias + "=" +
"\"inet6 %(ip)s prefixlen %(pref)s\"\n" % { 'ip' : ip, 'pref' : prefixlen }) "\"inet6 %(ip)s prefixlen %(pref)s\"\n"
#route6_name=device+"R"+str(ipv6_alias_counter)+"v6" % {'ip': ip, 'pref': prefixlen})
#route6 += route6_name+":"+device+" "
#f.write("route_"+route6_name+"=\"-net %(netw)s -gateway %(gw)s\"\n" % { 'netw' : ip_with_prefix.network, 'gw' : conf['gw6']})
f.write("ipv6_defaultrouter=\""+str(conf['gw6'])+"\"\n") f.write("ipv6_defaultrouter=\""+str(conf['gw6'])+"\"\n")
else: else:
if ipv4_alias_counter > 0: if ipv4_alias_counter > 0:
# az aliasok szamanak folytonosnak kell lennie # 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) 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 + "=" +
#route4_name=device+"R"+str(ipv4_alias_counter)+"v4" "\"inet %(ip)s/%(pref)s\"\n"
#route4 += route4_name+":"+device+" " % {'ip': ip, 'pref': prefixlen})
#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") 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: with open("/etc/resolv.conf", "w") as f:
f.write("nameserver "+dns) f.write("nameserver "+dns)
...@@ -95,4 +86,3 @@ def change_ip_freebsd(interfaces, dns): ...@@ -95,4 +86,3 @@ def change_ip_freebsd(interfaces, dns):
# u'02:00:00:02:A3:E9': { # u'02:00:00:02:A3:E9': {
# u'gw4': u'10.255.255.1', u'addresses': [u'10.255.255.9']}}, # u'gw4': u'10.255.255.1', u'addresses': [u'10.255.255.9']}},
# '8.8.8.8') # '8.8.8.8')
...@@ -23,10 +23,6 @@ class SerialLineReceiverBase(LineReceiver, object): ...@@ -23,10 +23,6 @@ class SerialLineReceiverBase(LineReceiver, object):
def handle_response(self, response, args): def handle_response(self, response, args):
raise NotImplementedError("Subclass must implement abstract method") raise NotImplementedError("Subclass must implement abstract method")
def dataReceivedd(self, data):
#print data
pass
def lineReceived(self, data): def lineReceived(self, data):
try: try:
data = json.loads(data) data = json.loads(data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment