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
c5840072
authored
Nov 02, 2023
by
Karsa Zoltán István
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rp create and delete
parent
86a187cb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
6 deletions
+29
-6
balancer/util.py
+21
-4
main.py
+8
-2
sredis/sredis.py
+0
-0
No files found.
balancer/util.py
View file @
c5840072
...
...
@@ -11,6 +11,7 @@ from fastapi import HTTPException
import
requests
import
json
from
core.models
import
ResourcePoolSchema
from
sredis.models
import
ResourcePool
import
logging
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -97,14 +98,14 @@ def create_rp(username: str, rp: ResourcePoolSchema):
for
dc
,
cnt
in
rp
.
manual
.
items
():
for
_
in
range
(
cnt
):
try
:
create_vm_from_template
(
body
=
create_vm_from_template
(
dc
,
username
,
name
=
f
"{rp.rpname} #{id}"
,
template_name
=
rp
.
from_template
,
)
save_rpvm
(
rp
.
rpname
,
username
,
dc
,
id
,
rp
.
key
)
save_rpvm
(
rp
.
rpname
,
username
,
dc
,
body
[
"id"
]
,
rp
.
key
)
id
+=
1
except
Exception
:
...
...
@@ -119,14 +120,14 @@ def create_rp(username: str, rp: ResourcePoolSchema):
cnt
=
int
(
frac
*
ram
/
details
[
"ram_size"
])
for
_
in
range
(
cnt
):
try
:
create_vm_from_template
(
body
=
create_vm_from_template
(
dc
,
username
,
name
=
f
"{rp.rpname} #{id}"
,
template_name
=
rp
.
from_template
,
)
save_rpvm
(
rp
.
rpname
,
username
,
dc
,
id
,
rp
.
key
)
save_rpvm
(
rp
.
rpname
,
username
,
dc
,
body
[
"id"
]
,
rp
.
key
)
id
+=
1
except
Exception
:
...
...
@@ -135,6 +136,22 @@ def create_rp(username: str, rp: ResourcePoolSchema):
return
id
,
errors
def
delete_rp
(
username
:
str
,
rpname
:
str
):
rpvm
=
ResourcePool
.
find
(
ResourcePool
.
rpname
==
rpname
)
.
first
()
while
rpvm
:
if
rpvm
.
owner
!=
username
:
raise
HTTPException
(
tatus_code
=
401
,
detail
=
f
"Cannot delete this resourcepool"
,
)
proxy_datacenters
(
f
"dashboard/acpi/vm/{rpvm.id}/"
,
username
,
"DELETE"
,
datacenter
=
rpvm
.
datacenter
)
rpvm
.
delete
()
rpvm
=
ResourcePool
.
find
(
ResourcePool
.
rpname
==
rpname
)
.
first
()
def
check_template_details_from_name
(
template_name
,
username
):
dcs
=
get_all_datacenter
()
...
...
main.py
View file @
c5840072
from
fastapi
import
FastAPI
,
Response
,
Body
,
Depends
import
os
from
typing
import
List
from
balancer.util
import
get_vm_from_rp
,
proxy_datacenters
,
create_rp
from
balancer.util
import
delete_rp
,
get_vm_from_rp
,
proxy_datacenters
,
create_rp
from
sredis.sredis
import
(
check_user
,
create_puser
,
...
...
@@ -97,10 +97,16 @@ def proxy_post_ff(
@app.post
(
"/createrp/"
)
def
create_resource_pool
(
username
=
Depends
(
get_current
_user
),
rp
:
ResourcePoolSchema
=
Body
(
...
)
username
=
Depends
(
admin
_user
),
rp
:
ResourcePoolSchema
=
Body
(
...
)
):
create_rp
(
username
,
rp
)
@app.delete
(
"/deleterp/"
)
def
create_resource_pool
(
username
=
Depends
(
admin_user
),
rpname
:
str
=
""
):
delete_rp
(
username
,
rpname
)
@app.post
(
"/rp/"
)
def
get_vm_from_pool
(
...
...
sredis/sredis.py
View file @
c5840072
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