由于500个服务器错误,无法使用SoftLayer API和Ansible配置VM

时间:2016-09-13 12:29:12

标签: ibm-cloud-infrastructure

我们正在使用Ansible来配置一组虚拟机。为此,我们使用此处的softlayer.py脚本作为ansible的一部分:https://github.com/ansible/ansible/blob/devel/contrib/inventory/softlayer.py

我们正在运行:ansible-playbook manifest.yml -s -i softlayer.py

manifest.yml包含一系列应该配置我们的VM的ansible任务。以下是删除所有敏感信息的示例:

- gather_facts: false
hosts: localhost
name: Build Servers
sudo: false
tasks:
- local_action: 
cpus: 4
datacenter: sjc03
dedicated: false
disks:
- 25
domain: test.example.sample.net
hostname: machine-one
hourly: false
memory: 8192
module: sl_vm
nic_speed: 1000
os_code: UBUNTU_14_64
private: true
private_vlan: 1234567
ssh_keys: []
tags:
- tagone
- tagtwo
- tagthree
- tagfour
- test.example.sample.net
name: Build machine-one server

以下是完整的错误输出,如果有任何用处:

Inventory script (softlayer.py) had an execution error: Traceback (most recent call last):
File "/opt/test/job/softlayer.py", line 207, in <module>
SoftLayerInventory()
File "/opt/test/job/softlayer.py", line 84, in __init__
self.get_all_servers()
File "/opt/test/job/softlayer.py", line 204, in get_all_servers
self.get_virtual_servers()
File "/opt/test/job/softlayer.py", line 188, in get_virtual_servers
instances = vs.list_instances(mask=mask)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer-4.0.3-py2.7.egg/SoftLayer/managers/vs.py", line 141, in list_instances
return func(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer-4.0.3-py2.7.egg/SoftLayer/API.py", line 362, in call_handler
return self(name, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer-4.0.3-py2.7.egg/SoftLayer/API.py", line 330, in call
return self.client.call(self.name, name, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer-4.0.3-py2.7.egg/SoftLayer/API.py", line 226, in call
return self.transport(request)
File "/usr/local/lib/python2.7/dist-packages/SoftLayer-4.0.3-py2.7.egg/SoftLayer/transports.py", line 162, in __call__
raise exceptions.TransportError(ex.response.status_code, str(ex))
SoftLayer.exceptions.TransportError: TransportError(500): 500 Server Error: Internal Server Error for url: https://api.softlayer.com/xmlrpc/v3.1/SoftLayer_Account

导致这种情况的原因是什么?

2 个答案:

答案 0 :(得分:1)

根据例外,由于多种原因,存在大量500错误:

  • 超时
  • 内存不足
  • 无效请求
  • 错误

我不确定Ansible如何处理并将参数发送到SoftLayer API Python Client,但快速查看,Ansible正在使用SoftLayer-4.0.3而SoftLayer API Python Client已经发布了v5.2.0,我们建议使用此功能,以获取最新更新并避免可能出现的问题。

我使用SoftLayer Python Command-line Interface发送了您尝试的相同参数进行了一些测试,并且工作正常:

{{1}}

我建议在以下链接中提交问题,以便Ansible可以验证并修复它:

https://github.com/ansible/ansible/issues

答案 1 :(得分:1)

这似乎特定于在https://api.softlayer.com/xmlrpc/v3.1/SoftLayer_Account上使用特定帐户和特定掩码上的特定凭据集调用getVirtualGuests。

<?xml version='1.0'?>
<methodCall>
<methodName>getVirtualGuests</methodName>
<params>
<param>
<value><struct>
<member>
<name>headers</name>
<value><struct>
<member>
<name>SoftLayer_ObjectMask</name>
<value><struct>
<member>
<name>mask</name>
<value><string>mask[id,globalIdentifier,hostname,domain,fullyQualifiedDomainName,primaryBackendIpAddress,primaryIpAddress,datacenter,tagReferences.tag.name,lastKnownPowerState.name,powerState,maxCpu,maxMemory,activeTransaction.transactionStatus[friendlyName,name],status]</string></value>
</member>
</struct></value>
</member>
<member>
<name>SoftLayer_AccountObjectFilter</name>
<value><struct>
</struct></value>
</member>
<member>
<name>authenticate</name>
<value><struct>
<member>
<name>apiKey</name>
<value><string>xxxxxxx</string></value>
</member>
<member>
<name>username</name>
<value><string>example</string></value>
</member>
</struct></value>
</member>
</struct></value>
</member>
</struct></value>
</param>
</params>
</methodCall>

将该XML发布到上面的xmlrpc端点我使用原始问题中提到的特定凭据点击了500错误。如果我使用一组不同的(有效)凭证,我会按照我的预期返回我的服务器列表。如果我提供无效凭据,则会收到&#34;无效的API令牌。&#34;我期待着回来。

500个案例中令人惊讶的是它似乎确实运行了查询(因为标题中返回了SoftLayer-Total-Items:70),但HTTP代码为500且响应的主体为空

如果我检查slcli -vvv vs list(成功)发出的http请求,我看到它向同一个方法发送了一个不同的掩码,所以ansible softlayer.py中的掩码也许是相关的。