Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f54804ca
authored
Oct 06, 2016
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Azure network creation functionality.
parent
ab26a51e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
21 deletions
+118
-21
circle/firewall/migrations/0006_auto_20161004_2003.py
+26
-0
circle/firewall/migrations/0007_auto_20161005_1702.py
+25
-0
circle/firewall/models.py
+40
-21
circle/firewall/tasks/azure_tasks.py
+27
-0
No files found.
circle/firewall/migrations/0006_auto_20161004_2003.py
0 → 100644
View file @
f54804ca
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
import
django.utils.timezone
import
model_utils.fields
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'firewall'
,
'0005_auto_20150520_2250'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'vlan'
,
name
=
'status'
,
field
=
model_utils
.
fields
.
StatusField
(
default
=
b
'CREATING'
,
max_length
=
100
,
verbose_name
=
'status'
,
no_check_for_status
=
True
,
choices
=
[(
0
,
'dummy'
)]),
),
migrations
.
AddField
(
model_name
=
'vlan'
,
name
=
'status_changed'
,
field
=
model_utils
.
fields
.
MonitorField
(
default
=
django
.
utils
.
timezone
.
now
,
verbose_name
=
'status changed'
,
monitor
=
'status'
),
),
]
circle/firewall/migrations/0007_auto_20161005_1702.py
0 → 100644
View file @
f54804ca
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
import
model_utils.fields
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'firewall'
,
'0006_auto_20161004_2003'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'vlan'
,
name
=
'azure_id'
,
field
=
models
.
TextField
(
blank
=
True
),
),
migrations
.
AlterField
(
model_name
=
'vlan'
,
name
=
'status'
,
field
=
model_utils
.
fields
.
StatusField
(
default
=
b
'PENDING'
,
max_length
=
100
,
verbose_name
=
'status'
,
no_check_for_status
=
True
,
choices
=
[(
0
,
'dummy'
)]),
),
]
circle/firewall/models.py
View file @
f54804ca
...
...
@@ -39,13 +39,15 @@ from django.db.models.signals import post_save, post_delete
from
celery.exceptions
import
TimeoutError
from
netaddr
import
IPSet
,
EUI
,
IPNetwork
,
IPAddress
,
ipv6_full
from
model_utils
import
Choices
from
model_utils.models
import
StatusModel
from
common.models
import
method_cache
,
WorkerNotFound
,
HumanSortField
from
firewall.tasks.
local_tasks
import
reloadtas
k
from
firewall.tasks.
azure_tasks
import
create_networ
k
from
firewall.tasks.remote_tasks
import
get_dhcp_clients
from
.iptables
import
IptRule
from
acl.models
import
AclBase
logger
=
logging
.
getLogger
(
__name__
)
settings
=
django
.
conf
.
settings
.
FIREWALL_SETTINGS
...
...
@@ -272,7 +274,7 @@ class Rule(models.Model):
)
class
Vlan
(
AclBase
,
models
.
Model
):
class
Vlan
(
AclBase
,
Status
Model
):
"""
A vlan of the network,
...
...
@@ -291,6 +293,13 @@ class Vlan(AclBase, models.Model):
)
CHOICES_NETWORK_TYPE
=
((
'public'
,
_
(
'public'
)),
(
'portforward'
,
_
(
'portforward'
)))
STATUS
=
Choices
(
(
'PENDING'
,
_
(
'pending'
)),
(
'CREATED'
,
_
(
'created'
)),
(
'ERROR'
,
_
(
'error'
)),
(
'DESTROYED'
,
_
(
'destroyed'
)),
)
azure_id
=
models
.
TextField
(
blank
=
True
)
vid
=
models
.
IntegerField
(
unique
=
True
,
verbose_name
=
_
(
'VID'
),
help_text
=
_
(
'The vlan ID of the subnet.'
),
...
...
@@ -988,17 +997,18 @@ class Firewall(models.Model):
@method_cache
(
20
)
def
get_dhcp_clients
(
self
):
try
:
return
get_dhcp_clients
.
apply_async
(
queue
=
self
.
get_remote_queue_name
(),
expires
=
60
)
.
get
(
timeout
=
2
)
except
TimeoutError
:
logger
.
info
(
"get_dhcp_clients task timed out"
)
except
IOError
:
logger
.
exception
(
"get_dhcp_clients failed. "
"maybe syslog isn't readble by firewall worker"
)
except
:
logger
.
exception
(
"get_dhcp_clients failed"
)
return
{}
#try:
# #return get_dhcp_clients.apply_async(
# queue=self.get_remote_queue_name(), expires=60).get(timeout=2)
#except TimeoutError:
# logger.info("get_dhcp_clients task timed out")
#except IOError:
# logger.exception("get_dhcp_clients failed. "
# "maybe syslog isn't readble by firewall worker")
#except:
# logger.exception("get_dhcp_clients failed")
#return {}
def
get_absolute_url
(
self
):
return
reverse
(
'network.firewall'
,
kwargs
=
{
'pk'
:
self
.
pk
})
...
...
@@ -1198,12 +1208,20 @@ class BlacklistItem(models.Model):
def
get_absolute_url
(
self
):
return
reverse
(
'network.blacklist'
,
kwargs
=
{
'pk'
:
self
.
pk
})
def
save_network_sender
(
sender
,
instance
,
created
=
False
,
**
kwargs
):
if
created
:
logger
.
debug
(
"Send azure create_network task for vlan
%
s."
%
instance
.
name
)
azure_id
=
create_network
.
apply_async
(
queue
=
'localhost.firewall'
,
args
=
[
instance
.
name
,
str
(
instance
.
network4
)])
.
get
(
timeout
=
60
)
if
azure_id
:
logger
.
debug
(
"created network with id:
%
s"
%
str
(
id
))
instance
.
status
=
Vlan
.
STATUS
.
CREATED
instance
.
azure_id
=
azure_id
instance
.
save
()
else
:
logger
.
error
(
"couldn't create network:
%
s"
%
instance
.
name
)
instance
.
status
=
Vlan
.
STATUS
.
ERROR
instance
.
save
()
def
send_task
(
sender
,
instance
,
created
=
False
,
**
kwargs
):
reloadtask
.
apply_async
(
queue
=
'localhost.man'
,
args
=
[
sender
.
__name__
])
for
sender
in
[
Host
,
Rule
,
Domain
,
Record
,
Vlan
,
Firewall
,
Group
,
BlacklistItem
,
SwitchPort
,
EthernetDevice
]:
post_save
.
connect
(
send_task
,
sender
=
sender
)
post_delete
.
connect
(
send_task
,
sender
=
sender
)
post_save
.
connect
(
save_network_sender
,
sender
=
Vlan
)
\ No newline at end of file
circle/firewall/tasks/azure_tasks.py
0 → 100644
View file @
f54804ca
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
#
# This file is part of CIRCLE Cloud.
#
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
logging
import
getLogger
from
manager.mancelery
import
celery
logger
=
getLogger
(
__name__
)
@celery.task
(
name
=
'firewall.create_network'
)
def
create_network
(
params
):
pass
\ No newline at end of file
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