gpt4 book ai didi

python - Windows Azure API : Programmatically create VM

转载 作者:行者123 更新时间:2023-11-28 16:42:12 24 4
gpt4 key购买 nike

我正在尝试使用 Python REST API 包装器以编程方式启动 Azure VM。我想要的只是一个简单的虚拟机,而不是部署的一部分或类似的东西。我按照这里的例子:http://www.windowsazure.com/en-us/develop/python/how-to-guides/service-management/#CreateVM

我已经获得了要运行的代码,但我在门户中没有看到任何新的虚拟机;它所做的只是创建一个新的云服务,该服务表示“您没有将任何内容部署到生产环境中”。我做错了什么?

最佳答案

您已创建托管服务(云服务),但尚未在该服务中部署任何内容。您还需要做一些事情,所以我将从您上次停下的地方继续,其中 name 是虚拟机的名称:

# Where should the OS VHD be created:
media_link = 'http://portalvhdsexample.blob.core.windows.net/vhds/%s.vhd' % name

# Linux username/password details:
linux_config = azure.servicemanagement.LinuxConfigurationSet(name, 'username', 'password', True)

# Endpoint (port) configuration example, since documentation on this is lacking:
endpoint_config = azure.servicemanagement.ConfigurationSet()
endpoint_config.configuration_set_type = 'NetworkConfiguration'
endpoint1 = azure.servicemanagement.ConfigurationSetInputEndpoint(name='HTTP', protocol='tcp', port='80', local_port='80', load_balanced_endpoint_set_name=None, enable_direct_server_return=False)
endpoint2 = azure.servicemanagement.ConfigurationSetInputEndpoint(name='SSH', protocol='tcp', port='22', local_port='22', load_balanced_endpoint_set_name=None, enable_direct_server_return=False)

endpoint_config.input_endpoints.input_endpoints.append(endpoint1)
endpoint_config.input_endpoints.input_endpoints.append(endpoint2)

# Set the OS HD up for the API:
os_hd = azure.servicemanagement.OSVirtualHardDisk(image_name, media_link)

# Actually create the machine and start it up:
try:
sms.create_virtual_machine_deployment(service_name=name, deployment_name=name,
deployment_slot='production', label=name, role_name=name,
system_config=linux_config, network_config=endpoint_config,
os_virtual_hard_disk=os_hd, role_size='Small')

except Exception as e:
logging.error('AZURE ERROR: %s' % str(e))
return False

return True

关于python - Windows Azure API : Programmatically create VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17928797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com