Browse Source

Refer to property_name as new_resource.property_name

In Chef 14, the short form of property_name is removed, in favor of
new_resource.property_name.[0]

[0] https://docs.chef.io/deprecations_namespace_collisions.html
Samuel Cassiba 1 year ago
parent
commit
a48eb7cca2

+ 7
- 7
libraries/openstack_domain.rb View File

@@ -25,23 +25,23 @@ module OpenstackclientCookbook
25 25
     default_action :create
26 26
 
27 27
     action :create do
28
-      domain = connection.domains.find { |u| u.id == domain_name } ||
29
-               connection.domains.find { |u| u.name == domain_name }
28
+      domain = new_resource.connection.domains.find { |u| u.id == new_resource.domain_name } ||
29
+               new_resource.connection.domains.find { |u| u.name == new_resource.domain_name }
30 30
       if domain
31
-        log "Domain with name: \"#{domain_name}\" already exists"
31
+        log "Domain with name: \"#{new_resource.domain_name}\" already exists"
32 32
       else
33
-        connection.domains.create(
34
-          name: domain_name
33
+        new_resource.connection.domains.create(
34
+          name: new_resource.domain_name
35 35
         )
36 36
       end
37 37
     end
38 38
 
39 39
     action :delete do
40
-      domain = connection.domains.find { |u| u.name == domain_name }
40
+      domain = new_resource.connection.domains.find { |u| u.name == new_resource.domain_name }
41 41
       if domain
42 42
         domain.destroy
43 43
       else
44
-        log "Domain with name: \"#{domain_name}\" doesn't exist"
44
+        log "Domain with name: \"#{new_resource.domain_name}\" doesn't exist"
45 45
       end
46 46
     end
47 47
   end

+ 12
- 12
libraries/openstack_endpoint.rb View File

@@ -29,31 +29,31 @@ module OpenstackclientCookbook
29 29
     default_action :create
30 30
 
31 31
     action :create do
32
-      service = connection.services.find { |s| s.name == service_name }
33
-      endpoint = connection.endpoints.find do |e|
34
-        e.service_id == service.id && e.interface == interface
32
+      service = new_resource.connection.services.find { |s| s.name == new_resource.service_name }
33
+      endpoint = new_resource.connection.endpoints.find do |e|
34
+        e.service_id == service.id && e.interface == new_resource.interface
35 35
       end
36 36
 
37 37
       if endpoint
38
-        log "#{interface}_endpoint for \"#{service_name}\" already exists"
38
+        log "#{new_resource.interface}_endpoint for \"#{new_resource.service_name}\" already exists"
39 39
       else
40
-        connection.endpoints.create(
41
-          interface: interface,
42
-          url: url,
40
+        new_resource.connection.endpoints.create(
41
+          interface: new_resource.interface,
42
+          url: new_resource.url,
43 43
           service_id: service.id,
44
-          name: endpoint_name,
45
-          region: region
44
+          name: new_resource.endpoint_name,
45
+          region: new_resource.region
46 46
         )
47 47
       end
48 48
     end
49 49
 
50 50
     action :delete do
51
-      service = connection.services.find { |s| s.name == service_name }
52
-      endpoint = connection.endpoints.find do |e|
51
+      service = new_resource.connection.services.find { |s| s.name == service_name }
52
+      endpoint = new_resource.connection.endpoints.find do |e|
53 53
         e.service_id == service.id && e.interface == interface
54 54
       end
55 55
       if endpoint
56
-        connection.endpoints.destroy(endpoint.id)
56
+        new_resource.connection.endpoints.destroy(endpoint.id)
57 57
       else
58 58
         log "#{interface}_endpoint for \"#{service_name}\" doesn't exist"
59 59
       end

+ 6
- 6
libraries/openstack_project.rb View File

@@ -25,20 +25,20 @@ module OpenstackclientCookbook
25 25
     default_action :create
26 26
 
27 27
     action :create do
28
-      project = connection.projects.find { |p| p.name == project_name }
28
+      project = new_resource.connection.projects.find { |p| p.name == new_resource.project_name }
29 29
       if project
30
-        log "Project with name: \"#{project_name}\" already exists"
30
+        log "Project with name: \"#{new_resource.project_name}\" already exists"
31 31
       else
32
-        connection.projects.create name: project_name
32
+        new_resource.connection.projects.create name: new_resource.project_name
33 33
       end
34 34
     end
35 35
 
36 36
     action :delete do
37
-      project = connection.projects.find { |p| p.name == project_name }
37
+      project = new_resource.connection.projects.find { |p| p.name == new_resource.project_name }
38 38
       if project
39
-        project.destroy
39
+        new_resource.project.destroy
40 40
       else
41
-        log "Project with name: \"#{project_name}\" doesn't exist"
41
+        log "Project with name: \"#{new_resource.project_name}\" doesn't exist"
42 42
       end
43 43
     end
44 44
   end

+ 5
- 5
libraries/openstack_role.rb View File

@@ -25,20 +25,20 @@ module OpenstackclientCookbook
25 25
     default_action :create
26 26
 
27 27
     action :create do
28
-      role = connection.roles.find { |r| r.name == role_name }
28
+      role = new_resource.connection.roles.find { |r| r.name == new_resource.role_name }
29 29
       if role
30
-        log "Role with name: \"#{role_name}\" already exists"
30
+        log "Role with name: \"#{new_resource.role_name}\" already exists"
31 31
       else
32
-        connection.roles.create name: role_name
32
+        new_resource.connection.roles.create name: new_resource.role_name
33 33
       end
34 34
     end
35 35
 
36 36
     action :delete do
37
-      role = connection.roles.find { |r| r.name == role_name }
37
+      role = new_resource.connection.roles.find { |r| r.name == new_resource.role_name }
38 38
       if role
39 39
         role.destroy
40 40
       else
41
-        log "Role with name: \"#{role_name}\" doesn't exist"
41
+        log "Role with name: \"#{new_resource.role_name}\" doesn't exist"
42 42
       end
43 43
     end
44 44
   end

+ 7
- 7
libraries/openstack_service.rb View File

@@ -26,23 +26,23 @@ module OpenstackclientCookbook
26 26
     default_action :create
27 27
 
28 28
     action :create do
29
-      service = connection.services.find { |s| s.name == service_name }
29
+      service = new_resource.connection.services.find { |s| s.name == new_resource.service_name }
30 30
       if service
31
-        log "Service with name: \"#{service_name}\" already exists"
31
+        log "Service with name: \"#{new_resource.service_name}\" already exists"
32 32
       else
33
-        connection.services.create(
34
-          name: service_name,
35
-          type: type
33
+        new_resource.connection.services.create(
34
+          name: new_resource.service_name,
35
+          type: new_resource.type
36 36
         )
37 37
       end
38 38
     end
39 39
 
40 40
     action :delete do
41
-      service = connection.services.find { |s| s.name == service_name }
41
+      service = new_resource.connection.services.find { |s| s.name == new_resource.service_name }
42 42
       if service
43 43
         service.destroy
44 44
       else
45
-        log "Service with name: \"#{service_name}\" doesn't exist"
45
+        log "Service with name: \"#{new_resource.service_name}\" doesn't exist"
46 46
       end
47 47
     end
48 48
   end

+ 27
- 27
libraries/openstack_user.rb View File

@@ -30,50 +30,50 @@ module OpenstackclientCookbook
30 30
     default_action :create
31 31
 
32 32
     action :create do
33
-      user = connection.users.find { |u| u.name == user_name }
34
-      project = connection.projects.find { |p| p.name == project_name }
35
-      domain = connection.domains.find { |u| u.name == domain_name }
33
+      user = new_resource.connection.users.find { |u| u.name == new_resource.user_name }
34
+      project = new_resource.connection.projects.find { |p| p.name == new_resource.project_name }
35
+      domain = new_resource.connection.domains.find { |u| u.name == new_resource.domain_name }
36 36
       if user
37
-        log "User with name: \"#{user_name}\" already exists"
37
+        log "User with name: \"#{new_resource.user_name}\" already exists"
38 38
       elsif domain
39
-        connection.users.create(
40
-          name: user_name,
39
+        new_resource.connection.users.create(
40
+          name: new_resource.user_name,
41 41
           domain_id: domain.id,
42
-          email: email,
42
+          email: new_resource.email,
43 43
           default_project_id: project ? project.id : nil,
44
-          password: password
44
+          password: new_resource.password
45 45
         )
46 46
       else
47
-        connection.users.create(
48
-          name: user_name,
49
-          email: email,
47
+        new_resource.connection.users.create(
48
+          name: new_resource.user_name,
49
+          email: new_resource.email,
50 50
           default_project_id: project ? project.id : nil,
51
-          password: password
51
+          password: new_resource.password
52 52
         )
53 53
       end
54 54
     end
55 55
 
56 56
     action :delete do
57
-      user = connection.users.find { |u| u.name == user_name }
57
+      user = new_resource.connection.users.find { |u| u.name == new_resource.user_name }
58 58
       if user
59 59
         user.destroy
60 60
       else
61
-        log "User with name: \"#{user_name}\" doesn't exist"
61
+        log "User with name: \"#{new_resource.user_name}\" doesn't exist"
62 62
       end
63 63
     end
64 64
 
65 65
     # Grant a role in a project
66 66
     action :grant_role do
67
-      user = connection.users.find { |u| u.name == user_name }
68
-      project = connection.projects.find { |p| p.name == project_name }
69
-      role = connection.roles.find { |r| r.name == role_name }
67
+      user = new_resource.connection.users.find { |u| u.name == new_resource.user_name }
68
+      project = new_resource.connection.projects.find { |p| p.name == new_resource.project_name }
69
+      role = new_resource.connection.roles.find { |r| r.name == new_resource.role_name }
70 70
       project.grant_role_to_user role.id, user.id if role && project && user
71 71
     end
72 72
 
73 73
     action :revoke_role do
74
-      user = connection.users.find { |u| u.name == user_name }
75
-      project = connection.projects.find { |p| p.name == project_name }
76
-      role = connection.roles.find { |r| r.name == role_name }
74
+      user = new_resource.connection.users.find { |u| u.name == new_resource.user_name }
75
+      project = new_resource.connection.projects.find { |p| p.name == new_resource.project_name }
76
+      role = new_resource.connection.roles.find { |r| r.name == new_resource.role_name }
77 77
       project.revoke_role_from_user role.id, user.id if role && project && user
78 78
     end
79 79
 
@@ -82,17 +82,17 @@ module OpenstackclientCookbook
82 82
     # only used to identify a user who is in that domain. This action grants
83 83
     # the user a role in the domain.
84 84
     action :grant_domain do
85
-      user = connection.users.find { |u| u.name == user_name }
86
-      domain = connection.domains.find { |p| p.name == domain_name }
87
-      role = connection.roles.find { |r| r.name == role_name }
85
+      user = new_resource.connection.users.find { |u| u.name == new_resource.user_name }
86
+      domain = new_resource.connection.domains.find { |p| p.name == new_resource.domain_name }
87
+      role = new_resource.connection.roles.find { |r| r.name == new_resource.role_name }
88 88
       user.grant_role role.id if role && domain && user
89 89
     end
90 90
 
91 91
     action :revoke_domain do
92
-      user = connection.users.find { |u| u.name == user_name }
93
-      domain = connection.domains.find { |p| p.name == domain_name }
94
-      role = connection.roles.find { |r| r.name == role_name }
95
-      user.revoke_role  role.id if role && domain && user
92
+      user = new_resource.connection.users.find { |u| u.name == new_resource.user_name }
93
+      domain = new_resource.connection.domains.find { |p| p.name == new_resource.domain_name }
94
+      role = new_resource.connection.roles.find { |r| r.name == new_resource.role_name }
95
+      user.revoke_role role.id if role && domain && user
96 96
     end
97 97
   end
98 98
 end

Loading…
Cancel
Save