-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kevin Gartland
committed
Sep 11, 2023
1 parent
3665d24
commit 06ae1a8
Showing
7 changed files
with
226 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import hashlib | ||
import shutil | ||
import os | ||
import sys | ||
from os.path import join | ||
|
||
server_txt = 'setup/servers.txt' | ||
server_json = 'setup/servers.json' | ||
shutil.copy(server_txt, server_json) | ||
|
||
def copyfile(server_txt, server_json): | ||
# source_path = server_json # Replace with the path of the source file | ||
destination_path = config_dirname() # Replace with the destination directory path | ||
# desitination_file = os.path.join(destination_path, "servers.json") | ||
print(destination_path) | ||
# Copy the file to the destination | ||
shutil.move(server_json, destination_path) | ||
print("File copied successfully.") | ||
|
||
def config_dirname(platform=sys.platform, env=os.environ): | ||
"""Get the user's configuration directory path for this platform.""" | ||
home = env.get("HOME", "~") | ||
base_dir = home | ||
|
||
if platform.startswith("linux"): | ||
base_dir = env.get("XDG_CONFIG_HOME", home) | ||
elif platform == "darwin": | ||
base_dir = join(home, "Library", "Application Support") | ||
elif platform == "win32": | ||
# noinspection SpellCheckingInspection | ||
base_dir = env.get("APPDATA", home) | ||
|
||
if base_dir == home: | ||
try: | ||
os.makedirs(base_dir+"/.rsconnect-python/") | ||
except OSError: | ||
pass | ||
base_dir=base_dir+"/.rsconnect-python" | ||
return join(base_dir) | ||
else: | ||
os.makedirs(base_dir+"/rsconnect-python/") | ||
base_dir=base_dir+"/rsconnect-python" | ||
return join(base_dir) | ||
|
||
def replace_apikey(username): | ||
# replace api key | ||
with open(server_json, 'r') as file: | ||
server = file.read() | ||
api_key = server.replace('API_KEY', get_hash(username)) | ||
with open(server_json, 'w') as file: | ||
file.write(api_key) | ||
file.close() | ||
# replace connect url | ||
with open(server_json, 'r') as file: | ||
server = file.read() | ||
connect_ip = server.replace('CONNECT_IP', os.environ['CONNECT_IP']) | ||
with open(server_json, 'w') as file: | ||
file.write(connect_ip) | ||
file.close() | ||
|
||
# Open the file for writing and overwrite with the modified content | ||
|
||
|
||
|
||
def get_hash(username): | ||
|
||
# Calculate the MD5 hash for the username to get an API Key | ||
md5_hash = hashlib.md5(username.encode()).hexdigest() | ||
return md5_hash | ||
|
||
replace_apikey('admin') | ||
copyfile(server_txt, server_json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import subprocess | ||
import json | ||
import requests | ||
import time | ||
|
||
alias = "perftest-connect-20230518" | ||
box_name = "connect-ci" | ||
list_command = "fuzzbucket-client -j list" | ||
create_command = "fuzzbucket-client create -c " + alias + " -n " + box_name | ||
remove_command = "fuzzbucket-client rm " + box_name | ||
|
||
def check_existing_boxes(box_name): | ||
output = subprocess.check_output(list_command, shell=True, text=True) | ||
if "\"boxes\": {}" not in output: | ||
boxes = json.loads(output) | ||
connect_ip = boxes["boxes"][box_name]["public_ip"] | ||
else: | ||
subprocess.check_output(create_command, shell=True, text=True) | ||
output = subprocess.check_output(list_command, shell=True, text=True) | ||
boxes = json.loads(output) | ||
time.sleep(5) | ||
connect_ip = boxes["boxes"][box_name]["public_ip"] | ||
return connect_ip | ||
|
||
def get_ip(box_name): | ||
connect_ip = check_existing_boxes(box_name) | ||
return connect_ip | ||
|
||
def connect_ready(box_name, max_attempts, interval): | ||
connect_box=get_ip(box_name) | ||
attempts = 0 | ||
while attempts < max_attempts: | ||
try: | ||
response = requests.get("http://"+connect_box+":3939/__ping__") | ||
if response.status_code == 200: | ||
return response.text | ||
except requests.RequestException: | ||
pass | ||
|
||
time.sleep(interval) | ||
attempts += 1 | ||
return None | ||
|
||
response = connect_ready(box_name, 20, 5) | ||
|
||
if response: | ||
print(get_ip(box_name)) | ||
else: | ||
print("Server did not respond after multiple attempts.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
requests | ||
fuzzbucket-client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"connect": { | ||
"name": "connect", | ||
"url": "http://CONNECT_IP:3939", | ||
"api_key": "API_KEY", | ||
"insecure": false, | ||
"ca_cert": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters