Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE3
/
balancer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
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
ab22253e
authored
Sep 13, 2023
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update dc stats
parent
0af3e59f
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
2 deletions
+54
-2
core/models.py
+8
-0
main.py
+18
-0
sredis/models.py
+8
-0
sredis/sredis.py
+20
-2
No files found.
core/models.py
View file @
ab22253e
...
@@ -44,3 +44,11 @@ class ResourcePoolSchema(BaseModel):
...
@@ -44,3 +44,11 @@ class ResourcePoolSchema(BaseModel):
class
VMFromRP
(
BaseModel
):
class
VMFromRP
(
BaseModel
):
rpname
:
str
=
Field
(
min_length
=
3
,
max_length
=
50
)
rpname
:
str
=
Field
(
min_length
=
3
,
max_length
=
50
)
username
:
str
=
Field
()
username
:
str
=
Field
()
class
ResourceStat
(
BaseModel
):
datacenter_name
:
str
mem_max
:
int
mem_used
:
int
cpu_usage
:
float
vm_count
:
int
main.py
View file @
ab22253e
...
@@ -10,7 +10,9 @@ from sredis.sredis import (
...
@@ -10,7 +10,9 @@ from sredis.sredis import (
create_superpuser
,
create_superpuser
,
get_rtokens
,
get_rtokens
,
reset
,
reset
,
update_datacenter_stats
,
update_datacenter_status
,
update_datacenter_status
,
update_stats
,
)
)
import
logging
import
logging
import
requests
import
requests
...
@@ -21,6 +23,7 @@ from core.models import (
...
@@ -21,6 +23,7 @@ from core.models import (
UserLoginSchema
,
UserLoginSchema
,
DataCenterSchema
,
DataCenterSchema
,
ResourcePoolSchema
,
ResourcePoolSchema
,
ResourceStat
,
)
)
from
core.auth
import
signJWT
from
core.auth
import
signJWT
from
core.bearer
import
get_current_user
,
admin_user
from
core.bearer
import
get_current_user
,
admin_user
...
@@ -108,6 +111,15 @@ def set_tokens(tokens: List[Token] = None, username=Depends(get_current_user)):
...
@@ -108,6 +111,15 @@ def set_tokens(tokens: List[Token] = None, username=Depends(get_current_user)):
return
tokens
return
tokens
@app.post
(
"/updatestat/"
)
def
update_datacenter_stat
(
stats
:
List
[
ResourceStat
]
=
None
,
username
=
Depends
(
admin_user
)
):
for
stat
in
stats
:
update_stats
(
stat
)
return
stats
@app.get
(
"/tokens/"
)
@app.get
(
"/tokens/"
)
def
get_tokens
(
username
=
Depends
(
get_current_user
)):
def
get_tokens
(
username
=
Depends
(
get_current_user
)):
return
get_rtokens
(
username
=
username
)
return
get_rtokens
(
username
=
username
)
...
@@ -117,3 +129,9 @@ def get_tokens(username=Depends(get_current_user)):
...
@@ -117,3 +129,9 @@ def get_tokens(username=Depends(get_current_user)):
@repeat_every
(
seconds
=
300
)
@repeat_every
(
seconds
=
300
)
def
update_datacenter_healt
():
def
update_datacenter_healt
():
update_datacenter_status
()
update_datacenter_status
()
@app.on_event
(
"startup"
)
@repeat_every
(
seconds
=
200
)
def
update_datacenter_stats_rep
():
update_datacenter_stats
()
sredis/models.py
View file @
ab22253e
...
@@ -20,3 +20,11 @@ class ResourcePool(HashModel):
...
@@ -20,3 +20,11 @@ class ResourcePool(HashModel):
owner
:
str
=
Field
(
default
=
""
)
owner
:
str
=
Field
(
default
=
""
)
datacenter
:
str
=
Field
(
default
=
""
)
datacenter
:
str
=
Field
(
default
=
""
)
id
:
int
=
Field
()
id
:
int
=
Field
()
class
DataCenterResource
(
HashModel
):
datacenter_name
:
str
=
Field
(
index
=
True
)
mem_max
:
int
=
Field
()
mem_used
:
int
=
Field
()
cpu_usage
:
float
=
Field
()
vm_count
:
int
=
Field
()
sredis/sredis.py
View file @
ab22253e
import
redis
import
redis
import
requests
import
requests
from
core.models
import
UserLoginSchema
from
core.models
import
UserLoginSchema
,
ResourceStat
from
.models
import
PUser
from
.models
import
PUser
,
DataCenterResource
from
passlib.hash
import
pbkdf2_sha256
from
passlib.hash
import
pbkdf2_sha256
from
core.models
import
User
,
DataCenterSchema
from
core.models
import
User
,
DataCenterSchema
from
core.auth
import
hash_pass
from
core.auth
import
hash_pass
...
@@ -56,6 +56,13 @@ def update_datacenter_status():
...
@@ -56,6 +56,13 @@ def update_datacenter_status():
update_status
(
datacenter
=
dc
)
update_status
(
datacenter
=
dc
)
def
update_datacenter_stats
():
logging
.
info
(
"Update datacenters stats"
)
all_keys
=
r
.
hgetall
(
"datacenters_hash"
)
for
dc
in
all_keys
.
values
():
logging
.
info
(
"Get stats from"
,
dc
)
def
add_datacenter
(
datacenter
:
str
):
def
add_datacenter
(
datacenter
:
str
):
cnt
=
int
(
r
.
get
(
"datacenters_cnt"
))
cnt
=
int
(
r
.
get
(
"datacenters_cnt"
))
r
.
hset
(
"datacenters_hash"
,
cnt
,
datacenter
)
r
.
hset
(
"datacenters_hash"
,
cnt
,
datacenter
)
...
@@ -128,3 +135,14 @@ def create_superpuser(user: User):
...
@@ -128,3 +135,14 @@ def create_superpuser(user: User):
puser
.
save
()
puser
.
save
()
return
True
return
True
return
False
return
False
def
update_stats
(
stat
:
ResourceStat
):
dc
=
DataCenterResource
.
find
(
DataCenterResource
.
datacenter_name
==
stat
.
datacenter_name
)
.
all
()
if
not
dc
:
dc
=
DataCenterResource
(
**
stat
)
else
:
dc
.
update
(
**
stat
)
dc
.
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