SoftLayer_Network_Gateway_Vlan :: getObject的SoftLayer_ObjectMask [英] SoftLayer_ObjectMask for SoftLayer_Network_Gateway_Vlan::getObject
问题描述
我想在Python中使用SoftLayer_Network_Gateway_Vlan :: getObject,以便在使用createObject之前检查VLAN是否已连接到网关. 我没问题可以将createObject与这样的代码一起使用:
I would like to use SoftLayer_Network_Gateway_Vlan::getObject in Python in order to check whether a VLAN is already attached to a gateway before using createObject. I have no problem to use createObject with such a piece of code:
obj = {'bypassFlag':False, 'id':None, 'networkGatewayId':module.params['gateway_id'], 'networkVlanId':module.params['vlan_id']}
try:
res = env['Network_Gateway_Vlan'].createObject(obj)
except SoftLayer.exceptions.SoftLayerAPIError as e:
module.fail_json(msg=e.faultString)
但是我不知道如何编写一段代码来检索已经连接到网关的VLAN列表:(
But I don't know how to write a piece of code to retrieve the list of VLANs that are already attached to a gateway :(
如果有人有使用getObject方法的示例,那就太好了,谢谢!
If somebody has a sample about using the getObject method it would be great, thanks!
推荐答案
Why do not use just the method getNetworkVlan? the method returns the VLAN associated to the SoftLayer_Network_Gateway_Vlan.
但是,如果您想使用getObject方法,则需要使用以下掩码:
but if you wanna use the getObject method this is the mask you need to use:
env['SoftLayer_Network_Gateway_Vlan'].getObject(id= myIdGatewayVlan, mask= "mask[networkVlan]")
但是我认为最好使用这个:
But I think is better to use this one:
env['SoftLayer_Account'].getNetworkGateways( mask="mask[insideVlans[networkVlan]]")
它将列出您帐户中的所有网关及其关联的VLAN.
that will list all the gateways in your account and its associated vlans.
甚至更好的是,您可以使用过滤器来检查VLAN是否已在任何 SoftLayer_Network_Gateway_Vlan
or even better you can use a filter to check if the VLAN is already set in any SoftLayer_Network_Gateway_Vlan
env['SoftLayer_Account'].getNetworkGateways( mask="mask[insideVlans[networkVlan]]", filter={"networkGateways":{"insideVlans":{"networkVlan":{"id":{"operation":1319435}}}}})
注意:将1319435替换为您要检查的VLAN的ID 如果以上请求返回空,则该VLAN未连接到任何SoftLayer_Network_Gateway_Vlan
note: replace 1319435 with the ID of the VLAN you wanna check If the request above returns empty so the VLAN is not attached to any SoftLayer_Network_Gateway_Vlan
这篇关于SoftLayer_Network_Gateway_Vlan :: getObject的SoftLayer_ObjectMask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!