diff --git a/lib/fog/openstack/models/planning/plan.rb b/lib/fog/openstack/models/planning/plan.rb index eeeaa4acd..f123b52aa 100644 --- a/lib/fog/openstack/models/planning/plan.rb +++ b/lib/fog/openstack/models/planning/plan.rb @@ -5,6 +5,9 @@ module Fog class Planning class Plan < Fog::Model + MASTER_TEMPLATE_NAME = 'plan.yaml' + ENVIRONMENT_NAME = 'environment.yaml' + identity :uuid attribute :description @@ -19,6 +22,24 @@ module Fog prepare_service_value(attributes) super end + + def templates + service.get_plan_templates(uuid).body + end + + def master_template + templates[MASTER_TEMPLATE_NAME] + end + + def environment + templates[ENVIRONMENT_NAME] + end + + def provider_resource_templates + templates.select do |key, template| + ![MASTER_TEMPLATE_NAME, ENVIRONMENT_NAME].include?(key) + end + end end end end diff --git a/lib/fog/openstack/planning.rb b/lib/fog/openstack/planning.rb index 936283494..71cbcebbf 100644 --- a/lib/fog/openstack/planning.rb +++ b/lib/fog/openstack/planning.rb @@ -28,6 +28,7 @@ module Fog # Plan requests request :list_plans + request :get_plan_templates request :get_plan class Mock diff --git a/lib/fog/openstack/requests/planning/get_plan_templates.rb b/lib/fog/openstack/requests/planning/get_plan_templates.rb new file mode 100644 index 000000000..5fb78a762 --- /dev/null +++ b/lib/fog/openstack/requests/planning/get_plan_templates.rb @@ -0,0 +1,28 @@ +module Fog + module Openstack + class Planning + class Real + def get_plan_templates(plan_uuid) + request( + :expects => [200, 204], + :method => 'GET', + :path => "plans/#{plan_uuid}/templates" + ) + end + end # class Real + + class Mock + def get_plan_templates(plan_uuid) + response = Excon::Response.new + response.status = [200, 204][rand(1)] + response.body = { + "environment.yaml" => "... content of template file ...", + "plan.yaml" => "... content of template file ...", + "provider-compute-1.yaml" => "... content of template file ..." + } + response + end # def get_plan_templates + end # class Mock + end # class Planning + end # module Openstack +end # module Fog diff --git a/tests/openstack/models/planning/plan_tests.rb b/tests/openstack/models/planning/plan_tests.rb new file mode 100644 index 000000000..c79a4cf64 --- /dev/null +++ b/tests/openstack/models/planning/plan_tests.rb @@ -0,0 +1,21 @@ +Shindo.tests("Fog::Openstack[:planning] | plan", ['openstack']) do + @instance = Fog::Openstack[:planning].plans.first + + tests('success') do + tests('#templates').succeeds do + @instance.templates + end + + tests('#master_template').succeeds do + @instance.master_template + end + + tests('#environment').succeeds do + @instance.environment + end + + tests('#provider_resource_templates').succeeds do + @instance.provider_resource_templates + end + end +end diff --git a/tests/openstack/requests/planning/plan_tests.rb b/tests/openstack/requests/planning/plan_tests.rb index 8675d48fb..eba159db8 100644 --- a/tests/openstack/requests/planning/plan_tests.rb +++ b/tests/openstack/requests/planning/plan_tests.rb @@ -12,6 +12,8 @@ Shindo.tests('Fog::Openstack[:planning] | Planning plan requests', ['openstack'] "version" => Fog::Nullable::Integer, } + @plan_templates_format = Hash + tests('success') do tests('#list_plans').data_matches_schema([@plan_format]) do plans = Fog::Openstack[:planning].list_plans.body @@ -22,5 +24,9 @@ Shindo.tests('Fog::Openstack[:planning] | Planning plan requests', ['openstack'] tests('#get_plan').data_matches_schema(@plan_format) do Fog::Openstack[:planning].get_plan(@instance['uuid']).body end + + tests('#get_plan_templates').data_matches_schema(@plan_templates_format) do + Fog::Openstack[:planning].get_plan_templates(@instance['uuid']).body + end end end