Hi,
I try to develop a new module to deploy resources with an API REST. But I have problems to define relationship between two resources.
I haven't problem to fetch and flush resource individually. This two resources are fetch with a REST endpoint but I can have the relationship between resources with only one endpoint. When I want to delete a resource, I must remove the relationship before removing this resource. But I can't know its dependencies because it is not returned by its REST endpoint. They are returned by the endpoint of the other resource.
It is not easy to describe it so I'm going to explain it with an example.
I have two resources group and user with two REST endpoints (with an example response) :
http://host/api/group :
[{name: 'developer'},{name: 'user'}]
http://host/api/user :
[{
name: 'bob',
groups: ['developer', 'user']
}, {
name: 'alex',
groups: ['user']
}]
So I create two types and two provider to manage them :
Puppet::Type.newtype(:group) do
apply_to_device
ensurable
newparam(:name, :namevar => true)
end
Puppet::Type.newtype(:user) do
apply_to_device
ensurable
newparam(:name, :namevar => true)
newproperty(:groups, :array_matching => :all)
autorequire(:group) do
self[:group]
end
end
The puppet config is :
node 'host' {
user { 'bob':
ensure => present,
groups => ['developer', 'user'],
}
user { 'alex':
ensure => present,
groups => ['user'],
}
group { 'developer',
ensure => present,
}
group { 'user',
ensure => present,
}
}
When I run "puppet device", the log is :
prefetch group
flush group 'developer'
flush group 'user'
prefetch user
flush user 'bob'
flush user 'alex'Now I want to delete a group :
node 'host' {
user { 'bob':
ensure => present,
groups => ['user'],
}
user { 'alex':
ensure => present,
groups => ['user'],
}
group { 'developer',
ensure => absent,
}
group { 'user',
ensure => present,
}
}
When I run "puppet device", the log should be :
prefetch group
destroy group 'developer'
prefetch user
flush user 'bob'But, when I want to delete a group, the endpoint check if is not affected to a user and throw an exception it there is any relationship. So, I must remove all user group before remove the group.
But I think this is not possible to do this with puppet because the management of each resource is by type. Puppet doesn't know the relations of a group when it flush the data group.
Is it possible with puppet to update the state of resources in this order :
prefetch group
prefetch user
destroy group 'developer' and relationship with user 'bob'
flush user 'bob'I try other solution with an autosubscribe instead of autorequire to have a notification when the group is deleted but this notification happens at the end :
prefetch group
destroy group 'developer'
flush group 'user'
prefetch user
flush user 'bob'
flush user 'alex'
notify user 'bob'I think the best order to do this is :
prefetch group
prefetch user
notify user 'bob' => Call an REST endpoint to remove relationship
destroy group 'developer'
flush group 'user'
flush user 'bob'
flush user 'alex'Cheers,
Thomas