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
4c1a75d2
authored
Oct 23, 2022
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'webhook-iac' into 'master'
Webhook iac See merge request
!21
parents
aa2237b4
3d3c1adb
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
24 additions
and
13 deletions
+24
-13
circle/dashboard/serializers.py
+5
-0
circle/dashboard/static/dashboard/dashboard.css
+0
-0
circle/dashboard/views/vm.py
+4
-1
circle/storage/models.py
+2
-2
circle/storage/tasks/storage_tasks.py
+4
-1
circle/vm/models/instance.py
+6
-7
circle/vm/tasks/local_tasks.py
+3
-2
No files found.
circle/dashboard/serializers.py
View file @
4c1a75d2
from
typing_extensions
import
Required
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework
import
serializers
from
django.contrib.auth.models
import
Group
,
User
...
...
@@ -161,6 +162,10 @@ class ResizeDiskSerializer(serializers.Serializer):
class
DownloadDiskSerializer
(
serializers
.
Serializer
):
url
=
serializers
.
CharField
(
max_length
=
500
)
name
=
serializers
.
CharField
(
max_length
=
100
)
resize
=
serializers
.
CharField
(
max_length
=
30
,
required
=
False
,
allow_blank
=
True
,
default
=
None
)
class
Meta
:
extra_kwargs
=
{
'resize'
:
{
'required'
:
False
,
'allow_blank'
:
True
,
'allow_empty'
:
True
}}
class
CreateTemplateSerializer
(
serializers
.
Serializer
):
name
=
serializers
.
CharField
(
max_length
=
100
)
...
...
circle/dashboard/static/dashboard/dashboard.css
View file @
4c1a75d2
circle/dashboard/views/vm.py
View file @
4c1a75d2
...
...
@@ -152,8 +152,11 @@ class DownloadPersistentDiskREST(APIView):
if
serializer
.
is_valid
():
disk_url
=
str
(
data
[
'url'
])
disk_name
=
str
(
data
[
'name'
])
resize
=
None
if
'resize'
in
data
:
resize
=
str
(
data
[
'resize'
])
store_act
=
StorageActivity
.
create
(
code_suffix
=
"download_disk"
,
user
=
request
.
user
)
abortable_async_downloaddisk_operation
.
apply_async
(
args
=
(
store_act
.
id
,
disk_url
,
disk_name
),
queue
=
'localhost.man.slow'
)
abortable_async_downloaddisk_operation
.
apply_async
(
args
=
(
store_act
.
id
,
disk_url
,
disk_name
,
resize
),
queue
=
'localhost.man.slow'
)
serializer
=
StorageActivitySerializer
(
store_act
,
many
=
False
)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
...
...
circle/storage/models.py
View file @
4c1a75d2
...
...
@@ -469,7 +469,7 @@ class Disk(TimeStampedModel):
return
disk
@classmethod
def
download
(
cls
,
url
,
task
,
user
=
None
,
**
params
):
def
download
(
cls
,
url
,
task
,
user
=
None
,
resize
=
None
,
**
params
):
"""Create disk object and download data from url synchronusly.
:param url: image url to download.
...
...
@@ -491,7 +491,7 @@ class Disk(TimeStampedModel):
queue_name
=
disk
.
get_remote_queue_name
(
'storage'
,
priority
=
'slow'
)
remote
=
storage_tasks
.
download
.
apply_async
(
kwargs
=
{
'url'
:
url
,
'parent_id'
:
task
.
request
.
id
,
'disk'
:
disk
.
get_disk_desc
()},
'disk'
:
disk
.
get_disk_desc
()
,
'resize'
:
resize
},
queue
=
queue_name
)
result
=
cls
.
_run_abortable_task
(
remote
,
task
)
disk
.
size
=
result
[
'size'
]
...
...
circle/storage/tasks/storage_tasks.py
View file @
4c1a75d2
...
...
@@ -37,9 +37,12 @@ def create(disk_desc):
def
create_ci_disk
(
disk_desc
,
meta_data
,
user_data
,
network_data
):
pass
@celery.task
(
name
=
'storagedriver.resizeqemu'
)
def
resizeqemu
(
disk_desc
,
newsize
):
pass
@celery.task
(
name
=
'storagedriver.download'
)
def
download
(
disk_desc
,
url
):
def
download
(
disk_desc
,
url
,
resize
):
pass
...
...
circle/vm/models/instance.py
View file @
4c1a75d2
...
...
@@ -104,12 +104,11 @@ chpasswd:
"""
.
strip
()
CI_NETWORK_CONFIG_DEF
=
"""
network:
version: 2
ethernets:
version: 2
ethernets:
ens3:
match:
macaddress: {{ net.mac }}
macaddress: '{{ net.mac }}'
addresses:
- {{ net.ipv4 }}/{{ net.mask4 }}
gateway4: {{ net.gateway4 }}
...
...
@@ -319,13 +318,13 @@ class NetTemplate:
self
.
name
=
str
(
net
.
vlan
.
name
)
self
.
gateway4
=
str
(
net
.
vlan
.
network4
)
.
split
(
"/"
)[
0
]
self
.
mask4
=
str
(
net
.
vlan
.
network4
)
.
split
(
"/"
)[
1
]
self
.
mac
=
str
(
net
.
host
.
mac
)
self
.
mac
=
str
(
net
.
host
.
mac
)
.
lower
()
def
__init__
(
self
,
instance
):
self
.
vlans
=
list
(
NetTemplate
.
Host
(
net
)
for
net
in
instance
.
interface_set
.
all
()
if
net
.
host
)
self
.
ipv4
=
str
(
instance
.
ipv4
)
self
.
ipv6
=
str
(
instance
.
ipv6
)
self
.
mac
=
str
(
instance
.
mac
)
self
.
mac
=
str
(
instance
.
mac
)
.
lower
()
if
instance
.
primary_host
:
addr
=
str
(
instance
.
primary_host
.
vlan
.
network4
)
.
split
(
"/"
)
self
.
gateway4
=
addr
[
0
]
...
...
@@ -501,7 +500,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
if
self
.
hookurl
:
logger
.
info
(
"notify remote host (callhookurl): "
+
str
(
self
.
hookurl
))
try
:
req
.
post
(
url
=
str
(
self
.
hookurl
))
req
.
post
(
url
=
str
(
self
.
hookurl
,
json
=
{
id
:
self
.
id
}
))
except
:
logger
.
info
(
"Error when call hookurl: "
+
str
(
self
.
hookurl
))
...
...
circle/vm/tasks/local_tasks.py
View file @
4c1a75d2
...
...
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
from
ctypes
import
resize
from
datetime
import
timezone
from
celery.contrib.abortable
import
AbortableTask
from
common.models
import
ActivityModel
...
...
@@ -59,12 +60,12 @@ def abortable_async_node_operation(task, operation_id, node_pk, activity_pk,
@celery.task
(
base
=
AbortableTask
,
bind
=
True
)
def
abortable_async_downloaddisk_operation
(
task
,
activity_pk
,
url
,
name
):
def
abortable_async_downloaddisk_operation
(
task
,
activity_pk
,
url
,
name
,
resize
):
activity
=
StorageActivity
.
objects
.
get
(
pk
=
activity_pk
)
activity
.
task_uuid
=
task
.
request
.
id
activity
.
save
()
disk
=
Disk
.
download
(
url
=
url
,
name
=
name
,
task
=
task
)
disk
=
Disk
.
download
(
url
=
url
,
name
=
name
,
task
=
task
,
resize
=
resize
)
disk
.
dev_num
=
'g'
disk
.
full_clean
()
disk
.
save
()
...
...
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