Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
Signed-off-by: Pranav Bhatt <[email protected]>
  • Loading branch information
pranav-bhatt committed Mar 25, 2022
1 parent 6ad4df5 commit 5407623
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 43 deletions.
6 changes: 6 additions & 0 deletions changelogs/fragments/changes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
minor_changes:
- Added Security Policies Global module
- Added Security Policies module
trivial:
- Fixed sanity tests
3 changes: 0 additions & 3 deletions changelogs/fragments/fix_sanity_list.yml

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions changelogs/fragments/sec_pol_global.yml

This file was deleted.

116 changes: 88 additions & 28 deletions plugins/module_utils/network/junos/facts/facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,98 @@

__metaclass__ = type

from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts import FactsBase
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos import HAS_PYEZ
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.legacy.base import Default, Hardware, Config, Interfaces, OFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.acls.acls import AclsFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.acl_interfaces.acl_interfaces import Acl_interfacesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.interfaces.interfaces import InterfacesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lacp.lacp import LacpFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lacp_interfaces.lacp_interfaces import Lacp_interfacesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lag_interfaces.lag_interfaces import Lag_interfacesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.l3_interfaces.l3_interfaces import L3_interfacesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lldp_global.lldp_global import Lldp_globalFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lldp_interfaces.lldp_interfaces import Lldp_interfacesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.vlans.vlans import VlansFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.l2_interfaces.l2_interfaces import L2_interfacesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.static_routes.static_routes import Static_routesFacts
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.facts.facts import (
FactsBase,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos import (
HAS_PYEZ,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.legacy.base import (
Default,
Hardware,
Config,
Interfaces,
OFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.acls.acls import (
AclsFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.acl_interfaces.acl_interfaces import (
Acl_interfacesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.interfaces.interfaces import (
InterfacesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lacp.lacp import (
LacpFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lacp_interfaces.lacp_interfaces import (
Lacp_interfacesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lag_interfaces.lag_interfaces import (
Lag_interfacesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.l3_interfaces.l3_interfaces import (
L3_interfacesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lldp_global.lldp_global import (
Lldp_globalFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.lldp_interfaces.lldp_interfaces import (
Lldp_interfacesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.vlans.vlans import (
VlansFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.l2_interfaces.l2_interfaces import (
L2_interfacesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.static_routes.static_routes import (
Static_routesFacts,
)

from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv2.ospfv2 import Ospfv2Facts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv3.ospfv3 import Ospfv3Facts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospf_interfaces.ospf_interfaces import Ospf_interfacesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.bgp_global.bgp_global import Bgp_globalFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.bgp_address_family.bgp_address_family import Bgp_address_familyFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.routing_instances.routing_instances import Routing_instancesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.prefix_lists.prefix_lists import Prefix_listsFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.logging_global.logging_global import Logging_globalFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ntp_global.ntp_global import Ntp_globalFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.security_policies.security_policies import Security_policiesFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv2.ospfv2 import (
Ospfv2Facts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospfv3.ospfv3 import (
Ospfv3Facts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ospf_interfaces.ospf_interfaces import (
Ospf_interfacesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.bgp_global.bgp_global import (
Bgp_globalFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.bgp_address_family.bgp_address_family import (
Bgp_address_familyFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.routing_instances.routing_instances import (
Routing_instancesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.prefix_lists.prefix_lists import (
Prefix_listsFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.logging_global.logging_global import (
Logging_globalFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.ntp_global.ntp_global import (
Ntp_globalFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.security_policies.security_policies import (
Security_policiesFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.security_policies_global.security_policies_global import (
Security_policies_globalFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.snmp_server.snmp_server import Snmp_serverFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.routing_options.routing_options import Routing_optionsFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.hostname.hostname import HostnameFacts
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.snmp_server.snmp_server import (
Snmp_serverFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.routing_options.routing_options import (
Routing_optionsFacts,
)
from ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.hostname.hostname import (
HostnameFacts,
)

FACT_LEGACY_SUBSETS = dict(
default=Default, hardware=Hardware, config=Config, interfaces=Interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def render_config(self, spec, conf):
security_policies_config = {}

# Parse facts for security policies
conf = conf.get("policies")
conf = conf.get("policies") or {}

if "policy" in conf:
security_policies_config["from_zones"] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def render_config(self, spec, conf):
security_policies_global_config = {}

# Parse facts for security policies global settings
global_policies = conf.get("policies")
global_policies = conf.get("policies") or {}

if "default-policy" in global_policies:
if "deny-all" in global_policies["default-policy"]:
Expand Down
17 changes: 15 additions & 2 deletions plugins/modules/junos_security_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@
platform specific CLI commands which will be returned in the I(rendered) key
within the result For state I(rendered) active connection to remote host is
not required
- The state I(replaced) will replace the running configuration with the provided
configuration
- The state I(replaced) and state I(overridden) have the same behaviour
- The state I(gathered) will fetch the running configuration from device and transform
it into structured data in the format as per the resource module argspec and
the value is returned in the I(gathered) key within the result
Expand Down Expand Up @@ -2583,7 +2586,7 @@
RETURN = """
before:
description: The configuration prior to the module execution.
returned: when state is I(merged), I(replaced), I(overridden), I(deleted) or I(purged)
returned: when state is I(merged), I(replaced), I(overridden) or I(deleted)
type: dict
sample: >
This output will always be in the same format as the
Expand All @@ -2597,7 +2600,7 @@
module argspec.
commands:
description: The set of commands pushed to the remote device.
returned: when state is I(merged), I(replaced), I(overridden), I(deleted) or I(purged)
returned: when state is I(merged), I(replaced), I(overridden) or I(deleted)
type: list
sample:
- "<rpc-reply>
Expand Down Expand Up @@ -2679,8 +2682,18 @@ def main():
:returns: the result form module invocation
"""

required_if = [
("state", "merged", ("config",)),
("state", "replaced", ("config",)),
("state", "overridden", ("config",)),
("state", "rendered", ("config",)),
("state", "parsed", ("running_config",)),
]

module = AnsibleModule(
argument_spec=Security_policiesArgs.argument_spec,
required_if=required_if,
supports_check_mode=True,
)

Expand Down
17 changes: 15 additions & 2 deletions plugins/modules/junos_security_policies_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@
within the result. For state I(rendered) active connection to remote host is
not required.
behaviour for this module.
- The state I(replaced) will replace the running configuration with the provided
configuration
- The state I(replaced) and state I(overridden) have the same behaviour
- The state I(gathered) will fetch the running configuration from device and transform
it into structured data in the format as per the resource module argspec and
the value is returned in the I(gathered) key within the result.
Expand Down Expand Up @@ -890,7 +893,7 @@
RETURN = """
before:
description: The configuration prior to the module execution.
returned: when state is I(merged), I(replaced), I(overridden), I(deleted) or I(purged)
returned: when state is I(merged), I(replaced), I(overridden), I(deleted)
type: dict
sample: >
This output will always be in the same format as the
Expand All @@ -904,7 +907,7 @@
module argspec.
commands:
description: The set of commands pushed to the remote device.
returned: when state is I(merged), I(replaced), I(overridden), I(deleted) or I(purged)
returned: when state is I(merged), I(replaced), I(overridden) or I(deleted)
type: list
sample:
- "<rpc-reply>
Expand Down Expand Up @@ -966,8 +969,18 @@ def main():
:returns: the result form module invocation
"""

required_if = [
("state", "merged", ("config",)),
("state", "replaced", ("config",)),
("state", "overridden", ("config",)),
("state", "rendered", ("config",)),
("state", "parsed", ("running_config",)),
]

module = AnsibleModule(
argument_spec=Security_policies_globalArgs.argument_spec,
required_if=required_if,
supports_check_mode=True,
)

Expand Down

0 comments on commit 5407623

Please sign in to comment.