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
80829ebb
authored
Aug 31, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create instances via rest and add disk
parent
bf49a963
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
34 deletions
+91
-34
circle/dashboard/serializers.py
+33
-1
circle/dashboard/urls.py
+4
-3
circle/dashboard/views/vm.py
+54
-30
circle/journalctl
+0
-0
No files found.
circle/dashboard/serializers.py
View file @
80829ebb
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework
import
serializers
from
vm.models
import
InstanceTemplate
,
Lease
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Interface
from
firewall.models
import
Vlan
from
storage.models
import
Disk
...
...
@@ -24,3 +25,33 @@ class DiskSerializer(serializers.ModelSerializer):
model
=
Disk
fields
=
[
'id'
,
'name'
,
'filename'
,
'datastore'
,
'type'
,
'bus'
,
'size'
,
'base'
,
'dev_num'
,
'destroyed'
,
'ci_disk'
,
'is_ready'
]
class
InstanceSerializer
(
serializers
.
ModelSerializer
):
ipv4addr
=
serializers
.
SerializerMethodField
(
'get_ipv4'
)
ipv6addr
=
serializers
.
SerializerMethodField
(
'get_ipv6'
)
def
get_ipv4
(
self
,
i
):
return
str
(
i
.
ipv4
)
def
get_ipv6
(
self
,
i
):
return
str
(
i
.
ipv6
)
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'
]
extra_kwargs
=
{
'disks'
:
{
'required'
:
False
}}
class
InterfaceSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Interface
fields
=
[
'id'
,
'vlan'
,
'host'
,
'instance'
,
'model'
]
class
VlanSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Vlan
fields
=
[
'id'
,
'vid'
,
'name'
,
'description'
,
'comment'
,
'domain'
]
\ No newline at end of file
circle/dashboard/urls.py
View file @
80829ebb
...
...
@@ -54,21 +54,22 @@ from .views import (
TransferTemplateOwnershipView
,
TransferTemplateOwnershipConfirmView
,
OpenSearchDescriptionView
,
NodeActivityView
,
UserList
,
TemplateREST
,
LeaseREST
,
DiskRest
,
UserList
,
TemplateREST
,
LeaseREST
,
DiskRest
,
InstanceREST
,
InterfaceREST
,
StorageDetail
,
DiskDetail
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
EnableTwoFactorView
,
DisableTwoFactorView
,
AclUserGroupAutocomplete
,
AclUserAutocomplete
,
RescheduleView
,
GroupImportView
,
GroupExportView
,
iac_vm_list
RescheduleView
,
GroupImportView
,
GroupExportView
,
)
from
.views.node
import
node_ops
from
.views.vm
import
vm_ops
,
vm_mass_ops
urlpatterns
=
[
path
(
'acpi/vm/'
,
iac_vm_list
),
path
(
'acpi/vm/'
,
InstanceREST
.
as_view
()
),
path
(
'acpi/template/'
,
TemplateREST
.
as_view
()),
path
(
'acpi/lease/'
,
LeaseREST
.
as_view
()),
path
(
'acpi/disk/'
,
DiskRest
.
as_view
()),
path
(
'acpi/interface/'
,
InterfaceREST
.
as_view
()),
url
(
r'^$'
,
IndexView
.
as_view
(),
name
=
"dashboard.index"
),
url
(
r"^profile/list/$"
,
UserList
.
as_view
(),
name
=
"dashboard.views.user-list"
),
...
...
circle/dashboard/views/vm.py
View file @
80829ebb
...
...
@@ -74,7 +74,7 @@ from ..forms import (
from
django.views.generic.edit
import
FormMixin
from
request.models
import
TemplateAccessType
,
LeaseType
from
request.forms
import
LeaseRequestForm
,
TemplateRequestForm
from
..models
import
Favourite
from
..models
import
Favourite
,
pwgen
from
manager.scheduler
import
has_traits
...
...
@@ -88,40 +88,64 @@ logger = logging.getLogger(__name__)
from
rest_framework
import
status
from
rest_framework.views
import
APIView
from
rest_framework.decorators
import
api_view
,
authentication_classes
,
permission_classes
from
rest_framework.
response
import
Response
from
rest_framework.authentication
import
TokenAuthentication
from
rest_framework.
parsers
import
JSONParser
from
rest_framework.authentication
import
TokenAuthentication
,
BasicAuthentication
from
rest_framework.permissions
import
IsAdminUser
@api_view
([
'GET'
])
@authentication_classes
([
TokenAuthentication
])
@permission_classes
([
IsAdminUser
])
def
iac_vm_list
(
request
):
instances
=
Instance
.
objects
.
all
()
instances
=
[{
'pk'
:
i
.
pk
,
'url'
:
reverse
(
'dashboard.views.detail'
,
args
=
[
i
.
pk
]),
'name'
:
i
.
name
,
'host'
:
i
.
short_hostname
,
'status'
:
i
.
get_status_display
(),
'owner'
:
(
i
.
owner
.
profile
.
get_display_name
()),
'node'
:
i
.
node
,
'timesuspend'
:
i
.
time_of_suspend
,
'timedelete'
:
i
.
time_of_delete
,
'timedestroy'
:
i
.
destroyed_at
,
'userdata'
:
i
.
get_user_data
,
'metadata'
:
i
.
get_meta_data
,
'template'
:
i
.
template
.
pk
if
i
.
template
else
None
,
'users'
:
list
({
'username'
:
u
.
username
,
'level'
:
l
}
for
u
,
l
in
i
.
get_users_with_level
()),
}
for
i
in
instances
]
return
Response
(
instances
)
from
dashboard.serializers
import
InstanceSerializer
,
InterfaceSerializer
@api_view
([
'POST'
])
@authentication_classes
([
TokenAuthentication
])
@permission_classes
([
IsAdminUser
])
def
iac_vm_create
(
request
):
return
Response
()
class
InterfaceREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
format
=
None
):
templates
=
Interface
.
objects
.
all
()
serializer
=
InterfaceSerializer
(
templates
,
many
=
True
)
return
JsonResponse
({
'interfaces'
:
serializer
.
data
},
safe
=
False
)
class
InstanceREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
format
=
None
):
templates
=
Instance
.
objects
.
all
()
serializer
=
InstanceSerializer
(
templates
,
many
=
True
)
return
JsonResponse
({
'instances'
:
serializer
.
data
},
safe
=
False
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
data
[
'pw'
]
=
pwgen
()
data
[
'status'
]
=
'STOPPED'
serializer
=
InstanceSerializer
(
data
=
data
)
if
serializer
.
is_valid
():
inst
=
serializer
.
save
()
networks
=
[]
for
v
in
data
[
'vlans'
]:
v
=
Vlan
.
objects
.
filter
(
vid
=
v
)
.
get
()
if
not
v
.
has_level
(
request
.
user
,
"user"
):
raise
PermissionDenied
()
networks
.
append
(
InterfaceTemplate
(
vlan
=
v
,
managed
=
v
.
managed
))
def
__on_commit
(
activity
):
activity
.
resultant_state
=
'PENDING'
with
inst
.
activity
(
code_suffix
=
'create'
,
readable_name
=
ugettext_noop
(
"create instance (REST)"
),
on_commit
=
__on_commit
,
user
=
inst
.
owner
)
as
act
:
for
net
in
networks
:
Interface
.
create
(
instance
=
inst
,
vlan
=
net
.
vlan
,
owner
=
inst
.
owner
,
managed
=
net
.
managed
,
base_activity
=
act
)
if
'create_disk'
in
data
:
inst
.
create_disk
(
size
=
data
[
'createdisk'
][
'size'
],
user
=
inst
.
owner
,
name
=
data
[
'createdisk'
][
'name'
],
activity
=
None
)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
VmDetailVncTokenView
(
CheckedDetailView
):
...
...
circle/journalctl
0 → 100644
View file @
80829ebb
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