Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mock-cheops
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
chephren
mock-cheops
Commits
ccd5ac52
Unverified
Commit
ccd5ac52
authored
1 year ago
by
REIG Julien
Browse files
Options
Downloads
Patches
Plain Diff
try to allow adding new nodes easily
parent
2f560129
No related branches found
No related tags found
1 merge request
!16
Node knowledge
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
utils/http_utils.py
+9
-0
9 additions, 0 deletions
utils/http_utils.py
utils/init_database.py
+9
-0
9 additions, 0 deletions
utils/init_database.py
with
18 additions
and
0 deletions
utils/http_utils.py
+
9
−
0
View file @
ccd5ac52
...
...
@@ -15,11 +15,20 @@ nodes = {
'
http://localhost:3003/
'
:
'
http://node4:3000/
'
,
}
def
get_internal_url
(
port
:
int
):
# keep last 3 digits
port
=
port
%
1000
new_url
=
f
"
http://node
{
port
}
:3000/
"
print
(
'
getInternalUrl
'
,
new_url
)
return
new_url
def
normalize_url
(
url
:
str
,
inter
:
bool
=
False
):
parsed_url
=
urlparse
(
url
)
format
=
parsed_url
.
scheme
+
"
://
"
+
parsed_url
.
netloc
+
"
/
"
if
inter
:
get_internal_url
(
parsed_url
.
port
|
3000
)
url
=
nodes
.
get
(
url
,
None
)
if
url
is
None
:
print
(
'
normalize intern
'
,
url
,
file
=
sys
.
stderr
)
...
...
This diff is collapsed.
Click to expand it.
utils/init_database.py
+
9
−
0
View file @
ccd5ac52
import
os
import
random
import
sqlite3
from
consts.status
import
Status
...
...
@@ -129,6 +130,8 @@ def init_database():
insert_node3
(
cursor
,
db_conn
)
elif
current_node
==
'
node4
'
:
insert_node4
(
cursor
,
db_conn
)
else
:
insert_other
(
cursor
,
db_conn
)
cursor
.
close
()
...
...
@@ -238,3 +241,9 @@ def insert_node4(cursor: sqlite3.Cursor, db_conn: sqlite3.Connection):
for
r
in
rs
:
cursor
.
executemany
(
commands_insert
,
commands
[
r
[
0
]])
db_conn
.
commit
()
def
insert_other
(
cursor
:
sqlite3
.
Cursor
,
db_conn
:
sqlite3
.
Connection
):
print
(
"
Inserting data for other nodes, just state table
"
)
state
=
random
.
choice
([
Status
.
ONLINE
.
value
,
Status
.
OFFLINE
.
value
])
cursor
.
execute
(
state_insert
,
(
state
,))
db_conn
.
commit
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment