Beispiel #1
0
    def build_config(self, devices=None, interfaces=None, links=None,
                     apply=True, attributes=None, **kwargs):
        attributes = AttributesHelper(self, attributes)
        cfgs = {}

        devices, interfaces, links = \
            consolidate_feature_args(self, devices, interfaces, links)

        for key, sub, attributes2 in attributes.mapping_items(
                'device_attr',
                keys=devices, sort=True):
            cfgs[key] = sub.build_config(apply=False, attributes=attributes2)
        if apply:
            for device_name, cfg in sorted(cfgs.items()):
                self.testbed.config_on_devices(cfg, fail_invalid=True)
        else:
            return cfgs
Beispiel #2
0
    def build_config(self, links=None, apply=True, attributes=None, **kwargs):
        attributes = AttributesHelper(self, attributes)

        cfgs = {}

        if links is None:
            devices = self.devices
        else:
            devices = set().union(*[link.devices for link in links])

        for key, sub, attributes2 in attributes.mapping_items('device_attr',
                                                              keys=devices,
                                                              sort=True):
            cfgs[key] = sub.build_config(apply=False, attributes=attributes2)

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            return cfgs
Beispiel #3
0
    def build_unconfig(self, devices=None, interfaces=None, links=None,
                       apply=True, attributes=None, **kwargs):
        cfgs = {}
        assert not kwargs, kwargs
        attributes = AttributesHelper(self, attributes)

        if devices is None:
            devices = self.devices
        devices = set(devices)

        for key, sub, attributes2 in attributes.mapping_items(
                'device_attr',
                keys=devices, sort=True):
            cfgs[key] = sub.build_unconfig(apply=False, attributes=attributes2)

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            return cfgs
Beispiel #4
0
    def build_unconfig(self, devices=None, apply=True, attributes=None, **kwargs):
        """method to build the unconfiguration based on attributes

        Api to build the unconfiguration of an Rip object.
        This configuration depends of the configurable attributes of
        this object.

        If Apply is set to True, then it will apply on the device(s)
        If it is set to False, then it will return a dictionary.

        If any kwargs are passed, then the configuration that is built
        will use those kwargs given, and not the object attributes. This
        is useful for modifying the configuration, without re-applying
        everything.


        Args:
            apply (`bool`): If True will apply the configuration on the device
                            and if False will return the configuration in a
                            dictionary
            kwargs (`dict`): If there is kwargs, then it will use those
                             attributes to configure the feature. Otherwise
                             will use the object attributes

        Return:
            `str`
        """
        attributes = AttributesHelper(self, attributes)

        # Get devices if none were passed
        if devices is None:
            devices = self.devices

        # For each device, loop over device_attr
        cfgs = {}
        for key, sub, attributes2 in attributes.mapping_items('device_attr', keys=devices):
            cfgs[key] = sub.build_unconfig(apply=False, attributes=attributes2, **kwargs)

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            # Return configuration
            return cfgs
Beispiel #5
0
    def build_unconfig(self,
                       devices=None,
                       interfaces=None,
                       apply=True,
                       attributes=None):
        attributes = AttributesHelper(self, attributes)
        cfgs = {}

        devices, interfaces, links = consolidate_feature_args(
            self, devices, interfaces, None)

        for key, sub, attributes2 in attributes.mapping_items('device_attr',
                                                              keys=devices,
                                                              sort=True):
            cfgs[key] = sub.build_unconfig(apply=False,
                                           attributes=attributes2,
                                           interfaces=interfaces)
        cfgs = {key: value for key, value in cfgs.items() if value}

        if apply:
            self.testbed.config_on_devices(cfgs, fail_invalid=True)
        else:
            return cfgs