Ejemplo n.º 1
0
def create_or_update_server_repository(db_session,
                                       hostname,
                                       server_type,
                                       server_url,
                                       username,
                                       vrf,
                                       server_directory,
                                       password,
                                       destination_on_host,
                                       created_by,
                                       server=None):

    hostname = check_acceptable_string(hostname)

    if server is None:
        server = Server(created_by=created_by)
        db_session.add(server)

    server.hostname = hostname
    server.server_type = server_type
    server.server_url = server_url
    server.username = username
    server.password = password
    server.vrf = vrf if (server_type == ServerType.TFTP_SERVER
                         or server_type == ServerType.FTP_SERVER) else ''
    server.server_directory = server_directory
    server.destination_on_host = destination_on_host if server_type == ServerType.SCP_SERVER else ''

    db_session.commit()

    return server
Ejemplo n.º 2
0
def create_or_update_server_repository(db_session, hostname, server_type, server_url, username, vrf,
                                       server_directory, password, destination_on_host, created_by, server=None):

    hostname = check_acceptable_string(hostname)

    if server is None:
        server = Server(created_by=created_by)
        db_session.add(server)

    server.hostname = hostname
    server.server_type = server_type
    server.server_url = server_url
    server.username = username
    server.password = password
    server.vrf = vrf if (server_type == ServerType.TFTP_SERVER or
                         server_type == ServerType.FTP_SERVER) else ''
    server.server_directory = server_directory
    server.destination_on_host = destination_on_host if server_type == ServerType.SCP_SERVER else ''

    db_session.commit()

    return server
Ejemplo n.º 3
0
def check_server_reachability():
    if not can_check_reachability(current_user):
        abort(401)

    hostname = request.args.get('hostname')
    server_type = request.args.get('server_type')
    server_url = request.args.get('server_url')
    username = request.args.get('username')
    password = request.args.get('password')
    server_directory = request.args.get('server_directory')

    server = Server(hostname=hostname,
                    server_type=server_type,
                    server_url=server_url,
                    username=username,
                    password=password,
                    server_directory=server_directory)
    # The form is in the edit mode and the user clicks Validate Reachability
    # If there is no password specified, try get it from the database.
    if (server_type == ServerType.FTP_SERVER
            or server_type == ServerType.SFTP_SERVER
            or server_type == ServerType.SCP_SERVER) and password == '':

        db_session = DBSession()
        server_in_db = get_server(db_session, hostname)
        if server_in_db is not None:
            server.password = server_in_db.password

    server_impl = get_server_impl(server)

    is_reachable, error = server_impl.check_reachability()

    if is_reachable:
        return jsonify({'status': 'OK'})
    else:
        return jsonify({'status': error})