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
cb8cfadc
authored
Nov 05, 2017
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network: add Vxlan form and views for CRUD operations
parent
154dd694
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
210 additions
and
6 deletions
+210
-6
circle/network/forms.py
+27
-0
circle/network/tables.py
+26
-0
circle/network/templates/network/vxlan-create.html
+22
-0
circle/network/templates/network/vxlan-edit.html
+32
-0
circle/network/templates/network/vxlan-list.html
+18
-0
circle/network/urls.py
+10
-0
circle/network/views.py
+75
-6
No files found.
circle/network/forms.py
View file @
cb8cfadc
...
...
@@ -27,6 +27,7 @@ from firewall.models import (
Host
,
Vlan
,
Domain
,
Group
,
Record
,
BlacklistItem
,
Rule
,
VlanGroup
,
SwitchPort
,
Firewall
)
from
network.models
import
Vxlan
class
LinkButton
(
BaseInput
):
...
...
@@ -348,3 +349,29 @@ class VlanGroupForm(ModelForm):
class
Meta
:
model
=
VlanGroup
fields
=
(
"name"
,
"vlans"
,
"description"
,
"owner"
,
)
class
VxlanForm
(
ModelForm
):
helper
=
FormHelper
()
helper
.
layout
=
Layout
(
Div
(
Fieldset
(
''
,
'name'
,
'vni'
,
'vlan'
,
'description'
,
'comment'
,
'owner'
,
)
),
FormActions
(
Submit
(
'submit'
,
_
(
"Save"
)),
LinkButton
(
'back'
,
_
(
"Back"
),
reverse_lazy
(
'network.vxlan-list'
))
)
)
class
Meta
:
model
=
Vxlan
fields
=
(
"name"
,
"vni"
,
"vlan"
,
"description"
,
"comment"
,
"owner"
,
)
circle/network/tables.py
View file @
cb8cfadc
...
...
@@ -24,6 +24,8 @@ from django_tables2.columns import (LinkColumn, TemplateColumn, Column,
BooleanColumn
)
from
firewall.models
import
Host
,
Vlan
,
Domain
,
Group
,
Record
,
Rule
,
SwitchPort
from
network.models
import
Vxlan
from
vm.models
import
Interface
class
MACColumn
(
Column
):
...
...
@@ -233,6 +235,16 @@ class VlanGroupTable(Table):
order_by
=
'name'
class
VxlanTable
(
Table
):
name
=
LinkColumn
(
'network.vxlan'
,
args
=
[
A
(
'vni'
)])
class
Meta
:
model
=
Vxlan
attrs
=
{
'class'
:
'table table-striped table-condensed'
}
fields
=
(
'vni'
,
'name'
,
)
order_by
=
'vni'
class
HostRecordsTable
(
Table
):
fqdn
=
LinkColumn
(
"network.record"
,
args
=
[
A
(
"pk"
)],
...
...
@@ -282,3 +294,17 @@ class FirewallRuleTable(Table):
'action'
,
'proto'
,
'actions'
)
order_by
=
'-pk'
empty_text
=
_
(
"No related rules found."
)
class
SmallVmTable
(
Table
):
instance
=
Column
(
accessor
=
A
(
'instance.name'
),
verbose_name
=
'VM'
)
instance_id
=
LinkColumn
(
'dashboard.views.detail'
,
args
=
[
A
(
'instance.pk'
)],
accessor
=
A
(
'instance.pk'
),
verbose_name
=
'ID'
)
class
Meta
:
model
=
Interface
attrs
=
{
'class'
:
'table table-striped'
}
fields
=
(
'instance'
,
)
sequence
=
(
'instance_id'
,
'instance'
,
)
order_by
=
'instance.pk'
circle/network/templates/network/vxlan-create.html
0 → 100644
View file @
cb8cfadc
{% extends "network/base.html" %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% load l10n %}
{% load staticfiles %}
{% load crispy_forms_tags %}
{% block title-page %}{% trans "Create" %} | {% trans "vxlan" %}{% endblock %}
{% block content %}
<div
class=
"page-header"
>
<h2>
{% trans "Create a new vxlan" %}
</h2>
</div>
<div
class=
"row"
>
<div
class=
"col-sm-8"
>
{% crispy form %}
</div>
<div
class=
"col-sm-4"
>
</div>
</div>
{% endblock %}
circle/network/templates/network/vxlan-edit.html
0 → 100644
View file @
cb8cfadc
{% extends "network/base.html" %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% load l10n %}
{% load staticfiles %}
{% load crispy_forms_tags %}
{% block title-page %}{{ form.name.value }} | {% trans "vxlan" %}{% endblock %}
{% block content %}
<div
class=
"page-header"
>
<a
href=
"{% url "
network
.
vxlan-delete
"
vni=
vxlan.vni
%}"
class=
"btn btn-danger pull-right"
><i
class=
"fa fa-times-circle"
></i>
{% trans "Delete this vxlan" %}
</a>
<h2>
{{ form.name.value }}
<small>
{% trans "details of vxlan" %}
</small></h2>
</div>
<div
class=
"row"
>
<div
class=
"col-sm-6"
>
{% crispy form %}
</div>
<div
class=
"col-sm-6"
>
<div
class=
"page-header"
>
<h3>
{% trans "Connected virtual machines" %}
</h3>
</div>
{% render_table vm_list %}
<div
class=
"page-header"
>
<h3>
{% trans "Manage access" %}
</h3>
</div>
{% include "dashboard/_manage_access.html" with table_id="vxlan-access-table" %}
</div>
</div>
{% endblock %}
circle/network/templates/network/vxlan-list.html
0 → 100644
View file @
cb8cfadc
{% extends "network/base.html" %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% load l10n %}
{% load staticfiles %}
{% block title-page %}{% trans "Vlans" %}{% endblock %}
{% block content %}
<div
class=
"page-header"
>
<a
href=
"{% url "
network
.
vxlan-create
"
%}"
class=
"btn btn-success pull-right"
><i
class=
"fa fa-plus-circle"
></i>
{% trans "Create a new vxlan" %}
</a>
<h1>
Vlans
<small>
{% trans "list of all vxlans" %}
</small></h1>
</div>
<div
class=
"table-responsive"
>
{% render_table table %}
</div>
{% endblock %}
circle/network/urls.py
View file @
cb8cfadc
...
...
@@ -20,6 +20,7 @@ from .views import (
IndexView
,
HostList
,
HostDetail
,
HostCreate
,
HostDelete
,
VlanList
,
VlanDetail
,
VlanDelete
,
VlanCreate
,
VxlanList
,
VxlanDetail
,
VxlanDelete
,
VxlanCreate
,
VxlanAclUpdateView
,
DomainList
,
DomainDetail
,
DomainDelete
,
DomainCreate
,
GroupList
,
GroupDetail
,
GroupDelete
,
GroupCreate
,
RecordList
,
RecordDetail
,
RecordCreate
,
RecordDelete
,
...
...
@@ -125,6 +126,15 @@ urlpatterns = [
url
(
'^rules/delete/(?P<pk>
\
d+)/$'
,
RuleDelete
.
as_view
(),
name
=
"network.rule_delete"
),
# vxlan
url
(
'^vxlans/$'
,
VxlanList
.
as_view
(),
name
=
'network.vxlan-list'
),
url
(
'^vxlans/create$'
,
VxlanCreate
.
as_view
(),
name
=
'network.vxlan-create'
),
url
(
'^vxlans/(?P<vni>
\
d+)/$'
,
VxlanDetail
.
as_view
(),
name
=
'network.vxlan'
),
url
(
'^vxlans/(?P<pk>
\
d+)/acl/$'
,
VxlanAclUpdateView
.
as_view
(),
name
=
'network.vxlan-acl'
),
url
(
'^vxlans/delete/(?P<vni>
\
d+)/$'
,
VxlanDelete
.
as_view
(),
name
=
"network.vxlan-delete"
),
# non class based views
url
(
'^hosts/(?P<pk>
\
d+)/remove/(?P<group_pk>
\
d+)/$'
,
remove_host_group
,
name
=
'network.remove_host_group'
),
...
...
circle/network/views.py
View file @
cb8cfadc
...
...
@@ -30,17 +30,19 @@ from django_tables2 import SingleTableView
from
firewall.models
import
(
Host
,
Vlan
,
Domain
,
Group
,
Record
,
BlacklistItem
,
Rule
,
VlanGroup
,
SwitchPort
,
EthernetDevice
,
Firewall
)
SwitchPort
,
EthernetDevice
,
Firewall
)
from
network.models
import
Vxlan
from
vm.models
import
Interface
from
.tables
import
(
HostTable
,
VlanTable
,
SmallHostTable
,
DomainTable
,
GroupTable
,
RecordTable
,
BlacklistItemTable
,
RuleTable
,
VlanGroupTable
,
SmallRuleTable
,
SmallGroupRuleTable
,
SmallRecordTable
,
SwitchPortTable
,
SmallDhcpTable
,
FirewallTable
,
FirewallRuleTable
,
SmallDhcpTable
,
FirewallTable
,
FirewallRuleTable
,
VxlanTable
,
SmallVmTable
,
)
from
.forms
import
(
HostForm
,
VlanForm
,
DomainForm
,
GroupForm
,
RecordForm
,
BlacklistItemForm
,
RuleForm
,
VlanGroupForm
,
SwitchPortForm
,
FirewallForm
RuleForm
,
VlanGroupForm
,
SwitchPortForm
,
FirewallForm
,
VxlanForm
)
from
django.contrib
import
messages
...
...
@@ -48,7 +50,6 @@ from django.contrib.messages.views import SuccessMessageMixin
from
django.views.generic.edit
import
FormMixin
from
django.utils.translation
import
ugettext_lazy
as
_
from
braces.views
import
LoginRequiredMixin
,
SuperuserRequiredMixin
# from django.db.models import Q
from
operator
import
itemgetter
from
itertools
import
chain
from
dashboard.views
import
AclUpdateView
...
...
@@ -802,6 +803,7 @@ class VlanDetail(VlanMagicMixin, LoginRequiredMixin, SuperuserRequiredMixin,
slug_field
=
'vid'
slug_url_kwarg
=
'vid'
success_message
=
_
(
u'Succesfully modified vlan
%(name)
s.'
)
success_url
=
reverse_lazy
(
'network.vlan_list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
VlanDetail
,
self
)
.
get_context_data
(
**
kwargs
)
...
...
@@ -813,8 +815,6 @@ class VlanDetail(VlanMagicMixin, LoginRequiredMixin, SuperuserRequiredMixin,
context
[
'aclform'
]
=
AclUserOrGroupAddForm
()
return
context
success_url
=
reverse_lazy
(
'network.vlan_list'
)
class
VlanCreate
(
VlanMagicMixin
,
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
InitialOwnerMixin
,
CreateView
):
...
...
@@ -916,6 +916,75 @@ class VlanGroupDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
return
reverse_lazy
(
'network.vlan_group_list'
)
class
VxlanList
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SingleTableView
):
model
=
Vxlan
table_class
=
VxlanTable
template_name
=
"network/vxlan-list.html"
table_pagination
=
False
class
VxlanAclUpdateView
(
AclUpdateView
):
model
=
Vxlan
class
VxlanDetail
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
SuccessMessageMixin
,
UpdateView
):
model
=
Vxlan
template_name
=
"network/vxlan-edit.html"
form_class
=
VxlanForm
slug_field
=
'vni'
slug_url_kwarg
=
'vni'
success_message
=
_
(
u'Succesfully modified vlan
%(name)
s.'
)
success_url
=
reverse_lazy
(
'network.vxlan-list'
)
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
VxlanDetail
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'vm_list'
]
=
SmallVmTable
(
self
.
object
.
vm_interface
.
all
())
context
[
'acl'
]
=
AclUpdateView
.
get_acl_data
(
self
.
object
,
self
.
request
.
user
,
'network.vxlan-acl'
)
context
[
'aclform'
]
=
AclUserOrGroupAddForm
()
return
context
class
VxlanCreate
(
LoginRequiredMixin
,
SuccessMessageMixin
,
InitialOwnerMixin
,
CreateView
):
model
=
Vxlan
template_name
=
"network/vxlan-create.html"
form_class
=
VxlanForm
success_message
=
_
(
u'Successfully created vxlan
%(name)
s.'
)
class
VxlanDelete
(
LoginRequiredMixin
,
SuperuserRequiredMixin
,
DeleteView
):
model
=
Vlan
template_name
=
"network/confirm/base_delete.html"
def
get_success_url
(
self
):
next
=
self
.
request
.
POST
.
get
(
'next'
)
if
next
:
return
next
else
:
return
reverse_lazy
(
'network.vxlan-list'
)
def
get_object
(
self
,
queryset
=
None
):
""" we identify vlans by vid and not pk """
return
Vxlan
.
objects
.
get
(
vni
=
self
.
kwargs
[
'vni'
])
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
self
.
object
=
self
.
get_object
()
if
unicode
(
self
.
object
)
!=
request
.
POST
.
get
(
'confirm'
):
messages
.
error
(
request
,
_
(
u"Object name does not match."
))
return
self
.
get
(
request
,
*
args
,
**
kwargs
)
response
=
super
(
VxlanDelete
,
self
)
.
delete
(
request
,
*
args
,
**
kwargs
)
messages
.
success
(
request
,
_
(
u"Vxlan successfully deleted."
))
return
response
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
(
VxlanDelete
,
self
)
.
get_context_data
(
**
kwargs
)
context
[
'confirmation'
]
=
True
return
context
def
remove_host_group
(
request
,
**
kwargs
):
host
=
Host
.
objects
.
get
(
pk
=
kwargs
[
'pk'
])
group
=
Group
.
objects
.
get
(
pk
=
kwargs
[
'group_pk'
])
...
...
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