#NEWLINE# def user_present( name , password , email , tenant = None , enabled = True , roles = None , profile = None , password_reset = True , **connection_args ) : #NEWLINE# #INDENT# '\n    Ensure that the keystone user is present with the specified properties.\n\n    name\n        The name of the user to manage\n\n    password\n        The password to use for this user\n\n    password_reset\n        Whether or not to reset password after initial set\n\n    email\n        The email address for this user\n\n    tenant\n        The tenant for this user\n\n    enabled\n        Availability state for this user\n\n    roles\n        The roles the user should have under given tenants.\n        Passed as a dictionary mapping tenant names to a list\n        of roles in this tenant, i.e.::\n\n            roles:\n                admin:   # tenant\n                  - admin  # role\n                service:\n                  - admin\n                  - Member\n    ' #NEWLINE# ret = { #NEWLINE# #INDENT# 'name' : name , #NEWLINE# 'changes' : { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , #NEWLINE# 'result' : True , #NEWLINE# 'comment' : 'User "{0}" will be updated' . format ( name ) , #NEWLINE# #UNINDENT# } #NEWLINE# if ( tenant is not None ) : #NEWLINE# #INDENT# tenantdata = __salt__ [ 'keystone.tenant_get' ] ( name = tenant , profile = profile , ** connection_args ) #NEWLINE# if ( 'Error' in tenantdata ) : #NEWLINE# #INDENT# ret [ 'result' ] = False #NEWLINE# ret [ 'comment' ] = 'Tenant "{0}" does not exist' . format ( tenant ) #NEWLINE# return ret #NEWLINE# #UNINDENT# tenant_id = tenantdata [ tenant ] [ 'id' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tenant_id = None #NEWLINE# #UNINDENT# user = __salt__ [ 'keystone.user_get' ] ( name = name , profile = profile , ** connection_args ) #NEWLINE# if ( 'Error' not in user ) : #NEWLINE# #INDENT# ret [ 'comment' ] = 'User "{0}" is already present' . format ( name ) #NEWLINE# if ( user [ name ] [ 'email' ] != email ) : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# ret [ 'changes' ] [ 'Email' ] = 'Will be updated' #NEWLINE# return ret #NEWLINE# #UNINDENT# __salt__ [ 'keystone.user_update' ] ( name = name , email = email , profile = profile , ** connection_args ) #NEWLINE# ret [ 'comment' ] = 'User "{0}" has been updated' . format ( name ) #NEWLINE# ret [ 'changes' ] [ 'Email' ] = 'Updated' #NEWLINE# #UNINDENT# if ( user [ name ] [ 'enabled' ] != enabled ) : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# ret [ 'changes' ] [ 'Enabled' ] = 'Will be {0}' . format ( enabled ) #NEWLINE# return ret #NEWLINE# #UNINDENT# __salt__ [ 'keystone.user_update' ] ( name = name , enabled = enabled , profile = profile , ** connection_args ) #NEWLINE# ret [ 'comment' ] = 'User "{0}" has been updated' . format ( name ) #NEWLINE# ret [ 'changes' ] [ 'Enabled' ] = 'Now {0}' . format ( enabled ) #NEWLINE# #UNINDENT# if ( tenant and ( ( 'tenant_id' not in user [ name ] ) or ( user [ name ] [ 'tenant_id' ] != tenant_id ) ) ) : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# ret [ 'changes' ] [ 'Tenant' ] = 'Will be added to "{0}" tenant' . format ( tenant ) #NEWLINE# return ret #NEWLINE# #UNINDENT# __salt__ [ 'keystone.user_update' ] ( name = name , tenant = tenant , profile = profile , ** connection_args ) #NEWLINE# ret [ 'comment' ] = 'User "{0}" has been updated' . format ( name ) #NEWLINE# ret [ 'changes' ] [ 'Tenant' ] = 'Added to "{0}" tenant' . format ( tenant ) #NEWLINE# #UNINDENT# if ( ( password_reset is True ) and ( not __salt__ [ 'keystone.user_verify_password' ] ( name = name , password = password , profile = profile , ** connection_args ) ) ) : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# ret [ 'changes' ] [ 'Password' ] = 'Will be updated' #NEWLINE# return ret #NEWLINE# #UNINDENT# __salt__ [ 'keystone.user_password_update' ] ( name = name , password = password , profile = profile , ** connection_args ) #NEWLINE# ret [ 'comment' ] = 'User "{0}" has been updated' . format ( name ) #NEWLINE# ret [ 'changes' ] [ 'Password' ] = 'Updated' #NEWLINE# #UNINDENT# if roles : #NEWLINE# #INDENT# for tenant in roles . keys ( ) : #NEWLINE# #INDENT# args = dict ( { #NEWLINE# #INDENT# 'user_name' : name , #NEWLINE# 'tenant_name' : tenant , #NEWLINE# 'profile' : profile , #NEWLINE# #UNINDENT# } , ** connection_args ) #NEWLINE# tenant_roles = __salt__ [ 'keystone.user_role_list' ] ( ** args ) #NEWLINE# for role in roles [ tenant ] : #NEWLINE# #INDENT# if ( role not in tenant_roles ) : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# if ( 'roles' in ret [ 'changes' ] ) : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'roles' ] . append ( role ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'roles' ] = [ role ] #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# addargs = dict ( { #NEWLINE# #INDENT# 'user' : name , #NEWLINE# 'role' : role , #NEWLINE# 'tenant' : tenant , #NEWLINE# 'profile' : profile , #NEWLINE# #UNINDENT# } , ** connection_args ) #NEWLINE# newrole = __salt__ [ 'keystone.user_role_add' ] ( ** addargs ) #NEWLINE# if ( 'roles' in ret [ 'changes' ] ) : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'roles' ] . append ( newrole ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'roles' ] = [ newrole ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# roles_to_remove = list ( ( set ( tenant_roles ) - set ( roles [ tenant ] ) ) ) #NEWLINE# for role in roles_to_remove : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# if ( 'roles' in ret [ 'changes' ] ) : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'roles' ] . append ( role ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'roles' ] = [ role ] #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# addargs = dict ( { #NEWLINE# #INDENT# 'user' : name , #NEWLINE# 'role' : role , #NEWLINE# 'tenant' : tenant , #NEWLINE# 'profile' : profile , #NEWLINE# #UNINDENT# } , ** connection_args ) #NEWLINE# oldrole = __salt__ [ 'keystone.user_role_remove' ] ( ** addargs ) #NEWLINE# if ( 'roles' in ret [ 'changes' ] ) : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'roles' ] . append ( oldrole ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ 'changes' ] [ 'roles' ] = [ oldrole ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if __opts__ [ 'test' ] : #NEWLINE# #INDENT# ret [ 'result' ] = None #NEWLINE# ret [ 'comment' ] = 'Keystone user "{0}" will be added' . format ( name ) #NEWLINE# ret [ 'changes' ] [ 'User' ] = 'Will be created' #NEWLINE# return ret #NEWLINE# #UNINDENT# __salt__ [ 'keystone.user_create' ] ( name = name , password = password , email = email , tenant_id = tenant_id , enabled = enabled , profile = profile , ** connection_args ) #NEWLINE# if roles : #NEWLINE# #INDENT# for tenant in roles . keys ( ) : #NEWLINE# #INDENT# for role in roles [ tenant ] : #NEWLINE# #INDENT# __salt__ [ 'keystone.user_role_add' ] ( user = name , role = role , tenant = tenant , profile = profile , ** connection_args ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# ret [ 'comment' ] = 'Keystone user {0} has been added' . format ( name ) #NEWLINE# ret [ 'changes' ] [ 'User' ] = 'Created' #NEWLINE# #UNINDENT# return ret