'Fetches the inventory information from Rudder and creates the inventory'

def update_cache(self):

    nodes = self.get_nodes()
    groups = self.get_groups()
    inventory = {}
    for group in groups:
        if self.fail_if_name_collision:
            if (groups[group]['name'] in inventory):
                self.fail_with_error(('Name    collision    on    groups:    "%s"    appears    twice' % groups[group]['name']), 'creating    groups')
        inventory[groups[group]['name']] = {}
        inventory[groups[group]['name']]['hosts'] = []
        inventory[groups[group]['name']]['vars'] = {}
        inventory[groups[group]['name']]['vars']['rudder_group_id'] = group
        for node in groups[group]['hosts']:
            inventory[groups[group]['name']]['hosts'].append(nodes[node]['hostname'])
    properties = {}
    for node in nodes:
        if self.fail_if_name_collision:
            if (nodes[node]['hostname'] in properties):
                self.fail_with_error(('Name    collision    on    hosts:    "%s"    appears    twice' % nodes[node]['hostname']), 'creating    hosts')
        properties[nodes[node]['hostname']] = {}
        properties[nodes[node]['hostname']]['rudder_node_id'] = node
        for node_property in nodes[node]['properties']:
            properties[nodes[node]['hostname']][self.to_safe(node_property['name'])] = node_property['value']
    inventory['_meta'] = {}
    inventory['_meta']['hostvars'] = properties
    self.inventory = inventory
    if (self.cache_max_age > 0):
        self.write_cache()
