<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update(self):
 """ Updates topology Links are not deleted straightaway but set as "disconnected" """

        from .link import Link  # avoid circular dependency
        diff = self.diff()

        status = {
            'added': 'active',
            'removed': 'disconnected',
            'changed': 'active'
        }

        for section in ['added', 'removed', 'changed']:
            # section might be empty
            if not diff[section]:
                continue
            for link_dict in diff[section]['links']:
                try:
                    link = Link.get_or_create(source=link_dict['source'],
                                              target=link_dict['target'],
                                              cost=link_dict['cost'],
                                              topology=self)
                except (LinkDataNotFound, ValidationError) as e:
                    msg = 'Exception while updating {0}'.format(self.__repr__())
                    logger.exception(msg)
                    print('{0}\n{1}\n'.format(msg, e))
                    continue
                link.ensure(status=status[section],
                            cost=link_dict['cost'])