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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
8b5c4576
authored
Jul 22, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ci text processing
parent
6160c35e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
4 deletions
+38
-4
circle/vm/models/instance.py
+36
-2
circle/vm/operations.py
+2
-2
No files found.
circle/vm/models/instance.py
View file @
8b5c4576
...
@@ -37,6 +37,8 @@ from django.urls import reverse
...
@@ -37,6 +37,8 @@ from django.urls import reverse
from
django.utils
import
timezone
from
django.utils
import
timezone
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
django.utils.translation
import
ugettext_lazy
as
_
,
ugettext_noop
from
passlib.hash
import
sha512_crypt
from
model_utils
import
Choices
from
model_utils
import
Choices
from
model_utils.managers
import
QueryManager
from
model_utils.managers
import
QueryManager
from
model_utils.models
import
TimeStampedModel
,
StatusModel
from
model_utils.models
import
TimeStampedModel
,
StatusModel
...
@@ -67,6 +69,25 @@ ACCESS_PROTOCOLS = django.conf.settings.VM_ACCESS_PROTOCOLS
...
@@ -67,6 +69,25 @@ ACCESS_PROTOCOLS = django.conf.settings.VM_ACCESS_PROTOCOLS
ACCESS_METHODS
=
[(
key
,
name
)
for
key
,
(
name
,
port
,
transport
)
ACCESS_METHODS
=
[(
key
,
name
)
for
key
,
(
name
,
port
,
transport
)
in
list
(
ACCESS_PROTOCOLS
.
items
())]
in
list
(
ACCESS_PROTOCOLS
.
items
())]
CI_META_DATA_DEF
=
"""
instance-id: {{hostname}}
local-hostname: {{hostname}}
"""
.
strip
()
CI_USER_DATA_DEF
=
"""
#cloud-config
users:
- default
- name: {{user}}
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash
ssh_pwauth: True
chpasswd: { expire: False }
lock-passwd: false
passwd: "{{password}}"
"""
.
strip
()
try
:
try
:
# Python 2: "unicode" is built-in
# Python 2: "unicode" is built-in
...
@@ -117,9 +138,9 @@ class VirtualMachineDescModel(BaseResourceConfigModel):
...
@@ -117,9 +138,9 @@ class VirtualMachineDescModel(BaseResourceConfigModel):
help_text
=
_
(
help_text
=
_
(
'VM use cloud-init, set user- and meta-data below'
))
'VM use cloud-init, set user- and meta-data below'
))
ci_meta_data
=
TextField
(
verbose_name
=
_
(
'ci_meta_data'
),
blank
=
True
,
help_text
=
_
(
ci_meta_data
=
TextField
(
verbose_name
=
_
(
'ci_meta_data'
),
blank
=
True
,
help_text
=
_
(
'When cloud-init is active, set meta-data (YAML format)'
),
default
=
'empty'
)
'When cloud-init is active, set meta-data (YAML format)'
),
default
=
CI_META_DATA_DEF
)
ci_user_data
=
TextField
(
verbose_name
=
_
(
'ci_user_data'
),
blank
=
True
,
help_text
=
_
(
ci_user_data
=
TextField
(
verbose_name
=
_
(
'ci_user_data'
),
blank
=
True
,
help_text
=
_
(
'When cloud-init is active, set user-data (YAML format)'
),
default
=
'empty'
)
'When cloud-init is active, set user-data (YAML format)'
),
default
=
CI_USER_DATA_DEF
)
req_traits
=
ManyToManyField
(
Trait
,
blank
=
True
,
req_traits
=
ManyToManyField
(
Trait
,
blank
=
True
,
help_text
=
_
(
"A set of traits required for a "
help_text
=
_
(
"A set of traits required for a "
"node to declare to be suitable "
"node to declare to be suitable "
...
@@ -341,6 +362,19 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
...
@@ -341,6 +362,19 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
DeprecationWarning
)
DeprecationWarning
)
return
self
.
status
return
self
.
status
@property
def
get_user_data
(
self
):
passwd
=
sha512_crypt
.
hash
(
self
.
pw
)
user
=
'cloud'
data
=
str
(
self
.
ci_user_data
)
.
replace
(
'{{user}}'
,
user
)
data
=
data
.
replace
(
'{{password}}'
,
passwd
)
return
data
@property
def
get_meta_data
(
self
):
data
=
str
(
self
.
ci_user_data
)
.
replace
(
'{{hostname}}'
,
self
.
short_hostname
)
return
data
def
_update_status
(
self
):
def
_update_status
(
self
):
"""Set the proper status of the instance to Instance.status.
"""Set the proper status of the instance to Instance.status.
"""
"""
...
...
circle/vm/operations.py
View file @
8b5c4576
...
@@ -500,8 +500,8 @@ class DeployOperation(InstanceOperation):
...
@@ -500,8 +500,8 @@ class DeployOperation(InstanceOperation):
def
_operation
(
self
,
user
,
activity
,
name
=
None
):
def
_operation
(
self
,
user
,
activity
,
name
=
None
):
logger
.
info
(
'create ci image'
)
logger
.
info
(
'create ci image'
)
disk
=
Disk
.
create_ci_disk
(
meta_data
=
self
.
instance
.
ci
_meta_data
,
disk
=
Disk
.
create_ci_disk
(
meta_data
=
self
.
instance
.
get
_meta_data
,
user_data
=
self
.
instance
.
ci
_user_data
)
user_data
=
self
.
instance
.
get
_user_data
)
disk
.
full_clean
()
disk
.
full_clean
()
disk
.
save
()
disk
.
save
()
self
.
instance
.
disks
.
add
(
disk
)
self
.
instance
.
disks
.
add
(
disk
)
...
...
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