Auto set first policy as default policy
Change-Id: I6bd5a8f9718ac9a282c3bd409ae261072a88b8b7
This commit is contained in:
parent
3223e42c21
commit
132891b988
|
@ -69,10 +69,14 @@ class CreateResourceTask(task.Task):
|
||||||
|
|
||||||
def execute(self, context, resource, **kwargs):
|
def execute(self, context, resource, **kwargs):
|
||||||
user = user_mod.User.load(context, user_id=resource.user_id)
|
user = user_mod.User.load(context, user_id=resource.user_id)
|
||||||
|
pid = user.policy_id
|
||||||
try:
|
try:
|
||||||
policy = policy_mod.Policy.load(context, policy_id=user.policy_id)
|
if pid:
|
||||||
except exception.PolicyNotFound:
|
policy = policy_mod.Policy.load(context, policy_id=pid)
|
||||||
policy = policy_mod.Policy.load_default(context)
|
else:
|
||||||
|
policy = policy_mod.Policy.load_default(context)
|
||||||
|
except exception.PolicyNotFound as e:
|
||||||
|
LOG.error(_LE("Error when find policy: %s"), e)
|
||||||
if policy is not None:
|
if policy is not None:
|
||||||
rule = policy.find_rule(context, resource.resource_type)
|
rule = policy.find_rule(context, resource.resource_type)
|
||||||
|
|
||||||
|
|
|
@ -555,6 +555,10 @@ class EngineService(service.Service):
|
||||||
'metadata': metadata,
|
'metadata': metadata,
|
||||||
}
|
}
|
||||||
policy = policy_mod.Policy(name, **kwargs)
|
policy = policy_mod.Policy(name, **kwargs)
|
||||||
|
if not policy.is_default:
|
||||||
|
default_policy = policy_mod.Policy.load_default(cnxt)
|
||||||
|
if default_policy is None:
|
||||||
|
policy.is_default = True
|
||||||
policy.store(cnxt)
|
policy.store(cnxt)
|
||||||
LOG.info(_LI("Successfully create policy (%s)."), policy.id)
|
LOG.info(_LI("Successfully create policy (%s)."), policy.id)
|
||||||
return policy.to_dict()
|
return policy.to_dict()
|
||||||
|
|
|
@ -14,4 +14,4 @@
|
||||||
|
|
||||||
import pbr.version
|
import pbr.version
|
||||||
|
|
||||||
version_info = pbr.version.VersionInfo('nova')
|
version_info = pbr.version.VersionInfo('bilean')
|
||||||
|
|
Loading…
Reference in New Issue