本文整理汇总了Python中spinnaker.yaml_util.YamlBindings.transform_yaml_source方法的典型用法代码示例。如果您正苦于以下问题:Python YamlBindings.transform_yaml_source方法的具体用法?Python YamlBindings.transform_yaml_source怎么用?Python YamlBindings.transform_yaml_source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spinnaker.yaml_util.YamlBindings
的用法示例。
在下文中一共展示了YamlBindings.transform_yaml_source方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_transform_ok
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import transform_yaml_source [as 别名]
def test_transform_ok(self):
bindings = YamlBindings()
bindings.import_dict({'a': {'b': { 'space': 'WithSpace',
'nospace': 'WithoutSpace',
'empty': 'Empty'}},
'x' : {'unique': True}})
template = """
a:
b:
space: {space}
nospace:{nospace}
empty:{empty}
unique:
b:
space: A
nospace:B
empty:
"""
source = template.format(space='SPACE', nospace='NOSPACE', empty='')
expect = template.format(space='WithSpace',
nospace=' WithoutSpace',
empty=' Empty')
got = source
for key in [ 'a.b.space', 'a.b.nospace', 'a.b.empty' ]:
got = bindings.transform_yaml_source(got, key)
self.assertEqual(expect, bindings.transform_yaml_source(expect, 'bogus'))
self.assertEqual(expect, got)
示例2: populate_google_yml
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import transform_yaml_source [as 别名]
def populate_google_yml(content):
credentials = {'project': '', 'jsonPath': ''}
google_dict = {'enabled': False,
'defaultRegion': 'us-central1',
'defaultZone': 'us-central1-f',}
google_dict['primaryCredentials'] = credentials
if is_google_instance():
zone = os.path.basename(
check_fetch(GOOGLE_INSTANCE_METADATA_URL + '/zone',
google=True).content)
google_dict['enabled'] = 'true'
google_dict['defaultRegion'] = zone[:-2]
google_dict['defaultZone'] = zone
credentials['project'] = check_fetch(
GOOGLE_METADATA_URL + '/project/project-id', google=True).content
bindings = YamlBindings()
bindings.import_dict({'providers': {'google': google_dict}})
content = bindings.transform_yaml_source(content, 'providers.google.enabled')
content = bindings.transform_yaml_source(
content, 'providers.google.defaultRegion')
content = bindings.transform_yaml_source(
content, 'providers.google.defaultZone')
content = bindings.transform_yaml_source(
content, 'providers.google.primaryCredentials.project')
content = bindings.transform_yaml_source(
content, 'providers.google.primaryCredentials.jsonPath')
return content
示例3: test_transform_fail
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import transform_yaml_source [as 别名]
def test_transform_fail(self):
bindings = YamlBindings()
bindings.import_dict({'a': {'b': { 'child': 'Hello, World!'}},
'x' : {'unique': True}})
yaml = """
a:
b:
child: Hello
"""
with self.assertRaises(ValueError):
bindings.transform_yaml_source(yaml, 'x.unique')
示例4: populate_aws_yml
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import transform_yaml_source [as 别名]
def populate_aws_yml(content):
aws_dict = {'enabled': False}
if is_aws_instance():
zone = (check_fetch(AWS_METADATA_URL + '/placement/availability-zone')
.content)
aws_dict['enabled'] = 'true'
aws_dict['defaultRegion'] = zone[:-1]
elif os.path.exists(os.path.join(os.environ['HOME'], '.aws/credentials')):
aws_dict['enabled'] = 'true'
aws_dict['defaultRegion'] = 'us-east-1'
bindings = YamlBindings()
bindings.import_dict({'providers': {'aws': aws_dict}})
content = bindings.transform_yaml_source(content, 'providers.aws.enabled')
content = bindings.transform_yaml_source(content,
'providers.aws.defaultRegion')
return content
示例5: populate_google_yml
# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import transform_yaml_source [as 别名]
def populate_google_yml(content):
credentials = {'project': '', 'jsonPath': ''}
google_dict = {'enabled': False,
'defaultRegion': 'us-central1',
'defaultZone': 'us-central1-f',}
google_dict['primaryCredentials'] = credentials
front50_dict = {}
if is_google_instance():
zone = os.path.basename(
check_fetch(GOOGLE_INSTANCE_METADATA_URL + '/zone',
google=True).content)
google_dict['enabled'] = 'true'
google_dict['defaultRegion'] = zone[:-2]
google_dict['defaultZone'] = zone
credentials['project'] = check_fetch(
GOOGLE_METADATA_URL + '/project/project-id', google=True).content
front50_dict['storage_bucket'] = '${{{env}:{default}}}'.format(
env='SPINNAKER_DEFAULT_STORAGE_BUCKET',
default=credentials['project'].replace(':', '-').replace('.', '-'))
bindings = YamlBindings()
bindings.import_dict({'providers': {'google': google_dict}})
bindings.import_dict({'services': {'front50': front50_dict}})
content = bindings.transform_yaml_source(content, 'providers.google.enabled')
content = bindings.transform_yaml_source(
content, 'providers.google.defaultRegion')
content = bindings.transform_yaml_source(
content, 'providers.google.defaultZone')
content = bindings.transform_yaml_source(
content, 'providers.google.primaryCredentials.project')
content = bindings.transform_yaml_source(
content, 'providers.google.primaryCredentials.jsonPath')
content = bindings.transform_yaml_source(
content, 'services.front50.storage_bucket')
return content