#! /usr/bin/python3

# ve-os-launcher
# Copyright (C) 2017-2018 NEC Corporation
# This file is part of VE system initialization
#
# VE system initialization is free software; you can redistribute it and/or 
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# VE system initialization is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with VE system initialization; if not, see
# <http://www.gnu.org/licenses/>

'''
This script launches veos process for the VE node specified by
the argument as follows:
  ve-os-launcher 0
starts VE OS for VE#0.
'''
import sys
sys.path.append('/opt/nec/ve/veos/lib/python3.12/site-packages')
import venodectl

VEOS = '/opt/nec/ve/veos/sbin/veos'
VEOS_SOCK_FMT = '/var/opt/nec/ve/veos/veos%d.sock'
VEOS_GLOBAL_OPTIONS_DIR = '/etc/opt/nec/ve/veos/ve-os-launcher.d'
VEOS_OPTIONS_DIR_FMT = VEOS_GLOBAL_OPTIONS_DIR + '/%d'

def main():
    if len(sys.argv) != 2:
        sys.exit("Usage: %s VE#" % sys.argv[0])

    vedev = int(sys.argv[1])
    veos_sock = VEOS_SOCK_FMT % vedev
    options_dirs = [VEOS_GLOBAL_OPTIONS_DIR, VEOS_OPTIONS_DIR_FMT % vedev]
    venodectl.start(vedev, VEOS, veos_sock, options_dirs)

if __name__ == "__main__":
    main()
