Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
 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))
Esempio n. 4
0
 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))
Esempio n. 5
0
 def enable(self, policy):
     """
     Set a layer 2 interface policy.
     
     :param str,Element policy: an InterfacePolicy or str href
     :raises LoadPolicyFailed: Invalid policy specified
     :raises ElementNotFound: InterfacePolicy not found
     :return: None
     """
     if hasattr(policy, 'href'):
         if not isinstance(policy, InterfacePolicy):
             raise LoadPolicyFailed('Invalid policy type specified. The policy'
                 'type must be InterfacePolicy')
             
     self.update(l2_interface_policy_ref=element_resolver(policy))
Esempio n. 6
0
    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)
Esempio n. 7
0
    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)
Esempio n. 8
0
    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)