def ensure_tenant_exists(keystone, tenant_name, tenant_description, check_mode):
 try:
  tenant = get_tenant(keystone, tenant_name)
 except KeyError:
  pass
 else:
  if (tenant.description == tenant_description):
   return (False, tenant.id)
  elif check_mode:
   return (True, tenant.id)
  else:
   tenant.update(description=tenant_description)
   return (True, tenant.id)
 if check_mode:
  return (True, None)
 ks_tenant = keystone.tenants.create(tenant_name=tenant_name, description=tenant_description, enabled=True)
 return (True, ks_tenant.id)

def ensure_tenant_exists ( keystone , tenant_name , tenant_description , check_mode ) : try : tenant = get_tenant ( keystone , tenant_name ) except KeyError : pass else : if ( tenant . description == tenant_description ) : return ( False , tenant . id ) elif check_mode : return ( True , tenant . id ) else : tenant . update ( description = tenant_description ) return ( True , tenant . id ) if check_mode : return ( True , None ) ks_tenant = keystone . tenants . create ( tenant_name = tenant_name , description = tenant_description , enabled = True ) return ( True , ks_tenant . id )
ensure that a tenant exists .