当前位置: 首页>>代码示例>>Python>>正文


Python YamlBindings.import_path方法代码示例

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


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

示例1: test_load_path

# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_path [as 别名]
  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,代码行数:27,代码来源:yaml_util_test.py

示例2: maybe_copy_master_yml

# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_path [as 别名]
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,代码行数:60,代码来源:create_google_dev_vm.py

示例3: copy_master_yml

# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_path [as 别名]
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,代码行数:59,代码来源:create_google_dev_vm.py

示例4: test_update_yml_source

# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_path [as 别名]
  def test_update_yml_source(self):
    yaml = """
a: A
b: 0
c:
  - A
  - B
d:
  child:
    grandchild: x
e:
"""
    fd, temp_path = tempfile.mkstemp()
    os.write(fd, yaml)
    os.close(fd)

    update_dict = {
      'b': 'Z',
      'd': {
        'child': {
          'grandchild': 'xy',
          'new_grandchild': {
             'new_node': 'inserted'
          }
        }
      },
      'e': 'AA'
    }

    expect = {'a': 'A',
              'b': 'Z',
              'c': ['A','B'],
              'd': {
                'child': {
                  'grandchild': 'xy',
                  'new_grandchild': {
                    'new_node': 'inserted'
                  }
                }
              },
              'e': 'AA'}

    with self.assertRaises(KeyError):
      YamlBindings.update_yml_source(
          temp_path, update_dict, add_new_nodes=False)

    # Reset the file
    with open(temp_path, 'w') as fd:
      fd.write(yaml)

    YamlBindings.update_yml_source(temp_path, update_dict)

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

示例5: maybe_copy_master_yml

# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_path [as 别名]
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,代码行数:56,代码来源:create_google_dev_vm.py

示例6: test_create_yml_source

# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_path [as 别名]
  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,代码行数:16,代码来源:yaml_util_test.py

示例7: test_update_yml_source

# 需要导入模块: from spinnaker.yaml_util import YamlBindings [as 别名]
# 或者: from spinnaker.yaml_util.YamlBindings import import_path [as 别名]
  def test_update_yml_source(self):
    yaml = """
a: A
b: 0
c:
  - A
  - B
d:
  child:
    grandchild: x
e:
"""
    fd, temp_path = tempfile.mkstemp()
    os.write(fd, yaml)
    os.close(fd)

    update_dict = {
      'b': 'Z',
      'd': {
        'child': {
          'grandchild': 'xy'
        }
      },
      'e': 'AA'
    }

    expect = {'a': 'A',
              'b': 'Z',
              'c': ['A','B'],
              'd': {
                'child': {
                  'grandchild': 'xy'
                }
              },
              'e': 'AA'}

    YamlBindings.update_yml_source(temp_path, update_dict)

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


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