def create(cls, name, template='Firewall Inspection Template'): """ Create Firewall Policy. Template policy is required for the policy. The template parameter should be the name of the firewall template. This policy will then inherit the Inspection and File Filtering policy from the specified template. :param str name: name of policy :param str template: name of the NGFW engine template to base policy on :raises LoadPolicyFailed: Cannot load the policy after creation :raises CreatePolicyFailed: policy creation failed with message :return: FirewallPolicy To use after successful creation, reference the policy to obtain context:: FirewallPolicy('newpolicy') """ try: if cls.typeof == 'fw_template_policy' and template is None: fw_template = None else: fw_template = FirewallTemplatePolicy(template).href except ElementNotFound: raise LoadPolicyFailed( 'Cannot find specified firewall template: {}'.format(template)) json = { 'name': name, 'template': fw_template} try: return ElementCreator(cls, json) except CreateElementFailed as err: raise CreatePolicyFailed(err)
def create(cls, name, template): """ Create Layer 2 Firewall Policy. Template policy is required for the policy. The template parameter should be the name of the template. The template should exist as a layer 2 template policy and should be referenced by name. This policy will then inherit the Inspection and File Filtering policy from the specified template. To use after successful creation, reference the policy to obtain context:: Layer2Policy('newpolicy') :param str name: name of policy :param str template: name of the FW template to base policy on :raises LoadPolicyFailed: cannot find policy by name :raises CreatePolicyFailed: cannot create policy with reason :return: Layer2Policy """ try: fw_template = Layer2TemplatePolicy(template).href except ElementNotFound: raise LoadPolicyFailed( 'Cannot find specified layer2 firewall template: {}'.format( template)) json = {'name': name, 'template': fw_template} try: return ElementCreator(cls, json) except CreateElementFailed as err: raise CreatePolicyFailed(err)
def create(cls, name, nat=False, mobile_vpn_toplogy_mode=None, vpn_profile=None): """ Create a new policy based VPN :param name: name of vpn policy :param bool nat: whether to apply NAT to the VPN (default False) :param mobile_vpn_toplogy_mode: whether to allow remote vpn :param VPNProfile vpn_profile: reference to VPN profile, or uses default :rtype: PolicyVPN """ vpn_profile = vpn_profile if vpn_profile else VPNProfile('VPN-A Suite') json = { 'mobile_vpn_topology_mode': mobile_vpn_toplogy_mode, 'name': name, 'nat': nat, 'vpn_profile': vpn_profile.href } try: return ElementCreator(cls, json) except CreateElementFailed as err: raise CreatePolicyFailed(err)
def create(cls, name, template): """ Create Firewall Policy. Template policy is required for the policy. The template parameter should be the name of the firewall template. This policy will then inherit the Inspection and File Filtering policy from the specified template. :mathod: POST :param str name: name of policy :param str template: name of the FW template to base policy on :return: :py:class:`smc.elements.policy.FirewallPolicy` :raises: :py:class:`smc.api.exceptions.LoadPolicyFailed`, :py:class:`smc.api.exceptions.CreatePolicyFailed` To use after successful creation, reference the policy to obtain context:: FirewallPolicy('newpolicy') """ try: fw_template = FirewallTemplatePolicy(template).href except ElementNotFound: raise LoadPolicyFailed( 'Cannot find specified firewall template: {}'.format(template)) cls.json = {'name': name, 'template': fw_template} try: result = ElementCreator(cls) return FirewallPolicy(name, Meta(href=result)) except CreateElementFailed as err: raise CreatePolicyFailed( 'Failed to create firewall policy: {}'.format(err))
def create(cls, name, template): try: fw_template = IPSTemplatePolicy(template).href except ElementNotFound: raise LoadPolicyFailed( 'Cannot find specified firewall template: {}'.format(template)) cls.json = {'name': name, 'template': fw_template} try: result = ElementCreator(cls) return IPSPolicy(name, Meta(href=result)) except CreateElementFailed as err: raise CreatePolicyFailed( 'Failed to create firewall policy: {}'.format(err))
def create(cls, name, template): """ Create an IPS Policy :param str name: Name of policy :param str template: name of template :raises CreatePolicyFailed: policy failed to create :return: IPSPolicy """ try: fw_template = IPSTemplatePolicy(template).href except ElementNotFound: raise LoadPolicyFailed( 'Cannot find specified firewall template: {}'.format(template)) json = {'name': name, 'template': fw_template} try: return ElementCreator(cls, json) except CreateElementFailed as err: raise CreatePolicyFailed(err)
def create(cls, name, template): """ Create a new Layer 2 Interface Policy. :param str name: name of policy :param str template: name of the NGFW Engine template to base policy on :raises LoadPolicyFailed: cannot find policy by name :raises CreatePolicyFailed: cannot create policy with reason :return: Layer2InterfacePolicy """ try: fw_template = InterfaceTemplatePolicy(template).href except ElementNotFound: raise LoadPolicyFailed( "Cannot find specified layer2 firewall template: {}".format( template)) json = {"name": name, "template": fw_template} try: return ElementCreator(cls, json) except CreateElementFailed as err: raise CreatePolicyFailed(err)
def create(cls, name, template="High-Security IPS Template"): """ Create an IPS Policy :param str name: Name of policy :param str template: name of template :raises CreatePolicyFailed: policy failed to create :return: IPSPolicy """ try: if cls.typeof == "ips_template_policy" and template is None: fw_template = None else: fw_template = IPSTemplatePolicy(template).href except ElementNotFound: raise LoadPolicyFailed( "Cannot find specified firewall template: {}".format(template)) json = {"name": name, "template": fw_template} try: return ElementCreator(cls, json) except CreateElementFailed as err: raise CreatePolicyFailed(err)
def create(cls, name, nat=False, mobile_vpn_toplogy_mode=None, vpn_profile=None): """ Create a new policy based VPN :param name: name of vpn policy :param boolean nat: whether to apply NAT to the VPN (default False) :param mobile_vpn_toplogy_mode: whether to allow remote vpn :param str vpn_profile: reference to VPN profile, or uses default :return: :py:class:`~VPNPolicy` """ cls.json = {'mobile_vpn_topology_mode': None, 'name': name, 'nat': nat, 'vpn_profile': vpn_profile} try: ElementCreator(cls) return VPNPolicy(name) except CreateElementFailed as err: raise CreatePolicyFailed('VPN Policy create failed. Reason: {}' .format(err))
def create(cls, name, nat=False, mobile_vpn_toplogy_mode=None, vpn_profile=None): """ Create a new policy based VPN :param name: name of vpn policy :param bool nat: whether to apply NAT to the VPN (default False) :param mobile_vpn_toplogy_mode: whether to allow remote vpn :param VPNProfile vpn_profile: reference to VPN profile, or uses default :rtype: PolicyVPN """ vpn_profile = element_resolver(vpn_profile) or VPNProfile("VPN-A Suite").href json = { "mobile_vpn_topology_mode": mobile_vpn_toplogy_mode, "name": name, "nat": nat, "vpn_profile": vpn_profile, } try: return ElementCreator(cls, json) except CreateElementFailed as err: raise CreatePolicyFailed(err)