def execute_module(self):
        """ Execute the module

        :rtype: A dictionary
        :returns: The result from module execution
        """
        result = {'changed': False}
        warnings = list()
        requests = list()

        existing_vlans_facts = self.get_vlans_facts()
        requests.extend(self.set_config(existing_vlans_facts))
        if requests:
            if not self._module.check_mode:
                send_requests(self._module, requests=requests)
            result['changed'] = True
        result['requests'] = requests

        changed_vlans_facts = self.get_vlans_facts()

        result['before'] = existing_vlans_facts
        if result['changed']:
            result['after'] = changed_vlans_facts

        result['warnings'] = warnings
        return result
    def populate_facts(self, connection, ansible_facts, data=None):
        """ Populate the facts for lldp_global
        :param connection: the device connection
        :param ansible_facts: Facts dictionary
        :param data: previously collected conf
        :rtype: dictionary
        :returns: facts
        """
        if not data:
            request = {
                "path": "/rest/restconf/data/openconfig-lldp:lldp/config/",
                "method": "GET",
            }
            data = send_requests(self._module, request)

        obj = {}
        if data:
            lldp_obj = self.render_config(self.generated_spec, data[0])
            if lldp_obj:
                obj = lldp_obj

        ansible_facts['ansible_network_resources'].pop('lldp_global', None)
        facts = {}

        params = utils.validate_config(self.argument_spec, {'config': obj})
        facts['lldp_global'] = params['config']

        ansible_facts['ansible_network_resources'].update(facts)
        return ansible_facts
Beispiel #3
0
    def populate_facts(self, connection, ansible_facts, data=None):
        """ Populate the facts for l2_interfaces
        :param connection: the device connection
        :param ansible_facts: Facts dictionary
        :param data: previously collected conf
        :rtype: dictionary
        :returns: facts
        """

        if not data:
            request = [{
                "path": "/rest/restconf/data/openconfig-interfaces:interfaces",
                "method": "GET"
            }]
            data = send_requests(self._module, requests=request)

        objs = []
        if data:
            for d in data[0]["openconfig-interfaces:interfaces"]["interface"]:
                obj = self.render_config(self.generated_spec, d)
                if obj:
                    objs.append(obj)

        ansible_facts['ansible_network_resources'].pop('l2_interfaces', None)
        facts = {}
        if objs:
            params = utils.validate_config(self.argument_spec,
                                           {'config': objs})
            facts['l2_interfaces'] = params['config']

        ansible_facts['ansible_network_resources'].update(facts)
        return ansible_facts