python requests 示例_Python requests.packages方法代码示例

# 需要导入模块: import requests [as 别名]

# 或者: from requests import packages [as 别名]

def get_cloud_init_data(self, radl=None, vm=None, public_key=None, user=None):

"""

Get the cloud init data specified by the user in the RADL

"""

cloud_config = {}

if radl:

configure_name = None

if radl.contextualize.items:

system_name = radl.systems[0].name

for item in radl.contextualize.items.values():

if item.system == system_name and item.get_ctxt_tool() == "cloud_init":

configure_name = item.configure

if configure_name:

cloud_config = yaml.safe_load(radl.get_configure_by_name(configure_name).recipes)

if not isinstance(cloud_config, dict):

# The cloud_init data is a shell script

cloud_config = radl.get_configure_by_name(configure_name).recipes.strip()

self.log_debug(cloud_config)

return cloud_config

# Only for those VMs with private IP

if Config.SSH_REVERSE_TUNNELS and vm and not vm.hasPublicNet():

if 'packages' not in cloud_config:

cloud_config['packages'] = []

cloud_config['packages'].extend(["curl", "sshpass"])

curl_command = vm.get_boot_curl_commands()

if 'bootcmd' not in cloud_config:

cloud_config['bootcmd'] = []

cloud_config['bootcmd'].extend(curl_command)

if vm and vm.getSSHPort() != 22:

if 'bootcmd' not in cloud_config:

cloud_config['bootcmd'] = []

cloud_config['bootcmd'].append("sed -i '/Port 22/c\\Port %s' /etc/ssh/sshd_config" % vm.getSSHPort())

cloud_config['bootcmd'].append("service sshd restart")

if public_key:

user_data = {}

user_data['name'] = user

user_data['sudo'] = "ALL=(ALL) NOPASSWD:ALL"

user_data['lock-passwd'] = True

user_data['ssh-import-id'] = user

# avoid to use default /home dir

user_data['homedir'] = "/opt/%s" % user

user_data['ssh-authorized-keys'] = [public_key.strip()]

if 'users' not in cloud_config:

cloud_config['users'] = []

cloud_config['users'].append(user_data)

if cloud_config:

if 'merge_how' not in cloud_config:

cloud_config['merge_how'] = 'list(append)+dict(recurse_array,no_replace)+str()'

res = yaml.safe_dump(cloud_config, default_flow_style=False, width=512)

self.log_debug("#cloud-config\n%s" % res)

return "#cloud-config\n%s" % res

else:

return None

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值