Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
fa4cc272
authored
Nov 22, 2015
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
storage: add DataStoreHost model, make DataStore and Disk model Ceph block store compatible
parent
1698b3d4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
138 additions
and
14 deletions
+138
-14
circle/storage/migrations/0003_auto_20151122_2104.py
+52
-0
circle/storage/models.py
+86
-14
No files found.
circle/storage/migrations/0003_auto_20151122_2104.py
0 → 100644
View file @
fa4cc272
# -*- coding: utf-8 -*-
from
__future__
import
unicode_literals
from
django.db
import
models
,
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'storage'
,
'0002_disk_bus'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'DataStoreHost'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
(
'address'
,
models
.
CharField
(
max_length
=
1024
,
verbose_name
=
'address'
)),
(
'port'
,
models
.
IntegerField
(
null
=
True
,
verbose_name
=
'port'
)),
],
),
migrations
.
AddField
(
model_name
=
'datastore'
,
name
=
'ceph_user'
,
field
=
models
.
CharField
(
max_length
=
255
,
null
=
True
,
verbose_name
=
'Ceph username'
),
),
migrations
.
AddField
(
model_name
=
'datastore'
,
name
=
'secret_uuid'
,
field
=
models
.
CharField
(
max_length
=
255
,
null
=
True
,
verbose_name
=
'uuid of secret'
),
),
migrations
.
AddField
(
model_name
=
'datastore'
,
name
=
'type'
,
field
=
models
.
CharField
(
default
=
'file'
,
max_length
=
10
,
verbose_name
=
'type'
,
choices
=
[(
'file'
,
'filesystem'
),
(
'ceph_block'
,
'Ceph block device'
)]),
),
migrations
.
AlterField
(
model_name
=
'datastore'
,
name
=
'hostname'
,
field
=
models
.
CharField
(
max_length
=
40
,
verbose_name
=
'hostname'
),
),
migrations
.
AlterField
(
model_name
=
'disk'
,
name
=
'type'
,
field
=
models
.
CharField
(
max_length
=
10
,
choices
=
[(
'qcow2-norm'
,
'qcow2 normal'
),
(
'qcow2-snap'
,
'qcow2 snapshot'
),
(
'ceph-norm'
,
'Ceph block normal'
),
(
'ceph-snap'
,
'Ceph block snapshot'
),
(
'iso'
,
'iso'
),
(
'raw-ro'
,
'raw read-only'
),
(
'raw-rw'
,
'raw'
)]),
),
migrations
.
AddField
(
model_name
=
'datastore'
,
name
=
'hosts'
,
field
=
models
.
ManyToManyField
(
to
=
'storage.DataStoreHost'
,
verbose_name
=
'hosts'
),
),
]
circle/storage/models.py
View file @
fa4cc272
...
...
@@ -27,7 +27,7 @@ import re
from
django.conf
import
settings
from
celery.contrib.abortable
import
AbortableAsyncResult
from
django.db.models
import
(
Model
,
BooleanField
,
CharField
,
DateTimeField
,
ForeignKey
)
ForeignKey
,
IntegerField
,
ManyToManyField
)
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
...
...
@@ -43,14 +43,30 @@ from common.models import (
logger
=
logging
.
getLogger
(
__name__
)
class
DataStoreHost
(
Model
):
""" Address and port of a data store.
"""
address
=
CharField
(
max_length
=
1024
,
verbose_name
=
_
(
'address'
))
port
=
IntegerField
(
null
=
True
,
verbose_name
=
_
(
'port'
))
class
DataStore
(
Model
):
"""Collection of virtual disks.
"""
TYPES
=
[(
'file'
,
'filesystem'
),
(
'ceph_block'
,
'Ceph block device'
)]
type
=
CharField
(
max_length
=
10
,
verbose_name
=
_
(
'type'
),
default
=
'file'
,
choices
=
TYPES
)
name
=
CharField
(
max_length
=
100
,
unique
=
True
,
verbose_name
=
_
(
'name'
))
path
=
CharField
(
max_length
=
200
,
unique
=
True
,
verbose_name
=
_
(
'path'
))
hostname
=
CharField
(
max_length
=
40
,
unique
=
True
,
verbose_name
=
_
(
'hostname'
))
hostname
=
CharField
(
max_length
=
40
,
verbose_name
=
_
(
'hostname'
))
hosts
=
ManyToManyField
(
'DataStoreHost'
,
verbose_name
=
_
(
'hosts'
))
ceph_user
=
CharField
(
max_length
=
255
,
null
=
True
,
verbose_name
=
_
(
'Ceph username'
))
secret_uuid
=
CharField
(
max_length
=
255
,
null
=
True
,
verbose_name
=
_
(
'uuid of secret'
))
class
Meta
:
ordering
=
[
'name'
]
...
...
@@ -79,6 +95,24 @@ class DataStore(Model):
self
.
disk_set
.
filter
(
destroyed__isnull
=
False
)
if
disk
.
is_deletable
]
def
get_disk_desc
(
self
,
disk
):
if
self
.
type
==
"ceph_block"
:
return
disk
.
get_disk_desc_for_ceph_block_device
()
return
disk
.
get_disk_desc_for_filesystem
()
def
get_vmdisk_desc
(
self
,
disk
):
if
self
.
type
==
"ceph_block"
:
return
disk
.
get_vmdisk_desc_for_ceph_block_device
()
return
disk
.
get_vmdisk_desc_for_filesystem
()
def
get_hosts
(
self
):
return
[(
host
.
address
,
host
.
port
)
for
host
in
self
.
hosts
.
all
()]
@method_cache
(
30
)
def
get_statistics
(
self
,
timeout
=
15
):
q
=
self
.
get_remote_queue_name
(
"storage"
,
priority
=
"fast"
)
...
...
@@ -126,8 +160,11 @@ class Disk(TimeStampedModel):
"""A virtual disk.
"""
TYPES
=
[(
'qcow2-norm'
,
'qcow2 normal'
),
(
'qcow2-snap'
,
'qcow2 snapshot'
),
(
'ceph-norm'
,
'Ceph block normal'
),
(
'ceph-snap'
,
'Ceph block snapshot'
),
(
'iso'
,
'iso'
),
(
'raw-ro'
,
'raw read-only'
),
(
'raw-rw'
,
'raw'
)]
BUS_TYPES
=
((
'virtio'
,
'virtio'
),
(
'ide'
,
'ide'
),
(
'scsi'
,
'scsi'
))
name
=
CharField
(
blank
=
True
,
max_length
=
100
,
verbose_name
=
_
(
"name"
))
filename
=
CharField
(
max_length
=
256
,
unique
=
True
,
verbose_name
=
_
(
"filename"
))
...
...
@@ -230,24 +267,28 @@ class Disk(TimeStampedModel):
return
join
(
self
.
datastore
.
path
,
self
.
filename
)
@property
def
vm_format
(
self
):
def
format_for_vmdriver
(
self
):
"""Returns the proper file format for different type of images.
"""
return
{
'qcow2-norm'
:
'qcow2'
,
'qcow2-snap'
:
'qcow2'
,
'ceph-norm'
:
'raw'
,
'ceph-snap'
:
'raw'
,
'iso'
:
'raw'
,
'raw-ro'
:
'raw'
,
'raw-rw'
:
'raw'
,
}[
self
.
type
]
@property
def
format
(
self
):
def
format
_for_storagedriver
(
self
):
"""Returns the proper file format for different types of images.
"""
return
{
'qcow2-norm'
:
'qcow2'
,
'qcow2-snap'
:
'qcow2'
,
'ceph-norm'
:
'rbd'
,
'ceph-snap'
:
'rbd'
,
'iso'
:
'iso'
,
'raw-ro'
:
'raw'
,
'raw-rw'
:
'raw'
,
...
...
@@ -260,6 +301,8 @@ class Disk(TimeStampedModel):
return
{
'qcow2-norm'
:
'vd'
,
'qcow2-snap'
:
'vd'
,
'ceph-norm'
:
'vd'
,
'ceph-snap'
:
'vd'
,
'iso'
:
'sd'
,
'raw-ro'
:
'vd'
,
'raw-rw'
:
'vd'
,
...
...
@@ -274,6 +317,8 @@ class Disk(TimeStampedModel):
return
{
'qcow2-norm'
:
'virtio'
,
'qcow2-snap'
:
'virtio'
,
'ceph-norm'
:
'virtio'
,
'ceph-snap'
:
'virtio'
,
'iso'
:
'ide'
,
'raw-ro'
:
'virtio'
,
'raw-rw'
:
'virtio'
,
...
...
@@ -334,27 +379,54 @@ class Disk(TimeStampedModel):
def
get_vmdisk_desc
(
self
):
"""Serialize disk object to the vmdriver.
"""
return
{
'source'
:
self
.
path
,
'driver_type'
:
self
.
vm_format
,
'driver_cache'
:
'none'
,
'target_device'
:
self
.
device_type
+
self
.
dev_num
,
'target_bus'
:
self
.
device_bus
,
'disk_device'
:
'cdrom'
if
self
.
type
==
'iso'
else
'disk'
}
return
self
.
datastore
.
get_vmdisk_desc
(
self
)
def
get_disk_desc
(
self
):
"""Serialize disk object to the storage driver.
"""
return
self
.
datastore
.
get_disk_desc
(
self
)
def
get_disk_desc_for_filesystem
(
self
):
return
{
'name'
:
self
.
filename
,
'dir'
:
self
.
datastore
.
path
,
'format'
:
self
.
format
,
'format'
:
self
.
format
_for_storagedriver
,
'size'
:
self
.
size
,
'base_name'
:
self
.
base
.
filename
if
self
.
base
else
None
,
'type'
:
'snapshot'
if
self
.
base
else
'normal'
}
def
get_disk_desc_for_ceph_block_device
(
self
):
desc
=
self
.
get_disk_desc_for_filesystem
()
desc
[
"hosts"
]
=
self
.
datastore
.
get_hosts
()
desc
[
"ceph_user"
]
=
self
.
datastore
.
ceph_user
desc
[
"secret_uuid"
]
=
self
.
datastore
.
secret_uuid
return
desc
def
get_vmdisk_desc_for_filesystem
(
self
):
return
{
'data_store_type'
:
self
.
datastore
.
type
,
'source'
:
self
.
path
,
'driver_type'
:
self
.
format_for_vmdriver
,
'driver_cache'
:
'none'
,
'target_device'
:
self
.
device_type
+
self
.
dev_num
,
'target_bus'
:
self
.
device_bus
,
'disk_device'
:
'cdrom'
if
self
.
type
==
'iso'
else
'disk'
}
def
get_vmdisk_desc_for_ceph_block_device
(
self
):
desc
=
self
.
get_vmdisk_desc_for_filesystem
()
desc
[
"hosts"
]
=
self
.
datastore
.
get_hosts
()
desc
[
"ceph_user"
]
=
self
.
datastore
.
ceph_user
desc
[
"secret_uuid"
]
=
self
.
datastore
.
secret_uuid
return
desc
def
get_remote_queue_name
(
self
,
queue_id
=
'storage'
,
priority
=
None
,
check_worker
=
True
):
"""Returns the proper queue name based on the datastore.
...
...
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