Первый стрим
This commit is contained in:
0
app/handlers/__init__.py
Normal file
0
app/handlers/__init__.py
Normal file
48
app/handlers/docker_commands.py
Normal file
48
app/handlers/docker_commands.py
Normal file
@ -0,0 +1,48 @@
|
||||
import subprocess
|
||||
|
||||
from aiogram.types import Message, CallbackQuery
|
||||
|
||||
from app.keyboards.docker_keyboards import container_names_keyboard, container_actions_keyboard
|
||||
|
||||
|
||||
async def get_containers(message: Message):
|
||||
sub = subprocess.check_output("docker ps -a").decode()
|
||||
keyboard = container_names_keyboard(sub)
|
||||
await message.answer(
|
||||
text=f"<pre><code>{sub}</code></pre>",
|
||||
parse_mode="HTML",
|
||||
reply_markup=keyboard.as_markup()
|
||||
)
|
||||
|
||||
|
||||
async def container_actions(call: CallbackQuery):
|
||||
name = call.data.split("_")[-1]
|
||||
keyboard = container_actions_keyboard(name)
|
||||
await call.message.answer(
|
||||
text=f"Выберите действие для контейнера {name}",
|
||||
parse_mode="HTML",
|
||||
reply_markup=keyboard.as_markup()
|
||||
)
|
||||
|
||||
|
||||
async def do_container_action(call: CallbackQuery):
|
||||
_, action, name = call.data.split("_")
|
||||
match action:
|
||||
case "start":
|
||||
subprocess.run(f"docker start {name}")
|
||||
message = f"Контейнер {name} успешно запущен"
|
||||
case "stop":
|
||||
subprocess.run(f"docker stop {name}")
|
||||
message = f"Контейнер {name} успешно остановлен"
|
||||
case "restart":
|
||||
subprocess.run(f"docker restart {name}")
|
||||
message = f"Контейнер {name} успешно перезапущен"
|
||||
case "delete":
|
||||
subprocess.run(f"docker rm -f {name}")
|
||||
message = f"Контейнер {name} успешно удалён"
|
||||
case _:
|
||||
message = f"Произошла необъяснимая ошибка"
|
||||
|
||||
await call.message.answer(
|
||||
text=message,
|
||||
)
|
11
app/handlers/user_command.py
Normal file
11
app/handlers/user_command.py
Normal file
@ -0,0 +1,11 @@
|
||||
import subprocess
|
||||
|
||||
from aiogram.types import Message
|
||||
|
||||
|
||||
async def execute_command(message: Message):
|
||||
user_command = message.text.split()[1:]
|
||||
print(user_command)
|
||||
sub = subprocess.check_output(user_command)
|
||||
# print(sub)
|
||||
await message.answer(f"<pre><code>{sub.decode()}</code></pre>", parse_mode="HTML")
|
Reference in New Issue
Block a user