2013-07-29 101 views
3

我試圖以編程方式使用Python REST API封裝器啓動Azure虛擬機。我只需要一個簡單的虛擬機,而不是部署的任何部分或類似的東西。我已經按照這裏的例子:http://www.windowsazure.com/en-us/develop/python/how-to-guides/service-management/#CreateVMWindows Azure API:以編程方式創建虛擬機

我已經得到了代碼運行,但我沒有看到門戶中的任何新的虛擬機;它所做的只是創建一個新的雲服務,其中說「您沒有任何部署到生產環境」。我究竟做錯了什麼?

回答

0

也許我不理解你的問題,但虛擬機本質上是一個雲服務內的部署(把它想象成一個邏輯容器)。

+0

我試圖讓一個部署設置了一個虛擬機下運行它(使用Python API包裝)。 –

3

您已經創建了hosted_service(雲服務),但尚未在該服務中部署任何內容。你需要做一些事情,所以我會從你離開的地方coninue,其中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