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
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
94 additions
and
38 deletions
+94
-38
circle/dashboard/serializers.py
+34
-3
circle/dashboard/urls.py
+4
-3
circle/dashboard/views/vm.py
+56
-32
circle/journalctl
+0
-0
No files found.
circle/dashboard/serializers.py
View file @
80829ebb
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework
import
serializers
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
from
storage.models
import
Disk
...
@@ -23,4 +24,34 @@ class DiskSerializer(serializers.ModelSerializer):
...
@@ -23,4 +24,34 @@ class DiskSerializer(serializers.ModelSerializer):
class
Meta
:
class
Meta
:
model
=
Disk
model
=
Disk
fields
=
[
'id'
,
'name'
,
'filename'
,
'datastore'
,
'type'
,
'bus'
,
'size'
,
'base'
,
fields
=
[
'id'
,
'name'
,
'filename'
,
'datastore'
,
'type'
,
'bus'
,
'size'
,
'base'
,
'dev_num'
,
'destroyed'
,
'ci_disk'
,
'is_ready'
]
'dev_num'
,
'destroyed'
,
'ci_disk'
,
'is_ready'
]
\ No newline at end of file
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 (
...
@@ -54,21 +54,22 @@ from .views import (
TransferTemplateOwnershipView
,
TransferTemplateOwnershipConfirmView
,
TransferTemplateOwnershipView
,
TransferTemplateOwnershipConfirmView
,
OpenSearchDescriptionView
,
OpenSearchDescriptionView
,
NodeActivityView
,
NodeActivityView
,
UserList
,
TemplateREST
,
LeaseREST
,
DiskRest
,
UserList
,
TemplateREST
,
LeaseREST
,
DiskRest
,
InstanceREST
,
InterfaceREST
,
StorageDetail
,
DiskDetail
,
StorageDetail
,
DiskDetail
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
MessageList
,
MessageDetail
,
MessageCreate
,
MessageDelete
,
EnableTwoFactorView
,
DisableTwoFactorView
,
EnableTwoFactorView
,
DisableTwoFactorView
,
AclUserGroupAutocomplete
,
AclUserAutocomplete
,
AclUserGroupAutocomplete
,
AclUserAutocomplete
,
RescheduleView
,
GroupImportView
,
GroupExportView
,
iac_vm_list
RescheduleView
,
GroupImportView
,
GroupExportView
,
)
)
from
.views.node
import
node_ops
from
.views.node
import
node_ops
from
.views.vm
import
vm_ops
,
vm_mass_ops
from
.views.vm
import
vm_ops
,
vm_mass_ops
urlpatterns
=
[
urlpatterns
=
[
path
(
'acpi/vm/'
,
iac_vm_list
),
path
(
'acpi/vm/'
,
InstanceREST
.
as_view
()
),
path
(
'acpi/template/'
,
TemplateREST
.
as_view
()),
path
(
'acpi/template/'
,
TemplateREST
.
as_view
()),
path
(
'acpi/lease/'
,
LeaseREST
.
as_view
()),
path
(
'acpi/lease/'
,
LeaseREST
.
as_view
()),
path
(
'acpi/disk/'
,
DiskRest
.
as_view
()),
path
(
'acpi/disk/'
,
DiskRest
.
as_view
()),
path
(
'acpi/interface/'
,
InterfaceREST
.
as_view
()),
url
(
r'^$'
,
IndexView
.
as_view
(),
name
=
"dashboard.index"
),
url
(
r'^$'
,
IndexView
.
as_view
(),
name
=
"dashboard.index"
),
url
(
r"^profile/list/$"
,
UserList
.
as_view
(),
url
(
r"^profile/list/$"
,
UserList
.
as_view
(),
name
=
"dashboard.views.user-list"
),
name
=
"dashboard.views.user-list"
),
...
...
circle/dashboard/views/vm.py
View file @
80829ebb
...
@@ -74,7 +74,7 @@ from ..forms import (
...
@@ -74,7 +74,7 @@ from ..forms import (
from
django.views.generic.edit
import
FormMixin
from
django.views.generic.edit
import
FormMixin
from
request.models
import
TemplateAccessType
,
LeaseType
from
request.models
import
TemplateAccessType
,
LeaseType
from
request.forms
import
LeaseRequestForm
,
TemplateRequestForm
from
request.forms
import
LeaseRequestForm
,
TemplateRequestForm
from
..models
import
Favourite
from
..models
import
Favourite
,
pwgen
from
manager.scheduler
import
has_traits
from
manager.scheduler
import
has_traits
...
@@ -88,40 +88,64 @@ logger = logging.getLogger(__name__)
...
@@ -88,40 +88,64 @@ logger = logging.getLogger(__name__)
from
rest_framework
import
status
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.decorators
import
api_view
,
authentication_classes
,
permission_classes
from
rest_framework.
response
import
Response
from
rest_framework.
parsers
import
JSONParser
from
rest_framework.authentication
import
TokenAuthentication
from
rest_framework.authentication
import
TokenAuthentication
,
BasicAuthentication
from
rest_framework.permissions
import
IsAdminUser
from
rest_framework.permissions
import
IsAdminUser
@api_view
([
'GET'
])
from
dashboard.serializers
import
InstanceSerializer
,
InterfaceSerializer
@authentication_classes
([
TokenAuthentication
])
@permission_classes
([
IsAdminUser
])
def
iac_vm_list
(
request
):
class
InterfaceREST
(
APIView
):
instances
=
Instance
.
objects
.
all
()
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
instances
=
[{
permission_classes
=
[
IsAdminUser
]
'pk'
:
i
.
pk
,
'url'
:
reverse
(
'dashboard.views.detail'
,
args
=
[
i
.
pk
]),
def
get
(
self
,
request
,
format
=
None
):
'name'
:
i
.
name
,
templates
=
Interface
.
objects
.
all
()
'host'
:
i
.
short_hostname
,
serializer
=
InterfaceSerializer
(
templates
,
many
=
True
)
'status'
:
i
.
get_status_display
(),
return
JsonResponse
({
'interfaces'
:
serializer
.
data
},
safe
=
False
)
'owner'
:
(
i
.
owner
.
profile
.
get_display_name
()),
'node'
:
i
.
node
,
'timesuspend'
:
i
.
time_of_suspend
,
class
InstanceREST
(
APIView
):
'timedelete'
:
i
.
time_of_delete
,
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
'timedestroy'
:
i
.
destroyed_at
,
permission_classes
=
[
IsAdminUser
]
'userdata'
:
i
.
get_user_data
,
'metadata'
:
i
.
get_meta_data
,
def
get
(
self
,
request
,
format
=
None
):
'template'
:
i
.
template
.
pk
if
i
.
template
else
None
,
templates
=
Instance
.
objects
.
all
()
'users'
:
list
({
'username'
:
u
.
username
,
'level'
:
l
}
for
u
,
l
in
i
.
get_users_with_level
()),
serializer
=
InstanceSerializer
(
templates
,
many
=
True
)
}
for
i
in
instances
]
return
JsonResponse
({
'instances'
:
serializer
.
data
},
safe
=
False
)
return
Response
(
instances
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
@api_view
([
'POST'
])
data
[
'pw'
]
=
pwgen
()
@authentication_classes
([
TokenAuthentication
])
data
[
'status'
]
=
'STOPPED'
@permission_classes
([
IsAdminUser
])
serializer
=
InstanceSerializer
(
data
=
data
)
def
iac_vm_create
(
request
):
if
serializer
.
is_valid
():
return
Response
()
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
):
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