簡體   English   中英

使用libcloud在azure上創建VM或雲服務?

[英]Create a vm or cloud service on azure using libcloud?

創建虛擬機或雲服務時,libcloud / drivers / azure.py出現問題,我總是收到一個400錯誤請求,沒有任何內容。 有人可以幫我這個忙嗎?

這是我的代碼:

# connectHandler use my pem file to create a connection with the server, return a AzureNodeDriver objet
conn = _connectHandler.api_connect(compute_ressource)
try:
    result = conn.ex_create_cloud_service(name= "testCloudServiceZT200", location= "Central US")
except Exception as e:
    logger.error(e)
else:
    return result

這是我得到的回報: <LibcloudError in <libcloud.compute.drivers.azure.AzureNodeDriver object at 0x7fceaeb457d0> 'Message: Bad Request, Body: , Status code: 400'>

有人可以告訴我為什么會出現這個錯誤,也許給我一些azure.py的例子,將不勝感激。 謝謝!!

Azure驅動程序似乎非常新,因為它甚至沒有包含在通過PyPI提供的最新版本中。 我遇到了同樣的問題,使用ipdb查看了由Azure驅動程序創建的請求和XML。 起初我以為我發現了許多問題,但是在查看了源代碼之后,不僅查看了調試器的輸出,還可以將其歸結為一個簡單的修復程序。

以下curl請求對我有用:

curl -v -E {PATH_TO_PEM_FILE} -H 'x-ms-version: 2015-04-01' -H 'Content-Type: application/xml' -d '<?xml version="1.0" encoding="utf-8"?><CreateHostedService xmlns="http://schemas.microsoft.com/windowsazure"><ServiceName>test-cloudservice-libcloud-azure-driver</ServiceName><Label>dGVzdC1jbG91ZHNlcnZpY2UtbGliY2xvdWQtYXp1cmUtZHJpdmVyCg==</Label><Location>West Europe</Location></CreateHostedService>' https://management.core.windows.net/{SUBSCRIPTION_ID}/services/hostedservices

但是由Azure驅動程序生成的XML包含encoding='utf8' ,這是行不通的。 它必須是utf-8 如果您將github存儲庫(e105433e941262e03eb3bb922db47dabdd8efa75)當前頭中的第2710行替換為result = ensure_string(ET.tostring(doc, encoding='utf-8')) ,則可以正常工作, encoding='utf8'是罪魁禍首至少對我來說。

我已經打開了請求請求,希望它也能為您解決問題: https : //github.com/apache/libcloud/pull/538

暫無
暫無

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

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