问题:我正在尝试使用API并为SoftLayer_Account#getVirtualGuests使用对象掩码,但它似乎被忽略了。
我尝试了什么:
使用标题
调用SoftLayer_Virtual_Guest.getObject<SoftLayer_Virtual_GuestObjectMask>
<mask>
<datacenter xsi:nil="true" />
<bandwidthAllotmentDetail><allocation xsi:nil="true" /></bandwidthAllotmentDetail>
</mask>
</SoftLayer_Virtual_GuestObjectMask>
完美无缺,但当我用标题调用SoftLayer_Account.getVirtualGuests时
<SoftLayer_AccountObjectMask>
<mask>
<datacenter xsi:nil="true" />
<bandwidthAllotmentDetail><allocation xsi:nil="true" /></bandwidthAllotmentDetail>
</mask>
</SoftLayer_AccountObjectMask>
它不起作用,正如我在https://sldn.softlayer.com/article/object-masks文章中看到的那样,当调用SoftLayer_Account :: getHardware时,你需要为特定类型设置root属性,但根据示例我无法想象如何使用SOAP调用。
如果可以提供一个关于如何使用对象掩码和对象过滤器的示例SoftLayer_Account.getVirtualGuests
,我可以自行处理。
谢谢
答案 0 :(得分:1)
请使用SOAP请求尝试以下示例:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v3="http://api.service.softlayer.com/soap/v3/">
<soapenv:Header>
<authenticate xsi:type="v3:authenticate">
<username xsi:type="xsd:string">?</username>
<apiKey xsi:type="xsd:string">?</apiKey>
</authenticate>
<v3:SoftLayer_ObjectMask xsi:type="v3:SoftLayer_ObjectMask">
<mask xsi:type="xsd:string">mask[id,datacenter,bandwidthAllotmentDetail]</mask>
</v3:SoftLayer_ObjectMask>
<SoftLayer_AccountObjectFilter xsi:type="v3:SoftLayer_AccountObjectFilter"/>
<SoftLayer_AccountObjectMask xsi:type="v3:SoftLayer_AccountObjectMask">
<mask xsi:type="v3:SoftLayer_Account"/>
</SoftLayer_AccountObjectMask>
</soapenv:Header>
<soapenv:Body>
<v3:getVirtualGuests soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</soapenv:Body>
</soapenv:Envelope>
如果您想合并object Masks
和object Filters
,请参阅:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v3="http://api.service.softlayer.com/soap/v3/">
<soapenv:Header>
<authenticate xsi:type="v3:authenticate">
<username xsi:type="xsd:string">?</username>
<apiKey xsi:type="xsd:string">?</apiKey>
</authenticate>
<v3:SoftLayer_ObjectMask xsi:type="v3:SoftLayer_ObjectMask">
<mask xsi:type="xsd:string">filteredMask[id,datacenter,bandwidthAllotmentDetail]</mask>
</v3:SoftLayer_ObjectMask>
<v3:SoftLayer_AccountObjectFilter xsi:type="v3:SoftLayer_AccountObjectFilter">
<virtualGuests>
<datacenter>
<name>
<operation>dal06</operation>
</name>
</datacenter>
</virtualGuests>
</v3:SoftLayer_AccountObjectFilter>
<SoftLayer_AccountObjectMask xsi:type="v3:SoftLayer_AccountObjectMask">
<mask xsi:type="v3:SoftLayer_Account"/>
</SoftLayer_AccountObjectMask>
</soapenv:Header>
<soapenv:Body>
<v3:getVirtualGuests soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</soapenv:Body>
</soapenv:Envelope>
答案 1 :(得分:0)
我没有看到使用带有getVirtualGuests调用的对象掩码的问题
curl -s -g --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" "https://api.softlayer.com/rest/v3/SoftLayer_Account/getVirtualGuests.json?objectMask=mask[domain,bandwidthAllotmentDetail]" | python -m json.tool
[
{
"bandwidthAllotmentDetail": {
"allocationId": 5318597,
"bandwidthAllotmentId": 138442,
"effectiveDate": "2016-02-12T11:45:38-06:00",
"endEffectiveDate": null,
"id": 5479443,
"serviceProviderId": 1
},
"domain": "tinylab.info"
},
{
"bandwidthAllotmentDetail": {
"allocationId": 5569801,
"bandwidthAllotmentId": 138442,
"effectiveDate": "2016-03-22T10:17:46-06:00",
"endEffectiveDate": null,
"id": 5736289,
"serviceProviderId": 1
},
"domain": "tinylayer.net"
},
{
"bandwidthAllotmentDetail": {
"allocationId": 5468679,
"bandwidthAllotmentId": 138442,
"effectiveDate": "2016-03-04T00:00:00-06:00",
"endEffectiveDate": null,
"id": 5633115,
"serviceProviderId": 1
},
"domain": "tinylab.info"
},
{
"bandwidthAllotmentDetail": {
"allocationId": 5600063,
"bandwidthAllotmentId": 138442,
"effectiveDate": "2016-03-28T08:32:41-06:00",
"endEffectiveDate": null,
"id": 5767743,
"serviceProviderId": 1
},
"domain": "tinylab.info"
}
]
这将返回我帐户中所有虚拟客人的json列表以及API响应的bandwidthAllotmentDetail部分。