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
d31bb288
authored
Mar 13, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add skeleton of save as template operation
parent
63501e0a
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
109 deletions
+29
-109
.idea/workspace.xml
+0
-0
circle/dashboard/views/vm.py
+20
-20
circle/vm/operations.py
+9
-89
No files found.
.idea/workspace.xml
View file @
d31bb288
This diff is collapsed.
Click to expand it.
circle/dashboard/views/vm.py
View file @
d31bb288
...
...
@@ -62,7 +62,7 @@ from .util import (
)
from
..forms
import
(
AclUserOrGroupAddForm
,
VmResourcesForm
,
VmCustomizeForm
,
VmDeployForm
,
VmFromPlainImageForm
,
VmRemoveInterfaceForm
,
VmAddInterfaceForm
)
VmAddInterfaceForm
,
VmSaveForm
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -523,24 +523,24 @@ class VmAddInterfaceView(FormOperationMixin, VmOperationView):
# return val
#
#
#
class VmSaveView(FormOperationMixin, VmOperationView):
#
#
op = 'save_as_template'
#
icon = 'save'
#
effect = 'info'
#
form_class = VmSaveForm
#
#
def get_form_kwargs(self):
# op = self.get_op
()
# val = super(VmSaveView, self).get_form_kwargs
()
# val['default'] = op._rename(op.instance.name)
# obj = self.get_object(
)
# if obj.template and obj.template.has_level(
# self.request.user, "owner"):
# val['clone'] = True
# return val
#
#
class
VmSaveView
(
FormOperationMixin
,
VmOperationView
):
op
=
'save_as_template'
icon
=
'save'
effect
=
'info'
form_class
=
VmSaveForm
def
get_form_kwargs
(
self
):
context
=
super
(
VmSaveView
,
self
)
.
get_form_kwargs
()
op
=
self
.
get_op
()
context
[
'default'
]
=
op
.
_rename
(
op
.
instance
.
name
)
obj
=
self
.
get_object
()
#context['clone'] = True #TODO: if instance has a template already this option allows clone of permissions
return
context
# class VmResourcesChangeView(VmOperationView):
# op = 'resources_change'
# icon = "save"
...
...
@@ -761,7 +761,7 @@ vm_ops = OrderedDict([
(
'sleep'
,
VmOperationView
.
factory
(
op
=
'sleep'
,
icon
=
'moon-o'
,
effect
=
'info'
)),
# ('migrate', VmMigrateView),
#
('save_as_template', VmSaveView),
(
'save_as_template'
,
VmSaveView
),
(
'reboot'
,
VmOperationView
.
factory
(
op
=
'reboot'
,
icon
=
'refresh'
,
effect
=
'warning'
)),
# ('reset', VmOperationView.factory(
...
...
circle/vm/operations.py
View file @
d31bb288
...
...
@@ -124,6 +124,7 @@ class InstanceOperation(Operation):
raise
self
.
instance
.
WrongStateError
(
self
.
instance
)
def
check_auth
(
self
,
user
,
request
):
if
self
.
os_policy_actions
:
from
django.utils.module_loading
import
import_string
check
=
import_string
(
"openstack_auth.policy.check"
)
...
...
@@ -505,15 +506,8 @@ class SaveAsTemplateOperation(InstanceOperation):
"with users and groups. Anyone who has access to a "
"template (and to the networks it uses) will be able to "
"start an instance of it."
)
has_percentage
=
True
abortable
=
True
required_perms
=
(
'vm.create_template'
,)
accept_states
=
(
'ACTIVE'
,
'STOPPED'
)
async_queue
=
"localhost.man.slow"
def
is_preferred
(
self
):
return
(
self
.
instance
.
is_base
and
self
.
instance
.
status
==
self
.
instance
.
STATUS
.
RUNNING
)
accept_states
=
(
'SHUTOFF'
,
'ACTIVE'
)
# TODO: try other states
# os_policy_actions = (("compute", "compute:stop"),)
@staticmethod
def
_rename
(
name
):
...
...
@@ -525,87 +519,13 @@ class SaveAsTemplateOperation(InstanceOperation):
v
=
1
return
"
%
s v
%
d"
%
(
name
,
v
)
def
on_abort
(
self
,
activity
,
error
):
if
hasattr
(
self
,
'disks'
):
for
disk
in
self
.
disks
:
disk
.
destroy
()
def
_operation
(
self
,
activity
,
user
,
system
,
name
=
None
,
def
_operation
(
self
,
request
,
user
,
system
,
name
=
None
,
with_shutdown
=
True
,
clone
=
False
,
task
=
None
,
**
kwargs
):
try
:
self
.
instance
.
_cleanup
(
parent_activity
=
activity
,
user
=
user
)
except
:
pass
if
with_shutdown
:
try
:
self
.
instance
.
shutdown
(
parent_activity
=
activity
,
user
=
user
,
task
=
task
)
except
Instance
.
WrongStateError
:
pass
# prepare parameters
params
=
{
'access_method'
:
self
.
instance
.
access_method
,
'arch'
:
self
.
instance
.
arch
,
'boot_menu'
:
self
.
instance
.
boot_menu
,
'description'
:
self
.
instance
.
description
,
'lease'
:
self
.
instance
.
lease
,
# Can be problem in new VM
'max_ram_size'
:
self
.
instance
.
max_ram_size
,
'name'
:
name
or
self
.
_rename
(
self
.
instance
.
name
),
'num_cores'
:
self
.
instance
.
num_cores
,
'owner'
:
user
,
'parent'
:
self
.
instance
.
template
or
None
,
# Can be problem
'priority'
:
self
.
instance
.
priority
,
'ram_size'
:
self
.
instance
.
ram_size
,
'raw_data'
:
self
.
instance
.
raw_data
,
'system'
:
self
.
instance
.
system
,
}
params
.
update
(
kwargs
)
params
.
pop
(
"parent_activity"
,
None
)
from
storage.models
import
Disk
def
__try_save_disk
(
disk
):
try
:
return
disk
.
save_as
(
task
)
except
Disk
.
WrongDiskTypeError
:
return
disk
self
.
disks
=
[]
for
disk
in
self
.
instance
.
disks
.
all
():
with
activity
.
sub_activity
(
'saving_disk'
,
readable_name
=
create_readable
(
ugettext_noop
(
"saving disk
%(name)
s"
),
name
=
disk
.
name
)
):
self
.
disks
.
append
(
__try_save_disk
(
disk
))
# create template and do additional setup
tmpl
=
InstanceTemplate
(
**
params
)
tmpl
.
full_clean
()
# Avoiding database errors.
tmpl
.
save
()
# Copy traits from the VM instance
tmpl
.
req_traits
.
add
(
*
self
.
instance
.
req_traits
.
all
())
if
clone
:
tmpl
.
clone_acl
(
self
.
instance
.
template
)
# Add permission for the original owner of the template
tmpl
.
set_level
(
self
.
instance
.
template
.
owner
,
'owner'
)
tmpl
.
set_level
(
user
,
'owner'
)
try
:
tmpl
.
disks
.
add
(
*
self
.
disks
)
# create interface templates
for
i
in
self
.
instance
.
interface_set
.
all
():
i
.
save_as_template
(
tmpl
)
except
:
tmpl
.
delete
()
raise
else
:
return
create_readable
(
ugettext_noop
(
"New template:
%(template)
s"
),
template
=
reverse
(
'dashboard.views.template-detail'
,
kwargs
=
{
'pk'
:
tmpl
.
pk
}))
print
"TODO: create template"
# return create_readable(
# ugettext_noop("New template: %(template)s"),
# template=reverse('dashboard.views.template-detail',
# kwargs={'pk': 0}))
@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