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
7e3037d9
authored
Oct 10, 2022
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
variables
parent
ee30f76a
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
109 additions
and
7 deletions
+109
-7
circle/dashboard/serializers.py
+7
-0
circle/dashboard/templates/dashboard/template-edit.html
+1
-0
circle/dashboard/urls.py
+3
-0
circle/dashboard/views/util.py
+37
-1
circle/vm/admin.py
+3
-0
circle/vm/migrations/0014_auto_20221010_1442.py
+41
-0
circle/vm/models/common.py
+8
-0
circle/vm/models/instance.py
+9
-6
No files found.
circle/dashboard/serializers.py
View file @
7e3037d9
...
...
@@ -5,6 +5,7 @@ from django.contrib.auth.models import Group, User
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
,
Interface
,
Node
,
InstanceActivity
from
firewall.models
import
Vlan
,
Rule
from
storage.models
import
Disk
,
StorageActivity
from
vm.models.common
import
Variable
class
RuleSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
...
...
@@ -60,6 +61,12 @@ class LeaseSerializer(serializers.ModelSerializer):
fields
=
[
'id'
,
'name'
,
'suspend_interval_seconds'
,
'delete_interval_seconds'
]
class
VariableSerializer
(
serializers
.
HyperlinkedModelSerializer
):
class
Meta
:
model
=
Variable
fields
=
[
'id'
,
'key'
,
'value'
,
'url'
]
class
DiskSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Disk
...
...
circle/dashboard/templates/dashboard/template-edit.html
View file @
7e3037d9
...
...
@@ -59,6 +59,7 @@
</div>
{{ form.cloud_init|as_crispy_field }}
{{ form.ci_meta_data|as_crispy_field }}
{{ form.ci_network_config|as_crispy_field }}
{{ form.ci_user_data|as_crispy_field }}
</fieldset>
<fieldset>
...
...
circle/dashboard/urls.py
View file @
7e3037d9
...
...
@@ -68,6 +68,7 @@ from .views import (
EnableTwoFactorView
,
DisableTwoFactorView
,
AclUserGroupAutocomplete
,
AclUserAutocomplete
,
RescheduleView
,
GroupImportView
,
GroupExportView
,
VariableREST
,
GetVariableREST
,
)
from
.views.node
import
node_ops
,
NodeREST
,
GetNodeREST
from
.views.vm
import
vm_ops
,
vm_mass_ops
...
...
@@ -83,6 +84,8 @@ urlpatterns = [
path
(
'acpi/group/'
,
GroupREST
.
as_view
()),
path
(
'acpi/group/<int:pk>/'
,
GetGroupREST
.
as_view
()),
path
(
'acpi/vm/'
,
InstanceREST
.
as_view
()),
path
(
'acpi/var/'
,
VariableREST
.
as_view
()),
path
(
'acpi/var/<int:pk>/'
,
GetVariableREST
.
as_view
(),
name
=
'variable-detail'
),
path
(
'acpi/node/'
,
NodeREST
.
as_view
()),
path
(
'acpi/node/<int:pk>/'
,
GetNodeREST
.
as_view
()),
path
(
'acpi/vm/<int:pk>/'
,
GetInstanceREST
.
as_view
()),
...
...
circle/dashboard/views/util.py
View file @
7e3037d9
...
...
@@ -18,6 +18,7 @@
import
json
import
logging
from
multiprocessing
import
context
import
re
from
collections
import
OrderedDict
from
urllib.parse
import
urljoin
...
...
@@ -56,9 +57,10 @@ from rest_framework.views import APIView
from
rest_framework.parsers
import
JSONParser
from
rest_framework.authentication
import
TokenAuthentication
,
BasicAuthentication
from
rest_framework.permissions
import
IsAdminUser
from
vm.models.common
import
Variable
from
storage.models
import
StorageActivity
from
dashboard.serializers
import
InstanceActivitySerializer
,
StorageActivitySerializer
from
dashboard.serializers
import
InstanceActivitySerializer
,
StorageActivitySerializer
,
VariableSerializer
from
common.models
import
HumanReadableException
,
HumanReadableObject
from
..models
import
GroupProfile
,
Profile
...
...
@@ -107,6 +109,40 @@ class GetStorageActivityREST(APIView):
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
VariableREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
format
=
None
):
if
request
.
query_params
.
get
(
'key'
):
try
:
template
=
Variable
.
objects
.
filter
(
key__istartswith
=
request
.
query_params
.
get
(
'key'
))
.
get
()
serializer
=
VariableSerializer
(
template
,
many
=
False
,
context
=
{
'request'
:
request
})
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
except
:
return
JsonResponse
({},
status
=
404
)
templates
=
Variable
.
objects
.
all
()
serializer
=
VariableSerializer
(
templates
,
many
=
True
,
context
=
{
'request'
:
request
})
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
def
post
(
self
,
request
,
format
=
None
):
data
=
JSONParser
()
.
parse
(
request
)
serializer
=
VariableSerializer
(
data
=
data
)
if
serializer
.
is_valid
():
serializer
.
save
()
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
class
GetVariableREST
(
APIView
):
authentication_classes
=
[
TokenAuthentication
,
BasicAuthentication
]
permission_classes
=
[
IsAdminUser
]
def
get
(
self
,
request
,
pk
,
format
=
None
):
act
=
Variable
.
objects
.
get
(
pk
=
pk
)
serializer
=
VariableSerializer
(
act
,
many
=
False
,
context
=
{
'request'
:
request
})
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
class
RedirectToLoginMixin
(
AccessMixin
):
redirect_exception_classes
=
(
PermissionDenied
,
)
...
...
circle/vm/admin.py
View file @
7e3037d9
...
...
@@ -17,6 +17,8 @@
from
django.contrib
import
admin
from
.models.common
import
Variable
from
.models
import
(
Instance
,
InstanceActivity
,
InstanceTemplate
,
Interface
,
InterfaceTemplate
,
Lease
,
NamedBaseResourceConfig
,
Node
,
NodeActivity
,
Trait
)
...
...
@@ -36,3 +38,4 @@ admin.site.register(NamedBaseResourceConfig)
admin
.
site
.
register
(
Node
)
admin
.
site
.
register
(
NodeActivity
)
admin
.
site
.
register
(
Trait
)
admin
.
site
.
register
(
Variable
)
circle/vm/migrations/0014_auto_20221010_1442.py
0 → 100644
View file @
7e3037d9
# Generated by Django 3.2.3 on 2022-10-10 14:42
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'vm'
,
'0013_auto_20221006_1509'
),
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Variable'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'key'
,
models
.
CharField
(
max_length
=
100
,
unique
=
True
,
verbose_name
=
'variable name'
)),
(
'value'
,
models
.
CharField
(
max_length
=
150
,
verbose_name
=
'variable value'
)),
],
),
migrations
.
AlterField
(
model_name
=
'instance'
,
name
=
'ci_network_config'
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
'network:
\n
version: 2
\n
ethernets:
\n
ens3:
\n
match:
\n
macaddress: {{ net.mac }}
\n
addresses:
\n
- {{ net.ipv4 }}/24
\n
gateway4: ipv4
\n
nameservers:
\n
addresses:
\n
- 8.8.8.8'
,
help_text
=
'When cloud-init is active, set network-config(YAML format)'
,
verbose_name
=
'CI Network Data'
),
),
migrations
.
AlterField
(
model_name
=
'instance'
,
name
=
'ci_user_data'
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
"#cloud-config
\n\n
ssh_pwauth: 1
\n\n
users:
\n
- name: {{ sysuser }}
\n
sudo: ['ALL=(ALL) NOPASSWD:ALL']
\n
groups: sudo
\n
shell: /bin/bash
\n
chpasswd: { expire: False }
\n
lock-passwd: false
\n
chpasswd:
\n
list: |
\n
{{ sysuser }}:{{ password }}
\n
expire: False"
,
help_text
=
'When cloud-init is active, set user-data (YAML format)'
,
verbose_name
=
'CI User Data'
),
),
migrations
.
AlterField
(
model_name
=
'instancetemplate'
,
name
=
'ci_network_config'
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
'network:
\n
version: 2
\n
ethernets:
\n
ens3:
\n
match:
\n
macaddress: {{ net.mac }}
\n
addresses:
\n
- {{ net.ipv4 }}/24
\n
gateway4: ipv4
\n
nameservers:
\n
addresses:
\n
- 8.8.8.8'
,
help_text
=
'When cloud-init is active, set network-config(YAML format)'
,
verbose_name
=
'CI Network Data'
),
),
migrations
.
AlterField
(
model_name
=
'instancetemplate'
,
name
=
'ci_user_data'
,
field
=
models
.
TextField
(
blank
=
True
,
default
=
"#cloud-config
\n\n
ssh_pwauth: 1
\n\n
users:
\n
- name: {{ sysuser }}
\n
sudo: ['ALL=(ALL) NOPASSWD:ALL']
\n
groups: sudo
\n
shell: /bin/bash
\n
chpasswd: { expire: False }
\n
lock-passwd: false
\n
chpasswd:
\n
list: |
\n
{{ sysuser }}:{{ password }}
\n
expire: False"
,
help_text
=
'When cloud-init is active, set user-data (YAML format)'
,
verbose_name
=
'CI User Data'
),
),
]
circle/vm/models/common.py
View file @
7e3037d9
...
...
@@ -33,6 +33,14 @@ ARCHITECTURES = (('x86_64', 'x86-64 (64 bit)'),
(
'i686'
,
'x86 (32 bit)'
))
class
Variable
(
Model
):
key
=
CharField
(
verbose_name
=
'variable name'
,
unique
=
True
,
max_length
=
100
)
value
=
CharField
(
verbose_name
=
'variable value'
,
max_length
=
150
)
def
__str__
(
self
):
return
self
.
key
class
BaseResourceConfigModel
(
Model
):
"""Abstract base for models with base resource configuration parameters.
...
...
circle/vm/models/instance.py
View file @
7e3037d9
...
...
@@ -61,7 +61,7 @@ from common.models import (
from
common.operations
import
OperatedMixin
from
..tasks
import
agent_tasks
from
.activity
import
(
ActivityInProgressError
,
InstanceActivity
)
from
.common
import
BaseResourceConfigModel
,
Lease
from
.common
import
BaseResourceConfigModel
,
Lease
,
Variable
from
.network
import
Interface
from
.node
import
Node
,
Trait
...
...
@@ -109,9 +109,9 @@ network:
ethernets:
ens3:
match:
macaddress:
'mac'
macaddress:
{{ net.mac }}
addresses:
-
ipv4
/24
-
{{ net.ipv4 }}
/24
gateway4: ipv4
nameservers:
addresses:
...
...
@@ -323,9 +323,7 @@ class NetTemplate:
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
)
.
lower
()
self
.
mac
=
str
(
instance
.
mac
)
class
Instance
(
AclBase
,
VirtualMachineDescModel
,
StatusModel
,
OperatedMixin
,
...
...
@@ -447,6 +445,10 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
return
self
.
status
def
get_ci_data_dict
(
self
):
list
=
Variable
.
objects
.
all
()
vars
=
{
}
for
var
in
list
:
vars
[
var
.
key
]
=
var
.
value
datas
=
{
"sysuser"
:
"cloud"
,
"hostname"
:
self
.
short_hostname
,
...
...
@@ -456,6 +458,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
"acl"
:
AclTemplate
(
self
),
"ssh"
:
SSHKeyTemplate
(
self
),
"ci"
:
CITemplate
(),
"variables"
:
vars
,
}
return
datas
...
...
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