From f26deea6b1d7a91da44979d8c7feaf1ff8970b25 Mon Sep 17 00:00:00 2001 From: yuntongjin Date: Sat, 28 Feb 2015 10:50:34 +0800 Subject: [PATCH] create install_default_policy Recent versions of oslo policy allow the use of a policy.d to break up policy in a more user understandable way. Nova is going to use this in Kilo to break out v2 and v2.1 API policy definitions. This provides a unified helper for installing sample policies. It makes some assumptions on project directory structure. Porting other projects to use this can happen in the future. Change-Id: Iec23b095176332414faf76a9c329f8bb5f3aa6c3 --- functions-common | 22 ++++++++++++++++++++++ lib/nova | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/functions-common b/functions-common index df69cbad16..8d7db96606 100644 --- a/functions-common +++ b/functions-common @@ -787,6 +787,28 @@ function get_field { done } +# install default policy +# copy over a default policy.json and policy.d for projects +function install_default_policy { + local project=$1 + local project_uc=$(echo $1|tr a-z A-Z) + local conf_dir="${project_uc}_CONF_DIR" + # eval conf dir to get the variable + conf_dir="${!conf_dir}" + local project_dir="${project_uc}_DIR" + # eval project dir to get the variable + project_dir="${!project_dir}" + local sample_conf_dir="${project_dir}/etc/${project}" + local sample_policy_dir="${project_dir}/etc/${project}/policy.d" + + # first copy any policy.json + cp -p $sample_conf_dir/policy.json $conf_dir + # then optionally copy over policy.d + if [[ -d $sample_policy_dir ]]; then + cp -r $sample_policy_dir $conf_dir/policy.d + fi +} + # Add a policy to a policy.json file # Do nothing if the policy already exists # ``policy_add policy_file policy_name policy_permissions`` diff --git a/lib/nova b/lib/nova index e9e78c7bc4..fe61e83620 100644 --- a/lib/nova +++ b/lib/nova @@ -261,7 +261,7 @@ function configure_nova { fi sudo chown $STACK_USER $NOVA_CONF_DIR - cp -p $NOVA_DIR/etc/nova/policy.json $NOVA_CONF_DIR + install_default_policy nova configure_nova_rootwrap