# Rules
## Add
`gpu_droplets.firewalls.rules.add(strfirewall_id, RuleAddParams**kwargs)`
**post** `/v2/firewalls/{firewall_id}/rules`
To add additional access rules to a firewall, send a POST request to
`/v2/firewalls/$FIREWALL_ID/rules`. The body of the request may include an
inbound_rules and/or outbound_rules attribute containing an array of rules to
be added.
No response body will be sent back, but the response code will indicate
success. Specifically, the response code will be a 204, which means that the
action was successful with no returned body data.
### Parameters
- `firewall_id: str`
- `inbound_rules: Optional[Iterable[InboundRule]]`
- `ports: str`
The ports on which traffic will be allowed specified as a string containing a single port, a range (e.g. "8000-9000"), or "0" when all ports are open for a protocol. For ICMP rules this parameter will always return "0".
- `protocol: Literal["tcp", "udp", "icmp"]`
The type of traffic to be allowed. This may be one of `tcp`, `udp`, or `icmp`.
- `"tcp"`
- `"udp"`
- `"icmp"`
- `sources: FirewallRuleTarget`
An object specifying locations from which inbound traffic will be accepted.
- `addresses: Optional[List[str]]`
An array of strings containing the IPv4 addresses, IPv6 addresses, IPv4 CIDRs, and/or IPv6 CIDRs to which the firewall will allow traffic.
- `droplet_ids: Optional[List[int]]`
An array containing the IDs of the Droplets to which the firewall will allow traffic.
- `kubernetes_ids: Optional[List[str]]`
An array containing the IDs of the Kubernetes clusters to which the firewall will allow traffic.
- `load_balancer_uids: Optional[List[str]]`
An array containing the IDs of the load balancers to which the firewall will allow traffic.
- `tags: Optional[List[str]]`
A flat array of tag names as strings to be applied to the resource. Tag names must exist in order to be referenced in a request.
Requires `tag:create` and `tag:read` scopes.
- `outbound_rules: Optional[Iterable[OutboundRule]]`
- `destinations: FirewallRuleTarget`
An object specifying locations to which outbound traffic that will be allowed.
- `addresses: Optional[List[str]]`
An array of strings containing the IPv4 addresses, IPv6 addresses, IPv4 CIDRs, and/or IPv6 CIDRs to which the firewall will allow traffic.
- `droplet_ids: Optional[List[int]]`
An array containing the IDs of the Droplets to which the firewall will allow traffic.
- `kubernetes_ids: Optional[List[str]]`
An array containing the IDs of the Kubernetes clusters to which the firewall will allow traffic.
- `load_balancer_uids: Optional[List[str]]`
An array containing the IDs of the load balancers to which the firewall will allow traffic.
- `tags: Optional[List[str]]`
A flat array of tag names as strings to be applied to the resource. Tag names must exist in order to be referenced in a request.
Requires `tag:create` and `tag:read` scopes.
- `ports: str`
The ports on which traffic will be allowed specified as a string containing a single port, a range (e.g. "8000-9000"), or "0" when all ports are open for a protocol. For ICMP rules this parameter will always return "0".
- `protocol: Literal["tcp", "udp", "icmp"]`
The type of traffic to be allowed. This may be one of `tcp`, `udp`, or `icmp`.
- `"tcp"`
- `"udp"`
- `"icmp"`
### Example
```python
from gradient import Gradient
client = Gradient()
client.gpu_droplets.firewalls.rules.add(
firewall_id="bb4b2611-3d72-467b-8602-280330ecd65c",
inbound_rules=[{
"protocol": "tcp",
"ports": "3306",
"sources": {
"droplet_ids": [49696269]
},
}],
outbound_rules=[{
"protocol": "tcp",
"ports": "3306",
"destinations": {
"droplet_ids": [49696269]
},
}],
)
```
## Remove
`gpu_droplets.firewalls.rules.remove(strfirewall_id, RuleRemoveParams**kwargs)`
**delete** `/v2/firewalls/{firewall_id}/rules`
To remove access rules from a firewall, send a DELETE request to
`/v2/firewalls/$FIREWALL_ID/rules`. The body of the request may include an
`inbound_rules` and/or `outbound_rules` attribute containing an array of rules
to be removed.
No response body will be sent back, but the response code will indicate
success. Specifically, the response code will be a 204, which means that the
action was successful with no returned body data.
### Parameters
- `firewall_id: str`
- `inbound_rules: Optional[Iterable[InboundRule]]`
- `ports: str`
The ports on which traffic will be allowed specified as a string containing a single port, a range (e.g. "8000-9000"), or "0" when all ports are open for a protocol. For ICMP rules this parameter will always return "0".
- `protocol: Literal["tcp", "udp", "icmp"]`
The type of traffic to be allowed. This may be one of `tcp`, `udp`, or `icmp`.
- `"tcp"`
- `"udp"`
- `"icmp"`
- `sources: FirewallRuleTarget`
An object specifying locations from which inbound traffic will be accepted.
- `addresses: Optional[List[str]]`
An array of strings containing the IPv4 addresses, IPv6 addresses, IPv4 CIDRs, and/or IPv6 CIDRs to which the firewall will allow traffic.
- `droplet_ids: Optional[List[int]]`
An array containing the IDs of the Droplets to which the firewall will allow traffic.
- `kubernetes_ids: Optional[List[str]]`
An array containing the IDs of the Kubernetes clusters to which the firewall will allow traffic.
- `load_balancer_uids: Optional[List[str]]`
An array containing the IDs of the load balancers to which the firewall will allow traffic.
- `tags: Optional[List[str]]`
A flat array of tag names as strings to be applied to the resource. Tag names must exist in order to be referenced in a request.
Requires `tag:create` and `tag:read` scopes.
- `outbound_rules: Optional[Iterable[OutboundRule]]`
- `destinations: FirewallRuleTarget`
An object specifying locations to which outbound traffic that will be allowed.
- `addresses: Optional[List[str]]`
An array of strings containing the IPv4 addresses, IPv6 addresses, IPv4 CIDRs, and/or IPv6 CIDRs to which the firewall will allow traffic.
- `droplet_ids: Optional[List[int]]`
An array containing the IDs of the Droplets to which the firewall will allow traffic.
- `kubernetes_ids: Optional[List[str]]`
An array containing the IDs of the Kubernetes clusters to which the firewall will allow traffic.
- `load_balancer_uids: Optional[List[str]]`
An array containing the IDs of the load balancers to which the firewall will allow traffic.
- `tags: Optional[List[str]]`
A flat array of tag names as strings to be applied to the resource. Tag names must exist in order to be referenced in a request.
Requires `tag:create` and `tag:read` scopes.
- `ports: str`
The ports on which traffic will be allowed specified as a string containing a single port, a range (e.g. "8000-9000"), or "0" when all ports are open for a protocol. For ICMP rules this parameter will always return "0".
- `protocol: Literal["tcp", "udp", "icmp"]`
The type of traffic to be allowed. This may be one of `tcp`, `udp`, or `icmp`.
- `"tcp"`
- `"udp"`
- `"icmp"`
### Example
```python
from gradient import Gradient
client = Gradient()
client.gpu_droplets.firewalls.rules.remove(
firewall_id="bb4b2611-3d72-467b-8602-280330ecd65c",
inbound_rules=[{
"protocol": "tcp",
"ports": "3306",
"sources": {
"droplet_ids": [49696269]
},
}],
outbound_rules=[{
"protocol": "tcp",
"ports": "3306",
"destinations": {
"droplet_ids": [49696269]
},
}],
)
```