コード例 #1
0
    def run(self, class_string, device_group, firewall, objects, pre_rulebase):

        device = self.get_panorama(firewall, device_group)
        pandevice_class = self.get_pandevice_class(class_string)
        cls = pandevice_class['cls']

        # we need some special logic for policies
        if device_group and pre_rulebase:
            rulebase = PreRulebase()
        elif device_group and not pre_rulebase:
            rulebase = PostRulebase()
        else:
            rulebase = Rulebase()

        device.add(rulebase)

        # because we are deleting in bulk, we do not refresh the object tree

        for obj in objects:
            if not isinstance(obj, str):
                raise ValueError("{} is not a valid {} object name!".format(
                    obj, cls.__name__))

            pandevice_object = cls(name=obj)
            rulebase.add(pandevice_object)

        pandevice_object.delete_similar()

        device_value = device_group or firewall
        return True, "{} objects successfully deleted from {}".format(
            cls.__name__, device_value)
コード例 #2
0
    def run(self, class_string, device_group, firewall, objects, pre_rulebase):

        device = self.get_panorama(firewall, device_group)
        pandevice_class = self.get_pandevice_class(class_string)
        cls = pandevice_class['cls']

        # we need some special logic for policies
        if device_group and pre_rulebase:
            rulebase = PreRulebase()
        elif device_group and not pre_rulebase:
            rulebase = PostRulebase()
        else:
            rulebase = Rulebase()

        device.add(rulebase)
        cls.refreshall(parent=rulebase)

        for obj in objects:
            if not isinstance(obj, dict):
                raise ValueError("{} is not a valid {} object!".format(
                    obj, cls.__name__))
            if not set(obj.keys()).issubset(set(
                    pandevice_class['valid_keys'])):
                raise ValueError(
                    "{} contains invalid values for a {} object!".format(
                        obj, cls.__name__))

            # manually update an existing object or add a new one
            pandevice_object = rulebase.find(obj['name'], class_type=cls)
            if pandevice_object is not None:
                for key, value in obj.items():
                    setattr(pandevice_object, key, value)

            else:
                pandevice_object = cls(**obj)
                rulebase.add(pandevice_object)

        pandevice_object.apply_similar()

        device_value = device_group or firewall
        return True, "{} objects successfully applied to {}".format(
            cls.__name__, device_value)
コード例 #3
0
    def run(self, class_string, device_group, firewall, pre_rulebase,
            **kwargs):

        device = self.get_panorama(firewall, device_group)
        pandevice_class = self.get_pandevice_class(class_string)
        cls = pandevice_class['cls']
        obj = cls(**kwargs)

        # we need some special logic for policies
        if device_group and pre_rulebase:
            rulebase = PreRulebase()
        elif device_group and not pre_rulebase:
            rulebase = PostRulebase()
        else:
            rulebase = Rulebase()

        device.add(rulebase)
        rulebase.add(obj)
        obj.delete()

        device_value = device_group or firewall
        return True, "{} {} successfully deleted from {}".format(
            cls.__name__, obj.name, device_value)