Skip to content

Commit

Permalink
Add some fix and code review
Browse files Browse the repository at this point in the history
  • Loading branch information
retspen committed Apr 11, 2014
1 parent b561681 commit 8f8e741
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -7,8 +7,8 @@ env:
install:
- pip install -r dev-requirements.txt --use-mirrors
script:
- pep8 --exclude=migrations --ignore=E501,E225 console hostdetail instance networks servers storages vrtManager
- pep8 --exclude=IPy.py --ignore=E501,E225 console hostdetail instance networks servers storages vrtManager
- pyflakes console hostdetail instance networks servers storages vrtManager
- pylint console hostdetail instance networks servers storages vrtManager
# - pylint console hostdetail instance networks servers storages vrtManager
- python manage.py syncdb --noinput
- python manage.py test
5 changes: 1 addition & 4 deletions dev-requirements.txt
Expand Up @@ -3,7 +3,4 @@
django-jenkins==0.14.1
pyflakes==0.7.3
pylint==1.1.0
pep8==1.4.6
# Utility Requirements
# for SECURE_KEY generation
lockfile>=0.9
pep8==1.4.6
2 changes: 1 addition & 1 deletion hostdetail/views.py
Expand Up @@ -32,7 +32,6 @@ def hostusage(request, host_id):
except libvirtError:
cpu_usage = 0


try:
cookies['cpu'] = request._cookies['cpu']
cookies['mem'] = request._cookies['mem']
Expand Down Expand Up @@ -118,6 +117,7 @@ def hostusage(request, host_id):
response.write(data)
return response


def overview(request, host_id):
"""
Overview page.
Expand Down
1 change: 1 addition & 0 deletions instance/templatetags/tags_active.py
Expand Up @@ -3,6 +3,7 @@

register = template.Library()


@register.simple_tag
def active(request, pattern):
if re.search(pattern, request.path):
Expand Down
5 changes: 4 additions & 1 deletion instance/views.py
Expand Up @@ -318,6 +318,7 @@ def instusage(request, host_id, vname):
response.write(data)
return response


def insts_status(request, host_id):
"""
Instances block
Expand Down Expand Up @@ -345,14 +346,15 @@ def insts_status(request, host_id):
'vcpu': conn.get_instance_vcpu(instance),
'uuid': conn.get_uuid(instance),
'dump': conn.get_instance_managed_save_image(instance)
})
})

data = json.dumps(instances)
response = HttpResponse()
response['Content-Type'] = "text/javascript"
response.write(data)
return response


def instances(request, host_id):
"""
Instances block
Expand Down Expand Up @@ -420,6 +422,7 @@ def instances(request, host_id):

return render_to_response('instances.html', locals(), context_instance=RequestContext(request))


def instance(request, host_id, vname):
"""
Instance block
Expand Down
1 change: 1 addition & 0 deletions networks/views.py
Expand Up @@ -54,6 +54,7 @@ def networks(request, host_id):

return render_to_response('networks.html', locals(), context_instance=RequestContext(request))


def network(request, host_id, pool):
"""
Networks block
Expand Down
5 changes: 3 additions & 2 deletions storages/views.py
Expand Up @@ -43,7 +43,8 @@ def storages(request, host_id):
except libvirtError as err:
errors.append(err.message)

return render_to_response('storages.html', locals(), context_instance=RequestContext(request))
return render_to_response('storages.html', locals(), context_instance=RequestContext(request))


def storage(request, host_id, pool):
"""
Expand Down Expand Up @@ -165,4 +166,4 @@ def handle_uploaded_file(path, f_name):
errors.append(error_msg.message)
conn.close()

return render_to_response('storage.html', locals(), context_instance=RequestContext(request))
return render_to_response('storage.html', locals(), context_instance=RequestContext(request))
1 change: 1 addition & 0 deletions vrtManager/connection.py
Expand Up @@ -11,6 +11,7 @@
SSH_PORT = 22
TCP_PORT = 16509


class wvmConnect(object):
def __init__(self, host, login, passwd, conn):
self.login = login
Expand Down
4 changes: 2 additions & 2 deletions vrtManager/hostdetails.py
Expand Up @@ -22,8 +22,8 @@ def get_memory_usage(self):
get_all_mem = self.wvm.getInfo()[1] * 1048576
get_freemem = self.wvm.getMemoryStats(-1, 0)
if type(get_freemem) == dict:
free = (get_freemem.values()[0] + \
get_freemem.values()[2] + \
free = (get_freemem.values()[0] +
get_freemem.values()[2] +
get_freemem.values()[3]) * 1024
percent = (100 - ((free * 100) / get_all_mem))
usage = (get_all_mem - free)
Expand Down
1 change: 1 addition & 0 deletions vrtManager/instance.py
Expand Up @@ -162,6 +162,7 @@ def fixed(ctx):
return host
return None
return util.get_xml_path(net.XMLDesc(0), func=fixed)

def networks(ctx):
result = []
for net in ctx.xpathEval('/domain/devices/interface'):
Expand Down
5 changes: 3 additions & 2 deletions vrtManager/network.py
Expand Up @@ -5,6 +5,7 @@
from vrtManager.IPy import IP
from vrtManager.connection import wvmConnect


def network_size(net, dhcp=None):
"""
Func return gateway, mask and dhcp pool.
Expand Down Expand Up @@ -74,8 +75,8 @@ def create_network(self, name, forward, gateway, mask, dhcp, bridge, fixed=False

class wvmNetwork(wvmConnect):
def __init__(self, host, login, passwd, conn, net):
wvmConnect.__init__(self, host, login, passwd, conn)
self.net = self.wvm.networkLookupByName(net)
wvmConnect.__init__(self, host, login, passwd, conn)
self.net = self.wvm.networkLookupByName(net)

def get_name(self):
return self.net.name()
Expand Down
15 changes: 7 additions & 8 deletions vrtManager/util.py
Expand Up @@ -17,20 +17,19 @@ def is_kvm_available(xml):

def randomMAC():
"""Generate a random MAC address."""
# qemu MAC
oui = [0x52, 0x54, 0x00]

oui = [ 0x52, 0x54, 0x00 ] # qemu MAC

mac = oui + [
random.randint(0x00, 0xff),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff)]
mac = oui + [random.randint(0x00, 0xff),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff)]
return ':'.join(map(lambda x: "%02x" % x, mac))


def randomUUID():
"""Generate a random UUID."""

u = [ random.randint(0, 255) for dummy in range(0, 16) ]
u = [random.randint(0, 255) for dummy in range(0, 16)]
return "-".join(["%02x" * 4, "%02x" * 2, "%02x" * 2, "%02x" * 2, "%02x" * 6]) % tuple(u)


Expand Down Expand Up @@ -94,7 +93,7 @@ def get_xml_path(xml, path=None, func=None):

if path:
ret = ctx.xpathEval(path)
if ret != None:
if ret is not None:
if type(ret) == list:
if len(ret) >= 1:
result = ret[0].content
Expand Down
1 change: 0 additions & 1 deletion webvirtmgr/local/__init__.py
@@ -1 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4 changes: 2 additions & 2 deletions webvirtmgr/settings.py
Expand Up @@ -86,12 +86,12 @@

# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
MEDIA_ROOT = os.path.join(os.path.dirname(__file__), '..', 'media')

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
MEDIA_URL = '/media/'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
Expand Down
6 changes: 3 additions & 3 deletions webvirtmgr/settings_jenkins.py
Expand Up @@ -64,15 +64,15 @@
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = os.path.join(os.path.dirname(__file__), '', 'static')
STATIC_ROOT = os.path.join(os.path.dirname(__file__), '..', 'static')

# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), '..', 'static'),
os.path.join(os.path.dirname(__file__), '', 'static'),
)

# List of finder classes that know how to find static files in
Expand Down Expand Up @@ -131,7 +131,7 @@
INSTALLED_APPS += ('django_jenkins',)

JENKINS_TASKS = (
'django_jenkins.tasks.run_pylint',
# 'django_jenkins.tasks.run_pylint',
'django_jenkins.tasks.with_coverage',
'django_jenkins.tasks.django_tests',
'django_jenkins.tasks.run_pep8',
Expand Down
1 change: 0 additions & 1 deletion webvirtmgr/utils/__init__.py
@@ -1 +0,0 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
6 changes: 2 additions & 4 deletions webvirtmgr/utils/secret_key.py
@@ -1,6 +1,3 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2012 Nebula, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
Expand Down Expand Up @@ -51,7 +48,8 @@ def generate_or_read_from_file(key_file='.secret_key', key_length=64):
throws an exception if not.
"""
lock = lockfile.FileLock(key_file)
with lock:
# with lock:
if not lock.is_locked():
if not os.path.exists(key_file):
key = generate_key(key_length)
old_umask = os.umask(0o177) # Use '0600' file permissions
Expand Down

0 comments on commit 8f8e741

Please sign in to comment.