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
0c41ced7
authored
Sep 21, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add vlans to rest
parent
bca0eb03
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
7 deletions
+29
-7
circle/dashboard/serializers.py
+11
-2
circle/dashboard/views/vm.py
+18
-5
No files found.
circle/dashboard/serializers.py
View file @
0c41ced7
...
...
@@ -3,9 +3,14 @@ from rest_framework import serializers
from
django.contrib.auth.models
import
Group
,
User
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Interface
,
Node
,
InstanceActivity
from
firewall.models
import
Vlan
from
firewall.models
import
Vlan
,
Rule
from
storage.models
import
Disk
,
StorageActivity
class
RuleSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Rule
fields
=
'__all__'
class
InstanceActivitySerializer
(
serializers
.
ModelSerializer
):
get_percentage
=
serializers
.
IntegerField
()
result_data
=
serializers
.
JSONField
()
...
...
@@ -65,6 +70,7 @@ class DiskSerializer(serializers.ModelSerializer):
class
InstanceSerializer
(
serializers
.
ModelSerializer
):
ipv4addr
=
serializers
.
SerializerMethodField
(
'get_ipv4'
)
ipv6addr
=
serializers
.
SerializerMethodField
(
'get_ipv6'
)
vlans
=
serializers
.
SerializerMethodField
(
'get_vlans'
)
def
get_ipv4
(
self
,
i
):
return
str
(
i
.
ipv4
)
...
...
@@ -72,11 +78,14 @@ class InstanceSerializer(serializers.ModelSerializer):
def
get_ipv6
(
self
,
i
):
return
str
(
i
.
ipv6
)
def
get_vlans
(
self
,
i
):
return
list
(
net
.
vlan
.
id
for
net
in
i
.
interface_set
.
all
()
if
net
.
host
)
class
Meta
:
model
=
Instance
fields
=
[
'id'
,
'name'
,
'description'
,
'status'
,
'owner'
,
'access_method'
,
'boot_menu'
,
'pw'
,
'is_base'
,
'lease'
,
'raw_data'
,
'cloud_init'
,
'ci_meta_data'
,
'ci_user_data'
,
'system'
,
'req_traits'
,
'has_agent'
,
'num_cores'
,
'ram_size'
,
'max_ram_size'
,
'arch'
,
'priority'
,
'disks'
,
'node'
,
'ipv4addr'
,
'ipv6addr'
]
'has_agent'
,
'num_cores'
,
'ram_size'
,
'max_ram_size'
,
'arch'
,
'priority'
,
'disks'
,
'node'
,
'ipv4addr'
,
'ipv6addr'
,
'vlans'
]
extra_kwargs
=
{
'disks'
:
{
'required'
:
False
,
'allow_empty'
:
True
,},
'req_traits'
:
{
'required'
:
False
,
'allow_empty'
:
True
,}
...
...
circle/dashboard/views/vm.py
View file @
0c41ced7
...
...
@@ -48,7 +48,7 @@ from django.views.generic import (
from
braces.views
import
SuperuserRequiredMixin
,
LoginRequiredMixin
from
storage.tasks
import
storage_tasks
from
vm.tasks.local_tasks
import
abortable_async_downloaddisk_operation
from
vm.operations
import
(
DeployOperation
,
DestroyOperation
,
DownloadDiskOperation
,
ShutdownOperation
,
RenewOperation
,
from
vm.operations
import
(
DeployOperation
,
DestroyOperation
,
DownloadDiskOperation
,
RemovePortOperation
,
ShutdownOperation
,
RenewOperation
,
ResizeDiskOperation
,
RemoveDiskOperation
,
SleepOperation
,
WakeUpOperation
,
AddPortOperation
,
SaveAsTemplateOperation
,
)
...
...
@@ -105,7 +105,7 @@ from rest_framework.permissions import IsAdminUser
from
dashboard.serializers
import
(
CreateTemplateSerializer
,
DiskSerializer
,
InstanceSerializer
,
InterfaceSerializer
,
CreateDiskSerializer
,
DownloadDiskSerializer
,
VMDeploySerializer
,
VlanSerializer
,
ResizeDiskSerializer
,
InstanceActivitySerializer
,
DestroyDiskSerializer
,
StorageActivitySerializer
,
AddPortSerializer
,
AddPortSerializer
,
RuleSerializer
,
)
def
size_util
(
size
:
str
):
...
...
@@ -337,6 +337,10 @@ class SleepInstanceREST(APIView):
return
JsonResponse
(
serializer
.
data
,
safe
=
False
,
status
=
201
)
class
RulesREST
(
APIView
):
def
post
():
pass
class
SetupPortREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
...
...
@@ -350,12 +354,21 @@ class SetupPortREST(APIView):
if
addport
.
is_valid
():
AddPortOperation
(
instance
)
.
call
(
port
=
int
(
data
[
'port_destination'
]),
proto
=
str
(
data
[
'type'
]),
host
=
interface
.
host
,
user
=
request
.
user
)
rules
=
Rule
.
objects
.
filter
(
host
=
interface
.
host
)
return
JsonResponse
({},
status
=
201
)
serializer
=
RuleSerializer
(
rules
,
many
=
True
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
,
status
=
201
)
return
JsonResponse
({},
status
=
400
)
def
delete
(
self
,
request
,
vm_id
,
vlan_id
,
format
=
None
):
return
JsonResponse
({},
safe
=
False
,
status
=
204
)
instance
=
Instance
.
objects
.
get
(
pk
=
vm_id
)
data
=
JSONParser
()
.
parse
(
request
)
addport
=
AddPortSerializer
(
data
=
data
)
vlan
=
Vlan
.
objects
.
get
(
pk
=
vlan_id
)
interface
=
Interface
.
objects
.
filter
(
instance
=
instance
)
.
filter
(
vlan
=
vlan
)
.
get
()
if
addport
.
is_valid
():
rule
=
Rule
.
objects
.
filter
(
host
=
interface
.
host
)
.
filter
(
dport
=
int
(
data
[
'port_destination'
]))
.
filter
(
proto
=
str
(
data
[
'type'
]))
.
get
()
RemovePortOperation
(
instance
)
.
call
(
rule
=
rule
,
user
=
request
.
user
)
return
JsonResponse
({},
safe
=
False
,
status
=
204
)
return
JsonResponse
({},
status
=
400
)
class
WakeUpInstanceREST
(
APIView
):
...
...
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