#!/home/vlt-os/env/bin/python
"""This file is part of Vulture OS.

Vulture OS 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 3 of the License, or
(at your option) any later version.

Vulture OS 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 Vulture OS.  If not, see http://www.gnu.org/licenses/.
"""

__author__ = "Jérémie JOURDIN"
__credits__ = []
__license__ = "GPLv3"
__version__ = "4.0.0"
__maintainer__ = "Vulture OS"
__email__ = ""
__doc__ = 'Initialize a Vulture Standalone cluster'

import os
import sys

if len(sys.argv) != 3:
    print ("Usage: /home/vlt-adm/gui/cluster_create <admin_user> <admin_password>")
    print ("")
    print ("This command will initialize a Vulture standalone node. It requires bootstrap first.")
    sys.exit(1)

sys.path.append("/home/vlt-os/vulture_os/")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'vulture_os.settings')
import django
try:
    django.setup()
    from django.core.management import call_command
    with open(os.devnull, 'w') as f:
        call_command('check', stdout = f)
except:
    print ("Error: This node is not bootstraped.")
    sys.exit(1)

from gui.views.install import cluster_create
cluster_create(sys.argv[1], sys.argv[2])