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

Fix typos. Code Inspection for pep8 conventions

This commit is contained in:
catborise 2019-10-30 11:05:50 +03:00
parent 568ff92449
commit f3f4f0afe8
6 changed files with 37 additions and 30 deletions

View file

@ -73,6 +73,7 @@ def allinstances(request):
def instances(request, compute_id): def instances(request, compute_id):
""" """
:param request: :param request:
:param compute_id
:return: :return:
""" """
all_host_vms = {} all_host_vms = {}
@ -224,9 +225,9 @@ def instance(request, compute_id, vname):
def get_network_tuple(network_source_str): def get_network_tuple(network_source_str):
network_source_pack = network_source_str.split(":", 1) network_source_pack = network_source_str.split(":", 1)
if len(network_source_pack) > 1: if len(network_source_pack) > 1:
return (network_source_pack[1], network_source_pack[0]) return network_source_pack[1], network_source_pack[0]
else: else:
return (network_source_pack[0], 'net') return network_source_pack[0], 'net'
def migrate_instance(new_compute, instance, live=False, unsafe=False, xml_del=False, offline=False): def migrate_instance(new_compute, instance, live=False, unsafe=False, xml_del=False, offline=False):
status = connection_manager.host_is_up(new_compute.type, new_compute.hostname) status = connection_manager.host_is_up(new_compute.type, new_compute.hostname)
@ -1104,10 +1105,13 @@ def instances_actions(request):
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
@login_required @login_required
def inst_graph(request, compute_id, vname): def inst_graph(request, compute_id, vname):
""" """
:param request: :param request:
:param compute_id:
:param vname:
:return: :return:
""" """
json_blk = [] json_blk = []
@ -1298,7 +1302,7 @@ def delete_instance(instance, delete_disk=False):
conn.delete() conn.delete()
instance.delete() instance.delete()
print("Instance {} on compute {} sucessfully deleted".format(instance_name, compute.hostname)) print("Instance {} on compute {} successfully deleted".format(instance_name, compute.hostname))
except libvirtError as lib_err: except libvirtError as lib_err:
print("Error removing instance {} on compute {}".format(instance_name, compute.hostname)) print("Error removing instance {} on compute {}".format(instance_name, compute.hostname))

View file

@ -61,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 compute_id:
:param iface: :param iface:
:return: :return:
""" """

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
from django.shortcuts import render
from django.http import HttpResponseRedirect from django.http import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404 from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -19,6 +18,7 @@ from logs.views import addlogmsg
def nwfilters(request, compute_id): def nwfilters(request, compute_id):
""" """
:param request: :param request:
:param compute_id:
:return: :return:
""" """
@ -31,9 +31,9 @@ def nwfilters(request, compute_id):
try: try:
conn = wvmNWFilters(compute.hostname, conn = wvmNWFilters(compute.hostname,
compute.login, compute.login,
compute.password, compute.password,
compute.type) compute.type)
if request.method == 'POST': if request.method == 'POST':
if 'create_nwfilter' in request.POST: if 'create_nwfilter' in request.POST:
@ -63,7 +63,7 @@ def nwfilters(request, compute_id):
addlogmsg(request.user.username, compute.hostname, lib_err.message) addlogmsg(request.user.username, compute.hostname, lib_err.message)
if 'del_nwfilter' in request.POST: if 'del_nwfilter' in request.POST:
name = request.POST.get('nwfiltername','') name = request.POST.get('nwfiltername', '')
msg = _("Deleting NWFilter: %s" % name) msg = _("Deleting NWFilter: %s" % name)
in_use = False in_use = False
nwfilter = conn.get_nwfilter(name) nwfilter = conn.get_nwfilter(name)
@ -71,7 +71,6 @@ def nwfilters(request, compute_id):
is_conn = wvmInstances(compute.hostname, compute.login, compute.password, compute.type) is_conn = wvmInstances(compute.hostname, compute.login, compute.password, compute.type)
instances = is_conn.get_instances() instances = is_conn.get_instances()
for inst in instances: for inst in instances:
# if in_use: break
i_conn = wvmInstance(compute.hostname, compute.login, compute.password, compute.type, inst) i_conn = wvmInstance(compute.hostname, compute.login, compute.password, compute.type, inst)
dom_filterrefs = i_conn.get_filterrefs() dom_filterrefs = i_conn.get_filterrefs()
@ -90,10 +89,10 @@ def nwfilters(request, compute_id):
if 'cln_nwfilter' in request.POST: if 'cln_nwfilter' in request.POST:
name = request.POST.get('nwfiltername','') name = request.POST.get('nwfiltername', '')
cln_name = request.POST.get('cln_name', name + '-clone') cln_name = request.POST.get('cln_name', name + '-clone')
conn.clone_nwfilter(name,cln_name) conn.clone_nwfilter(name, cln_name)
msg = _("Cloning NWFilter %s as %s" % (name, cln_name)) msg = _("Cloning NWFilter %s as %s" % (name, cln_name))
addlogmsg(request.user.username, compute.hostname, msg) addlogmsg(request.user.username, compute.hostname, msg)
@ -122,14 +121,14 @@ def nwfilter(request, compute_id, nwfltr):
try: try:
nwfilter = wvmNWFilter(compute.hostname, nwfilter = wvmNWFilter(compute.hostname,
compute.login, compute.login,
compute.password, compute.password,
compute.type, compute.type,
nwfltr) nwfltr)
conn = wvmNWFilters(compute.hostname, conn = wvmNWFilters(compute.hostname,
compute.login, compute.login,
compute.password, compute.password,
compute.type) compute.type)
for nwf in conn.get_nwfilters(): for nwf in conn.get_nwfilters():
nwfilters_all.append(conn.get_nwfilter_info(nwf)) nwfilters_all.append(conn.get_nwfilter_info(nwf))
@ -208,4 +207,4 @@ def nwfilter(request, compute_id, nwfltr):
except Exception as error_msg: except Exception as error_msg:
error_messages.append(error_msg) error_messages.append(error_msg)
return render(request, 'nwfilter.html', locals()) return render(request, 'nwfilter.html', locals())

View file

@ -12,6 +12,7 @@ from libvirt import libvirtError
def secrets(request, compute_id): def secrets(request, compute_id):
""" """
:param request: :param request:
:param compute_id:
:return: :return:
""" """

View file

@ -318,9 +318,9 @@ class IPint(object):
(self._ipversion == 6 and self._prefixlen == 128): (self._ipversion == 6 and self._prefixlen == 128):
if self.NoPrefixForSingleIp: if self.NoPrefixForSingleIp:
want = 0 want = 0
if want == None: if want is None:
want = self.WantPrefixLen want = self.WantPrefixLen
if want == None: if want is None:
want = 1 want = 1
if want: if want:
if want == 2: if want == 2:
@ -354,7 +354,7 @@ class IPint(object):
""" """
bits = _ipVersionToLen(self._ipversion) bits = _ipVersionToLen(self._ipversion)
if self.WantPrefixLen == None and wantprefixlen == None: if self.WantPrefixLen is None and wantprefixlen is None:
wantprefixlen = 0 wantprefixlen = 0
ret = _intToBin(self.ip) ret = _intToBin(self.ip)
return '0' * (bits - len(ret)) + ret + self._printPrefix(wantprefixlen) return '0' * (bits - len(ret)) + ret + self._printPrefix(wantprefixlen)
@ -370,7 +370,7 @@ class IPint(object):
'ffff:ffff:ffff:ffff:ffff:f:f:fffc/127' 'ffff:ffff:ffff:ffff:ffff:f:f:fffc/127'
""" """
if self.WantPrefixLen == None and wantprefixlen == None: if self.WantPrefixLen is None and wantprefixlen is None:
wantprefixlen = 1 wantprefixlen = 1
if self._ipversion == 4: if self._ipversion == 4:
@ -413,7 +413,7 @@ class IPint(object):
2001:658:22a:cafe:200:0:0:1 2001:658:22a:cafe:200:0:0:1
""" """
if self.WantPrefixLen == None and wantprefixlen == None: if self.WantPrefixLen is None and wantprefixlen is None:
wantprefixlen = 1 wantprefixlen = 1
if self._ipversion == 4: if self._ipversion == 4:
@ -434,7 +434,7 @@ class IPint(object):
2001:0658:022a:cafe:0200:0000:0000:0001 2001:0658:022a:cafe:0200:0000:0000:0001
""" """
if self.WantPrefixLen == None and wantprefixlen == None: if self.WantPrefixLen is None and wantprefixlen is None:
wantprefixlen = 1 wantprefixlen = 1
return intToIp(self.ip, self._ipversion) + self._printPrefix(wantprefixlen) return intToIp(self.ip, self._ipversion) + self._printPrefix(wantprefixlen)
@ -448,7 +448,7 @@ class IPint(object):
0x20010658022acafe0200000000000001 0x20010658022acafe0200000000000001
""" """
if self.WantPrefixLen == None and wantprefixlen == None: if self.WantPrefixLen is None and wantprefixlen is None:
wantprefixlen = 0 wantprefixlen = 0
x = '0x%x' % self.ip x = '0x%x' % self.ip
@ -463,7 +463,7 @@ class IPint(object):
42540616829182469433547762482097946625 42540616829182469433547762482097946625
""" """
if self.WantPrefixLen == None and wantprefixlen == None: if self.WantPrefixLen is None and wantprefixlen is None:
wantprefixlen = 0 wantprefixlen = 0
x = '%d' % self.ip x = '%d' % self.ip

View file

@ -247,7 +247,7 @@ class wvmInstance(wvmConnect):
def get_disk_devices(self): def get_disk_devices(self):
def disks(doc): def disks(doc):
result = [] result = []
dev = volume = storage = src_file = None dev = volume = storage = src_file = bus = None
disk_format = used_size = disk_size = disk_cache = None disk_format = used_size = disk_size = disk_cache = None
for disk in doc.xpath('/domain/devices/disk'): for disk in doc.xpath('/domain/devices/disk'):
@ -288,7 +288,7 @@ class wvmInstance(wvmConnect):
def get_media_devices(self): def get_media_devices(self):
def disks(doc): def disks(doc):
result = [] result = []
dev = volume = storage = None dev = volume = storage = bus = None
src_file = None src_file = None
for media in doc.xpath('/domain/devices/disk'): for media in doc.xpath('/domain/devices/disk'):
device = media.xpath('@device')[0] device = media.xpath('@device')[0]
@ -341,6 +341,7 @@ class wvmInstance(wvmConnect):
def get_bootorder(self): def get_bootorder(self):
boot_order = {} boot_order = {}
type = target = None
tree = ElementTree.fromstring(self._XMLDesc(0)) tree = ElementTree.fromstring(self._XMLDesc(0))
os = tree.find('os') os = tree.find('os')
boot = os.findall('boot') boot = os.findall('boot')
@ -363,7 +364,7 @@ class wvmInstance(wvmConnect):
devices = tree.find('devices') devices = tree.find('devices')
for dev in devices: for dev in devices:
dev_target = dev_type = dev_device = dev_alias = None dev_target = None
boot_dev = dev.find('boot') boot_dev = dev.find('boot')
if boot_dev is not None: if boot_dev is not None:
idx = boot_dev.get('order') idx = boot_dev.get('order')
@ -439,6 +440,7 @@ class wvmInstance(wvmConnect):
disk.insert(2, src_media) disk.insert(2, src_media)
return True return True
vol = None
storages = self.get_storages(only_actives=True) storages = self.get_storages(only_actives=True)
for storage in storages: for storage in storages:
stg = self.get_storage(storage) stg = self.get_storage(storage)