示例#1
0
 def testServerExistance(self) -> None:
     srv_manager = server_manager()
     with mock.patch.object(Path, 'exists') as mock_exists:
         mock_exists.return_value = False
         self.assertEqual(srv_manager.check_if_server_exists('bous_server'),
                          False)
         mock_exists.return_value = True
         self.assertEqual(srv_manager.check_if_server_exists('bous_server'),
                          True)
示例#2
0
def delete_server_instance(server_name: str) -> None:
    """
    This method runs whole flow of deleting a server instance
    """
    srv_mgr = server_manager()

    if not srv_mgr.check_if_server_exists(server_name):
        print(f"Server {server_name} doesn't exist!")
        sys.exit(1)

    # delete this server
    if srv_mgr.delete_server_instance(server_name):
        print('Server instance deleted!')
        sys.exit(0)
    else:
        print("Could not delete this server instance!")
        sys.exit(1)
示例#3
0
def show_servers_info() -> None:
    srv_mgr = server_manager()
    server_instances = srv_mgr.list_server_instances()
    if server_instances:
        print(f"Found {len(server_instances)} server(s):\n")
        print('\n'.join(f'{_srv}' for _srv in server_instances) + "\n")
    else:
        print("No server instances found. Create a new server?\n")

    active_server_name = srv_mgr.get_active_server_name()
    if active_server_name:
        print(f'Active server name: {active_server_name}\n')
    else:
        print(f'No active server found. Set an active server?\n')

    server_state = srv_mgr.is_server_running()
    if server_state is True:
        print('Server system service is running properly')
    else:
        print(f'Looks like server system service is stopped: {server_state}')

    sys.exit(0)
示例#4
0
#!/usr/bin/env python

import sys
from mc_srv_manager.server_manager import server_manager
from pathlib import Path

srv_mgr = server_manager()


def activate(server_name: str) -> None:
    """
    This method runs whole flow of activating a new server
    """

    if not srv_mgr.check_if_server_exists(server_name):
        print(f"Server {server_name} doesn't exist!")
        sys.exit(1)

    if srv_mgr.is_server_running():
        srv_mgr.stop_server()

    # activate this server
    if srv_mgr.remove_current_version_symlinks():
        if not srv_mgr.create_new_version_symlinks(server_name):
            print("Can't create symlinks!")
            sys.exit(1)
        else:
            print('New version symlinked succesfully!')
    else:
        print("Can't remove symlinks to the current version of the server!")
        sys.exit(1)
示例#5
0
from flask_api import FlaskAPI, status, exceptions
from flask_cors import CORS
from flask import request
from mc_srv_manager.server_manager import server_manager

# configuration
DEBUG = True

app = FlaskAPI(__name__)
app.config.from_object(__name__)

# enable CORS
CORS(app, resources={r'/*': {'origins': '*'}})

server_manager = server_manager()


@app.route('/health', methods=['GET'])
def ping_pong():
    return {'status': 'OK'}


@app.route('/get_servers', methods=['GET'])
def get_servers():

    servers = []
    for srv_name in server_manager.list_server_instances():
        servers.append({'server_name': srv_name})

    servers = sorted(servers, key=lambda k: k['server_name'])