Skip to content
Snippets Groups Projects
Unverified Commit ccd5ac52 authored by REIG Julien's avatar REIG Julien
Browse files

try to allow adding new nodes easily

parent 2f560129
No related branches found
No related tags found
1 merge request!16Node knowledge
......@@ -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)
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment