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
e837067b
authored
Jul 21, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cloud init beta
parent
325a7ee9
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
13 deletions
+88
-13
circle/dashboard/views/template.py
+0
-8
circle/storage/models.py
+6
-3
circle/vm/migrations/0008_auto_20220721_0756.py
+23
-0
circle/vm/migrations/0009_auto_20220721_1118.py
+33
-0
circle/vm/models/instance.py
+2
-2
circle/vm/operations.py
+24
-0
No files found.
circle/dashboard/views/template.py
View file @
e837067b
...
...
@@ -169,14 +169,6 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
networks
=
networks
,
tags
=
tags
,
req_traits
=
req_traits
)
if
post
[
'cloud_init'
]:
disk
=
Disk
.
create_ci_disk
(
meta_data
=
post
[
'ci_meta_data'
],
user_data
=
post
[
'ci_user_data'
],
user
=
request
.
user
)
disk
.
full_clean
()
disk
.
save
()
inst
.
disks
.
add
(
disk
)
inst
.
_attach_disk
(
disk
=
disk
)
return
HttpResponseRedirect
(
"
%
s#resources"
%
inst
.
get_absolute_url
())
...
...
circle/storage/models.py
View file @
e837067b
...
...
@@ -450,14 +450,17 @@ class Disk(TimeStampedModel):
@classmethod
def
create_ci_disk
(
cls
,
meta_data
,
user_data
,
user
=
None
,
**
params
):
params
.
setdefault
(
'name'
,
'ci-disk'
)
params
.
setdefault
(
'type'
,
'
is
o'
)
params
.
setdefault
(
'size'
,
200
)
params
.
setdefault
(
'type'
,
'
raw-r
o'
)
params
.
setdefault
(
'size'
,
None
)
disk
=
cls
.
__create
(
params
=
params
,
user
=
user
)
queue_name
=
disk
.
get_remote_queue_name
(
'storage'
,
priority
=
"fast"
)
disk_desc
=
disk
.
get_disk_desc
()
storage_tasks
.
create_ci_disk
.
apply_async
(
args
=
[
disk_desc
,
user_data
,
meta
_data
],
result
=
storage_tasks
.
create_ci_disk
.
apply_async
(
args
=
[
disk_desc
,
meta_data
,
user
_data
],
queue
=
queue_name
)
.
get
(
timeout
=
15
)
disk
.
size
=
result
[
'size'
]
disk
.
type
=
'raw-ro'
disk
.
checksum
=
result
[
'checksum'
]
disk
.
is_ready
=
True
disk
.
save
()
return
disk
...
...
circle/vm/migrations/0008_auto_20220721_0756.py
0 → 100644
View file @
e837067b
# Generated by Django 3.2.3 on 2022-07-21 07:56
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'vm'
,
'0007_auto_20220720_1312'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'instance'
,
name
=
'cloud_init'
,
field
=
models
.
BooleanField
(
default
=
False
,
help_text
=
'VM use cloud-init, set user- and meta-data below'
,
verbose_name
=
'Use Cloud-init'
),
),
migrations
.
AlterField
(
model_name
=
'instancetemplate'
,
name
=
'cloud_init'
,
field
=
models
.
BooleanField
(
default
=
False
,
help_text
=
'VM use cloud-init, set user- and meta-data below'
,
verbose_name
=
'Use Cloud-init'
),
),
]
circle/vm/migrations/0009_auto_20220721_1118.py
0 → 100644
View file @
e837067b
# Generated by Django 3.2.3 on 2022-07-21 11:18
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'vm'
,
'0008_auto_20220721_0756'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'instance'
,
name
=
'ci_meta_data'
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
'empty'
,
help_text
=
'When cloud-init is active, set meta-data (YAML format)'
,
verbose_name
=
'ci_meta_data'
),
),
migrations
.
AlterField
(
model_name
=
'instance'
,
name
=
'ci_user_data'
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
'empty'
,
help_text
=
'When cloud-init is active, set user-data (YAML format)'
,
verbose_name
=
'ci_user_data'
),
),
migrations
.
AlterField
(
model_name
=
'instancetemplate'
,
name
=
'ci_meta_data'
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
'empty'
,
help_text
=
'When cloud-init is active, set meta-data (YAML format)'
,
verbose_name
=
'ci_meta_data'
),
),
migrations
.
AlterField
(
model_name
=
'instancetemplate'
,
name
=
'ci_user_data'
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
'empty'
,
help_text
=
'When cloud-init is active, set user-data (YAML format)'
,
verbose_name
=
'ci_user_data'
),
),
]
circle/vm/models/instance.py
View file @
e837067b
...
...
@@ -117,9 +117,9 @@ class VirtualMachineDescModel(BaseResourceConfigModel):
help_text
=
_
(
'VM use cloud-init, set user- and meta-data below'
))
ci_meta_data
=
TextField
(
verbose_name
=
_
(
'ci_meta_data'
),
blank
=
True
,
help_text
=
_
(
'When cloud-init is active, set meta-data (YAML format)'
))
'When cloud-init is active, set meta-data (YAML format)'
)
,
default
=
'empty'
)
ci_user_data
=
TextField
(
verbose_name
=
_
(
'ci_user_data'
),
blank
=
True
,
help_text
=
_
(
'When cloud-init is active, set user-data (YAML format)'
))
'When cloud-init is active, set user-data (YAML format)'
)
,
default
=
'empty'
)
req_traits
=
ManyToManyField
(
Trait
,
blank
=
True
,
help_text
=
_
(
"A set of traits required for a "
"node to declare to be suitable "
...
...
circle/vm/operations.py
View file @
e837067b
...
...
@@ -21,6 +21,7 @@ from io import StringIO
from
base64
import
encodestring
from
hashlib
import
md5
from
logging
import
getLogger
import
logging
from
string
import
ascii_lowercase
from
tarfile
import
TarFile
,
TarInfo
from
urllib.parse
import
urlsplit
...
...
@@ -435,6 +436,9 @@ class DeployOperation(InstanceOperation):
else
:
self
.
instance
.
allocate_node
()
if
self
.
instance
.
cloud_init
:
self
.
instance
.
_create_ci_image
(
parent_activity
=
activity
)
# Deploy virtual images
try
:
self
.
instance
.
_deploy_disks
(
parent_activity
=
activity
)
...
...
@@ -483,6 +487,22 @@ class DeployOperation(InstanceOperation):
node
=
self
.
instance
.
node
)
@register_operation
class
CreateCloudInitImage
(
SubOperationMixin
,
InstanceOperation
):
id
=
"_create_ci_image"
name
=
_
(
"create cloud-init image"
)
description
=
_
(
"create cloud init iso from user and meta-data"
)
acl_level
=
"owner"
def
_operation
(
self
,
user
,
activity
,
name
=
None
):
logger
.
info
(
'create ci image'
)
disk
=
Disk
.
create_ci_disk
(
meta_data
=
self
.
instance
.
ci_meta_data
,
user_data
=
self
.
instance
.
ci_user_data
)
disk
.
full_clean
()
disk
.
save
()
self
.
instance
.
disks
.
add
(
disk
)
# self.instance._attach_disk(disk=disk, parent_activity=activity)
@register_operation
class
DeployDisksOperation
(
SubOperationMixin
,
InstanceOperation
):
id
=
"_deploy_disks"
name
=
_
(
"deploy disks"
)
...
...
@@ -815,7 +835,11 @@ class SaveAsTemplateOperation(InstanceOperation):
'ram_size'
:
self
.
instance
.
ram_size
,
'raw_data'
:
self
.
instance
.
raw_data
,
'system'
:
self
.
instance
.
system
,
'cloud_init'
:
self
.
instance
.
cloud_init
,
'ci_meta_data'
:
self
.
instance
.
ci_meta_data
,
'ci_user_data'
:
self
.
instance
.
ci_user_data
,
}
print
(
params
)
params
.
update
(
kwargs
)
params
.
pop
(
"parent_activity"
,
None
)
...
...
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