Browse Source

Allow user creation in domain other than default

For reasonably recent OpenStack releases, users are always created in a
domain (by default in the aptly named 'Default' domain). With this
patch, a new domain name attribute can be passed to the openstack_user's
:create action in order to create a user in a specific domain.
Roger Luethi 1 year ago
parent
commit
bfafac1d99
2 changed files with 10 additions and 0 deletions
  1. 9
    0
      libraries/openstack_user.rb
  2. 1
    0
      spec/user_spec.rb

+ 9
- 0
libraries/openstack_user.rb View File

@@ -32,8 +32,17 @@ module OpenstackclientCookbook
32 32
     action :create do
33 33
       user = connection.users.find { |u| u.name == user_name }
34 34
       project = connection.projects.find { |p| p.name == project_name }
35
+      domain = connection.domains.find { |u| u.name == domain_name }
35 36
       if user
36 37
         log "User with name: \"#{user_name}\" already exists"
38
+      elsif domain
39
+        connection.users.create(
40
+          name: user_name,
41
+          domain_id: domain.id,
42
+          email: email,
43
+          default_project_id: project ? project.id : nil,
44
+          password: password
45
+        )
37 46
       else
38 47
         connection.users.create(
39 48
           name: user_name,

+ 1
- 0
spec/user_spec.rb View File

@@ -133,6 +133,7 @@ describe 'openstackclient_test::user' do
133 133
       expect(users_empty).to receive(:create)
134 134
         .with(
135 135
           name: 'myuser',
136
+          domain_id: 5,
136 137
           email: 'myemail',
137 138
           default_project_id: 42,
138 139
           password: 'mypassword'

Loading…
Cancel
Save