docker-composer/basic_management.py

70 lines
2.3 KiB
Python
Raw Normal View History

2022-12-15 11:24:29 -06:00
from docker_wrapper import Docker
from pprint import pprint
2022-12-14 15:45:53 -06:00
2022-12-15 10:31:15 -06:00
while True:
2022-12-15 11:24:29 -06:00
# Main Menu
2022-12-15 10:31:15 -06:00
print('Select the container to manage:')
2022-12-15 11:24:29 -06:00
containers = Docker.containers()
for i in range(len(containers)):
print(f' {i} - {containers[i]}')
print(' q - quit')
container_i = input()
2022-12-15 11:24:29 -06:00
print()
if container_i == 'q':
2022-12-15 11:24:29 -06:00
exit(0)
while True:
# Container Menu
container = containers[int(container_i)]
2022-12-15 11:24:29 -06:00
print()
print(f'You selected {container}. What would you like to do with it?')
print(f' view - View container info - (docker ps -a)')
2022-12-15 11:24:29 -06:00
print(f' start - Starts the container (docker start {container})')
print(f' stop - Stops the container (docker stop {container}')
print(f' rm - Deletes the container (docker rm {container})')
print( ' menu - Back to the main menu')
selection = input()
print()
2022-12-15 11:24:29 -06:00
if selection == 'menu':
break
elif selection == 'view':
pprint(Docker.container_info(container)) # TODO: Make better, custom printer
2022-12-15 11:24:29 -06:00
elif selection == 'start':
print('Starting...')
2022-12-15 11:24:29 -06:00
status = Docker.start(container)
2022-12-15 11:24:29 -06:00
elif selection == 'stop':
print('Stopping...')
2022-12-15 11:24:29 -06:00
status = Docker.stop(container)
print('Done.')
2022-12-15 11:24:29 -06:00
elif selection == 'rm':
break_later = False
2022-12-15 11:24:29 -06:00
while selection != 'y' and selection != 'n' and selection != 'Y' and selection != 'N':
print(f'WARNING! This will DELETE {container}!')
print(f'Are you absolutely sure you want to delete {container}? (y/N)')
selection = input()
if selection == 'y' or selection == 'Y':
print('Deleting...')
status = Docker.rm(container)
print('Done')
break_later = True
2022-12-15 11:24:29 -06:00
elif selection == 'n' or selection == 'N':
print(f'Operation cancelled, returning to {container} menu...')
if break_later:
break
2022-12-15 11:24:29 -06:00
elif selection == 'menu':
print('Returning to main menu...')
break
else:
print('Selection invalid. Please try again.')
print()