1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 23:25:24 +00:00

pep8 style code corrections

This commit is contained in:
catborise 2019-09-10 09:48:31 +03:00
parent fdbb6739c1
commit 828a271789
18 changed files with 69 additions and 64 deletions

View file

@ -2,7 +2,6 @@ from django.shortcuts import render
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from accounts.models import * from accounts.models import *
from instances.models import Instance from instances.models import Instance
@ -11,7 +10,6 @@ from django.conf import settings
from django.core.validators import ValidationError from django.core.validators import ValidationError
@login_required @login_required
def profile(request): def profile(request):
""" """
@ -70,6 +68,7 @@ def profile(request):
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
return render(request, 'profile.html', locals()) return render(request, 'profile.html', locals())
@login_required @login_required
def accounts(request): def accounts(request):
""" """
@ -154,6 +153,7 @@ def accounts(request):
def account(request, user_id): def account(request, user_id):
""" """
:param request: :param request:
:param user_id:
:return: :return:
""" """

View file

@ -1,4 +1,3 @@
import time
import json import json
from django.utils import timezone from django.utils import timezone
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
@ -140,6 +139,7 @@ def computes(request):
def overview(request, compute_id): def overview(request, compute_id):
""" """
:param request: :param request:
:param compute_id:
:return: :return:
""" """
@ -171,6 +171,7 @@ def overview(request, compute_id):
def compute_graph(request, compute_id): def compute_graph(request, compute_id):
""" """
:param request: :param request:
:param compute_id:
:return: :return:
""" """
compute = get_object_or_404(Compute, pk=compute_id) compute = get_object_or_404(Compute, pk=compute_id)
@ -207,17 +208,16 @@ def get_compute_disk_buses(request, compute_id, disk):
compute.type) compute.type)
disk_device_types = conn.get_disk_device_types() disk_device_types = conn.get_disk_device_types()
disk_bus_types = conn.get_disk_bus_types()
if disk in disk_device_types: if disk in disk_device_types:
if disk == 'disk': if disk == 'disk':
data['bus'] = sorted(disk_device_types) data['bus'] = sorted(disk_device_types)
elif disk == 'cdrom': elif disk == 'cdrom':
data['bus'] = ['ide', 'sata', 'scsi',] data['bus'] = ['ide', 'sata', 'scsi']
elif disk == 'floppy': elif disk == 'floppy':
data['bus'] = ['fdc',] data['bus'] = ['fdc']
elif disk == 'lun': elif disk == 'lun':
data['bus'] = ['scsi',] data['bus'] = ['scsi']
except libvirtError: except libvirtError:
pass pass

View file

@ -120,7 +120,7 @@ def get_connection_infos(token):
console_host = conn.get_console_listen_addr() console_host = conn.get_console_listen_addr()
console_port = conn.get_console_port() console_port = conn.get_console_port()
console_socket = conn.get_console_socket() console_socket = conn.get_console_socket()
except Exception, e: except Exception as e:
logging.error('Fail to retrieve console connection infos for token %s : %s' % (token, e)) logging.error('Fail to retrieve console connection infos for token %s : %s' % (token, e))
raise raise
return (connhost, connport, connuser, conntype, console_host, return (connhost, connport, connuser, conntype, console_host,

View file

@ -1,7 +1,5 @@
import re import re
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from instances.models import Instance from instances.models import Instance
from vrtManager.instance import wvmInstance from vrtManager.instance import wvmInstance

View file

@ -21,6 +21,7 @@ from logs.views import addlogmsg
def create_instance(request, compute_id): def create_instance(request, compute_id):
""" """
:param request: :param request:
:param compute_id:
:return: :return:
""" """
@ -175,7 +176,7 @@ def create_instance(request, compute_id):
addlogmsg(request.user.username, create_instance.name, msg) addlogmsg(request.user.username, create_instance.name, msg)
return HttpResponseRedirect(reverse('instance', args=[compute_id, data['name']])) return HttpResponseRedirect(reverse('instance', args=[compute_id, data['name']]))
except libvirtError as lib_err: except libvirtError as lib_err:
if data['hdd_size'] or volume_list.count() > 0: if data['hdd_size'] or len(volume_list) > 0:
for vol in volume_list: for vol in volume_list:
conn.delete_volume(vol['path']) conn.delete_volume(vol['path'])
error_messages.append(lib_err) error_messages.append(lib_err)

View file

@ -70,8 +70,8 @@ def get_client_ip(request):
def get_hostname_by_ip(ip): def get_hostname_by_ip(ip):
try: try:
addrs = socket.gethostbyaddr(ip) addrs = socket.gethostbyaddr(ip)
except Exception: except:
addrs = [ip,] addrs = [ip]
return addrs[0] return addrs[0]

View file

@ -12,6 +12,7 @@ from libvirt import libvirtError
def interfaces(request, compute_id): def interfaces(request, compute_id):
""" """
:param request: :param request:
:param compute_id:
:return: :return:
""" """
@ -60,6 +61,7 @@ def interfaces(request, compute_id):
def interface(request, compute_id, iface): def interface(request, compute_id, iface):
""" """
:param request: :param request:
:param iface:
:return: :return:
""" """

View file

@ -10,7 +10,9 @@ import json
def addlogmsg(user, instance, message): def addlogmsg(user, instance, message):
""" """
:param request: :param user:
:param instance:
:param message:
:return: :return:
""" """
add_log_msg = Logs(user=user, instance=instance, message=message) add_log_msg = Logs(user=user, instance=instance, message=message)
@ -21,6 +23,7 @@ def addlogmsg(user, instance, message):
def showlogs(request, page=1): def showlogs(request, page=1):
""" """
:param request: :param request:
:param page:
:return: :return:
""" """
@ -36,11 +39,12 @@ def showlogs(request, page=1):
return render(request, 'showlogs.html', locals()) return render(request, 'showlogs.html', locals())
@login_required @login_required
def vm_logs(request, vname): def vm_logs(request, vname):
""" """
:param request: :param request:
:param vm: :param vname:
:return: :return:
""" """
@ -51,7 +55,7 @@ def vm_logs(request, vname):
logs_ = Logs.objects.filter(instance=vm.name, date__gte=vm.created).order_by('-date') logs_ = Logs.objects.filter(instance=vm.name, date__gte=vm.created).order_by('-date')
logs = [] logs = []
for l in logs_: for l in logs_:
log = {} log = dict()
log['user'] = l.user log['user'] = l.user
log['instance'] = l.instance log['instance'] = l.instance
log['message'] = l.message log['message'] = l.message

View file

@ -15,6 +15,7 @@ from django.contrib import messages
def networks(request, compute_id): def networks(request, compute_id):
""" """
:param request: :param request:
:param compute_id:
:return: :return:
""" """
@ -64,6 +65,8 @@ def networks(request, compute_id):
def network(request, compute_id, pool): def network(request, compute_id, pool):
""" """
:param request: :param request:
:param compute_id:
:param pool:
:return: :return:
""" """

View file

@ -10,10 +10,12 @@ from libvirt import libvirtError
from django.contrib import messages from django.contrib import messages
import json import json
@login_required @login_required
def storages(request, compute_id): def storages(request, compute_id):
""" """
:param request: :param request:
:param compute_id:
:return: :return:
""" """
@ -72,6 +74,8 @@ def storages(request, compute_id):
def storage(request, compute_id, pool): def storage(request, compute_id, pool):
""" """
:param request: :param request:
:param compute_id:
:param pool:
:return: :return:
""" """

View file

@ -2,7 +2,7 @@ import libvirt
import threading import threading
import socket import socket
from vrtManager import util from vrtManager import util
from rwlock import ReadWriteLock from vrtManager.rwlock import ReadWriteLock
from django.conf import settings from django.conf import settings
from libvirt import libvirtError from libvirt import libvirtError

View file

@ -2,7 +2,6 @@ import string
from vrtManager import util from vrtManager import util
from vrtManager.connection import wvmConnect from vrtManager.connection import wvmConnect
from webvirtcloud.settings import QEMU_CONSOLE_DEFAULT_TYPE from webvirtcloud.settings import QEMU_CONSOLE_DEFAULT_TYPE
from webvirtcloud.settings import QEMU_CONSOLE_LISTEN_ADDRESSES
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_OWNER as default_owner from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_OWNER as default_owner
from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_FORMAT from webvirtcloud.settings import INSTANCE_VOLUME_DEFAULT_FORMAT
@ -107,7 +106,7 @@ class wvmCreate(wvmConnect):
if not pool: if not pool:
storages = self.get_storages(only_actives=True) storages = self.get_storages(only_actives=True)
else: else:
storages = [pool,] storages = [pool]
for storage in storages: for storage in storages:
stg = self.get_storage(storage) stg = self.get_storage(storage)
if stg.info()[0] != 0: if stg.info()[0] != 0:
@ -204,7 +203,6 @@ class wvmCreate(wvmConnect):
hd_disk_letters = list(string.lowercase) hd_disk_letters = list(string.lowercase)
sd_disk_letters = list(string.lowercase) sd_disk_letters = list(string.lowercase)
add_cd = True add_cd = True
#for image, img_type in images.items():
for volume in images: for volume in images:
stg = self.get_storage_by_vol_path(volume['path']) stg = self.get_storage_by_vol_path(volume['path'])
stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type") stg_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
@ -283,8 +281,4 @@ class wvmCreate(wvmConnect):
<memballoon model='virtio'/> <memballoon model='virtio'/>
</devices> </devices>
</domain>""" % video </domain>""" % video
self._defineXML(xml) self._defineXML(xml)

View file

@ -58,7 +58,7 @@ class wvmHostDetails(wvmConnect):
""" """
Function return host server information: hostname, cpu, memory, ... Function return host server information: hostname, cpu, memory, ...
""" """
info = [] info = list()
info.append(self.wvm.getHostname()) # hostname info.append(self.wvm.getHostname()) # hostname
info.append(self.wvm.getInfo()[0]) # architecture info.append(self.wvm.getInfo()[0]) # architecture
info.append(self.wvm.getInfo()[1] * 1048576) # memory info.append(self.wvm.getInfo()[1] * 1048576) # memory

View file

@ -237,7 +237,7 @@ class wvmInstance(wvmConnect):
try: try:
net = self.get_network(network_host) net = self.get_network(network_host)
ip = get_mac_ipaddr(net, mac_host) ip = get_mac_ipaddr(net, mac_host)
except libvirtError as e: except libvirtError:
ip = None ip = None
result.append({'mac': mac_host, 'nic': network_host, 'target': target_host, 'ip': ip, 'filterref': filterref_host}) result.append({'mac': mac_host, 'nic': network_host, 'target': target_host, 'ip': ip, 'filterref': filterref_host})
return result return result
@ -322,7 +322,7 @@ class wvmInstance(wvmConnect):
os = tree.find('os') os = tree.find('os')
menu = os.find("bootmenu") menu = os.find("bootmenu")
if menu == None: if menu is None:
bootmenu = ElementTree.fromstring("<bootmenu enable='yes'/>") bootmenu = ElementTree.fromstring("<bootmenu enable='yes'/>")
os.append(bootmenu) os.append(bootmenu)
menu = os.find("bootmenu") menu = os.find("bootmenu")
@ -365,7 +365,7 @@ class wvmInstance(wvmConnect):
for dev in devices: for dev in devices:
dev_target = dev_type = dev_device = dev_alias = None dev_target = dev_type = dev_device = dev_alias = None
boot_dev = dev.find('boot') boot_dev = dev.find('boot')
if boot_dev != None: if boot_dev is not None:
idx = boot_dev.get('order') idx = boot_dev.get('order')
dev_type = dev.get('type') dev_type = dev.get('type')
dev_device = dev.get('device') dev_device = dev.get('device')
@ -398,7 +398,7 @@ class wvmInstance(wvmConnect):
# Remove rest of them # Remove rest of them
for dev in tree.find('devices'): for dev in tree.find('devices'):
boot_dev = dev.find('boot') boot_dev = dev.find('boot')
if boot_dev != None: if boot_dev is not None:
dev.remove(boot_dev) dev.remove(boot_dev)
return tree return tree
@ -410,19 +410,19 @@ class wvmInstance(wvmConnect):
devices = tree.findall("./devices/disk[@device='disk']") devices = tree.findall("./devices/disk[@device='disk']")
for d in devices: for d in devices:
device = d.find("./target[@dev='{}']".format(dev['dev'])) device = d.find("./target[@dev='{}']".format(dev['dev']))
if device != None: if device is not None:
d.append(order) d.append(order)
elif dev['type'] == 'cdrom': elif dev['type'] == 'cdrom':
devices = tree.findall("./devices/disk[@device='cdrom']") devices = tree.findall("./devices/disk[@device='cdrom']")
for d in devices: for d in devices:
device = d.find("./target[@dev='{}']".format(dev['dev'])) device = d.find("./target[@dev='{}']".format(dev['dev']))
if device != None: if device is not None:
d.append(order) d.append(order)
elif dev['type'] == 'network': elif dev['type'] == 'network':
devices = tree.findall("./devices/interface[@type='network']") devices = tree.findall("./devices/interface[@type='network']")
for d in devices: for d in devices:
device = d.find("mac[@address='{}']".format(dev['dev'])) device = d.find("mac[@address='{}']".format(dev['dev']))
if device != None: if device is not None:
d.append(order) d.append(order)
else: else:
raise Exception('Invalid Device Type for boot order') raise Exception('Invalid Device Type for boot order')
@ -478,7 +478,6 @@ class wvmInstance(wvmConnect):
self._defineXML(xmldom) self._defineXML(xmldom)
def attach_disk(self, source, target, sourcetype='file', device='disk', driver='qemu', subdriver='raw', cache='none', targetbus='ide'): def attach_disk(self, source, target, sourcetype='file', device='disk', driver='qemu', subdriver='raw', cache='none', targetbus='ide'):
tree = ElementTree.fromstring(self._XMLDesc(0))
xml_disk = "<disk type='%s' device='%s'>" % (sourcetype, device) xml_disk = "<disk type='%s' device='%s'>" % (sourcetype, device)
if device == 'cdrom': if device == 'cdrom':
xml_disk += "<driver name='%s' type='%s'/>" % (driver, subdriver) xml_disk += "<driver name='%s' type='%s'/>" % (driver, subdriver)
@ -805,7 +804,7 @@ class wvmInstance(wvmConnect):
new_xml = ElementTree.tostring(tree) new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml) self._defineXML(new_xml)
def resize_disk(self, disks=[]): def resize_disk(self, disks):
""" """
Function change disks on vds. Function change disks on vds.
""" """
@ -1007,7 +1006,6 @@ class wvmInstance(wvmConnect):
return bridge_name return bridge_name
def add_network(self, mac_address, source, source_type='net', interface_type='bridge', model='virtio', nwfilter=None): def add_network(self, mac_address, source, source_type='net', interface_type='bridge', model='virtio', nwfilter=None):
tree = ElementTree.fromstring(self._XMLDesc(0))
bridge_name = self.get_bridge_name(source, source_type) bridge_name = self.get_bridge_name(source, source_type)
xml_interface = """ xml_interface = """
<interface type='%s'> <interface type='%s'>
@ -1029,7 +1027,6 @@ class wvmInstance(wvmConnect):
def delete_network(self, mac_address): def delete_network(self, mac_address):
tree = ElementTree.fromstring(self._XMLDesc(0)) tree = ElementTree.fromstring(self._XMLDesc(0))
devices = tree.find('devices')
for interface in tree.findall('devices/interface'): for interface in tree.findall('devices/interface'):
source = interface.find('mac') source = interface.find('mac')
if source.get('address', '') == mac_address: if source.get('address', '') == mac_address:
@ -1089,7 +1086,7 @@ class wvmInstance(wvmConnect):
option = tree.find(o) option = tree.find(o)
option_value = options.get(o, '').strip() option_value = options.get(o, '').strip()
if not option_value: if not option_value:
if not option is None: if option is not None:
tree.remove(option) tree.remove(option)
else: else:
if option is None: if option is None:

View file

@ -22,6 +22,7 @@ def network_size(net, dhcp=None):
class wvmNetworks(wvmConnect): class wvmNetworks(wvmConnect):
def get_networks_info(self): def get_networks_info(self):
get_networks = self.get_networks() get_networks = self.get_networks()
networks = [] networks = []
@ -166,7 +167,7 @@ class wvmNetwork(wvmConnect):
return dhcp[1] return dhcp[1]
def can_pxe(self): def can_pxe(self):
xml = self.get_xml() xml = self._XMLDesc(0)
forward = self.get_ipv4_forward()[0] forward = self.get_ipv4_forward()[0]
if forward and forward != "nat": if forward and forward != "nat":
return True return True

View file

@ -7,11 +7,11 @@ class wvmSecrets(wvmConnect):
xml = """<secret ephemeral='%s' private='%s'> xml = """<secret ephemeral='%s' private='%s'>
<usage type='%s'>""" % (ephemeral, private, secret_type) <usage type='%s'>""" % (ephemeral, private, secret_type)
if secret_type == 'ceph': if secret_type == 'ceph':
xml += """<name>%s</name>""" % (data) xml += """<name>%s</name>""" % data
if secret_type == 'volume': if secret_type == 'volume':
xml += """<volume>%s</volume>""" % (data) xml += """<volume>%s</volume>""" % data
if secret_type == 'iscsi': if secret_type == 'iscsi':
xml += """<target>%s</target>""" % (data) xml += """<target>%s</target>""" % data
xml += """</usage> xml += """</usage>
</secret>""" </secret>"""
self.wvm.secretDefineXML(xml) self.wvm.secretDefineXML(xml)

View file

@ -119,6 +119,7 @@ def get_xpath(doc, path):
return result return result
def pretty_mem(val): def pretty_mem(val):
val = int(val) val = int(val)
if val > (10 * 1024 * 1024): if val > (10 * 1024 * 1024):