From d26f78851978555029391eaa43dede6d5c3114d5 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Tue, 22 Mar 2016 12:13:35 +0000 Subject: [PATCH] Allow passing domain name on os_server A cloud admin can search domains, thus it should be possible to pass a domain name, just like ids. --- cloud/openstack/os_user.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cloud/openstack/os_user.py b/cloud/openstack/os_user.py index a3c2cb4ef08..af6bd0c5bca 100644 --- a/cloud/openstack/os_user.py +++ b/cloud/openstack/os_user.py @@ -175,6 +175,22 @@ def main(): module.fail_json(msg='Default project %s is not valid' % default_project) project_id = project['id'] + if domain: + opcloud = shade.operator_cloud(**module.params) + try: + # We assume admin is passing domain id + dom = opcloud.get_domain(domain)['id'] + domain = dom + except: + # If we fail, maybe admin is passing a domain name. + # Note that domains have unique names, just like id. + try: + dom = opcloud.search_domains(filters={'name': domain})[0]['id'] + domain = dom + except: + # Ok, let's hope the user is non-admin and passing a sane id + pass + if state == 'present': if user is None: user = cloud.create_user(