Commit d0221951 by Bach Dániel

fix flake8 warnings

parent 67650b8d
......@@ -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'))
......
......@@ -28,7 +28,7 @@ def get_context():
elif system == "Linux":
from linux._linuxcontext import Context
elif system == "FreeBSD":
from freebsd._freebsdcontext import Context
from freebsd._freebsdcontext import Context
else:
raise NotImplementedError("Platform %s is not supported.", system)
return Context
......
......@@ -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'],
stdin=subprocess.PIPE)
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'],
stdin=subprocess.PIPE)
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)
......@@ -133,7 +135,7 @@ class Context(BaseContext):
if not (line.startswith('//') and ' smbfs ' in line):
print line.rstrip()
with open(NSMBRC, 'w') as f:
with open(NSMBRC, 'w') as f:
chmod(NSMBRC, 0600)
f.write(nsmbrc_template_freebsd % data)
......@@ -209,7 +211,7 @@ class Context(BaseContext):
'/etc/nsmb.conf'
'/root/.nsmbrc.conf'
'/home/cloud/.nsmbrc.conf'
]
]
+ glob('/etc/ssh/ssh_host_*'))
for f in filelist:
rmtree(f, ignore_errors=True)
......
import netifaces
from netaddr import IPNetwork
import fileinput
import logging
import subprocess
import os
......@@ -10,10 +9,11 @@ logger = logging.getLogger()
rcconf_dir = '/etc/rc.conf.d/'
def get_interfaces_freebsd(interfaces):
for ifname in netifaces.interfaces():
if ifname == 'lo0':
continue # XXXOP: ?
continue # XXXOP: ?
logger.debug("get_interfaces: " + ifname)
mac = netifaces.ifaddresses(ifname)[18][0]['addr']
logger.debug("get_interfaces: " + mac)
......@@ -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')
......@@ -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)
......
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