Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
5
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
66b3e551
authored
a year ago
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update models and views for stats
parent
6277a2eb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
8 deletions
+49
-8
circle/dashboard/forms.py
+22
-0
circle/dashboard/serializers.py
+1
-1
circle/dashboard/urls.py
+2
-1
circle/dashboard/views/node.py
+16
-0
circle/storage/models.py
+5
-5
circle/vm/operations.py
+3
-1
No files found.
circle/dashboard/forms.py
View file @
66b3e551
...
...
@@ -94,6 +94,28 @@ class VmSaveForm(OperationForm):
help_text
=
_
(
'Backing file location'
))
overlay_path
=
forms
.
ModelChoiceField
(
queryset
=
None
,
initial
=
0
,
empty_label
=
None
,
help_text
=
_
(
'Overlay image dir'
))
cache_size
=
forms
.
CharField
(
widget
=
FileSizeWidget
,
initial
=
(
1
<<
20
),
label
=
_
(
'Metadata cache size'
),
help_text
=
_
(
'Backing file metadata cache size, '
'like KB, MB'
))
cluster_size
=
forms
.
CharField
(
widget
=
FileSizeWidget
,
initial
=
(
1
<<
16
),
label
=
_
(
'Cluster size'
),
help_text
=
_
(
'Backing file disk cluster (block) size, '
'like KB'
))
def
clean_cache_size
(
self
):
size_in_kbytes
=
self
.
cleaned_data
.
get
(
"cache_size"
)
if
not
size_in_kbytes
.
isdigit
()
and
len
(
size_in_kbytes
)
>
0
:
raise
forms
.
ValidationError
(
_
(
"Invalid format, you can use "
" KB or MB!"
))
return
int
(
size_in_kbytes
)
/
1024
def
clean_cluster_size
(
self
):
size_in_kbytes
=
self
.
cleaned_data
.
get
(
"cluster_size"
)
if
not
size_in_kbytes
.
isdigit
()
and
len
(
size_in_kbytes
)
>
0
:
raise
forms
.
ValidationError
(
_
(
"Invalid format, you can use "
" KB or MB!"
))
return
int
(
size_in_kbytes
)
/
1024
def
__init__
(
self
,
*
args
,
**
kwargs
):
default
=
kwargs
.
pop
(
'default'
,
None
)
...
...
This diff is collapsed.
Click to expand it.
circle/dashboard/serializers.py
View file @
66b3e551
...
...
@@ -45,7 +45,7 @@ class NodeSerializer(serializers.ModelSerializer):
class
Meta
:
model
=
Node
fields
=
[
'id'
,
'name'
,
'priority'
,
'host'
,
'enabled'
,
'schedule_enabled'
,
'traits'
,
'overcommit'
,
'ram_weight'
,
'cpu_weight'
,
'time_stamp'
]
'traits'
,
'overcommit'
,
'ram_weight'
,
'cpu_weight'
,
'time_stamp'
,
'allocated_ram'
,
'ram_size'
,
'num_cores'
]
class
InstanceTemplateSerializer
(
serializers
.
ModelSerializer
):
...
...
This diff is collapsed.
Click to expand it.
circle/dashboard/urls.py
View file @
66b3e551
...
...
@@ -70,7 +70,7 @@ from .views import (
RescheduleView
,
GroupImportView
,
GroupExportView
,
VariableREST
,
GetVariableREST
,
HotplugMemSetREST
,
HotplugVCPUSetREST
)
from
.views.node
import
node_ops
,
NodeREST
,
GetNodeREST
from
.views.node
import
node_ops
,
NodeREST
,
GetNodeREST
,
GetNodeRESTSum
from
.views.vm
import
vm_ops
,
vm_mass_ops
urlpatterns
=
[
...
...
@@ -88,6 +88,7 @@ urlpatterns = [
path
(
'acpi/var/<int:pk>/'
,
GetVariableREST
.
as_view
(),
name
=
'variable-detail'
),
path
(
'acpi/node/'
,
NodeREST
.
as_view
()),
path
(
'acpi/node/<int:pk>/'
,
GetNodeREST
.
as_view
()),
path
(
'acpi/nodesum/'
,
GetNodeRESTSum
.
as_view
()),
path
(
'acpi/vm/<int:pk>/'
,
GetInstanceREST
.
as_view
()),
path
(
'acpi/template/<int:pk>/'
,
GetTemplateREST
.
as_view
()),
path
(
'acpi/template/'
,
TemplateREST
.
as_view
()),
...
...
This diff is collapsed.
Click to expand it.
circle/dashboard/views/node.py
View file @
66b3e551
...
...
@@ -30,6 +30,7 @@ from django.shortcuts import redirect
from
django.template.loader
import
render_to_string
from
django.utils.translation
import
ugettext
as
_
from
django.views.generic
import
DetailView
,
TemplateView
,
View
from
rest_framework.response
import
Response
from
rest_framework
import
status
from
rest_framework.views
import
APIView
...
...
@@ -81,6 +82,21 @@ class GetNodeREST(APIView):
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
GetNodeRESTSum
(
APIView
):
permission_classes
=
[]
def
get
(
self
,
request
,
format
=
None
):
nodes
=
Node
.
objects
.
filter
(
enabled
=
True
,
schedule_enabled
=
True
)
cpu_core
=
0
max_memory
=
0
for
i
in
nodes
:
cpu_core
=
cpu_core
+
i
.
info
[
'core_num'
]()
max_memory
=
max_memory
+
i
.
info
[
'ram_size'
]
return
Response
(
{
"core_num"
:
cpu_core
,
"max_ram"
:
max_memory
}
)
def
get_operations
(
instance
,
user
):
ops
=
[]
for
k
,
v
in
list
(
node_ops
.
items
()):
...
...
This diff is collapsed.
Click to expand it.
circle/storage/models.py
View file @
66b3e551
...
...
@@ -339,8 +339,8 @@ class Disk(TimeStampedModel):
new_type
=
type_mapping
[
self
.
type
]
return
Disk
.
create
(
base
=
self
,
datastore
=
self
.
datastore
if
datastore
is
None
else
datastore
,
name
=
self
.
name
,
size
=
self
.
size
,
type
=
new_type
,
dev_num
=
self
.
dev_num
)
name
=
self
.
name
,
size
=
self
.
size
,
cache_size
=
self
.
cache_size
,
type
=
new_type
,
dev_num
=
self
.
dev_num
,
cluster_size
=
self
.
cluster_size
)
def
get_vmdisk_desc
(
self
):
"""Serialize disk object to the vmdriver.
...
...
@@ -367,7 +367,7 @@ class Disk(TimeStampedModel):
'base_name'
:
self
.
base
.
filename
if
self
.
base
else
None
,
'type'
:
'snapshot'
if
self
.
base
else
'normal'
,
'base_dir'
:
self
.
base
.
datastore
.
path
if
self
.
base
else
None
,
'cluster_size'
:
self
.
cluster_size
'cluster_size'
:
self
.
cluster_size
,
}
def
get_remote_queue_name
(
self
,
queue_id
=
'storage'
,
priority
=
None
,
...
...
@@ -568,7 +568,7 @@ class Disk(TimeStampedModel):
args
=
[
self
.
datastore
.
path
,
self
.
filename
],
queue
=
queue_name
)
.
get
(
timeout
=
timeout
)
def
save_as
(
self
,
task
=
None
,
user
=
None
,
task_uuid
=
None
,
datastore
=
None
,
timeout
=
300
):
def
save_as
(
self
,
task
=
None
,
user
=
None
,
task_uuid
=
None
,
datastore
=
None
,
timeout
=
300
,
cache_size
=
1024
,
cluster_size
=
64
):
"""Save VM as template.
Based on disk type:
...
...
@@ -602,7 +602,7 @@ class Disk(TimeStampedModel):
disk
=
Disk
.
create
(
datastore
=
datastore
,
base
=
new_base
,
name
=
self
.
name
,
size
=
self
.
size
,
type
=
new_type
,
dev_num
=
self
.
dev_num
)
type
=
new_type
,
dev_num
=
self
.
dev_num
,
cluster_size
=
cluster_size
,
cache_size
=
cache_size
)
queue_name
=
self
.
get_remote_queue_name
(
"storage"
,
priority
=
"slow"
)
remote
=
storage_tasks
.
merge
.
apply_async
(
kwargs
=
{
...
...
This diff is collapsed.
Click to expand it.
circle/vm/operations.py
View file @
66b3e551
...
...
@@ -895,12 +895,14 @@ class SaveAsTemplateOperation(InstanceOperation):
params
.
update
(
kwargs
)
params
.
pop
(
"parent_activity"
,
None
)
cache_size
=
params
.
pop
(
'cache_size'
,
1024
)
cluster_size
=
params
.
pop
(
'cluster_size'
,
64
)
from
storage.models
import
Disk
def
__try_save_disk
(
disk
,
datastore
):
try
:
return
disk
.
save_as
(
task
,
datastore
=
datastore
)
return
disk
.
save_as
(
task
,
datastore
=
datastore
,
cache_size
=
cache_size
,
cluster_size
=
cluster_size
)
except
Disk
.
WrongDiskTypeError
:
return
disk
...
...
This diff is collapsed.
Click to expand it.
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