问题
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)
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 :(
If somebody has a sample about using the getObject method it would be great, thanks!
回答1:
Why do not use just the method getNetworkVlan? the method returns the VLAN associated to the SoftLayer_Network_Gateway_Vlan.
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]]")
that will list all the gateways in your account and its associated vlans.
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}}}}})
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
来源:https://stackoverflow.com/questions/49198871/softlayer-objectmask-for-softlayer-network-gateway-vlangetobject