首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SoftLayer接口createObject

SoftLayer接口createObject
EN

Stack Overflow用户
提问于 2017-01-13 23:41:23
回答 1查看 105关注 0票数 0

几天来,我一直在尝试让API服务{'Network_Firewall_Update_Request_Rule'].createObject工作,但没有成功。我确实让firewallManager edit_dedicated_fwl_rules工作了,但现在我也想让它工作。我在网上找了一遍也没找到答案。

我的问题是,传递给防火墙规则的服务createObject的参数的语法是什么?你有一个例子吗?

正在使用的命令是:

代码语言:javascript
复制
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=",因为这会成功创建规则。

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2017-01-13 23:45:58

查看这篇文章:

I need to create a softlayer network firewall rule through REST API

创建规则的REST示例如下所示:

代码语言:javascript
复制
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“,它可以像这样得到:

代码语言:javascript
复制
GET https://$USERID:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/$VSIID/getFirewallServiceComponent

使用Python时,上面的示例如下所示:

代码语言:javascript
复制
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“属性:

代码语言:javascript
复制
client['Virtual_Guest'].getFirewallServiceComponent(id=VirtualGuest)

请注意,以上示例用于编辑连接到VSI的防火墙的规则。

为了在VLAN中为专用防火墙创建规则,请求如下:

代码语言:javascript
复制
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“的值,您需要使用以下代码:

代码语言:javascript
复制
client['SoftLayer_Network_Vlan'].getFirewallInterfaces(id=vlanId, mask="mask[firewallContextAccessControlLists]")

上面的方法将返回外部和内部接口,目前只有您可以设置外部接口的规则

问候

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41638259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档