• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python yaml_util.YamlBindings类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中spinnaker.yaml_util.YamlBindings的典型用法代码示例。如果您正苦于以下问题:Python YamlBindings类的具体用法?Python YamlBindings怎么用?Python YamlBindings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了YamlBindings类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_load_key_not_found

  def test_load_key_not_found(self):
    bindings = YamlBindings()
    bindings.import_dict({'field': '${injected.value}', 'injected': {}})

    with self.assertRaises(KeyError):
      bindings['unknown']
    self.assertEqual(None, bindings.get('unknown', None))
开发者ID:sstrato,项目名称:spinnaker,代码行数:7,代码来源:yaml_util_test.py


示例2: test_load_path

  def test_load_path(self):
    yaml = """
a: A
b: 0
c:
  - A
  - B
d:
  child:
    grandchild: x
e:
"""
    expect = {'a': 'A',
              'b': 0,
              'c': ['A','B'],
              'd': {'child': {'grandchild': 'x'}},
              'e': None}

    fd, temp_path = tempfile.mkstemp()
    os.write(fd, yaml)
    os.close(fd)

    bindings = YamlBindings()
    bindings.import_path(temp_path)
    self.assertEqual(expect, bindings.map)
开发者ID:sstrato,项目名称:spinnaker,代码行数:25,代码来源:yaml_util_test.py


示例3: test_list

 def test_list(self):
    bindings = YamlBindings()
    bindings.import_string(
       "root:\n - elem: 'first'\n - elem: 2\n - elem: true\ncopy: ${root}")
    self.assertEqual([{'elem': 'first'}, {'elem': 2}, {'elem': True}],
                     bindings.get('root'))
    self.assertEqual(bindings.get('root'), bindings.get('copy'))
开发者ID:sstrato,项目名称:spinnaker,代码行数:7,代码来源:yaml_util_test.py


示例4: test_bool

 def test_bool(self):
    bindings = YamlBindings()
    bindings.import_string(
       "root:\n - elem: true\n - elem: True\n - elem: false\n - elem: False\ncopy: ${root}")
    self.assertEqual([{'elem': True}, {'elem': True}, {'elem': False}, {'elem': False}],
                     bindings.get('root'))
    self.assertEqual(bindings.get('root'), bindings.get('copy'))
开发者ID:sstrato,项目名称:spinnaker,代码行数:7,代码来源:yaml_util_test.py


示例5: test_true_false_not_resolved

 def test_true_false_not_resolved(self):
     bindings = YamlBindings()
     bindings.import_dict({'indirect': '${t}'})
     validator = ValidateConfig(
           configurator=Configurator(bindings=bindings))
     self.assertFalse(validator.verify_true_false('indirect'))
     self.assertEqual('Missing "indirect".', validator.errors[0])
开发者ID:PioTi,项目名称:spinnaker,代码行数:7,代码来源:validate_configuration_test.py


示例6: test_update_field_union_child

 def test_update_field_union_child(self):
   bindings = YamlBindings()
   bindings.import_dict({'parent1': {'a': 'A'}, 'parent2': {'x': 'X'}})
   bindings.import_dict({'parent1': {'b': 'B'}})
   self.assertEqual({'parent1': {'a': 'A', 'b': 'B'},
                     'parent2': {'x': 'X'}},
                    bindings.map)
开发者ID:sstrato,项目名称:spinnaker,代码行数:7,代码来源:yaml_util_test.py


示例7: test_transform_ok

  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)
开发者ID:sstrato,项目名称:spinnaker,代码行数:28,代码来源:yaml_util_test.py


示例8: maybe_copy_master_yml

def maybe_copy_master_yml(options):
    """Copy the specified master spinnaker-local.yml, and credentials.

    This will look for paths to credentials within the spinnaker-local.yml, and
    copy those as well. The paths to the credentials (and the reference
    in the config file) will be changed to reflect the filesystem on the
    new instance, which may be different than on this instance.

    Args:
      options [Namespace]: The parser namespace options contain information
        about the instance we're going to copy to, as well as the source
        of the master spinnaker-local.yml file.
    """
    if not options.master_yml:
        maybe_inform("custom spinnaker-local.yml", ".spinnaker/spinnaker-local.yml", "--copy_master_yml")
        return

    bindings = YamlBindings()
    bindings.import_path(options.master_yml)

    try:
        json_credential_path = bindings.get("providers.google.primaryCredentials.jsonPath")
    except KeyError:
        json_credential_path = None

    gcp_home = os.path.join("/home", os.environ["LOGNAME"], ".spinnaker")

    # If there are credentials, write them to this path
    gcp_credential_path = os.path.join(gcp_home, "google-credentials.json")

    with open(options.master_yml, "r") as f:
        content = f.read()

    # Replace all the occurances of the original credentials path with the
    # path that we are going to place the file in on the new instance.
    if json_credential_path:
        if not os.path.exists(json_credential_path):
            raise ValueError(
                "{0} specifies google credentials in {1},"
                " which does not exist.".format(options.master_yml, json_credential_path)
            )

        content = content.replace(json_credential_path, gcp_credential_path)

    fd, temp_path = tempfile.mkstemp()
    os.fchmod(fd, os.stat(options.master_yml).st_mode)  # Copy original mode
    os.write(fd, content)
    os.close(fd)
    actual_path = temp_path

    # Copy the credentials here. The cfg file will be copied after.
    copy_custom_file(options, actual_path, ".spinnaker/spinnaker-local.yml")

    if json_credential_path:
        copy_custom_file(options, json_credential_path, ".spinnaker/google-credentials.json")

    if temp_path:
        os.remove(temp_path)
开发者ID:vnandha,项目名称:spinnaker,代码行数:58,代码来源:create_google_dev_vm.py


示例9: copy_master_yml

def copy_master_yml(options):
    """Copy the specified master spinnaker-local.yml, and credentials.

    This will look for paths to credentials within the spinnaker-local.yml, and
    copy those as well. The paths to the credentials (and the reference
    in the config file) will be changed to reflect the filesystem on the
    new instance, which may be different than on this instance.

    Args:
      options [Namespace]: The parser namespace options contain information
        about the instance we're going to copy to, as well as the source
        of the master spinnaker-local.yml file.
    """
    print 'Creating .spinnaker directory...'
    check_run_quick('gcloud compute ssh --command "mkdir -p .spinnaker"'
                    ' --project={project} --zone={zone} {instance}'
                    .format(project=get_project(options),
                            zone=options.zone,
                            instance=options.instance),
                    echo=False)

    bindings = YamlBindings()
    bindings.import_path(options.master_yml)

    try:
      json_credential_path = bindings.get(
          'providers.google.primaryCredentials.jsonPath')
    except KeyError:
      json_credential_path = None

    gcp_home = os.path.join('/home', os.environ['LOGNAME'], '.spinnaker')

    # If there are credentials, write them to this path
    gcp_credential_path = os.path.join(gcp_home, 'google-credentials.json')

    with open(options.master_yml, 'r') as f:
        content = f.read()

    # Replace all the occurances of the original credentials path with the
    # path that we are going to place the file in on the new instance.
    if json_credential_path:
        content = content.replace(json_credential_path, gcp_credential_path)

    fd, temp_path = tempfile.mkstemp()
    os.write(fd, content)
    os.close(fd)
    actual_path = temp_path

    # Copy the credentials here. The cfg file will be copied after.
    copy_file(options, actual_path, '.spinnaker/spinnaker-local.yml')

    if json_credential_path:
        copy_file(options, json_credential_path,
                  '.spinnaker/google-credentials.json')

    if temp_path:
      os.remove(temp_path)
开发者ID:hadoop835,项目名称:spinnaker,代码行数:57,代码来源:create_google_dev_vm.py


示例10: test_true_false_good

 def test_true_false_good(self):
     bindings = YamlBindings()
     bindings.import_dict(
         {'t': True, 'f':False, 'indirect':'${t}', 'default': '${x:true}'})
     validator = ValidateConfig(
           configurator=Configurator(bindings=bindings))
     self.assertTrue(validator.verify_true_false('t'))
     self.assertTrue(validator.verify_true_false('f'))
     self.assertTrue(validator.verify_true_false('indirect'))
     self.assertTrue(validator.verify_true_false('default'))
开发者ID:PioTi,项目名称:spinnaker,代码行数:10,代码来源:validate_configuration_test.py


示例11: test_load_dict

  def test_load_dict(self):
    expect = {'a': 'A',
              'b': 0,
              'c': ['A','B'],
              'd': {'child': {'grandchild': 'x'}},
              'e': None}

    bindings = YamlBindings()
    bindings.import_dict(expect)
    self.assertEqual(expect, bindings.map)
开发者ID:sstrato,项目名称:spinnaker,代码行数:10,代码来源:yaml_util_test.py


示例12: maybe_copy_master_yml

def maybe_copy_master_yml(options):
    """Copy the specified master spinnaker-local.yml, and credentials.

    This will look for paths to credentials within the spinnaker-local.yml, and
    copy those as well. The paths to the credentials (and the reference
    in the config file) will be changed to reflect the filesystem on the
    new instance, which may be different than on this instance.

    Args:
      options [Namespace]: The parser namespace options contain information
        about the instance we're going to copy to, as well as the source
        of the master spinnaker-local.yml file.
    """
    if not options.master_yml:
        maybe_inform('custom spinnaker-local.yml',
                     '.spinnaker/spinnaker-local.yml', '--copy_master_yml')
        return

    bindings = YamlBindings()
    bindings.import_path(options.master_yml)

    try:
      json_credential_path = bindings.get(
          'providers.google.primaryCredentials.jsonPath')
    except KeyError:
      json_credential_path = None

    gcp_home = os.path.join('/home', os.environ['LOGNAME'], '.spinnaker')

    # If there are credentials, write them to this path
    gcp_credential_path = os.path.join(gcp_home, 'google-credentials.json')

    with open(options.master_yml, 'r') as f:
        content = f.read()

    # Replace all the occurances of the original credentials path with the
    # path that we are going to place the file in on the new instance.
    if json_credential_path:
        content = content.replace(json_credential_path, gcp_credential_path)

    fd, temp_path = tempfile.mkstemp()
    os.write(fd, content)
    os.close(fd)
    actual_path = temp_path

    # Copy the credentials here. The cfg file will be copied after.
    copy_custom_file(options, actual_path, '.spinnaker/spinnaker-local.yml')

    if json_credential_path:
        copy_custom_file(options, json_credential_path,
                         '.spinnaker/google-credentials.json')

    if temp_path:
      os.remove(temp_path)
开发者ID:hippocampi,项目名称:spinnaker,代码行数:54,代码来源:create_google_dev_vm.py


示例13: host_test_helper

 def host_test_helper(self, tests, valid, required=False):
     bindings = YamlBindings()
     bindings.import_dict(tests)
     validator = ValidateConfig(
           configurator=Configurator(bindings=bindings))
     for key, value in tests.items():
         msg = '"{key}" was {valid}'.format(
             key=key, valid='invalid' if valid else 'valid')
                                            
         self.assertEqual(valid, validator.verify_host(key, required), msg)
     return validator
开发者ID:PioTi,项目名称:spinnaker,代码行数:11,代码来源:validate_configuration_test.py


示例14: test_transform_fail

  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')
开发者ID:sstrato,项目名称:spinnaker,代码行数:11,代码来源:yaml_util_test.py


示例15: test_verify_at_least_one_provider_enabled_good

 def test_verify_at_least_one_provider_enabled_good(self):
     bindings = YamlBindings()
     bindings.import_dict({
         'providers': {
             'aws': { 'enabled': False },
             'google': {'enabled': False },
             'another': {'enabled': True }
         },
     })
     validator = ValidateConfig(
           configurator=Configurator(bindings=bindings))
     self.assertTrue(validator.verify_at_least_one_provider_enabled())
开发者ID:PioTi,项目名称:spinnaker,代码行数:12,代码来源:validate_configuration_test.py


示例16: disable_destructive_action_challenge

def disable_destructive_action_challenge():
  """Disables destructive action challenge for codelab.

  """
  YamlBindings.update_yml_source(
    '/opt/spinnaker/config/clouddriver.yml',
    {
      'credentials': {
        'challengeDestructiveActionsEnvironments': ''
      }
    }
  )
开发者ID:ajordens,项目名称:spinnaker,代码行数:12,代码来源:codelab_config.py


示例17: test_create_yml_source

  def test_create_yml_source(self):
    expect = {
      'first': { 'child': 'FirstValue' },
      'second': { 'child': True }
    }
    fd, temp_path = tempfile.mkstemp()
    os.write(fd, "")
    os.close(fd)
    YamlBindings.update_yml_source(temp_path, expect)

    comparison_bindings = YamlBindings()
    comparison_bindings.import_path(temp_path)
    self.assertEqual(expect, comparison_bindings.map)
    os.remove(temp_path)
开发者ID:PioTi,项目名称:spinnaker,代码行数:14,代码来源:yaml_util_test.py


示例18: test_verify_at_least_one_provider_enabled_bad

 def test_verify_at_least_one_provider_enabled_bad(self):
     bindings = YamlBindings()
     bindings.import_dict({
         'providers': {
             'aws': { 'enabled': False },
             'google': {'enabled': False }
         },
         'services': {'test': { 'enabled': True }}
     })
     validator = ValidateConfig(
           configurator=Configurator(bindings=bindings))
     self.assertFalse(validator.verify_at_least_one_provider_enabled())
     self.assertEqual('None of the providers are enabled.',
                      validator.errors[0])
开发者ID:PioTi,项目名称:spinnaker,代码行数:14,代码来源:validate_configuration_test.py


示例19: populate_google_yml

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
开发者ID:343829084,项目名称:spinnaker,代码行数:31,代码来源:dev_runner.py


示例20: baseUrl_test_helper

 def baseUrl_test_helper(self, tests, valid, scheme_optional):
     bindings = YamlBindings()
     bindings.import_dict(tests)
     validator = ValidateConfig(
           configurator=Configurator(bindings=bindings))
     for key, value in tests.items():
         msg = '"{key}" was {valid}'.format(
             key=key, valid='invalid' if valid else 'valid')
                                            
         self.assertEqual(
             valid,
             validator.verify_baseUrl(key, True,
                                      scheme_optional=scheme_optional),
             msg)
开发者ID:PioTi,项目名称:spinnaker,代码行数:14,代码来源:validate_configuration_test.py



注:本文中的spinnaker.yaml_util.YamlBindings类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.login函数代码示例发布时间:2022-05-27
下一篇:
Python validate_configuration.ValidateConfig类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap