Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
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
ef0ed6be
authored
Mar 08, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable 'Add network interface' operation
parent
cb15e6e4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
95 deletions
+52
-95
.idea/workspace.xml
+0
-0
circle/dashboard/templates/dashboard/vm-detail/network.html
+0
-9
circle/dashboard/views/vm.py
+48
-48
circle/vm/operations.py
+4
-38
No files found.
.idea/workspace.xml
View file @
ef0ed6be
This diff is collapsed.
Click to expand it.
circle/dashboard/templates/dashboard/vm-detail/network.html
View file @
ef0ed6be
...
@@ -8,15 +8,6 @@
...
@@ -8,15 +8,6 @@
<i
class=
"fa fa-{{op.icon}}"
></i>
{% trans "add interface" %}
</a>
<i
class=
"fa fa-{{op.icon}}"
></i>
{% trans "add interface" %}
</a>
{% endif %}{% endwith %}
{% endif %}{% endwith %}
</div>
</div>
<br
/>
<br
/>
<div
id=
"vm-details-add-user-interface"
>
{% with op=op.add_user_interface %}{% if op %}
<a
href=
"{{op.get_url}}"
class=
"btn btn-{{op.effect}} operation pull-right"
{%
if
op
.
disabled
%}
disabled
{%
endif
%}
>
<i
class=
"fa fa-{{op.icon}}"
></i>
{% trans "add user interface" %}
</a>
{% endif %}{% endwith %}
</div>
<h2>
<h2>
{% trans "Interfaces" %}
{% trans "Interfaces" %}
</h2>
</h2>
...
...
circle/dashboard/views/vm.py
View file @
ef0ed6be
...
@@ -60,7 +60,8 @@ from .util import (
...
@@ -60,7 +60,8 @@ from .util import (
FormOperationMixin
,
FilterMixin
,
GraphMixin
FormOperationMixin
,
FilterMixin
,
GraphMixin
)
)
from
..forms
import
(
from
..forms
import
(
AclUserOrGroupAddForm
,
VmResourcesForm
,
VmCustomizeForm
,
VmDeployForm
,
VmFromPlainImageForm
)
AclUserOrGroupAddForm
,
VmResourcesForm
,
VmCustomizeForm
,
VmDeployForm
,
VmFromPlainImageForm
,
VmRemoveInterfaceForm
,
VmAddInterfaceForm
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -308,52 +309,51 @@ def get_operations(instance, user, request):
...
@@ -308,52 +309,51 @@ def get_operations(instance, user, request):
else
:
else
:
ops
.
append
(
v
.
bind_to_object
(
instance
))
ops
.
append
(
v
.
bind_to_object
(
instance
))
return
ops
return
ops
#
#
#
class
VmRemoveInterfaceView
(
FormOperationMixin
,
VmOperationView
):
# class VmRemoveInterfaceView(FormOperationMixin, VmOperationView):
op
=
'remove_interface'
# op = 'remove_interface'
form_class
=
VmRemoveInterfaceForm
# form_class = VmRemoveInterfaceForm
show_in_toolbar
=
False
# show_in_toolbar = False
wait_for_result
=
0.5
# wait_for_result = 0.5
icon
=
'times'
# icon = 'times'
effect
=
"danger"
# effect = "danger"
with_reload
=
True
# with_reload = True
#
def
get_form_kwargs
(
self
):
# def get_form_kwargs(self):
instance
=
self
.
get_op
()
.
instance
# instance = self.get_op().instance
choices
=
instance
.
interface_set
.
all
()
# choices = instance.interface_set.all()
interface_pk
=
self
.
request
.
GET
.
get
(
'interface'
)
# interface_pk = self.request.GET.get('interface')
if
interface_pk
:
# if interface_pk:
try
:
# try:
default
=
choices
.
get
(
pk
=
interface_pk
)
# default = choices.get(pk=interface_pk)
except
(
ValueError
,
Interface
.
DoesNotExist
):
# except (ValueError, Interface.DoesNotExist):
raise
Http404
()
# raise Http404()
else
:
# else:
default
=
None
# default = None
#
val
=
super
(
VmRemoveInterfaceView
,
self
)
.
get_form_kwargs
()
# val = super(VmRemoveInterfaceView, self).get_form_kwargs()
val
.
update
({
'choices'
:
choices
,
'default'
:
default
})
# val.update({'choices': choices, 'default': default})
return
val
# return val
#
#
class
VmAddInterfaceView
(
FormOperationMixin
,
VmOperationView
):
# class VmAddInterfaceView(FormOperationMixin, VmOperationView):
op
=
'add_interface'
#
form_class
=
VmAddInterfaceForm
# op = 'add_interface'
show_in_toolbar
=
False
# form_class = VmAddInterfaceForm
icon
=
'globe'
# show_in_toolbar = False
effect
=
'success'
# icon = 'globe'
with_reload
=
True
# effect = 'success'
# with_reload = True
def
get_form_kwargs
(
self
):
#
inst
=
self
.
get_op
()
.
instance
# def get_form_kwargs(self):
choices
=
Vlan
.
get_objects_with_level
(
# inst = self.get_op().instance
"user"
,
self
.
request
.
user
)
.
exclude
(
# choices = Vlan.get_objects_with_level(
vm_interface__instance__in
=
[
inst
])
# "user", self.request.user).exclude(
val
=
super
(
VmAddInterfaceView
,
self
)
.
get_form_kwargs
()
# vm_interface__instance__in=[inst])
val
.
update
({
'choices'
:
choices
})
# val = super(VmAddInterfaceView, self).get_form_kwargs()
return
val
# val.update({'choices': choices})
# return val
#
#
#
# class VmDiskModifyView(FormOperationMixin, VmOperationView):
# class VmDiskModifyView(FormOperationMixin, VmOperationView):
# show_in_toolbar = False
# show_in_toolbar = False
...
@@ -761,8 +761,8 @@ vm_ops = OrderedDict([
...
@@ -761,8 +761,8 @@ vm_ops = OrderedDict([
# ('remove_disk', VmDiskModifyView.factory(
# ('remove_disk', VmDiskModifyView.factory(
# op='remove_disk', form_class=VmDiskRemoveForm,
# op='remove_disk', form_class=VmDiskRemoveForm,
# icon='times', effect="danger")),
# icon='times', effect="danger")),
#
('add_interface', VmAddInterfaceView),
(
'add_interface'
,
VmAddInterfaceView
),
#
('remove_interface', VmRemoveInterfaceView),
(
'remove_interface'
,
VmRemoveInterfaceView
),
# ('remove_port', VmPortRemoveView),
# ('remove_port', VmPortRemoveView),
# ('add_port', VmPortAddView),
# ('add_port', VmPortAddView),
# ('renew', VmRenewView),
# ('renew', VmRenewView),
...
...
circle/vm/operations.py
View file @
ef0ed6be
...
@@ -185,46 +185,12 @@ class RemoteAgentOperation(EnsureAgentMixin, RemoteInstanceOperation):
...
@@ -185,46 +185,12 @@ class RemoteAgentOperation(EnsureAgentMixin, RemoteInstanceOperation):
class
AddInterfaceOperation
(
InstanceOperation
):
class
AddInterfaceOperation
(
InstanceOperation
):
id
=
'add_interface'
id
=
'add_interface'
name
=
_
(
"add interface"
)
name
=
_
(
"add interface"
)
description
=
_
(
"Add a new network interface for the specified VLAN to "
description
=
_
(
"Add a new network interface for the specified network to the VM."
)
"the VM."
)
accept_states
=
(
'SHUTOFF'
,
'ACTIVE'
)
#TODO: try other states
required_perms
=
()
os_policy_actions
=
((
"compute"
,
"compute:attach_interface"
),)
accept_states
=
(
'STOPPED'
,
'PENDING'
,
'ACTIVE'
)
accept_states
=
(
'STOPPED'
,
'PENDING'
,
'RUNNING'
)
network_type
=
None
def
rollback
(
self
,
net
,
activity
):
with
activity
.
sub_activity
(
'destroying_net'
,
readable_name
=
ugettext_noop
(
"destroy network (rollback)"
)):
net
.
destroy
()
net
.
delete
()
def
_operation
(
self
,
activity
,
user
,
system
,
vlan
,
managed
=
None
):
def
_operation
(
self
,
activity
,
user
,
system
,
vlan
,
managed
=
None
):
if
not
vlan
.
has_level
(
user
,
'user'
):
print
(
"Adding interface"
)
raise
humanize_exception
(
ugettext_noop
(
"User acces to vlan
%(vlan)
s is required."
),
PermissionDenied
(),
vlan
=
vlan
)
if
managed
is
None
:
managed
=
vlan
.
managed
net
=
Interface
.
create
(
base_activity
=
activity
,
instance
=
self
.
instance
,
managed
=
managed
,
owner
=
user
,
vlan
=
vlan
)
if
self
.
instance
.
is_running
:
try
:
self
.
instance
.
_attach_network
(
interface
=
net
,
parent_activity
=
activity
)
except
Exception
as
e
:
if
hasattr
(
e
,
'libvirtError'
):
self
.
rollback
(
net
,
activity
)
raise
net
.
deploy
()
self
.
instance
.
_change_ip
(
parent_activity
=
activity
)
self
.
instance
.
_restart_networking
(
parent_activity
=
activity
)
def
get_activity_name
(
self
,
kwargs
):
return
create_readable
(
ugettext_noop
(
"add
%(vlan)
s interface"
),
vlan
=
kwargs
[
'vlan'
])
@register_operation
@register_operation
...
...
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