82 lines
2.3 KiB
Python
Executable File
82 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
|
|
# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import os
|
|
import os.path
|
|
import logging
|
|
import logging.config
|
|
import sys
|
|
import traceback
|
|
|
|
#this needs to happen immediately (or thats what it seems)
|
|
log_fn = os.getenv('LOG_FILE')
|
|
if(log_fn == None):
|
|
log_fn = os.path.normpath(os.path.join("conf", 'logging.ini'))
|
|
logging.config.fileConfig(log_fn)
|
|
|
|
from devstack import opts
|
|
from devstack import settings
|
|
from devstack import shell as sh
|
|
from devstack import utils
|
|
|
|
#these are the program runtimes that actually do the running
|
|
from devstack.progs import actions
|
|
|
|
#the user who's user id should be 0
|
|
ROOT_USER = 'root'
|
|
|
|
|
|
def main():
|
|
#names!
|
|
prog_name = os.path.basename(sys.argv[0])
|
|
pretty_name = settings.PROG_NICE_NAME
|
|
|
|
#do this first so people can see the help message...
|
|
args = opts.parse()
|
|
|
|
#will need root to setup openstack
|
|
if not sh.got_root():
|
|
msg = "%s needs to be ran as %s!" % (pretty_name, ROOT_USER)
|
|
print(utils.color_text(msg, 'red', True))
|
|
msg = "Perhaps you should try %s" % \
|
|
(utils.color_text("sudo %s" % (prog_name), "red", True))
|
|
print(msg)
|
|
return 1
|
|
|
|
#drop to usermode
|
|
sh.user_mode()
|
|
try:
|
|
# now let's go
|
|
started_ok = actions.run(args)
|
|
if not started_ok:
|
|
me = utils.color_text(prog_name, "red", True)
|
|
me += " " + utils.color_text('--help', 'red')
|
|
print("Perhaps you should try %s" % (me))
|
|
return 1
|
|
else:
|
|
utils.goodbye(True)
|
|
return 0
|
|
except Exception:
|
|
utils.goodbye(False)
|
|
traceback.print_exc(file=sys.stdout)
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|