Incoporate oslo.config facilities in Inception
Convert Inception code to use a configuration file and command line options as processed by oslo.config. + orchestrator modified to use oslo.config for options + sample config file introduced + dependency on oslo.config added to setup.py + version string moved from setup.py to module init for ready access for --version and others Implements: blueprint Inception Configuration Blueprint Change-Id: I984700867d8ddf5ee1602cc4ed6608f36a38a6be
This commit is contained in:
parent
53e6f000dc
commit
03ed5b7e9f
|
@ -0,0 +1,48 @@
|
|||
# inception.conf
|
||||
#
|
||||
# To use this configuration, add one of the following options to your command
|
||||
# line:
|
||||
#
|
||||
# --config-file <d>/inception.conf
|
||||
# or
|
||||
# --config-dir <d>
|
||||
#
|
||||
# where <d> is the path to the directory containing this file
|
||||
|
||||
[DEFAULT]
|
||||
|
||||
# user - login id with sudo for image used for nodes in Inception Cloud
|
||||
user = ubuntu
|
||||
|
||||
# image - id of image used to construct nodes in Inception Cloud
|
||||
image = f3d62d5b-a76b-4997-a579-ff946a606132
|
||||
|
||||
# flavor - id of machine flavor used for nodes in Inception Cloud (3 = med)
|
||||
flavor = 3
|
||||
|
||||
# gateway_flavor - id of machine flavor used to construct GW in Inception Cloud
|
||||
gateway_flavor = 1
|
||||
|
||||
# key_name - name of PK pair for node access
|
||||
key_name = <your_key_name_here>
|
||||
|
||||
# security_groups - firewall rules
|
||||
security_groups = default, ssh
|
||||
|
||||
# src_dir - source location of various chef-related setup scripts on client
|
||||
src_dir = ../bin/
|
||||
|
||||
# dst_dir - absolute destination path for chef-related setup scripts on nodes
|
||||
dst_dir = /home/ubuntu/
|
||||
|
||||
# userdata - bash script run by cloud-init in late boot stage (rc.local-like)
|
||||
userdata = userdata.sh.template
|
||||
|
||||
# timeout - maximum time to wait for all servers to be reachable (seconds)
|
||||
timeout = 999999
|
||||
|
||||
# poll_interval - interval between readiness [ssh+userdata] polls (seconds)
|
||||
poll_interval = 5
|
||||
|
||||
# pool - name of pool for floating IP addresses
|
||||
pool = research
|
|
@ -0,0 +1 @@
|
|||
__version__ = '0.0.1'
|
|
@ -38,9 +38,90 @@ import traceback
|
|||
|
||||
import IPython
|
||||
from novaclient.v1_1.client import Client
|
||||
from oslo.config import cfg
|
||||
|
||||
from inception import __version__
|
||||
from inception.utils import cmd
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
inception_opts = [
|
||||
cfg.StrOpt('prefix',
|
||||
default=None,
|
||||
metavar='PREFIX',
|
||||
required=True,
|
||||
short='p',
|
||||
help='(unique) prefix for node names (no hyphens allowed)'),
|
||||
cfg.IntOpt('num_workers',
|
||||
default=2,
|
||||
metavar='NUM',
|
||||
short='n',
|
||||
help='number of worker nodes to create'),
|
||||
cfg.BoolOpt('shell',
|
||||
default=False,
|
||||
help='initialize, then drop to embedded IPython shell'),
|
||||
cfg.BoolOpt('atomic',
|
||||
default=False,
|
||||
help='on error, run as if --cleanup was specified'),
|
||||
cfg.BoolOpt('cleanup',
|
||||
default=False,
|
||||
help='take down the inception cloud'),
|
||||
cfg.BoolOpt('parallel',
|
||||
default=False,
|
||||
help='execute chef-related setup tasks in parallel'),
|
||||
cfg.StrOpt('chef_repo',
|
||||
default='git://github.com/maoy/inception-chef-repo.git',
|
||||
metavar='URL',
|
||||
help='URL of Chef repo'),
|
||||
cfg.StrOpt('chef_repo_branch',
|
||||
default='master',
|
||||
metavar='BRANCH',
|
||||
help='name of branch of Chef repo to use'),
|
||||
cfg.StrOpt('ssh_keyfile',
|
||||
default=None,
|
||||
metavar='PATH',
|
||||
help='path of additional keyfile for node access via ssh'),
|
||||
cfg.StrOpt('pool',
|
||||
default='research',
|
||||
help='name of pool for floating IP addresses'),
|
||||
cfg.StrOpt('user',
|
||||
default='ubuntu',
|
||||
help=''),
|
||||
cfg.StrOpt('image',
|
||||
default='f3d62d5b-a76b-4997-a579-ff946a606132',
|
||||
help=''),
|
||||
cfg.IntOpt('flavor',
|
||||
default=3,
|
||||
help='id of machine flavor used for nodes'),
|
||||
cfg.IntOpt('gateway_flavor',
|
||||
default=1,
|
||||
help='id of machine flavor used for gateway'),
|
||||
cfg.StrOpt('key_name',
|
||||
default='<your_key_name_here>',
|
||||
help='name of key for node access via ssh'),
|
||||
cfg.ListOpt('security_groups',
|
||||
default=['default', 'ssh'],
|
||||
help='list of security groups for nodes'),
|
||||
cfg.StrOpt('src_dir',
|
||||
default='../bin/',
|
||||
help='path of setup script source dir on client'),
|
||||
cfg.StrOpt('dst_dir',
|
||||
default='/home/ubuntu/',
|
||||
help='path of setup script destination dir on nodes'),
|
||||
cfg.StrOpt('userdata',
|
||||
default='userdata.sh.template',
|
||||
help='template for user data script'),
|
||||
cfg.IntOpt('timeout',
|
||||
default=999999,
|
||||
help='number of seconds for creation timeout'),
|
||||
cfg.IntOpt('poll_interval',
|
||||
default=5,
|
||||
help='interval (in seconds) between readiness polls'),
|
||||
]
|
||||
|
||||
# Register options
|
||||
CONF.register_cli_opts(inception_opts)
|
||||
|
||||
|
||||
class Orchestrator(object):
|
||||
"""
|
||||
|
@ -59,7 +140,7 @@ class Orchestrator(object):
|
|||
image='f3d62d5b-a76b-4997-a579-ff946a606132',
|
||||
flavor=3,
|
||||
gateway_flavor=1,
|
||||
key_name='shared',
|
||||
key_name='<your_key_name_here>',
|
||||
security_groups=('default', 'ssh'),
|
||||
src_dir='../bin/',
|
||||
dst_dir='/home/ubuntu/',
|
||||
|
@ -508,63 +589,41 @@ def main():
|
|||
"""
|
||||
program starting point
|
||||
"""
|
||||
# default argument values
|
||||
shell = False
|
||||
atomic = False
|
||||
cleanup = False
|
||||
chef_repo = "git://github.com/maoy/inception-chef-repo.git"
|
||||
chef_repo_branch = "master"
|
||||
parallel = False
|
||||
ssh_keyfile = None
|
||||
pool = 'research'
|
||||
|
||||
# Processes both config file and cmd line opts
|
||||
try:
|
||||
optlist, _ = getopt.getopt(sys.argv[1:], 'p:n:',
|
||||
["shell", "atomic", "cleanup", "parallel",
|
||||
"chef-repo=", "chef-repo-branch=",
|
||||
"ssh-keyfile=", 'pool='])
|
||||
optdict = dict(optlist)
|
||||
prefix = optdict['-p']
|
||||
num_workers = int(optdict['-n'])
|
||||
if "--shell" in optdict:
|
||||
shell = True
|
||||
if "--atomic" in optdict:
|
||||
atomic = True
|
||||
if "--cleanup" in optdict:
|
||||
cleanup = True
|
||||
if "--chef-repo" in optdict:
|
||||
chef_repo = optdict["--chef-repo"]
|
||||
if "--chef-repo-branch" in optdict:
|
||||
chef_repo_branch = optdict["--chef-repo-branch"]
|
||||
if "--parallel" in optdict:
|
||||
parallel = True
|
||||
if "--ssh-keyfile" in optdict:
|
||||
ssh_keyfile = optdict["--ssh-keyfile"]
|
||||
if "--pool" in optdict:
|
||||
pool = optdict["--pool"]
|
||||
except Exception:
|
||||
print traceback.format_exc()
|
||||
usage()
|
||||
sys.exit(1)
|
||||
orchestrator = Orchestrator(prefix, num_workers, chef_repo,
|
||||
chef_repo_branch, parallel, ssh_keyfile, pool)
|
||||
if shell:
|
||||
CONF(args=sys.argv[1:], version="Inception: version %s" % __version__)
|
||||
except Exception, e:
|
||||
print e
|
||||
sys.exit(-2)
|
||||
|
||||
orchestrator = Orchestrator(CONF.prefix,
|
||||
CONF.num_workers,
|
||||
CONF.chef_repo,
|
||||
CONF.chef_repo_branch,
|
||||
CONF.parallel,
|
||||
CONF.ssh_keyfile,
|
||||
CONF.pool,
|
||||
CONF.user,
|
||||
CONF.image,
|
||||
CONF.flavor,
|
||||
CONF.gateway_flavor,
|
||||
CONF.key_name,
|
||||
CONF.security_groups,
|
||||
CONF.src_dir,
|
||||
CONF.dst_dir,
|
||||
CONF.userdata,
|
||||
CONF.timeout,
|
||||
CONF.poll_interval)
|
||||
|
||||
if CONF.shell:
|
||||
# give me a ipython shell
|
||||
IPython.embed()
|
||||
return
|
||||
if cleanup:
|
||||
if CONF.cleanup:
|
||||
orchestrator.cleanup()
|
||||
else:
|
||||
orchestrator.start(atomic)
|
||||
|
||||
|
||||
def usage():
|
||||
print """
|
||||
python %s -p <prefix> -n <num_workers> [--shell] [--atomic] [--cleanup]
|
||||
[--parallel] [--chef-repo=git://github.com/maoy/inception-chef-repo.git]
|
||||
[--chef-repo-branch=master] [--ssh-keyfile=/path/to/key] [--pool=nova]
|
||||
|
||||
Note: make sure OpenStack-related environment variables are defined.
|
||||
""" % (__file__,)
|
||||
orchestrator.start(CONF.atomic)
|
||||
|
||||
##############################################
|
||||
if __name__ == "__main__":
|
||||
|
|
7
setup.py
7
setup.py
|
@ -7,17 +7,20 @@ try:
|
|||
except ImportError:
|
||||
from distutils.core import setup
|
||||
|
||||
version = '0.0.1'
|
||||
|
||||
# move version string out of setup so it is readily available to others
|
||||
from inception import __version__
|
||||
|
||||
setup(
|
||||
name='inception',
|
||||
version=version,
|
||||
version=__version__,
|
||||
description="Inception: Towards a Nested Cloud Architecture",
|
||||
license="Apache 2.0",
|
||||
classifiers=["Programming Language :: Python"],
|
||||
url='https://github.com/maoy/inception',
|
||||
packages=["inception"],
|
||||
install_requires=[
|
||||
"oslo.config>=1.1.1",
|
||||
"python-novaclient>=2.13.0",
|
||||
"IPython>=0.13.2",
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue