Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c83ead96
authored
Nov 11, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix pep8
parent
4a19156a
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
60 additions
and
40 deletions
+60
-40
circle/acl/management/__init__.py
+4
-2
circle/circle/settings/__init__.py
+0
-1
circle/circle/settings/base.py
+1
-0
circle/circle/settings/local.py
+1
-1
circle/circle/settings/production.py
+3
-2
circle/circle/settings/test.py
+1
-1
circle/dashboard/models.py
+0
-2
circle/firewall/admin.py
+4
-3
circle/firewall/fw.py
+29
-14
circle/monitor/calvin/examples/basic.py
+5
-5
circle/monitor/calvin/examples/test.py
+4
-3
circle/network/models.py
+0
-2
circle/templates/registration/login.html
+1
-1
circle/vm/models.py
+6
-3
circle/vm/tests/test_models.py
+1
-0
No files found.
circle/acl/management/__init__.py
View file @
c83ead96
...
@@ -19,7 +19,8 @@ def create_levels(app, created_models, verbosity, db=DEFAULT_DB_ALIAS,
...
@@ -19,7 +19,8 @@ def create_levels(app, created_models, verbosity, db=DEFAULT_DB_ALIAS,
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.contenttypes.models
import
ContentType
app_models
=
[
k
for
k
in
get_models
(
app
)
if
AclBase
in
k
.
__bases__
]
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
# This will hold the levels we're looking for as
# (content_type, (codename, name))
# (content_type, (codename, name))
...
@@ -59,7 +60,8 @@ def create_levels(app, created_models, verbosity, db=DEFAULT_DB_ALIAS,
...
@@ -59,7 +60,8 @@ def create_levels(app, created_models, verbosity, db=DEFAULT_DB_ALIAS,
Level
.
objects
.
using
(
db
)
.
bulk_create
(
levels
)
Level
.
objects
.
using
(
db
)
.
bulk_create
(
levels
)
if
verbosity
>=
2
:
if
verbosity
>=
2
:
print
(
"Adding levels [
%
s]."
%
", "
.
join
(
levels
))
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
]))
print
(
"All: [
%
s]."
%
", "
.
join
([
unicode
(
l
)
for
l
in
all_levels
]))
# set weights
# set weights
...
...
circle/circle/settings/__init__.py
View file @
c83ead96
circle/circle/settings/base.py
View file @
c83ead96
"""Common settings and globals."""
"""Common settings and globals."""
# flake8: noqa
from
datetime
import
timedelta
from
datetime
import
timedelta
from
os
import
environ
from
os
import
environ
...
...
circle/circle/settings/local.py
View file @
c83ead96
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
# from os.path import join, normpath
# from os.path import join, normpath
from
base
import
*
from
base
import
*
# noqa
########## DEBUG CONFIGURATION
########## DEBUG CONFIGURATION
...
...
circle/circle/settings/production.py
View file @
c83ead96
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
from
os
import
environ
from
os
import
environ
from
base
import
*
from
base
import
*
# noqa
def
get_env_setting
(
setting
):
def
get_env_setting
(
setting
):
...
@@ -15,7 +15,8 @@ def get_env_setting(setting):
...
@@ -15,7 +15,8 @@ def get_env_setting(setting):
raise
ImproperlyConfigured
(
error_msg
)
raise
ImproperlyConfigured
(
error_msg
)
########## HOST CONFIGURATION
########## 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
(
','
)
ALLOWED_HOSTS
=
get_env_setting
(
'DJANGO_ALLOWED_HOSTS'
)
.
split
(
','
)
########## END HOST CONFIGURATION
########## END HOST CONFIGURATION
...
...
circle/circle/settings/test.py
View file @
c83ead96
from
base
import
*
from
base
import
*
# noqa
########## TEST SETTINGS
########## TEST SETTINGS
TEST_RUNNER
=
'discover_runner.DiscoverRunner'
TEST_RUNNER
=
'discover_runner.DiscoverRunner'
...
...
circle/dashboard/models.py
View file @
c83ead96
from
django.db
import
models
# Create your models here.
# Create your models here.
circle/firewall/admin.py
View file @
c83ead96
...
@@ -55,9 +55,7 @@ class RuleAdmin(admin.ModelAdmin):
...
@@ -55,9 +55,7 @@ class RuleAdmin(admin.ModelAdmin):
def
color_desc
(
self
,
instance
):
def
color_desc
(
self
,
instance
):
"""Returns a colorful description of the instance."""
"""Returns a colorful description of the instance."""
return
(
u'<span style="color: #FF0000;">[
%(type)
s]</span> '
data
=
{
u'
%(src)
s<span style="color: #0000FF;"> ▸ </span>
%(dst)
s '
u'
%(para)
s
%(desc)
s'
)
%
{
'type'
:
instance
.
r_type
,
'type'
:
instance
.
r_type
,
'src'
:
(
instance
.
foreign_network
.
name
'src'
:
(
instance
.
foreign_network
.
name
if
instance
.
direction
==
'1'
else
instance
.
r_type
),
if
instance
.
direction
==
'1'
else
instance
.
r_type
),
...
@@ -72,6 +70,9 @@ class RuleAdmin(admin.ModelAdmin):
...
@@ -72,6 +70,9 @@ class RuleAdmin(admin.ModelAdmin):
if
instance
.
dport
else
''
)
+
if
instance
.
dport
else
''
)
+
'</span>'
),
'</span>'
),
'desc'
:
instance
.
description
}
'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'
)
%
data
color_desc
.
allow_tags
=
True
color_desc
.
allow_tags
=
True
@staticmethod
@staticmethod
...
...
circle/firewall/fw.py
View file @
c83ead96
...
@@ -195,17 +195,33 @@ class Firewall:
...
@@ -195,17 +195,33 @@ class Firewall:
self
.
iptablesnat
(
'COMMIT'
)
self
.
iptablesnat
(
'COMMIT'
)
def
ipt_filter
(
self
):
def
ipt_filter
(
self
):
ipv4_re
=
re
.
compile
(
'([0-9]{1,3}
\
.){3}[0-9]{1,3}'
)
# pre-run stuff
self
.
prerun
()
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
f
in
self
.
fw
:
for
rule
in
f
.
rules
.
all
():
for
rule
in
f
.
rules
.
all
():
self
.
fw2vlan
(
rule
)
self
.
fw2vlan
(
rule
)
# zonak kozotti lancokra ugras
def
ipt_filter_zones
(
self
):
"""Jumping to chains between zones."""
for
s_vlan
in
self
.
vlans
:
for
s_vlan
in
self
.
vlans
:
for
d_vlan
in
self
.
vlans
:
for
d_vlan
in
self
.
vlans
:
self
.
iptables
(
'-N
%
s_
%
s'
%
(
s_vlan
,
d_vlan
))
self
.
iptables
(
'-N
%
s_
%
s'
%
(
s_vlan
,
d_vlan
))
...
@@ -213,7 +229,9 @@ class Firewall:
...
@@ -213,7 +229,9 @@ class Firewall:
(
s_vlan
.
name
,
d_vlan
.
name
,
s_vlan
,
(
s_vlan
.
name
,
d_vlan
.
name
,
s_vlan
,
d_vlan
))
d_vlan
))
# hosts' rules
def
ipt_filter_host_rules
(
self
):
"""Build hosts' rules."""
for
i_vlan
in
self
.
vlans
:
for
i_vlan
in
self
.
vlans
:
for
i_host
in
i_vlan
.
host_set
.
all
():
for
i_host
in
i_vlan
.
host_set
.
all
():
for
group
in
i_host
.
groups
.
all
():
for
group
in
i_host
.
groups
.
all
():
...
@@ -222,23 +240,20 @@ class Firewall:
...
@@ -222,23 +240,20 @@ class Firewall:
for
rule
in
i_host
.
rules
.
all
():
for
rule
in
i_host
.
rules
.
all
():
self
.
host2vlan
(
i_host
,
rule
)
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
s_vlan
in
self
.
vlans
:
for
rule
in
s_vlan
.
rules
.
all
():
for
rule
in
s_vlan
.
rules
.
all
():
self
.
vlan2vlan
(
s_vlan
,
rule
)
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
s_vlan
in
self
.
vlans
:
for
d_vlan
in
self
.
vlans
:
for
d_vlan
in
self
.
vlans
:
self
.
iptables
(
'-A
%
s_
%
s -g LOG_DROP'
%
(
s_vlan
,
d_vlan
))
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
):
def
__init__
(
self
,
proto
=
4
):
self
.
RULES
=
[]
self
.
RULES
=
[]
self
.
RULES_NAT
=
[]
self
.
RULES_NAT
=
[]
...
...
circle/monitor/calvin/examples/basic.py
View file @
c83ead96
from
calvin
import
*
from
calvin
import
*
# noqa
server_name
=
"0.0.0.0"
server_name
=
"0.0.0.0"
server_port
=
"8080"
server_port
=
"8080"
...
@@ -10,12 +10,12 @@ query.setFormat("json") #Not neccesary, default is json
...
@@ -10,12 +10,12 @@ query.setFormat("json") #Not neccesary, default is json
query
.
setRelativeStart
(
1
,
"minutes"
)
#Current cpu usage
query
.
setRelativeStart
(
1
,
"minutes"
)
#Current cpu usage
query
.
generate
()
query
.
generate
()
#print(query.getGenerated())
#
print(query.getGenerated())
print
(
query
.
getStart
())
print
(
query
.
getStart
())
#query.setAbsoluteStart("1889", "04", "20", "00", "00")
#
query.setAbsoluteStart("1889", "04", "20", "00", "00")
#query.setRelativeEnd(...)
#
query.setRelativeEnd(...)
#query.setAbsoluteEnd(...)
#
query.setAbsoluteEnd(...)
handler
=
GraphiteHandler
(
server_name
,
server_port
)
handler
=
GraphiteHandler
(
server_name
,
server_port
)
...
...
circle/monitor/calvin/examples/test.py
View file @
c83ead96
from
calvin
import
*
from
calvin
import
*
# noqa
import
datetime
import
datetime
query
=
Query
()
query
=
Query
()
...
@@ -9,7 +9,8 @@ query.generate()
...
@@ -9,7 +9,8 @@ query.generate()
handler
=
GraphiteHandler
(
"10.9.1.209"
)
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
()
global_start
=
datetime
.
datetime
.
now
()
for
i
in
range
(
1
,
times
):
for
i
in
range
(
1
,
times
):
...
@@ -17,7 +18,7 @@ for i in range(1, times):
...
@@ -17,7 +18,7 @@ for i in range(1, times):
handler
.
put
(
query
)
handler
.
put
(
query
)
handler
.
send
()
handler
.
send
()
local_end
=
datetime
.
datetime
.
now
()
local_end
=
datetime
.
datetime
.
now
()
print
((
local_end
-
local_start
)
.
microseconds
)
print
((
local_end
-
local_start
)
.
microseconds
)
global_end
=
datetime
.
datetime
.
now
()
global_end
=
datetime
.
datetime
.
now
()
print
(
"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
)
print
(
"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
)
...
...
circle/network/models.py
View file @
c83ead96
from
django.db
import
models
# Create your models here.
# Create your models here.
circle/templates/registration/login.html
View file @
c83ead96
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
{% load staticfiles %}
{% load staticfiles %}
{% get_current_language as LANGUAGE_CODE %}
{% get_current_language as LANGUAGE_CODE %}
{% block content %}
{% block content %}
<form
action=
"
/ufo/
"
method=
"POST"
>
<form
action=
""
method=
"POST"
>
{% csrf_token %}
{% csrf_token %}
{{ form }}
{{ form }}
<input
type=
"submit"
value=
"LOGIN"
/>
<input
type=
"submit"
value=
"LOGIN"
/>
...
...
circle/vm/models.py
View file @
c83ead96
...
@@ -506,7 +506,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
...
@@ -506,7 +506,7 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
'name'
:
self
.
vm_name
,
'name'
:
self
.
vm_name
,
'vcpu'
:
self
.
num_cores
,
'vcpu'
:
self
.
num_cores
,
'memory'
:
int
(
self
.
ram_size
)
*
1024
,
# convert from MiB to KiB
'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
,
'cpu_share'
:
self
.
priority
,
'arch'
:
self
.
arch
,
'arch'
:
self
.
arch
,
'boot_menu'
:
self
.
boot_menu
,
'boot_menu'
:
self
.
boot_menu
,
...
@@ -762,9 +762,12 @@ class InstanceActivity(ActivityModel):
...
@@ -762,9 +762,12 @@ class InstanceActivity(ActivityModel):
def
__unicode__
(
self
):
def
__unicode__
(
self
):
if
self
.
parent
:
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
:
else
:
return
self
.
activity_code
+
"("
+
self
.
instance
.
name
+
")"
return
'{}({})'
.
format
(
self
.
activity_code
,
self
.
instance
.
name
)
@classmethod
@classmethod
def
create
(
cls
,
code_suffix
,
instance
,
task_uuid
=
None
,
user
=
None
):
def
create
(
cls
,
code_suffix
,
instance
,
task_uuid
=
None
,
user
=
None
):
...
...
circle/vm/tests/test_models.py
View file @
c83ead96
...
@@ -6,4 +6,5 @@ class TemplateTestCase(TestCase):
...
@@ -6,4 +6,5 @@ class TemplateTestCase(TestCase):
def
test_template_creation
(
self
):
def
test_template_creation
(
self
):
template
=
InstanceTemplate
(
name
=
'My first template'
,
template
=
InstanceTemplate
(
name
=
'My first template'
,
access_method
=
'ssh'
,
)
access_method
=
'ssh'
,
)
template
.
clean
()
# TODO add images & net
# TODO add images & net
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment