Ejemplo n.º 1
0
    def populate_facts(self, connection, ansible_facts, data=None):
        """ Populate the facts for BGP
        :param connection: the device connection
        :param ansible_facts: Facts dictionary
        :param data: previously collected conf
        :rtype: dictionary
        :returns: facts
        """
        objs = list()

        if not data:
            data = get_all_bgp_neighbors(self._module)
            filtered_data = self.filter_neighbors_data(data)
            if filtered_data:
                data = filtered_data

        for conf in data:
            if conf:
                obj = self.render_config(self.generated_spec, conf)
                if obj:
                    objs.append(obj)

        ansible_facts['ansible_network_resources'].pop('bgp_neighbors', None)
        facts = {}
        if objs:
            params = utils.validate_config(self.argument_spec, {'config': remove_empties_from_list(objs)})
            facts['bgp_neighbors'] = params['config']
        ansible_facts['ansible_network_resources'].update(facts)
        return ansible_facts
Ejemplo n.º 2
0
    def populate_facts(self, connection, ansible_facts, data=None):
        """ Populate the facts for BGP
        :param connection: the device connection
        :param ansible_facts: Facts dictionary
        :param data: previously collected conf
        :rtype: dictionary
        :returns: facts
        """
        objs = list()
        if connection:  # just for linting purposes, remove
            pass

        if not data:
            data = get_bgp_data(self._module, self.global_params_map)
            self.normalise_bgp_data(data)

        # operate on a collection of resource x
        for conf in data:
            if conf:
                obj = self.render_config(self.generated_spec, conf)
                # split the config into instances of the resource
                if obj:
                    objs.append(obj)

        ansible_facts['ansible_network_resources'].pop('bgp', None)
        facts = {}
        if objs:
            params = utils.validate_config(
                self.argument_spec, {'config': remove_empties_from_list(objs)})
            facts['bgp'] = params['config']
        ansible_facts['ansible_network_resources'].update(facts)
        return ansible_facts
Ejemplo n.º 3
0
    def set_config(self, existing_vlans_facts):
        """ Collect the configuration from the args passed to the module,
            collect the current configuration (as a dict from facts)

        :rtype: A list
        :returns: the commands necessary to migrate the current configuration
                  to the desired configuration
        """
        want = remove_empties_from_list(self._module.params['config'])
        have = existing_vlans_facts
        resp = self.set_state(want, have)
        return to_list(resp)
Ejemplo n.º 4
0
    def populate_facts(self, connection, ansible_facts, data=None):
        """ Populate the facts for BGP
        :param connection: the device connection
        :param ansible_facts: Facts dictionary
        :param data: previously collected conf
        :rtype: dictionary
        :returns: facts
        """
        objs = list()
        if connection:  # just for linting purposes, remove
            pass

        if not data:
            data = get_all_bgp_neighbors(self._module)

        new_data = []
        for conf in data:
            if not conf:
                continue
            new_item = {}
            new_item['bgp_as'] = conf['bgp_as']
            new_item['vrf_name'] = conf['vrf_name']
            neighbors = conf.get('neighbors', None)
            if not neighbors:
                new_data.append(new_item)
                continue
            neighbors = neighbors.get('neighbor', None)
            if not neighbors:
                new_data.append(new_item)
                continue

            new_neighbors = self.normalize_neighbors_af_data(neighbors)
            if new_neighbors:
                new_item['neighbors'] = new_neighbors
            if new_item:
                new_data.append(new_item)

        # operate on a collection of resource x
        for conf in new_data:
            if conf:
                obj = self.render_config(self.generated_spec, conf)
        # split the config into instances of the resource
                if obj:
                    objs.append(obj)

        ansible_facts['ansible_network_resources'].pop('bgp_neighbors_af', None)
        facts = {}
        if objs:
            params = utils.validate_config(self.argument_spec, {'config': remove_empties_from_list(objs)})
            facts['bgp_neighbors_af'] = params['config']
        ansible_facts['ansible_network_resources'].update(facts)
        return ansible_facts
Ejemplo n.º 5
0
    def set_state(self, want, have):
        """ Select the appropriate function based on the state provided

        :param want: the desired configuration as a dictionary
        :param have: the current configuration as a dictionary
        :rtype: A list
        :returns: the commands necessary to migrate the current configuration
                  to the desired configuration
        """
        state = self._module.params['state']
        # diff method works on dict, so creating temp dict
        diff = get_diff(want, have, TEST_KEYS)

        if state == 'overridden':
            commands, requests = self._state_overridden(want, have, diff)
        elif state == 'deleted':
            commands, requests = self._state_deleted(want, have, diff)
        elif state == 'merged':
            commands, requests = self._state_merged(want, have, diff)
        elif state == 'replaced':
            commands, requests = self._state_replaced(want, have, diff)

        ret_commands = remove_empties_from_list(commands)
        return ret_commands, requests
Ejemplo n.º 6
0
    def _state_deleted(self, want, have, diff):
        """ The command generator when state is deleted

        :rtype: A list
        :returns: the commands necessary to remove the current configuration
                  of the provided objects
        """
        commands = list()
        requests = list()
        portchannel_requests = list()
        # if want is none, then delete all the lag interfaces and all portchannels
        if not want:
            requests = self.get_delete_all_lag_interfaces_requests()
            portchannel_requests = self.get_delete_all_portchannel_requests()
            requests.extend(portchannel_requests)
            commands.extend(update_states(have, "Deleted"))
        else:  # delete specific lag interfaces and specific portchannels
            commands = get_diff(want, diff, TEST_KEYS)
            commands = remove_empties_from_list(commands)
            want_members, want_portchannels = self.diff_list_for_member_creation(
                commands)
            commands, requests = self.template_for_lag_deletion(
                have, want_members, want_portchannels, "deleted")
        return commands, requests