几天来,我一直在尝试让API服务{'Network_Firewall_Update_Request_Rule'].createObject工作,但没有成功。我确实让firewallManager edit_dedicated_fwl_rules工作了,但现在我也想让它工作。我在网上找了一遍也没找到答案。
我的问题是,传递给防火墙规则的服务createObject的参数的语法是什么?你有一个例子吗?
正在使用的命令是:
client = SoftLayer.create_client_from_env(username=user, api_key=api)
client['Network_Firewall_Update_Request_Rule'].createObject(id=12345, [{'action': 'permit'}])是的,我知道我需要更多的规则语句来创建。这将返回"SyntaxError: non-keyword arg after keyword arg" because of the "id=".
将"id="放在接口的末尾:client['Network_Firewall_Update_Request_Rule'].createObject([{'action': 'permit'}], id=12345) then the error is "Either a component ID or an ACL ID must be supplied."
如果我删除了"id=“并且只有client['Network_Firewall_Update_Request_Rule'].createObject(12345, [{'action': 'permit'}])
则错误为“必须提供组件ID或ACL ID”。
我知道当此命令工作时,我必须拥有"id=":
client['Network_Firewall_Update_Request'].getRules(id=12345)
但是使用Manager API命令fw.edit_dedicated_fwl_rules(12345, [{'action': 'permit'}])
没有"id=",因为这会成功创建规则。
谢谢你的帮助。
发布于 2017-01-13 23:45:58
查看这篇文章:
I need to create a softlayer network firewall rule through REST API
创建规则的REST示例如下所示:
POST https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Network_Firewall_Update_Request/createObjec
Payload:
{
"parameters": [
{
"networkComponentFirewallId": 72605,
"rules": [
{
"action": "permit",
"destinationIpAddress": "159.8.52.188",
"destinationIpCidr": 32,
"destinationPortRangeEnd": 122,
"destinationPortRangeStart": 12,
"notes": "This is a test",
"orderValue": 1,
"protocol": "tcp",
"sourceIpAddress": "10.10.10.0",
"sourceIpCidr": 32,
"version": 4
}
]
}
]
}您需要根据需要的配置替换所有的值。
现在你需要得到上面请求的"networkComponentFirewallId“,它可以像这样得到:
GET https://$USERID:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/$VSIID/getFirewallServiceComponent使用Python时,上面的示例如下所示:
client['Network_Firewall_Update_Request_Rule'].createObject(
{
"networkComponentFirewallId": 72605,
"rules": [
{
"action": "permit",
"destinationIpAddress": "159.8.52.188",
"destinationIpCidr": 32,
"destinationPortRangeEnd": 122,
"destinationPortRangeStart": 12,
"notes": "This is a test",
"orderValue": 1,
"protocol": "tcp",
"sourceIpAddress": "10.10.10.0",
"sourceIpCidr": 32,
"version": 4
}
]
}
)并获取"networkComponentFirewallId“属性:
client['Virtual_Guest'].getFirewallServiceComponent(id=VirtualGuest)请注意,以上示例用于编辑连接到VSI的防火墙的规则。
为了在VLAN中为专用防火墙创建规则,请求如下:
client['Network_Firewall_Update_Request_Rule'].createObject(
{
"firewallContextAccessControlListId": 3092,
"rules": [{
"action": "permit",
"destinationIpAddress": "any",
"destinationIpCidr": 32,
"destinationIpSubnetMask": "255.255.255.255",
"destinationPortRangeEnd": 65535,
"destinationPortRangeStart": 1,
"id": 5669281,
"orderValue": 1,
"protocol": "tcp",
"sourceIpAddress": "0.0.0.0",
"sourceIpCidr": 0,
"sourceIpSubnetMask": "0.0.0.0",
"status": "allow_edit",
"version": 4
}]
}
)现在如何获取"firewallContextAccessControlListId“的值,您需要使用以下代码:
client['SoftLayer_Network_Vlan'].getFirewallInterfaces(id=vlanId, mask="mask[firewallContextAccessControlLists]")上面的方法将返回外部和内部接口,目前只有您可以设置外部接口的规则
问候
https://stackoverflow.com/questions/41638259
复制相似问题