Possible to use relative paths in CR
Useful for CRs that are outside of repo (ie. riak_cluster.yaml) Change-Id: I7f436cb447a22c9bc5b68a35d1c73538571dfd10
This commit is contained in:
parent
b9d230aa95
commit
eb703d5ff8
@ -2,28 +2,31 @@ id: riak_cluster
|
||||
|
||||
resources:
|
||||
- id: riak_service1
|
||||
from: examples/riak/riak_service.yaml
|
||||
# `./` added by intention
|
||||
from: ./riak_service.yaml
|
||||
input:
|
||||
node: #{nodes[0]}#
|
||||
index: 1
|
||||
index: 1
|
||||
join_to: ''
|
||||
|
||||
- id: riak_service2
|
||||
from: examples/riak/riak_service.yaml
|
||||
# `./` ommited by intention
|
||||
from: riak_service.yaml
|
||||
input:
|
||||
node: #{nodes[1]}#
|
||||
index: 2
|
||||
index: 2
|
||||
join_to: riak_service1
|
||||
|
||||
- id: riak_service3
|
||||
from: examples/riak/riak_service.yaml
|
||||
# `./` ommited by intention
|
||||
from: riak_service.yaml
|
||||
input:
|
||||
node: #{nodes[2]}#
|
||||
index: 3
|
||||
index: 3
|
||||
join_to: riak_service1
|
||||
|
||||
- id: haproxy_riak_config
|
||||
from: examples/riak/haproxy_riak_config.yaml
|
||||
from: ./haproxy_riak_config.yaml
|
||||
input:
|
||||
http_listen_port: 8098
|
||||
pb_listen_port: 8087
|
||||
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
import click
|
||||
@ -74,6 +75,10 @@ def clear_all():
|
||||
@click.argument('base_path')
|
||||
@click.argument('args', nargs=-1)
|
||||
def create(args, base_path, name):
|
||||
if base_path.startswith('./'):
|
||||
base_path = os.path.abspath(base_path)
|
||||
elif base_path.endswith('.yaml'):
|
||||
base_path = os.path.abspath(base_path)
|
||||
args_parsed = {}
|
||||
|
||||
click.echo('create {} {} {}'.format(name, base_path, args))
|
||||
|
@ -53,7 +53,7 @@ def create(name, spec, inputs=None, tags=None):
|
||||
if os.path.isfile(spec):
|
||||
template = _compile_file(name, spec, inputs)
|
||||
yaml_template = yaml.load(StringIO(template))
|
||||
rs = apply_composer_file(name, yaml_template, tags)
|
||||
rs = apply_composer_file(spec, name, yaml_template, tags)
|
||||
else:
|
||||
r = create_resource(name, spec, inputs=inputs, tags=tags,)
|
||||
rs = [r]
|
||||
@ -65,7 +65,7 @@ def create(name, spec, inputs=None, tags=None):
|
||||
path = repo.get_composer_file_path(spec)
|
||||
template = _compile_file(name, path, inputs)
|
||||
yaml_template = yaml.load(StringIO(template))
|
||||
rs = apply_composer_file(name, yaml_template, tags)
|
||||
rs = apply_composer_file(path, name, yaml_template, tags)
|
||||
else:
|
||||
r = create_resource(name, spec, inputs=inputs, tags=tags)
|
||||
rs = [r]
|
||||
@ -94,12 +94,16 @@ def create_resource(name, spec, inputs=None, tags=None):
|
||||
return r
|
||||
|
||||
|
||||
def apply_composer_file(vr_name, template, tags=None):
|
||||
def apply_composer_file(base_path, vr_name, template, tags=None):
|
||||
template_resources = template.get('resources', [])
|
||||
template_events = template.get('events', [])
|
||||
resources_to_update = template.get('updates', [])
|
||||
|
||||
created_resources = create_resources(template_resources, tags=tags)
|
||||
created_resources = create_resources(
|
||||
base_path,
|
||||
template_resources,
|
||||
tags=tags
|
||||
)
|
||||
events = parse_events(template_events)
|
||||
for event in events:
|
||||
add_event(event)
|
||||
@ -137,7 +141,8 @@ def _get_template(name, content, kwargs, inputs):
|
||||
return template
|
||||
|
||||
|
||||
def create_resources(resources, tags=None):
|
||||
def create_resources(base_path, resources, tags=None):
|
||||
|
||||
created_resources = []
|
||||
for r in resources:
|
||||
resource_name = r['id']
|
||||
@ -146,9 +151,15 @@ def create_resources(resources, tags=None):
|
||||
values_from = r.get('values_from')
|
||||
spec = r.get('from', None)
|
||||
tags = r.get('tags', [])
|
||||
is_composer_file = False
|
||||
if spec.startswith('./') or spec.endswith('.yaml'):
|
||||
spec = os.path.join(base_path, '..', spec)
|
||||
spec = os.path.abspath(os.path.normpath(spec))
|
||||
is_composer_file = True
|
||||
|
||||
new_resources = create(resource_name, spec, inputs=inputs, tags=tags)
|
||||
created_resources += new_resources
|
||||
is_composer_file = False
|
||||
|
||||
if not spec.startswith('/'):
|
||||
repo, parsed_spec = Repository.parse(spec)
|
||||
is_composer_file = repo.is_composer_file(spec)
|
||||
|
Loading…
x
Reference in New Issue
Block a user