anvil/stack

76 lines
2.2 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 logging.config
import sys
import traceback
from devstack import settings
#this needs to happen immediately (or thats what it seems)
LOG_FN = os.getenv(settings.STACK_LOG_ENV_LOCATION)
if not LOG_FN or not os.path.isfile(LOG_FN):
LOG_FN = settings.STACK_LOG_CFG_LOCATION
logging.config.fileConfig(LOG_FN)
from devstack import opts
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
def main():
#do this first so people can see the help message...
args = opts.parse()
prog_name = sys.argv[0]
#will need root to setup openstack
if not sh.got_root():
rest_args = sys.argv[1:]
print("This program requires a user with sudo access.")
msg = "Perhaps you should try %s %s" % \
(utils.color_text("sudo %s" % (prog_name), "red", True), " ".join(rest_args))
print(msg)
return 1
#drop to usermode
sh.user_mode(False)
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())