使用 libcloud 在 Azure 上创建虚拟机或云服务?
Create a vm or cloud service on azure using libcloud?
我在创建 VM 或云服务时遇到了 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
这是我在 return 中得到的:
<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'
是罪魁祸首,至少对我来说是这样。
我已经打开了一个 pull request,希望它也能解决你的问题:https://github.com/apache/libcloud/pull/538
我在创建 VM 或云服务时遇到了 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
这是我在 return 中得到的:
<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'
是罪魁祸首,至少对我来说是这样。
我已经打开了一个 pull request,希望它也能解决你的问题:https://github.com/apache/libcloud/pull/538