Skip to content

Commit 5a0f2ac

Browse files
committed
orchestration: support stack template composition
In order for composable stack templates to work, the following changes are needed: * a child template URL must be interpreted as relative to its parent template, not to the base URL * the child templates and 'get_file' of child templates must also be included in the stack create request * the references within child templates (to other templates or files) must be resolved so the correct URLs are provided, matching the files provided in the OS stack create request, just like is done for the top-level template. Signed-off-by: David Verbeiren <david.verbeiren@tessares.net>
1 parent 2d81ddd commit 5a0f2ac

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

openstack/orchestration/v1/stacks/template.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package stacks
22

33
import (
44
"fmt"
5+
"path/filepath"
56
"reflect"
67
"strings"
78

@@ -76,12 +77,12 @@ func (t *Template) getFileContents(te interface{}, ignoreIf igFunc, recurse bool
7677

7778
// initialize child template
7879

79-
// get the base location of the child template
80-
baseURL, err := gophercloud.NormalizePathURL(t.baseURL, value)
81-
if err != nil {
82-
return err
80+
// get the base location of the child template. Child path is relative
81+
// to its parent location so that templates can be composed
82+
if t.URL != "" {
83+
childTemplate.baseURL = filepath.Dir(t.URL)
8384
}
84-
childTemplate.baseURL = baseURL
85+
childTemplate.URL = value
8586
childTemplate.client = t.client
8687

8788
// fetch the contents of the child template
@@ -98,14 +99,21 @@ func (t *Template) getFileContents(te interface{}, ignoreIf igFunc, recurse bool
9899
if err := childTemplate.getFileContents(childTemplate.Parsed, ignoreIf, recurse); err != nil {
99100
return err
100101
}
102+
childTemplate.fixFileRefs()
101103
}
102104
}
105+
// If it doesn't parse as a template, it a 'get_file'
103106
}
107+
104108
// update parent template with current child templates' content.
105109
// At this point, the child template has been parsed recursively.
106110
t.fileMaps[value] = childTemplate.URL
107111
t.Files[childTemplate.URL] = string(childTemplate.Bin)
108112

113+
// Also add child templates' own children (templates or get_file)!
114+
for k, v := range childTemplate.Files {
115+
t.Files[k] = v
116+
}
109117
}
110118
}
111119
return nil

0 commit comments

Comments
 (0)