Skip to content

Commit

Permalink
Merge pull request #102 from nutanix/imprv/pbr
Browse files Browse the repository at this point in the history
fix sanity and add doc and integration test  for PBR module : Gihub#101
  • Loading branch information
alaa-bish authored Feb 17, 2022
2 parents 2440af2 + 679c561 commit 14e93fb
Show file tree
Hide file tree
Showing 6 changed files with 615 additions and 64 deletions.
4 changes: 2 additions & 2 deletions plugins/module_utils/prism/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def __init__(self, module):
resource_type = "/groups"
super(Groups, self).__init__(module, resource_type=resource_type)

def get_uuid(self, entity_type, filter):
data = {"entity_type": entity_type, "filter_criteria": filter}
def get_uuid(self, value, key):
data = {"entity_type": value, "filter_criteria": key}
resp, status = self.list(data, use_base_url=True)
if resp.get("group_results"):
return resp["group_results"][0]["entity_results"][0]["entity_id"]
Expand Down
33 changes: 22 additions & 11 deletions plugins/module_utils/prism/pbrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, module):
"source": self._build_spec_source,
"destination": self._build_spec_destination,
"protocol": self._build_spec_protocol,
"action": self._build_spec_action
"action": self._build_spec_action,
}

def _get_default_spec(self):
Expand All @@ -31,8 +31,7 @@ def _get_default_spec(self):
"api_version": "3.1.0",
"metadata": {"kind": "routing_policy"},
"spec": {
"resources": {
},
"resources": {},
},
}
)
Expand Down Expand Up @@ -60,8 +59,10 @@ def _build_spec_source(self, payload, config):
elif config.get("external"):
source["address_type"] = "INTERNET"
elif config.get("network"):
source["ip_subnet"] = {"ip": config["network"].get("ip"),
"prefix_length": int(config["network"].get("prefix"))}
source["ip_subnet"] = {
"ip": config["network"].get("ip"),
"prefix_length": int(config["network"].get("prefix")),
}

payload["spec"]["resources"]["source"] = source

Expand All @@ -74,8 +75,10 @@ def _build_spec_destination(self, payload, config):
elif config.get("external"):
destination["address_type"] = "INTERNET"
elif config.get("network"):
destination["ip_subnet"] = {"ip": config["network"].get("ip"),
"prefix_length": int(config["network"].get("prefix"))}
destination["ip_subnet"] = {
"ip": config["network"].get("ip"),
"prefix_length": int(config["network"].get("prefix")),
}

payload["spec"]["resources"]["destination"] = destination

Expand All @@ -91,12 +94,16 @@ def _build_spec_protocol(self, payload, config):
if "*" not in config["tcp"]["src"]:
for port in config["tcp"]["src"]:
port = port.split("-")
src_port_range_list.append({"start_port": int(port[0]), "end_port": int(port[-1])})
src_port_range_list.append(
{"start_port": int(port[0]), "end_port": int(port[-1])}
)
dest_port_range_list = []
if "*" not in config["tcp"]["dst"]:
for port in config["tcp"]["dst"]:
port = port.split("-")
dest_port_range_list.append({"start_port": int(port[0]), "end_port": int(port[-1])})
dest_port_range_list.append(
{"start_port": int(port[0]), "end_port": int(port[-1])}
)
if src_port_range_list:
tcp["source_port_range_list"] = src_port_range_list
if dest_port_range_list:
Expand All @@ -111,12 +118,16 @@ def _build_spec_protocol(self, payload, config):
if "*" not in config["udp"]["src"]:
for port in config["udp"]["src"]:
port = port.split("-")
src_port_range_list.append({"start_port": int(port[0]), "end_port": int(port[-1])})
src_port_range_list.append(
{"start_port": int(port[0]), "end_port": int(port[-1])}
)
dest_port_range_list = []
if "*" not in config["udp"]["dst"]:
for port in config["udp"]["dst"]:
port = port.split("-")
dest_port_range_list.append({"start_port": int(port[0]), "end_port": int(port[-1])})
dest_port_range_list.append(
{"start_port": int(port[0]), "end_port": int(port[-1])}
)
if src_port_range_list:
udp["source_port_range_list"] = src_port_range_list
if dest_port_range_list:
Expand Down
Loading

0 comments on commit 14e93fb

Please sign in to comment.