From 52f22cf7a50ae491d066a092d387d2920cf90f35 Mon Sep 17 00:00:00 2001 From: Yun Mao Date: Mon, 20 May 2013 18:22:24 -0400 Subject: [PATCH] Add new options to customize chef repo --git-chef-repo and --git-chef-repo-branch are added from the command line to allow customized chef repo. Change-Id: Ie27b844ea7e396120d06e48fa697f46951cadc61 --- bin/setup_chef_repo.sh | 5 ++++- inception/orchestrator.py | 28 ++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/bin/setup_chef_repo.sh b/bin/setup_chef_repo.sh index d1b5252..a7e84d9 100755 --- a/bin/setup_chef_repo.sh +++ b/bin/setup_chef_repo.sh @@ -5,10 +5,13 @@ set -e HOSTNAME_ARRAY=(${HOSTNAME//-/ }) # split the hostname by "-" PREFIX=${HOSTNAME_ARRAY[0]} # the first half is prefix +CHEF_REPO=${1} +GIT_BRANCH=${2} + mkdir -p ~/chef-repo # first, clone the repo -git clone --recursive git://github.com/maoy/inception-chef-repo.git ~/chef-repo +git clone -b ${GIT_BRANCH} --recursive ${CHEF_REPO} ~/chef-repo cd ~/chef-repo/environments/ ./instantiate.sh ${PREFIX} allinone diff --git a/inception/orchestrator.py b/inception/orchestrator.py index 4c62fe0..4dc95ad 100644 --- a/inception/orchestrator.py +++ b/inception/orchestrator.py @@ -52,6 +52,8 @@ class Orchestrator(object): def __init__(self, prefix, num_workers, + git_chef_repo, + git_chef_repo_branch, user='ubuntu', image='3ab46178-eaae-46f0-8c13-6aad4d62ecde', flavor=3, @@ -90,6 +92,8 @@ class Orchestrator(object): ## args self.prefix = prefix self.num_workers = num_workers + self.git_chef_repo = git_chef_repo + self.git_chef_repo_branch = git_chef_repo_branch self.user = user self.image = image self.flavor = flavor @@ -261,7 +265,8 @@ class Orchestrator(object): "/bin/bash " + command, screen_output=True) ssh_chefserver('install_chefserver.sh') ssh_chefserver('configure_knife.sh') - ssh_chefserver('setup_chef_repo.sh') + ssh_chefserver('setup_chef_repo.sh %s %s' + % (self.git_chef_repo, self.git_chef_repo_branch)) def _checkin_chefserver(self): """ @@ -328,8 +333,12 @@ def main(): """ shell = False atomic = False + git_chef_repo = "git://github.com/maoy/inception-chef-repo.git" + git_chef_repo_branch = "master" try: - optlist, _ = getopt.getopt(sys.argv[1:], 'p:n:', ["shell", "atomic"]) + optlist, _ = getopt.getopt(sys.argv[1:], 'p:n:', + ["shell", "atomic", "git-chef-repo=", + "git-chef-repo-branch="]) optdict = dict(optlist) prefix = optdict['-p'] if '-' in prefix: @@ -339,11 +348,16 @@ def main(): shell = True if "--atomic" in optdict: atomic = True + if "--git-chef-repo" in optdict: + git_chef_repo = optdict["--git-chef-repo"] + if "--git-chef-repo-branch" in optdict: + git_chef_repo_branch = optdict["--git-chef-repo-branch"] except Exception: print traceback.format_exc() usage() sys.exit(1) - orchestrator = Orchestrator(prefix, num_workers) + orchestrator = Orchestrator(prefix, num_workers, git_chef_repo, + git_chef_repo_branch) if shell: # give me a ipython shell IPython.embed() @@ -353,10 +367,12 @@ def main(): def usage(): print """ - (make sure OpenStack-related environment variables are defined) +python %s -p -n [--shell] [--atomic] + [--git-chef-repo=git://github.com/maoy/inception-chef-repo.git] + [--chef-branch=git://github.com/maoy/inception-chef-repo.git] - python %s -p -n [--shell] [--atomic] - """ % (__file__,) +Note: make sure OpenStack-related environment variables are defined. +""" % (__file__,) ############################################## if __name__ == "__main__":