簡體   English   中英

DM Python 模板 - 如何為 GCE 實例添加 ssh 訪問權限?

[英]DM Python template - how do you add ssh access to GCE instances?

我可以使用部署管理器 Python 模板創建基本實例,但如何啟用 ssh 訪問? 使用屬性/元數據字段? 任何例子將不勝感激!

如果您在創建實例后無法通過 SSH 連接到機器,您可能需要添加防火牆規則以允許端口 22 上的連接。類似於下面的內容將起作用。

def GenerateConfig(context):


"""Creates the firewall with environment variables."""

  resources = [{
      'name': context.env['name'],
      'type': 'compute.v1.firewall',
      'properties': {
          'network': '$(ref.' + context.properties['network'] + '.selfLink)',
          'sourceRanges': ['0.0.0.0/0'],
          'allowed': [{
              'IPProtocol': 'TCP',
              'ports': [22]
          }]
      }
  }]
  return {'resources': resources}

參考: https : //github.com/GoogleCloudPlatform/deploymentmanager-samples/blob/master/examples/v2/step_by_step_guide/step7_use_environment_variables/python/firewall-template.py

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM