summaryrefslogtreecommitdiff
path: root/nova/policy.py
diff options
context:
space:
mode:
authorAndrew Laski <andrew@lascii.com>2016-06-29 16:59:20 -0400
committerAndrew Laski <andrew@lascii.com>2016-08-24 16:37:13 -0400
commit3b609a52fb4ac030eef95dd8588e7d54abcc0615 (patch)
tree6398f2144fa83d488cba3609ff58c9aff7426110 /nova/policy.py
parentd23fb5ff9f10559681adc04b5b4116cfb0ede9df (diff)
downloadnova-3b609a52fb4ac030eef95dd8588e7d54abcc0615.tar.gz
Add entry_point for oslo policy scripts
There are two helper scripts in oslo.policy to help deployers understand their policy configuration better. With the setup.cfg entry these can be called directly from oslo.policy. Change-Id: I08dc33367401ec1f98e1795a52d4e981f09a07de Implements: bp policy-in-code
Diffstat (limited to 'nova/policy.py')
-rw-r--r--nova/policy.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/nova/policy.py b/nova/policy.py
index 6a2bc8192d..f494b323ed 100644
--- a/nova/policy.py
+++ b/nova/policy.py
@@ -14,6 +14,7 @@
# under the License.
"""Policy Engine For Nova."""
+import sys
from oslo_config import cfg
from oslo_log import log as logging
@@ -155,3 +156,23 @@ def get_rules():
def register_rules(enforcer):
enforcer.register_defaults(policies.list_rules())
+
+
+def get_enforcer():
+ # This method is for use by oslopolicy CLI scripts. Those scripts need the
+ # 'output-file' and 'namespace' options, but having those in sys.argv means
+ # loading the Nova config options will fail as those are not expected to
+ # be present. So we pass in an arg list with those stripped out.
+ conf_args = []
+ # Start at 1 because cfg.CONF expects the equivalent of sys.argv[1:]
+ i = 1
+ while i < len(sys.argv):
+ if sys.argv[i].strip('-') in ['namespace', 'output-file']:
+ i += 2
+ continue
+ conf_args.append(sys.argv[i])
+ i += 1
+
+ cfg.CONF(conf_args, project='nova')
+ init()
+ return _ENFORCER