Wrap the logic for creating resource and location_rule in its own function

In order to support resource update we will need to add more complex
logic around resource creation. In preparation for that let's split off
the creation of resources and location_rule in their own function, in
order to simplify the code in the create() functions

Change-Id: I960c72668938566aa83ed36230d4c8af04849317
This commit is contained in:
Michele Baldessari
2018-04-06 08:11:29 +02:00
parent 52e85b0b5f
commit ec5e694df0
2 changed files with 32 additions and 24 deletions

View File

@@ -61,6 +61,20 @@ Puppet::Type.type(:pcmk_bundle).provide(:default) do
@locations_state = {}
end
def create_bundle_and_location(location_rule)
cmd = build_pcs_bundle_cmd()
if location_rule then
pcs('create', @resource[:name], "#{cmd} --disabled", @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
location_rule_create()
pcs('create', @resource[:name], "resource enable #{@resource[:name]}", @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
else
pcs('create', @resource[:name], cmd, @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
end
end
def create
# We need to probe the existance of both location and resource
# because we do not know why we're being created (if for both or
@@ -74,20 +88,10 @@ Puppet::Type.type(:pcmk_bundle).provide(:default) do
# If both the resource and the location do not exist, we create them both
# if a location_rule is specified otherwise only the resource
if not did_location_exist and not did_resource_exist
if location_rule
pcs('create', @resource[:name], "#{cmd} --disabled", @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
location_rule_create()
pcs('create', @resource[:name], "resource enable #{@resource[:name]}", @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
else
pcs('create', @resource[:name], cmd, @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
end
create_bundle_and_location(location_rule)
# If the location_rule already existed, we only create the resource
elsif did_location_exist and not did_resource_exist
pcs('create', @resource[:name], cmd, @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
create_bundle_and_location(false)
# The location_rule does not exist and the resource does exist
elsif not did_location_exist and did_resource_exist
if location_rule

View File

@@ -69,6 +69,20 @@ Puppet::Type.type(:pcmk_resource).provide(:default) do
@locations_state = {}
end
def create_resource_and_location(location_rule)
cmd = build_pcs_resource_cmd()
if location_rule then
pcs('create', @resource[:name], "#{cmd} --disabled", @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
location_rule_create()
pcs('create', @resource[:name], "resource enable #{@resource[:name]}", @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
else
pcs('create', @resource[:name], cmd, @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
end
end
def create
# We need to probe the existance of both location and resource
# because we do not know why we're being created (if for both or
@@ -82,20 +96,10 @@ Puppet::Type.type(:pcmk_resource).provide(:default) do
# If both the resource and the location do not exist, we create them both
# if a location_rule is specified otherwise only the resource
if not did_location_exist and not did_resource_exist
if location_rule
pcs('create', @resource[:name], "#{cmd} --disabled", @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
location_rule_create()
pcs('create', @resource[:name], "resource enable #{@resource[:name]}", @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
else
pcs('create', @resource[:name], cmd, @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
end
create_resource_and_location(location_rule)
# If the location_rule already existed, we only create the resource
elsif did_location_exist and not did_resource_exist
pcs('create', @resource[:name], cmd, @resource[:tries],
@resource[:try_sleep], @resource[:verify_on_create], @resource[:post_success_sleep])
create_resource_and_location(false)
# The location_rule does not exist and the resource does exist
elsif not did_location_exist and did_resource_exist
if location_rule