<tfoot id='JJ2Ps'></tfoot>

      <small id='JJ2Ps'></small><noframes id='JJ2Ps'>

        <bdo id='JJ2Ps'></bdo><ul id='JJ2Ps'></ul>

      <i id='JJ2Ps'><tr id='JJ2Ps'><dt id='JJ2Ps'><q id='JJ2Ps'><span id='JJ2Ps'><b id='JJ2Ps'><form id='JJ2Ps'><ins id='JJ2Ps'></ins><ul id='JJ2Ps'></ul><sub id='JJ2Ps'></sub></form><legend id='JJ2Ps'></legend><bdo id='JJ2Ps'><pre id='JJ2Ps'><center id='JJ2Ps'></center></pre></bdo></b><th id='JJ2Ps'></th></span></q></dt></tr></i><div id='JJ2Ps'><tfoot id='JJ2Ps'></tfoot><dl id='JJ2Ps'><fieldset id='JJ2Ps'></fieldset></dl></div>
    1. <legend id='JJ2Ps'><style id='JJ2Ps'><dir id='JJ2Ps'><q id='JJ2Ps'></q></dir></style></legend>

    2. 使用Python SDK for Azure在创建虚拟机操作中添加用户数据

      时间:2024-08-22
        <bdo id='I6vHe'></bdo><ul id='I6vHe'></ul>
        <i id='I6vHe'><tr id='I6vHe'><dt id='I6vHe'><q id='I6vHe'><span id='I6vHe'><b id='I6vHe'><form id='I6vHe'><ins id='I6vHe'></ins><ul id='I6vHe'></ul><sub id='I6vHe'></sub></form><legend id='I6vHe'></legend><bdo id='I6vHe'><pre id='I6vHe'><center id='I6vHe'></center></pre></bdo></b><th id='I6vHe'></th></span></q></dt></tr></i><div id='I6vHe'><tfoot id='I6vHe'></tfoot><dl id='I6vHe'><fieldset id='I6vHe'></fieldset></dl></div>
          <tbody id='I6vHe'></tbody>

          • <small id='I6vHe'></small><noframes id='I6vHe'>

            <legend id='I6vHe'><style id='I6vHe'><dir id='I6vHe'><q id='I6vHe'></q></dir></style></legend>

              1. <tfoot id='I6vHe'></tfoot>
              2. 本文介绍了使用Python SDK for Azure在创建虚拟机操作中添加用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用Python SDK进行Azure创建虚拟机操作。我希望在VM启动时执行一些脚本。因此,我尝试在使用Python创建VM时添加自定义数据。

                我的目录:

                • user-data.sh
                • create_VM.py

                user-data.sh文件类似于:

                #!/bin/bash
                sudo apt install apache2 -y
                sudo apt install git -y
                

                我在create_VM.py文件上使用了base64包,如下所示:

                import base64
                
                ...
                
                file = open("user-data.sh", "r")
                a = file.read().encode()
                encoded_string = base64.b64encode(a)
                
                ...
                
                poller = compute_client.virtual_machines.create_or_update(RESOURCE_GROUP_NAME, VM_NAME,
                    {
                        "location": LOCATION,
                        "storage_profile": {
                            "image_reference": {
                                "publisher": 'Canonical',
                                "offer": "UbuntuServer",
                                "sku": "16.04.0-LTS",
                                "version": "latest"
                            }
                        },
                        "hardware_profile": {
                            "vm_size": "Standard_DS1_v2"
                        },
                        "os_profile": {
                            "computer_name": VM_NAME,
                            "admin_username": USERNAME,
                            "admin_password": PASSWORD,
                            "custom_data": encoded_string
                        },
                        "network_profile": {
                            "network_interfaces": [{
                                "id": nic_result.id,
                            }]
                        }
                    }
                )
                ...
                

                我收到的错误是:

                Azure Error: InvalidParameter
                Message: Custom data in OSProfile must be in Base64 encoding and with a maximum length of 87380 characters.
                Target: customData
                

                如何解决此问题?

                推荐答案

                请试试这件,它在我的身上起作用。

                import base64
                
                ...
                
                file = open("user-data.sh", "r")
                a = file.read().encode()
                
                ...
                                
                CUSTOM_DATA = base64.b64encode(a.encode('utf-8')).decode('latin-1')
                

                这篇关于使用Python SDK for Azure在创建虚拟机操作中添加用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Heroku每24小时重置我项目中的文本文件 下一篇:Tkinter选项菜单将命令添加到多个选项菜单

                相关文章

                  <bdo id='LehG1'></bdo><ul id='LehG1'></ul>

                1. <i id='LehG1'><tr id='LehG1'><dt id='LehG1'><q id='LehG1'><span id='LehG1'><b id='LehG1'><form id='LehG1'><ins id='LehG1'></ins><ul id='LehG1'></ul><sub id='LehG1'></sub></form><legend id='LehG1'></legend><bdo id='LehG1'><pre id='LehG1'><center id='LehG1'></center></pre></bdo></b><th id='LehG1'></th></span></q></dt></tr></i><div id='LehG1'><tfoot id='LehG1'></tfoot><dl id='LehG1'><fieldset id='LehG1'></fieldset></dl></div>

                  <small id='LehG1'></small><noframes id='LehG1'>

                  1. <legend id='LehG1'><style id='LehG1'><dir id='LehG1'><q id='LehG1'></q></dir></style></legend>
                  2. <tfoot id='LehG1'></tfoot>