diff --git a/circle/acl/management/__init__.py b/circle/acl/management/__init__.py index d44b240..4d88ed1 100644 --- a/circle/acl/management/__init__.py +++ b/circle/acl/management/__init__.py @@ -19,7 +19,8 @@ def create_levels(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, from django.contrib.contenttypes.models import ContentType app_models = [k for k in get_models(app) if AclBase in k.__bases__] - print "Creating levels for models: %s." % ", ".join([m.__name__ for m in app_models]) + print "Creating levels for models: %s." % ", ".join( + [m.__name__ for m in app_models]) # This will hold the levels we're looking for as # (content_type, (codename, name)) @@ -59,7 +60,8 @@ def create_levels(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, Level.objects.using(db).bulk_create(levels) if verbosity >= 2: print("Adding levels [%s]." % ", ".join(levels)) - print("Searched: [%s]." % ", ".join([unicode(l) for l in searched_levels])) + print("Searched: [%s]." % ", ".join( + [unicode(l) for l in searched_levels])) print("All: [%s]." % ", ".join([unicode(l) for l in all_levels])) # set weights diff --git a/circle/circle/settings/__init__.py b/circle/circle/settings/__init__.py index 8b13789..e69de29 100644 --- a/circle/circle/settings/__init__.py +++ b/circle/circle/settings/__init__.py @@ -1 +0,0 @@ - diff --git a/circle/circle/settings/base.py b/circle/circle/settings/base.py index 8392f4b..d34679c 100644 --- a/circle/circle/settings/base.py +++ b/circle/circle/settings/base.py @@ -1,4 +1,5 @@ """Common settings and globals.""" +# flake8: noqa from datetime import timedelta from os import environ diff --git a/circle/circle/settings/local.py b/circle/circle/settings/local.py index 1dd20b2..1d4bce3 100644 --- a/circle/circle/settings/local.py +++ b/circle/circle/settings/local.py @@ -3,7 +3,7 @@ # from os.path import join, normpath -from base import * +from base import * # noqa ########## DEBUG CONFIGURATION diff --git a/circle/circle/settings/production.py b/circle/circle/settings/production.py index 087935c..869dfd2 100644 --- a/circle/circle/settings/production.py +++ b/circle/circle/settings/production.py @@ -3,7 +3,7 @@ from os import environ -from base import * +from base import * # noqa def get_env_setting(setting): @@ -15,7 +15,8 @@ def get_env_setting(setting): raise ImproperlyConfigured(error_msg) ########## HOST CONFIGURATION -# See: https://docs.djangoproject.com/en/1.5/releases/1.5/#allowed-hosts-required-in-production +# See: https://docs.djangoproject.com/en/1.5/releases/1.5/ +# #allowed-hosts-required-in-production ALLOWED_HOSTS = get_env_setting('DJANGO_ALLOWED_HOSTS').split(',') ########## END HOST CONFIGURATION diff --git a/circle/circle/settings/test.py b/circle/circle/settings/test.py index 49fccc6..a0d98cb 100644 --- a/circle/circle/settings/test.py +++ b/circle/circle/settings/test.py @@ -1,4 +1,4 @@ -from base import * +from base import * # noqa ########## TEST SETTINGS TEST_RUNNER = 'discover_runner.DiscoverRunner' diff --git a/circle/dashboard/models.py b/circle/dashboard/models.py index 71a8362..6b20219 100644 --- a/circle/dashboard/models.py +++ b/circle/dashboard/models.py @@ -1,3 +1 @@ -from django.db import models - # Create your models here. diff --git a/circle/firewall/admin.py b/circle/firewall/admin.py index 629c14b..2271927 100644 --- a/circle/firewall/admin.py +++ b/circle/firewall/admin.py @@ -55,23 +55,24 @@ class RuleAdmin(admin.ModelAdmin): def color_desc(self, instance): """Returns a colorful description of the instance.""" + data = { + 'type': instance.r_type, + 'src': (instance.foreign_network.name + if instance.direction == '1' else instance.r_type), + 'dst': (instance.r_type if instance.direction == '1' + else instance.foreign_network.name), + 'para': (u'<span style="color: #00FF00;">' + + (('proto=%s ' % instance.proto) + if instance.proto else '') + + (('sport=%s ' % instance.sport) + if instance.sport else '') + + (('dport=%s ' % instance.dport) + if instance.dport else '') + + '</span>'), + 'desc': instance.description} return (u'<span style="color: #FF0000;">[%(type)s]</span> ' u'%(src)s<span style="color: #0000FF;">ββΈβ</span>%(dst)s ' - u'%(para)s %(desc)s') % { - 'type': instance.r_type, - 'src': (instance.foreign_network.name - if instance.direction == '1' else instance.r_type), - 'dst': (instance.r_type if instance.direction == '1' - else instance.foreign_network.name), - 'para': (u'<span style="color: #00FF00;">' + - (('proto=%s ' % instance.proto) - if instance.proto else '') + - (('sport=%s ' % instance.sport) - if instance.sport else '') + - (('dport=%s ' % instance.dport) - if instance.dport else '') + - '</span>'), - 'desc': instance.description} + u'%(para)s %(desc)s') % data color_desc.allow_tags = True @staticmethod diff --git a/circle/firewall/fw.py b/circle/firewall/fw.py index 5b32c9b..89c5c99 100644 --- a/circle/firewall/fw.py +++ b/circle/firewall/fw.py @@ -195,17 +195,33 @@ class Firewall: self.iptablesnat('COMMIT') def ipt_filter(self): - ipv4_re = re.compile('([0-9]{1,3}\.){3}[0-9]{1,3}') - # pre-run stuff self.prerun() - # firewall's own rules + self.ipt_filter_firewall() + self.ipt_filter_zones() + self.ipt_filter_host_rules() + self.ipt_filter_vlan_rules() + self.ipt_filter_vlan_drop() + + self.postrun() + + if self.proto == 6: # remove ipv4-specific rules + ipv4_re = re.compile('([0-9]{1,3}\.){3}[0-9]{1,3}') + self.RULES = [x for x in self.RULES if not ipv4_re.search(x)] + self.RULES = [x.replace('icmp', 'icmpv6') for x in self.RULES] + + + def ipt_filter_firewall(self): + """Build firewall's own rules.""" + for f in self.fw: for rule in f.rules.all(): self.fw2vlan(rule) - # zonak kozotti lancokra ugras + def ipt_filter_zones(self): + """Jumping to chains between zones.""" + for s_vlan in self.vlans: for d_vlan in self.vlans: self.iptables('-N %s_%s' % (s_vlan, d_vlan)) @@ -213,7 +229,9 @@ class Firewall: (s_vlan.name, d_vlan.name, s_vlan, d_vlan)) - # hosts' rules + def ipt_filter_host_rules(self): + """Build hosts' rules.""" + for i_vlan in self.vlans: for i_host in i_vlan.host_set.all(): for group in i_host.groups.all(): @@ -222,23 +240,20 @@ class Firewall: for rule in i_host.rules.all(): self.host2vlan(i_host, rule) - # enable communication between VLANs + def ipt_filter_vlan_rules(self): + """Enable communication between VLANs.""" + for s_vlan in self.vlans: for rule in s_vlan.rules.all(): self.vlan2vlan(s_vlan, rule) - # zonak kozotti lancokat zarja le + def ipt_filter_vlan_drop(self): + """Close intra-VLAN chains.""" + for s_vlan in self.vlans: for d_vlan in self.vlans: self.iptables('-A %s_%s -g LOG_DROP' % (s_vlan, d_vlan)) - # post-run stuff - self.postrun() - - if self.proto == 6: - self.RULES = [x for x in self.RULES if not ipv4_re.search(x)] - self.RULES = [x.replace('icmp', 'icmpv6') for x in self.RULES] - def __init__(self, proto=4): self.RULES = [] self.RULES_NAT = [] diff --git a/circle/monitor/calvin/examples/basic.py b/circle/monitor/calvin/examples/basic.py index e694c26..3365d0f 100644 --- a/circle/monitor/calvin/examples/basic.py +++ b/circle/monitor/calvin/examples/basic.py @@ -1,4 +1,4 @@ -from calvin import * +from calvin import * # noqa server_name = "0.0.0.0" server_port = "8080" @@ -10,12 +10,12 @@ query.setFormat("json") #Not neccesary, default is json query.setRelativeStart(1, "minutes") #Current cpu usage query.generate() -#print(query.getGenerated()) +# print(query.getGenerated()) print(query.getStart()) -#query.setAbsoluteStart("1889", "04", "20", "00", "00") -#query.setRelativeEnd(...) -#query.setAbsoluteEnd(...) +# query.setAbsoluteStart("1889", "04", "20", "00", "00") +# query.setRelativeEnd(...) +# query.setAbsoluteEnd(...) handler = GraphiteHandler(server_name, server_port) diff --git a/circle/monitor/calvin/examples/test.py b/circle/monitor/calvin/examples/test.py index c6faf01..3c338a6 100644 --- a/circle/monitor/calvin/examples/test.py +++ b/circle/monitor/calvin/examples/test.py @@ -1,4 +1,4 @@ -from calvin import * +from calvin import * # noqa import datetime query = Query() @@ -9,7 +9,8 @@ query.generate() handler = GraphiteHandler("10.9.1.209") -times = int(input("How many requests do you intend to send? [postive integer] ")) +times = int(input( + "How many requests do you intend to send? [postive integer] ")) global_start = datetime.datetime.now() for i in range(1, times): @@ -17,7 +18,7 @@ for i in range(1, times): handler.put(query) handler.send() local_end = datetime.datetime.now() - print((local_end-local_start).microseconds) + print((local_end - local_start).microseconds) global_end = datetime.datetime.now() print("*-*-*-*-*-*-*-*-*-*-*-*-*-*-*") diff --git a/circle/network/models.py b/circle/network/models.py index 71a8362..6b20219 100644 --- a/circle/network/models.py +++ b/circle/network/models.py @@ -1,3 +1 @@ -from django.db import models - # Create your models here. diff --git a/circle/templates/registration/login.html b/circle/templates/registration/login.html index ec3e4cf..21ad59c 100644 --- a/circle/templates/registration/login.html +++ b/circle/templates/registration/login.html @@ -3,7 +3,7 @@ {% load staticfiles %} {% get_current_language as LANGUAGE_CODE %} {% block content %} -<form action="/ufo/" method="POST"> +<form action="" method="POST"> {% csrf_token %} {{ form }} <input type="submit" value="LOGIN" /> diff --git a/circle/vm/models.py b/circle/vm/models.py index 8058eb2..c868050 100644 --- a/circle/vm/models.py +++ b/circle/vm/models.py @@ -506,7 +506,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): 'name': self.vm_name, 'vcpu': self.num_cores, 'memory': int(self.ram_size) * 1024, # convert from MiB to KiB - 'memory_max': int(self.max_ram_size) * 1024, # convert from MiB to KiB + 'memory_max': int(self.max_ram_size) * 1024, # convert MiB to KiB 'cpu_share': self.priority, 'arch': self.arch, 'boot_menu': self.boot_menu, @@ -762,9 +762,12 @@ class InstanceActivity(ActivityModel): def __unicode__(self): if self.parent: - return self.parent.activity_code + "(" + self.instance.name + ")" + "->" + self.activity_code + return '{}({})->{}'.format(self.parent.activity_code, + self.instance.name, + self.activity_code) else: - return self.activity_code + "(" + self.instance.name + ")" + return '{}({})'.format(self.activity_code, + self.instance.name) @classmethod def create(cls, code_suffix, instance, task_uuid=None, user=None): diff --git a/circle/vm/tests/test_models.py b/circle/vm/tests/test_models.py index a05d595..d4ea667 100644 --- a/circle/vm/tests/test_models.py +++ b/circle/vm/tests/test_models.py @@ -6,4 +6,5 @@ class TemplateTestCase(TestCase): def test_template_creation(self): template = InstanceTemplate(name='My first template', access_method='ssh', ) + template.clean() # TODO add images & net