How to use the genie.conf.base.config.CliConfig function in genie

To help you get started, we’ve selected a few genie examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / testbed / __init__.py View on Github external
if not cfgs:
        return add_to_cfgs

    if isinstance(cfgs, str):
        # Need a device object to instantiate CliConfig
        if device is None:
            raise ValueError(cfgs)
        if isinstance(device, str):
            if not testbed:
                testbed = Genie.testbed
            device = testbed.devices[device]
        elif not isinstance(device, Device):
            # A Feature?
            device = device.device
            assert isinstance(device, Device)
        cfgs = CliConfig(cfgs, device=device)
        # Fallthrough to Config case below...

    elif isinstance(cfgs, abc.Mapping):
        for device, device_cfgs in cfgs.items():
            _clean_cfgs_dict_inner(device_cfgs, testbed=testbed, device=device,
                                   add_to_cfgs=add_to_cfgs)
        return add_to_cfgs

    elif isinstance(cfgs, abc.Iterable):
        for device_cfg in cfgs:
            _clean_cfgs_dict_inner(device_cfg, testbed=testbed, device=device,
                                   add_to_cfgs=add_to_cfgs)
        return add_to_cfgs

    if isinstance(cfgs, Config):
        device = cfgs.device.name
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / testbed / __init__.py View on Github external
def _clean_cfgs_list_merge(device_cfgs):

    new_device_cfgs = []

    for device_cfg in device_cfgs:
        if isinstance(device_cfg, CliConfig) and not str(device_cfg):
            # Empty, ignore it.
            continue
        if new_device_cfgs and \
                isinstance(device_cfg, CliConfig) \
                and type(device_cfg) is type(new_device_cfgs[-1]) \
                and device_cfg.device is new_device_cfgs[-1].device \
                and device_cfg.unconfig == new_device_cfgs[-1].unconfig \
                and device_cfg.fkwargs == new_device_cfgs[-1].fkwargs:
            # Replace previous with new merged CLI.
            new_device_cfg = type(device_cfg)(
                device=device_cfg.device,
                unconfig=device_cfg.unconfig,
                cli_config='\n'.join([
                    str(new_device_cfgs[-1]),
                    str(device_cfg),
                ]),
                **device_cfg.fkwargs)
            new_device_cfgs[-1] = new_device_cfg
            continue
        new_device_cfgs.append(device_cfg)
github CiscoTestAutomation / genielibs / src / conf / igmp / nxos / igmp.py View on Github external
if attributes.value('require_router_alert'):
                configurations.append_line('ip igmp enforce-router-alert')
 
            # VrfAttributes
            for sub, attributes2 in attributes.mapping_values('vrf_attr',
                    sort=True, keys=self.vrf_attr):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig))            
            
            if apply:
                if configurations:
                    self.device.configure(configurations)
            else:
                return CliConfig(device=self.device, unconfig=unconfig,
                                 cli_config=configurations)
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / device / ios / device.py View on Github external
def build_unconfig(self, apply=True, attributes=None, **kwargs):
        attributes = AttributesHelper(self, attributes)
        configurations = CliConfigBuilder()

        configurations.append_block(
            super().build_unconfig(apply=False, attributes=attributes,
                                   **kwargs))

        if apply:
            if configurations:
                self.configure(str(configurations), fail_invalid=True)
        else:
            # Return configuration
            return CliConfig(device=self, unconfig=True,
                             cli_config=configurations, fail_invalid=True)
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / hsrp / iosxr / hsrp.py View on Github external
unconfig=False, **kwargs):
            assert not apply
            attributes = AttributesHelper(self, attributes)
            configurations = CliConfigBuilder(unconfig=unconfig)

            # iosxr: router hsrp
            configurations.append_line(attributes.format('router hsrp',
                                                         force=True))

            # loop over all interfaces
            for sub, attributes2 in attributes.mapping_values('interface_attr',
                    keys=self.interface_attr.keys()):
                configurations.append_block(sub.build_config(apply=False,
                        attributes=attributes2, unconfig=unconfig, **kwargs))

            return CliConfig(device=self.device, unconfig=unconfig,
                             cli_config=configurations)
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / vxlan / nxos / vxlan.py View on Github external
if attributes.value('evpn_vni_rd'):
                                configurations.append_line(attributes.format('rd {evpn_vni_rd}'))

                            for sub, attributes2 in attributes.mapping_values('route_target_attr',
                                                                              sort=True,
                                                                              keys=self.route_target_attr):
                                configurations.append_block(
                                    sub.build_config(apply=False,
                                                     attributes=attributes2,
                                                     unconfig=unconfig))

                    if apply:
                        if configurations:
                            self.device.configure(configurations)
                    else:
                        return CliConfig(device=self.device, unconfig=unconfig,
                                     cli_config=configurations)
github CiscoTestAutomation / genielibs / src / conf / ospf / nxos / ospf.py View on Github external
if attributes.value('enabled'):
                if unconfig is False:
                    configurations.append_line(
                        attributes.format('feature ospf'))

                # Make sure that only enabled was provided in attributes
                # If wildcard,  then delete everything
                elif unconfig is True and\
                     attributes.attributes == {'enabled': {True: None}} or \
                        attributes.iswildcard:
                    configurations.append_line('no feature ospf', raw=True)
                    if apply:
                        if configurations:
                            self.device.configure(configurations)
                    else:
                        return CliConfig(device=self.device, unconfig=unconfig,
                                         cli_config=configurations)

            #  +- DeviceAttributes
            #      +- VrfAttributes
            for sub, attributes2 in attributes.mapping_values('vrf_attr', 
                                                              sort=True, 
                                                              keys=self.vrf_attr):
                configurations.append_block(
                    sub.build_config(apply=False,
                                     attributes=attributes2,
                                     unconfig=unconfig))

            # Add InterfaceAttribute configuration
            configurations.append_block(self.interface_config)

            if apply:
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / ntp / nxos / ntp.py View on Github external
if attributes.value('enabled'):
                if unconfig is False:
                    configurations.append_line(
                        attributes.format('feature ntp'))

                # Make sure that only enabled was provided in attributes
                # If wildcard,  then delete everything
                elif unconfig is True and\
                     attributes.attributes == {'enabled': {True: None}} or \
                        attributes.iswildcard:
                    configurations.append_line('no feature ntp', raw=True)
                    if apply:
                        if configurations:
                            self.device.configure(configurations)
                    else:
                        return CliConfig(device=self.device, unconfig=unconfig,
                                         cli_config=configurations)

            # master_stratum
            if attributes.value('master_stratum'):
                configurations.append_line(
                    attributes.format('ntp master {master_stratum}'))

            # auth_enabled
            if attributes.value('auth_enabled'):
                configurations.append_line('ntp authenticate')
 
            # VrfAttributes
            for sub, attributes1 in attributes.mapping_values('vrf_attr',
                    sort=True, keys=self.vrf_attr):
                        configurations.append_block(
                            sub.build_config(apply=False,
github CiscoTestAutomation / genielibs / pkgs / conf-pkg / src / genie / libs / conf / bgp / nxos / bgp.py View on Github external
unconfig=unconfig,
                                             **kwargs))

                for sub, attributes2 in attributes.mapping_values(
                    'peer_policy_attr', keys=self.peer_policy_attr):
                        configurations.append_block(
                            sub.build_config(apply=False,
                                             attributes=attributes2,
                                             unconfig=unconfig,
                                             **kwargs))

            if apply:
                if configurations:
                    self.device.configure(configurations)
            else:
                return CliConfig(device=self.device, unconfig=unconfig,
                                 cli_config=configurations)