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
94d2ea62
authored
Mar 13, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add initial template creation
parent
bad51a79
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
179 additions
and
34 deletions
+179
-34
.idea/workspace.xml
+0
-0
circle/circle/db.sqlite3
+0
-0
circle/network/migrations/0005_auto_20180313_1453.py
+53
-0
circle/vm/migrations/0009_auto_20180313_1453.py
+97
-0
circle/vm/models/instance.py
+19
-33
circle/vm/operations.py
+10
-1
No files found.
.idea/workspace.xml
View file @
94d2ea62
This diff is collapsed.
Click to expand it.
circle/circle/db.sqlite3
View file @
94d2ea62
No preview for this file type
circle/network/migrations/0005_auto_20180313_1453.py
0 → 100644
View file @
94d2ea62
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-03-13 13:53
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'network'
,
'0004_remove_vxlan_owner'
),
]
operations
=
[
migrations
.
AlterModelOptions
(
name
=
'vxlan'
,
options
=
{},
),
migrations
.
RemoveField
(
model_name
=
'vxlan'
,
name
=
'comment'
,
),
migrations
.
RemoveField
(
model_name
=
'vxlan'
,
name
=
'created_at'
,
),
migrations
.
RemoveField
(
model_name
=
'vxlan'
,
name
=
'description'
,
),
migrations
.
RemoveField
(
model_name
=
'vxlan'
,
name
=
'modified_at'
,
),
migrations
.
RemoveField
(
model_name
=
'vxlan'
,
name
=
'name'
,
),
migrations
.
RemoveField
(
model_name
=
'vxlan'
,
name
=
'vlan'
,
),
migrations
.
RemoveField
(
model_name
=
'vxlan'
,
name
=
'vni'
,
),
migrations
.
AddField
(
model_name
=
'vxlan'
,
name
=
'os_network_id'
,
field
=
models
.
CharField
(
default
=
1
,
max_length
=
100
,
unique
=
True
),
preserve_default
=
False
,
),
]
circle/vm/migrations/0009_auto_20180313_1453.py
0 → 100644
View file @
94d2ea62
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2018-03-13 13:53
from
__future__
import
unicode_literals
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'vm'
,
'0008_merge_20180226_1259'
),
]
operations
=
[
migrations
.
AlterModelOptions
(
name
=
'instancetemplate'
,
options
=
{
'ordering'
:
(
'name'
,),
'verbose_name'
:
'template'
,
'verbose_name_plural'
:
'templates'
},
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'access_method'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'boot_menu'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'disks'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'has_agent'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'lease'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'max_ram_size'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'num_cores'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'owner'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'parent'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'priority'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'ram_size'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'raw_data'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'req_traits'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'system'
,
),
migrations
.
RemoveField
(
model_name
=
'instancetemplate'
,
name
=
'tags'
,
),
migrations
.
AddField
(
model_name
=
'instancetemplate'
,
name
=
'flavor_id'
,
field
=
models
.
CharField
(
default
=
1
,
max_length
=
100
,
unique
=
True
),
preserve_default
=
False
,
),
migrations
.
AddField
(
model_name
=
'instancetemplate'
,
name
=
'image_id'
,
field
=
models
.
CharField
(
default
=
1
,
max_length
=
100
,
unique
=
True
),
preserve_default
=
False
,
),
migrations
.
AddField
(
model_name
=
'instancetemplate'
,
name
=
'owner_id'
,
field
=
models
.
CharField
(
default
=
1
,
max_length
=
100
,
unique
=
True
),
preserve_default
=
False
,
),
]
circle/vm/models/instance.py
View file @
94d2ea62
...
@@ -127,33 +127,29 @@ class VirtualMachineDescModel(BaseResourceConfigModel):
...
@@ -127,33 +127,29 @@ class VirtualMachineDescModel(BaseResourceConfigModel):
abstract
=
True
abstract
=
True
class
InstanceTemplate
(
VirtualMachineDescModel
,
TimeStampedModel
):
class
InstanceTemplate
(
TimeStampedModel
):
"""Virtual machine template.
"""Virtual machine template.
"""
"""
name
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'name'
),
name
=
CharField
(
max_length
=
100
,
verbose_name
=
_
(
'name'
),
help_text
=
_
(
'Human readable name of template.'
))
help_text
=
_
(
'Human readable name of template.'
))
description
=
TextField
(
verbose_name
=
_
(
'description'
),
blank
=
True
)
description
=
TextField
(
verbose_name
=
_
(
'description'
),
blank
=
True
)
parent
=
ForeignKey
(
'self'
,
null
=
True
,
blank
=
True
,
# parent = ForeignKey('self', null=True, blank=True,
verbose_name
=
_
(
'parent template'
),
# verbose_name=_('parent template'),
on_delete
=
SET_NULL
,
# on_delete=SET_NULL,
help_text
=
_
(
'Template which this one is derived of.'
))
# help_text=_('Template which this one is derived of.'))
disks
=
ManyToManyField
(
'storage.Disk'
,
verbose_name
=
_
(
'disks'
),
# disks = ManyToManyField('storage.Disk', verbose_name=_('disks'),
related_name
=
'template_set'
,
# related_name='template_set',
help_text
=
_
(
'Disks which are to be mounted.'
))
# help_text=_('Disks which are to be mounted.'))
owner
=
ForeignKey
(
User
)
# lease = ForeignKey(Lease, help_text=_("Preferred expiration periods."),
# verbose_name=_("Lease"))
image_id
=
CharField
(
blank
=
False
,
max_length
=
100
,
unique
=
True
)
flavor_id
=
CharField
(
blank
=
False
,
max_length
=
100
,
unique
=
True
)
owner_id
=
CharField
(
blank
=
False
,
max_length
=
100
,
unique
=
True
)
class
Meta
:
class
Meta
:
app_label
=
'vm'
app_label
=
'vm'
db_table
=
'vm_instancetemplate'
db_table
=
'vm_instancetemplate'
ordering
=
(
'name'
,
)
ordering
=
(
'name'
,
)
permissions
=
(
(
'create_template'
,
_
(
'Can create an instance template.'
)),
(
'create_base_template'
,
_
(
'Can create an instance template (base).'
)),
(
'change_template_resources'
,
_
(
'Can change resources of a template.'
)),
)
verbose_name
=
_
(
'template'
)
verbose_name
=
_
(
'template'
)
verbose_name_plural
=
_
(
'templates'
)
verbose_name_plural
=
_
(
'templates'
)
...
@@ -162,9 +158,7 @@ class InstanceTemplate(VirtualMachineDescModel, TimeStampedModel):
...
@@ -162,9 +158,7 @@ class InstanceTemplate(VirtualMachineDescModel, TimeStampedModel):
@property
@property
def
running_instances
(
self
):
def
running_instances
(
self
):
"""The number of running instances of the template.
return
0
#TODO: see get_running_instances
"""
return
sum
(
1
for
i
in
self
.
instance_set
.
all
()
if
i
.
is_running
)
@property
@property
def
os_type
(
self
):
def
os_type
(
self
):
...
@@ -174,35 +168,27 @@ class InstanceTemplate(VirtualMachineDescModel, TimeStampedModel):
...
@@ -174,35 +168,27 @@ class InstanceTemplate(VirtualMachineDescModel, TimeStampedModel):
return
'windows'
return
'windows'
else
:
else
:
return
'linux'
return
'linux'
#TODO
@property
def
is_ready
(
self
):
return
all
(
disk
.
is_ready
for
disk
in
self
.
disks
)
def
save
(
self
,
*
args
,
**
kwargs
):
is_new
=
getattr
(
self
,
"pk"
,
None
)
is
None
super
(
InstanceTemplate
,
self
)
.
save
(
*
args
,
**
kwargs
)
if
is_new
:
self
.
set_level
(
self
.
owner
,
'owner'
)
@permalink
@permalink
def
get_absolute_url
(
self
):
def
get_absolute_url
(
self
):
return
(
'dashboard.views.template-detail'
,
None
,
{
'pk'
:
self
.
pk
})
return
(
'dashboard.views.template-detail'
,
None
,
{
'pk'
:
self
.
pk
})
def
remove_disk
(
self
,
disk
,
**
kwargs
):
def
remove_disk
(
self
,
disk
,
**
kwargs
):
#TODO: why?
self
.
disks
.
remove
(
disk
)
self
.
disks
.
remove
(
disk
)
def
destroy_disks
(
self
):
def
destroy_disks
(
self
):
"""Destroy all associated disks.
#TODO: why?
"""
for
disk
in
self
.
disks
.
all
():
for
disk
in
self
.
disks
.
all
():
disk
.
destroy
()
disk
.
destroy
()
def
get_running_instances
(
self
):
def
get_running_instances
(
self
):
return
Instance
.
active
.
filter
(
template
=
self
,
status
=
"RUNNING"
)
return
()
#TODO: do we need this? if so, store created vm ids in template
@property
@property
def
metric_prefix
(
self
):
def
metric_prefix
(
self
):
#TODO: what is this?
return
'template.
%
d'
%
self
.
pk
return
'template.
%
d'
%
self
.
pk
...
...
circle/vm/operations.py
View file @
94d2ea62
...
@@ -521,7 +521,16 @@ class SaveAsTemplateOperation(InstanceOperation):
...
@@ -521,7 +521,16 @@ class SaveAsTemplateOperation(InstanceOperation):
def
_operation
(
self
,
request
,
user
,
system
,
name
=
None
,
def
_operation
(
self
,
request
,
user
,
system
,
name
=
None
,
with_shutdown
=
True
,
clone
=
False
,
task
=
None
,
**
kwargs
):
with_shutdown
=
True
,
clone
=
False
,
task
=
None
,
**
kwargs
):
print
"TODO: create template"
template_image_id
=
openstack_api
.
nova
.
snapshot_create
(
request
,
self
.
instance
.
id
,
name
)
template
=
InstanceTemplate
(
name
=
name
,
image_id
=
template_image_id
,
flavor_id
=
self
.
instance
.
flavor
[
"id"
],
owner_id
=
user
.
id
,
)
template
.
save
()
# return create_readable(
# return create_readable(
# ugettext_noop("New template: %(template)s"),
# ugettext_noop("New template: %(template)s"),
# template=reverse('dashboard.views.template-detail',
# template=reverse('dashboard.views.template-detail',
...
...
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