Compare commits
1 commit
main
...
renovate/h
Author | SHA1 | Date | |
---|---|---|---|
dba8ce7f71 |
4 changed files with 41 additions and 113 deletions
|
@ -1,12 +0,0 @@
|
||||||
skip_clone: true
|
|
||||||
steps:
|
|
||||||
- name: awx
|
|
||||||
image: curlimages/curl
|
|
||||||
environment:
|
|
||||||
TOKEN:
|
|
||||||
from_secret: AWX_TOKEN
|
|
||||||
commands:
|
|
||||||
- "curl -k -X POST -H \"Authorization: Bearer $TOKEN\" https://awx-aaron.apps.yolokube.de/api/v2/job_templates/16/launch/"
|
|
||||||
when:
|
|
||||||
- event: push
|
|
||||||
branch: main
|
|
|
@ -1,10 +1,3 @@
|
||||||
{
|
{
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||||
"packageRules": [
|
|
||||||
{
|
|
||||||
"matchPackagePatterns": ["*"],
|
|
||||||
"automerge": true,
|
|
||||||
"automergeType": "branch"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
tabulate==0.9.0
|
tabulate==0.9.0
|
||||||
hcloud==2.4.0
|
hcloud==1.18.1
|
||||||
rich==13.9.4
|
rich==12.6.0
|
105
shcloud.py
105
shcloud.py
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python3
|
#!/bin/python3
|
||||||
import sys
|
import sys
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.table import Table
|
from rich.table import Table
|
||||||
|
@ -9,8 +9,7 @@ from rich.prompt import Confirm
|
||||||
from os import environ, system, path
|
from os import environ, system, path
|
||||||
import subprocess
|
import subprocess
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import argparse
|
#from tabulate import tabulate
|
||||||
|
|
||||||
from hcloud import Client
|
from hcloud import Client
|
||||||
from hcloud.images.domain import Image
|
from hcloud.images.domain import Image
|
||||||
from hcloud.server_types.domain import ServerType
|
from hcloud.server_types.domain import ServerType
|
||||||
|
@ -22,26 +21,21 @@ from hcloud.servers.domain import ServerCreatePublicNetwork
|
||||||
from hcloud.locations.domain import Location
|
from hcloud.locations.domain import Location
|
||||||
|
|
||||||
server_name = "lgsm-1"
|
server_name = "lgsm-1"
|
||||||
server_game = "fctrserver"
|
server_game = "sfserver"
|
||||||
server_type = "ccx13"
|
#server_type = "cx11"
|
||||||
server_type_id = None
|
server_type_id = None
|
||||||
server_key = 6513932
|
server_key = 6513932
|
||||||
server_image = 114690387
|
server_image = 45557056
|
||||||
server_ipv4 = 11737045
|
server_ipv4 = 11737045
|
||||||
server_ipv6 = 11737053
|
server_ipv6 = 11737053
|
||||||
volume_id = 102426010
|
volume_id = 11742041
|
||||||
game_choices = ["fctrserver", "sfserver", "cs2server"]
|
|
||||||
backup_paths = {
|
|
||||||
"sfserver": "/gameserver/home/.config/Epic/FactoryGame/Saved/SaveGames/server/*",
|
|
||||||
"fctrserver": "/gameserver/fctrserver/serverfiles/save1.zip",
|
|
||||||
}
|
|
||||||
|
|
||||||
# please put the token in a file named .token in the same dir as the python script
|
# please put the token in a file named .token in the same dir as the python script
|
||||||
token_file = open("%s/.token"%path.dirname(__file__), "r")
|
token_file = open("%s/.token"%path.dirname(__file__), "r")
|
||||||
token = token_file.read().replace("\n","")
|
token = token_file.read().replace("\n","")
|
||||||
token_file.close()
|
token_file.close()
|
||||||
client = Client(token=token)
|
client = Client(token=token)
|
||||||
console = Console() # for rich module≈
|
console = Console() # for rich module
|
||||||
|
|
||||||
# get volume
|
# get volume
|
||||||
volume = Volume(volume_id)
|
volume = Volume(volume_id)
|
||||||
|
@ -49,50 +43,15 @@ volume = Volume(volume_id)
|
||||||
# get server types
|
# get server types
|
||||||
models = client.server_types.get_all()
|
models = client.server_types.get_all()
|
||||||
|
|
||||||
# parse arguments
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument("action", type=str, help="create or delete")
|
|
||||||
parser.add_argument("-t", "--type", help="server type")
|
|
||||||
parser.add_argument(
|
|
||||||
"-g", "--game", help="game", choices=game_choices, default=server_game
|
|
||||||
)
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
|
|
||||||
# functions
|
# functions
|
||||||
def delete_server(s):
|
def delete_server(s):
|
||||||
with Progress() as progress:
|
with Progress() as progress:
|
||||||
check_connection = progress.add_task(
|
|
||||||
"[green]Check connection to server", total=None
|
|
||||||
)
|
|
||||||
subprocess.check_output(
|
|
||||||
f"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null shcloud.eu whoami",
|
|
||||||
shell=True,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
)
|
|
||||||
progress.update(check_connection, completed=1, total=1)
|
|
||||||
task_stop_game = progress.add_task("[red]Stop Game", total=None)
|
task_stop_game = progress.add_task("[red]Stop Game", total=None)
|
||||||
subprocess.check_output(
|
subprocess.check_output("ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null shcloud.eu 'su -c \"cd /gameserver/%s && /gameserver/%s/%s stop\" gameserver'"%(server_game, server_game, server_game), shell=True,stderr=subprocess.STDOUT)
|
||||||
"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null shcloud.eu 'su -c \"cd /gameserver/%s && /gameserver/%s/%s stop\" gameserver'"
|
|
||||||
% (server_game, server_game, server_game),
|
|
||||||
shell=True,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
)
|
|
||||||
progress.update(task_stop_game, completed=1, total=1)
|
progress.update(task_stop_game, completed=1, total=1)
|
||||||
|
|
||||||
# backup game files
|
# backup game files
|
||||||
if server_game in backup_paths:
|
|
||||||
task_backup = progress.add_task("[red]Backup files", total=None)
|
task_backup = progress.add_task("[red]Backup files", total=None)
|
||||||
subprocess.check_output(
|
subprocess.check_output("scp shcloud.eu:/gameserver/home/gameserver/.config/Epic/FactoryGame/Saved/SaveGames/server/* /root/backup/sfserver/", shell=True,stderr=subprocess.STDOUT)
|
||||||
f"mkdir -p /root/backup/{server_game}",
|
|
||||||
shell=True,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
)
|
|
||||||
subprocess.check_output(
|
|
||||||
f"scp shcloud.eu:{backup_paths[server_game]} /root/backup/{server_game}/",
|
|
||||||
shell=True,
|
|
||||||
stderr=subprocess.STDOUT,
|
|
||||||
)
|
|
||||||
progress.update(task_backup, completed=1, total=1)
|
progress.update(task_backup, completed=1, total=1)
|
||||||
response = s.shutdown()
|
response = s.shutdown()
|
||||||
track_progress(response.id, response.command)
|
track_progress(response.id, response.command)
|
||||||
|
@ -101,14 +60,12 @@ def delete_server(s):
|
||||||
response = s.delete()
|
response = s.delete()
|
||||||
track_progress(response.id, response.command)
|
track_progress(response.id, response.command)
|
||||||
|
|
||||||
|
|
||||||
def check_servertype(server_type):
|
def check_servertype(server_type):
|
||||||
# return id or None
|
# return id or None
|
||||||
for m in models:
|
for m in models:
|
||||||
if m.name == server_type and m.deprecated == False:
|
if m.name == server_type and m.deprecated == False:
|
||||||
return m.id
|
return(m.id)
|
||||||
return None
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
def select_servertype():
|
def select_servertype():
|
||||||
# return id or None
|
# return id or None
|
||||||
|
@ -128,20 +85,9 @@ def select_servertype():
|
||||||
|
|
||||||
for m in models:
|
for m in models:
|
||||||
#if str(m.cpu_type) == "shared":
|
#if str(m.cpu_type) == "shared":
|
||||||
table.add_row(
|
table.add_row(str(m.id), str(m.name), str(m.description), str(m.cores), str(int(m.memory)) + " GB", str(m.disk) + " GB", str(m.cpu_type) , format(float(m.prices[0]["price_hourly"]["gross"]), '.2f') + " €", format(float(m.prices[0]["price_monthly"]["gross"]), '.2f') + " €")
|
||||||
str(m.id),
|
|
||||||
str(m.name),
|
|
||||||
str(m.description),
|
|
||||||
str(m.cores),
|
|
||||||
str(int(m.memory)) + " GB",
|
|
||||||
str(m.disk) + " GB",
|
|
||||||
str(m.cpu_type),
|
|
||||||
format(float(m.prices[0]["price_hourly"]["gross"]), ".2f") + " €",
|
|
||||||
format(float(m.prices[0]["price_monthly"]["gross"]), ".2f") + " €",
|
|
||||||
)
|
|
||||||
console.print(table)
|
console.print(table)
|
||||||
return Prompt.ask("Selection: ", default=server_type)
|
return(Prompt.ask("Selection: ", default="ccx22"))
|
||||||
|
|
||||||
|
|
||||||
def track_progress(a_id, description):
|
def track_progress(a_id, description):
|
||||||
with Progress() as progress:
|
with Progress() as progress:
|
||||||
|
@ -158,8 +104,15 @@ def track_progress(a_id, description):
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print("shcloud python script")
|
||||||
|
print("")
|
||||||
|
print("usage:")
|
||||||
|
print("shcloud.py create <server_model>")
|
||||||
|
print("shcloud.py delete")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
if args.action == "delete":
|
if sys.argv[1] == "delete":
|
||||||
with Progress() as progress:
|
with Progress() as progress:
|
||||||
task_search = progress.add_task("[green]Search for server", total=None)
|
task_search = progress.add_task("[green]Search for server", total=None)
|
||||||
s = client.servers.get_by_name(server_name)
|
s = client.servers.get_by_name(server_name)
|
||||||
|
@ -172,11 +125,11 @@ if args.action == "delete":
|
||||||
delete_server(s)
|
delete_server(s)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
if args.action == "create":
|
if sys.argv[1] == "create":
|
||||||
# check if server model was selected
|
# check if server model was selected
|
||||||
if args.type:
|
if len(sys.argv) > 2:
|
||||||
# get server models
|
# get server models
|
||||||
server_type_id = check_servertype(args.type)
|
server_type_id = check_servertype(sys.argv[2])
|
||||||
# if not found force the user to select one
|
# if not found force the user to select one
|
||||||
while server_type_id == None:
|
while server_type_id == None:
|
||||||
console.print("[red]Server type not found.")
|
console.print("[red]Server type not found.")
|
||||||
|
@ -206,14 +159,8 @@ if args.action == "create":
|
||||||
location=Location(name="fsn1"),
|
location=Location(name="fsn1"),
|
||||||
volumes=[Volume(id=volume_id)],
|
volumes=[Volume(id=volume_id)],
|
||||||
labels={"game" : server_game},
|
labels={"game" : server_game},
|
||||||
user_data="#!/bin/bash\ncurl -sL ar21.de/shinit.php?GAME=%s\\&VOLUME=%s | bash"
|
user_data="#!/bin/bash\ncurl -sL ar21.de/shinit.php?GAME=%s\\&VOLUME=%s | bash"%(server_game, volume_id),
|
||||||
% (server_game, volume_id),
|
public_net=ServerCreatePublicNetwork(ipv4=PrimaryIP(id=server_ipv4),ipv6=PrimaryIP(id=server_ipv6),enable_ipv4 = True, enable_ipv6 = True)
|
||||||
public_net=ServerCreatePublicNetwork(
|
|
||||||
ipv4=PrimaryIP(id=server_ipv4),
|
|
||||||
ipv6=PrimaryIP(id=server_ipv6),
|
|
||||||
enable_ipv4=True,
|
|
||||||
enable_ipv6=True,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
track_progress(response.action.id, response.action.command)
|
track_progress(response.action.id, response.action.command)
|
||||||
for a in response.next_actions:
|
for a in response.next_actions:
|
||||||
|
|
Loading…
Add table
Reference in a new issue