예제 #1
0
    def update_viewer_client(self,
                             domain_id,
                             phase,
                             ip_client=False,
                             when=False):

        dict_viewer = {}
        r_conn = new_rethink_connection()

        # PHASE == 0 => CONNECTED
        if phase == 0:
            dict_viewer['client_addr'] = ip_client
            dict_viewer['client_since'] = when

        # PHASE == 1 => DISCONNECT
        if phase > 1:
            dict_viewer['client_addr'] = False
            dict_viewer['client_since'] = False

        rtable = r.table('domains')
        results = rtable.get(domain_id).update({
            'viewer': dict_viewer
        }).run(r_conn)

        close_rethink_connection(r_conn)
        return results
예제 #2
0
    def insert_event_in_db(self, dict_event):

        log.debug(pformat(dict_event))
        r_conn = new_rethink_connection()
        try:
            r.table('hypervisors_events').insert(dict_event).run(r_conn)
            close_rethink_connection(r_conn)
        except Exception as e:
            log.error('rethink insert hyp event fail: {}'.format(e))
예제 #3
0
    def insert_event_in_db(self, dict_event):

        log.debug(pformat(dict_event))
        r_conn = new_rethink_connection()
        try:
            r.table('hypervisors_events').insert(dict_event).run(r_conn)
            close_rethink_connection(r_conn)
        except Exception as e:
            log.error('rethink insert hyp event fail: {}'.format(e))
예제 #4
0
        def run(self):
            self.tid = get_tid()
            logs.main.info('starting thread: {} (TID {})'.format(
                self.name, self.tid))
            self.r_conn = new_rethink_connection()
            # rtable=r.table('disk_operations')
            # for c in r.table('hypervisors').changes(include_initial=True, include_states=True).run(r_conn):
            for c in r.table('hypervisors').pluck('capabilities',
                                                  'enabled',
                                                  'hostname',
                                                  'hypervisors_pools',
                                                  'port',
                                                  'user',
                                                  'viewer_hostname',
                                                  'viewer_nat_hostname').merge({'table': 'hypervisors'}).changes().\
                    union(r.table('engine').pluck('threads', 'status_all_threads').merge({'table': 'engine'}).changes())\
                    .run(self.r_conn):

                #stop thread
                if self.stop is True:
                    break

                if c['new_val'] is not None:
                    if c['new_val']['table'] == 'engine':
                        if c['new_val']['status_all_threads'] == 'Stopping':
                            break

                # hypervisor deleted
                if c['new_val'] is None:
                    if c['old_val'].get('table', False) == 'hypervisors':

                        logs.main.info('hypervisor deleted in rethink')
                        logs.main.info(pprint.pformat(c))
                        #TODO: verify no domains in hypervisor running (front end and backend) and fence or unknown if
                        # domains are running and hypevisor communication have lost
                        engine_restart()
                # hypervisor created
                elif c['old_val'] is None:
                    if c['new_val'].get('table', False) == 'hypervisors':
                        logs.main.info('hypervisor created in rethink')
                        logs.main.info(pprint.pformat(c))
                        engine_restart()
                else:
                    if c['new_val'].get('table', False) == 'hypervisors':
                        #TODO: verify no domains in hypervisor running (front end and backend) and fence or unknown if
                        # domains are running and hypevisor communication have lost
                        logs.main.info('hypervisor fields modified in rethink')
                        logs.main.info(pprint.pformat(c))
                        engine_restart()

                    #self.manager.q.background.put({'type': 'add_hyp'})

            self.r_conn.close()
예제 #5
0
        def run(self):
            self.tid = get_tid()
            logs.main.info('starting thread: {} (TID {})'.format(self.name, self.tid))
            self.r_conn = new_rethink_connection()
            # rtable=r.table('disk_operations')
            # for c in r.table('hypervisors').changes(include_initial=True, include_states=True).run(r_conn):
            for c in r.table('hypervisors').pluck('capabilities',
                                                  'enabled',
                                                  'hostname',
                                                  'hypervisors_pools',
                                                  'port',
                                                  'user').merge({'table': 'hypervisors'}).changes().\
                    union(r.table('engine').pluck('threads', 'status_all_threads').merge({'table': 'engine'}).changes())\
                    .run(self.r_conn):

                #stop thread
                if self.stop is True:
                    break

                if c['new_val'] is not None:
                    if c['new_val']['table'] == 'engine':
                        if c['new_val']['status_all_threads'] == 'Stopping':
                            break

                # hypervisor deleted
                if c['new_val'] is None:
                    if c['old_val'].get('table',False) == 'hypervisors':

                        logs.main.info('hypervisor deleted in rethink')
                        logs.main.info(pprint.pformat(c))
                        #TODO: verify no domains in hypervisor running (front end and backend) and fence or unknown if
                        # domains are running and hypevisor communication have lost
                        engine_restart()
                # hypervisor created
                elif c['old_val'] is None:
                    if c['new_val'].get('table',False) == 'hypervisors':
                        logs.main.info('hypervisor created in rethink')
                        logs.main.info(pprint.pformat(c))
                        engine_restart()
                else:
                    if c['new_val'].get('table', False) == 'hypervisors':
                        #TODO: verify no domains in hypervisor running (front end and backend) and fence or unknown if
                        # domains are running and hypevisor communication have lost
                        logs.main.info('hypervisor fields modified in rethink')
                        logs.main.info(pprint.pformat(c))
                        engine_restart()

                    #self.manager.q.background.put({'type': 'add_hyp'})

            self.r_conn.close()
예제 #6
0
    def update_viewer_client(self, domain_id, phase, ip_client=False, when=False):

        dict_viewer = {}
        r_conn = new_rethink_connection()

        # PHASE == 0 => CONNECTED
        if phase == 0:
            dict_viewer['client_addr'] = ip_client
            dict_viewer['client_since'] = when

        # PHASE == 1 => DISCONNECT
        if phase > 1:
            dict_viewer['client_addr'] = False
            dict_viewer['client_since'] = False

        rtable = r.table('domains')
        results = rtable.get(domain_id).update({'viewer': dict_viewer}).run(r_conn)

        close_rethink_connection(r_conn)
        return results
예제 #7
0
    def run(self):
        self.tid = get_tid()
        logs.downloads.debug(
            'RUN-DOWNLOAD-THREAD-------------------------------------')
        pool_id = 'default'
        first_loop = True
        if self.stop is False:
            if first_loop is True:
                # if domains or media have status Downloading when engine restart
                # we need to resetdownloading deleting file and
                first_loop = False
                # wait a hyp to downloads
                next_hyp = False
                while next_hyp is False:
                    logs.downloads.info(
                        'waiting an hypervisor online to launch downloading actions'
                    )
                    if pool_id in self.manager.pools.keys():
                        next_hyp = self.manager.pools[pool_id].get_next()
                    sleep(1)

                for hyp_id in get_hypers_in_pool():
                    self.killall_curl(hyp_id)

                domains_status_downloading = get_domains_with_status(
                    'Downloading')
                medias_status_downloading = get_media_with_status(
                    'Downloading')

                for id_domain in domains_status_downloading:
                    create_dict = get_domain(id_domain)['create_dict']
                    dict_changes = {
                        'id': id_domain,
                        'table': 'domains',
                        'create_dict': create_dict
                    }
                    update_domain_status('ResetDownloading', id_domain)
                    self.abort_download(dict_changes,
                                        final_status='DownloadFailed')

                for id_media in medias_status_downloading:
                    dict_media = get_media(id_media)
                    dict_changes = {
                        'id': id_media,
                        'table': 'media',
                        'path': dict_media['path'],
                        'hypervisors_pools': dict_media['hypervisors_pools']
                    }
                    update_status_table('media', 'ResetDownloading', id_media)
                    self.abort_download(dict_changes,
                                        final_status='DownloadFailed')

            self.r_conn = new_rethink_connection()
            update_table_field('hypervisors_pools', pool_id,
                               'download_changes', 'Started')
            for c in r.table('media').get_all(r.args(
                    ['Deleting', 'Deleted', 'Downloaded', 'DownloadFailed', 'DownloadStarting', 'Downloading', 'Download',
                     'DownloadAborting','ResetDownloading']), index='status'). \
                    pluck('id',
                          'path',
                          'url-isard',
                          'url-web',
                          'status'
                          ).merge(
                {'table': 'media'}).changes(include_initial=True).union(
                r.table('domains').get_all(
                    r.args(['Downloaded', 'DownloadFailed','DownloadStarting', 'Downloading', 'DownloadAborting','ResetDownloading']), index='status'). \
                        pluck('id',
                              'create_dict',
                              'url-isard',
                              'url-web',
                              'status').merge(
                    {"table": "domains"}).changes(include_initial=True)).union(
                r.table('engine').pluck('threads', 'status_all_threads').merge({'table': 'engine'}).changes()).run(
                self.r_conn):

                if self.stop:
                    break
                if c.get('new_val', None) is not None:
                    if c['new_val'].get('table', False) == 'engine':
                        if c['new_val']['status_all_threads'] == 'Stopping':
                            break
                        else:
                            continue

                logs.downloads.debug('DOWNLOAD CHANGES DETECTED:')
                logs.downloads.debug(pprint.pformat(c))

                if c.get('old_val', None) is None:
                    if c['new_val']['status'] == 'DownloadStarting':
                        self.start_download(c['new_val'])
                elif c.get('new_val', None) is None:
                    if c['old_val']['status'] in ['DownloadAborting']:
                        self.remove_download_thread(c['old_val'])

                elif 'old_val' in c and 'new_val' in c:
                    if c['old_val']['status'] == 'DownloadFailed' and c[
                            'new_val']['status'] == 'DownloadStarting':
                        self.start_download(c['new_val'])

                    elif c['old_val']['status'] == 'Downloaded' and c[
                            'new_val']['status'] == 'Deleting':
                        if c['new_val']['table'] == 'media':
                            self.delete_media(c['new_val'])

                    elif c['old_val']['status'] == 'Deleting' and c['new_val'][
                            'status'] == 'Deleted':
                        if c['new_val']['table'] == 'media':
                            remove_media(c['new_val']['id'])

                    elif c['old_val']['status'] == 'Downloading' and c[
                            'new_val']['status'] == 'DownloadFailed':
                        pass

                    elif c['old_val']['status'] == 'DownloadStarting' and c[
                            'new_val']['status'] == 'Downloading':
                        pass

                    elif c['old_val']['status'] == 'Downloading' and c[
                            'new_val']['status'] == 'Downloaded':
                        pass

                    elif c['old_val']['status'] == 'Downloading' and c[
                            'new_val']['status'] == 'DownloadAborting':
                        self.abort_download(c['new_val'])

                    elif c['old_val']['status'] == 'Downloading' and c[
                            'new_val']['status'] == 'ResetDownloading':
                        self.abort_download(c['new_val'],
                                            final_status='DownloadFailed')
예제 #8
0
        def run(self):
            self.tid = get_tid()
            logs.changes.info('starting thread: {} (TID {})'.format(
                self.name, self.tid))
            logs.changes.debug(
                '^^^^^^^^^^^^^^^^^^^ DOMAIN CHANGES THREAD ^^^^^^^^^^^^^^^^^')
            ui = UiActions(self.manager)
            self.r_conn = new_rethink_connection()

            cursor = r.table('domains').pluck('id', 'kind', 'status', 'detail').merge({'table': 'domains'}).changes().\
                union(r.table('engine').pluck('threads', 'status_all_threads').merge({'table': 'engine'}).changes()).\
                run(self.r_conn)

            for c in cursor:

                if self.stop is True:
                    break

                if c.get('new_val', None) is not None:
                    if c['new_val']['table'] == 'engine':
                        if c['new_val']['status_all_threads'] == 'Stopping':
                            break
                        else:
                            continue

                logs.changes.debug('domain changes detected in main thread')

                detail_msg_if_no_hyps_online = 'No hypervisors Online in pool'
                if self.manager.check_actions_domains_enabled() is False:
                    if c.get('new_val', None) is not None:
                        if c.get('old_val', None) is not None:
                            if c['new_val']['status'][-3:] == 'ing':
                                update_domain_status(
                                    c['old_val']['status'],
                                    c['old_val']['id'],
                                    detail=detail_msg_if_no_hyps_online)

                    #if no hypervisor availables no check status changes
                    continue

                new_domain = False
                new_status = False
                old_status = False
                import pprint
                logs.changes.debug(pprint.pformat(c))

                # action deleted
                if c.get('new_val', None) is None:
                    pass
                # action created
                if c.get('old_val', None) is None:
                    new_domain = True
                    new_status = c['new_val']['status']
                    domain_id = c['new_val']['id']
                    logs.changes.debug('domain_id: {}'.format(new_domain))
                    # if engine is stopped/restarting or not hypervisors online
                    if self.manager.check_actions_domains_enabled() is False:
                        continue
                    pass

                if c.get('new_val', None) is not None and c.get(
                        'old_val', None) is not None:
                    old_status = c['old_val']['status']
                    new_status = c['new_val']['status']
                    new_detail = c['new_val']['detail']
                    domain_id = c['new_val']['id']
                    logs.changes.debug('domain_id: {}'.format(domain_id))
                    # if engine is stopped/restarting or not hypervisors online

                    if old_status != new_status:

                        # print('&&&&&&& ID DOMAIN {} - old_status: {} , new_status: {}, detail: {}'.format(domain_id,old_status,new_status, new_detail))
                        # if new_status[-3:] == 'ing':
                        if 1 > 0:
                            date_now = datetime.now()
                            update_domain_history_from_id_domain(
                                domain_id, new_status, new_detail, date_now)
                    else:
                        # print('&&&&&&&ESTADOS IGUALES OJO &&&&&&&\n&&&&&&&& ID DOMAIN {} - old_status: {} , new_status: {}, detail: {}'.
                        #       format(domain_id,old_status,new_status,new_detail))
                        pass

                if (new_domain is True and new_status == "CreatingDiskFromScratch") or \
                        (old_status == 'FailedCreatingDomain' and new_status == "CreatingDiskFromScratch"):
                    ui.creating_disk_from_scratch(domain_id)

                if (new_domain is True and new_status == "Creating") or \
                        (old_status == 'FailedCreatingDomain' and new_status == "Creating"):
                    ui.creating_disks_from_template(domain_id)

                if (new_domain is True
                        and new_status == "CreatingAndStarting"):
                    update_domain_start_after_created(domain_id)
                    ui.creating_disks_from_template(domain_id)

                    # INFO TO DEVELOPER
                    # recoger template de la que hay que derivar
                    # verificar que realmente es una template
                    # hay que recoger ram?? cpu?? o si no hay nada copiamos de la template??

                if (new_domain is True and new_status == "CreatingFromBuilder") or \
                        (old_status == 'FailedCreatingDomain' and new_status == "CreatingFromBuilder"):
                    ui.creating_disk_from_virtbuilder(domain_id)

                if (old_status in ['CreatingDisk','CreatingDiskFromScratch'] and new_status == "CreatingDomain") or \
                        (old_status == 'RunningVirtBuilder' and new_status == "CreatingDomainFromBuilder"):
                    logs.changes.debug(
                        'llamo a creating_and_test_xml con domain id {}'.
                        format(domain_id))
                    if new_status == "CreatingDomainFromBuilder":
                        ui.creating_and_test_xml_start(
                            domain_id,
                            creating_from_create_dict=True,
                            xml_from_virt_install=True)
                    if new_status == "CreatingDomain":
                        ui.creating_and_test_xml_start(
                            domain_id, creating_from_create_dict=True)

                if old_status == 'Stopped' and new_status == "CreatingTemplate":
                    ui.create_template_disks_from_domain(domain_id)

                if old_status == 'Stopped' and new_status == "Deleting":
                    ui.deleting_disks_from_domain(domain_id)

                if (old_status == 'Stopped' and new_status == "Updating") or \
                        (old_status == 'Downloaded' and new_status == "Updating"):
                    ui.updating_from_create_dict(domain_id)

                if old_status == 'DeletingDomainDisk' and new_status == "DiskDeleted":
                    logs.changes.debug(
                        'disk deleted, mow remove domain form database')
                    remove_domain(domain_id)
                    if get_domain(domain_id) is None:
                        logs.changes.info(
                            'domain {} deleted from database'.format(
                                domain_id))
                    else:
                        update_domain_status(
                            'Failed',
                            id_domain,
                            detail='domain {} can not be deleted from database'
                            .format(domain_id))

                if old_status == 'CreatingTemplateDisk' and new_status == "TemplateDiskCreated":
                    # create_template_from_dict(dict_new_template)
                    if get_if_all_disk_template_created(domain_id):
                        ui.create_template_in_db(domain_id)
                    else:
                        # INFO TO DEVELOPER, este else no se si tiene mucho sentido, hay que hacer pruebas con la
                        # creación de una template con dos discos y ver si pasa por aquí
                        # waiting to create other disks
                        update_domain_status(
                            status='CreatingTemplateDisk',
                            id_domain=domain_id,
                            hyp_id=False,
                            detail='Waiting to create more disks for template')

                if (old_status == 'Stopped' and new_status == "Starting") or \
                        (old_status == 'Failed' and new_status == "Starting"):
                    ui.start_domain_from_id(id=domain_id, ssl=True)

                if (old_status == 'Started' and new_status == "Stopping" ) or \
                        (old_status == 'Suspended' and new_status == "Stopping" ):
                    # INFO TO DEVELOPER Esto es lo que debería ser, pero hay líos con el hyp_started
                    # ui.stop_domain_from_id(id=domain_id)
                    hyp_started = get_domain_hyp_started(domain_id)
                    if hyp_started:
                        ui.stop_domain(id_domain=domain_id, hyp_id=hyp_started)
                    else:
                        logs.main.error(
                            'domain without hyp_started can not be stopped: {}. '
                            .format(domain_id))

                if (old_status == 'Started' and new_status == "StoppingAndDeleting" ) or \
                        (old_status == 'Suspended' and new_status == "StoppingAndDeleting" ):
                    # INFO TO DEVELOPER Esto es lo que debería ser, pero hay líos con el hyp_started
                    # ui.stop_domain_from_id(id=domain_id)
                    hyp_started = get_domain_hyp_started(domain_id)
                    print(hyp_started)
                    ui.stop_domain(id_domain=domain_id,
                                   hyp_id=hyp_started,
                                   delete_after_stopped=True)

            logs.main.info('finalished thread domain changes')
예제 #9
0
    def run(self):
        self.tid = get_tid()
        logs.downloads.debug(
            'RUN-DOWNLOAD-THREAD-------------------------------------')
        if self.stop is False:
            self.r_conn = new_rethink_connection()
            for c in r.table('media').get_all(r.args(['Deleting','Deleted','Downloaded','DownloadStarting', 'Downloading','Download','DownloadAborting']), index='status').\
                    pluck('id',
                          'path',
                          'url-isard',
                          'url-web',
                          'status'
                          ).merge(
                {'table': 'media'}).changes(include_initial=True).union(
                r.table('domains').get_all(r.args(['Downloaded','DownloadStarting', 'Downloading','DownloadAborting']), index='status').\
                        pluck('id',
                              'create_dict',
                              'url-isard',
                              'url-web',
                              'status').merge(
                    {"table": "domains"}).changes(include_initial=True)).union(
                r.table('engine').pluck('threads', 'status_all_threads').merge({'table': 'engine'}).changes()).run(self.r_conn):

                if self.stop:
                    break
                if c.get('new_val', None) is not None:
                    if c['new_val'].get('table', False) == 'engine':
                        if c['new_val']['status_all_threads'] == 'Stopping':
                            break
                        else:
                            continue

                logs.downloads.debug('DOWNLOAD CHANGES DETECTED:')
                logs.downloads.debug(pprint.pformat(c))

                if c.get('old_val', None) is None:
                    if c['new_val']['status'] == 'DownloadStarting':
                        self.start_download(c['new_val'])
                elif c.get('new_val', None) is None:
                    if c['old_val']['status'] in ['DownloadAborting']:
                        self.remove_download_thread(c['old_val'])

                elif 'old_val' in c and 'new_val' in c:
                    if c['old_val']['status'] == 'FailedDownload' and c[
                            'new_val']['status'] == 'DownloadStarting':
                        self.start_download(c['new_val'])

                    elif c['old_val']['status'] == 'Downloaded' and c[
                            'new_val']['status'] == 'Deleting':
                        if c['new_val']['table'] == 'media':
                            self.delete_media(c['new_val'])

                    elif c['old_val']['status'] == 'Deleting' and c['new_val'][
                            'status'] == 'Deleted':
                        if c['new_val']['table'] == 'media':
                            remove_media(c['new_val']['id'])

                    elif c['old_val']['status'] == 'Downloading' and c[
                            'new_val']['status'] == 'FailedDownload':
                        pass

                    elif c['old_val']['status'] == 'DownloadStarting' and c[
                            'new_val']['status'] == 'Downloading':
                        pass

                    elif c['old_val']['status'] == 'Downloading' and c[
                            'new_val']['status'] == 'Downloaded':
                        pass

                    elif c['old_val']['status'] == 'Downloading' and c[
                            'new_val']['status'] == 'DownloadAborting':
                        self.abort_download(c['new_val'])
예제 #10
0
        def run(self):
            self.tid = get_tid()
            logs.changes.info('starting thread: {} (TID {})'.format(self.name, self.tid))
            logs.changes.debug('^^^^^^^^^^^^^^^^^^^ DOMAIN CHANGES THREAD ^^^^^^^^^^^^^^^^^')
            ui = UiActions(self.manager)

            self.r_conn = new_rethink_connection()

            cursor = r.table('domains').pluck('id', 'kind', 'status', 'detail').merge({'table': 'domains'}).changes().\
                union(r.table('engine').pluck('threads', 'status_all_threads').merge({'table': 'engine'}).changes()).\
                run(self.r_conn)

            for c in cursor:

                if self.stop is True:
                    break

                if c.get('new_val', None) is not None:
                    if c['new_val']['table'] == 'engine':
                        if c['new_val']['status_all_threads'] == 'Stopping':
                            break
                        else:
                            continue

                logs.changes.debug('domain changes detected in main thread')

                detail_msg_if_no_hyps_online = 'No hypervisors Online in pool'
                if self.manager.check_actions_domains_enabled() is False:
                    if c.get('new_val', None) is not None:
                        if c.get('old_val', None) is not None:
                            if c['new_val']['status'][-3:] == 'ing':
                                update_domain_status(c['old_val']['status'], c['old_val']['id'], detail=detail_msg_if_no_hyps_online)

                    #if no hypervisor availables no check status changes
                    continue

                new_domain = False
                new_status = False
                old_status = False
                logs.changes.debug(pprint.pformat(c))



                # action deleted
                if c.get('new_val', None) is None:
                    pass
                # action created
                if c.get('old_val', None) is None:
                    new_domain = True
                    new_status = c['new_val']['status']
                    domain_id = c['new_val']['id']
                    logs.changes.debug('domain_id: {}'.format(new_domain))
                    # if engine is stopped/restarting or not hypervisors online
                    if self.manager.check_actions_domains_enabled() is False:
                        continue
                    pass

                if c.get('new_val', None) is not None and c.get('old_val', None) is not None:
                    old_status = c['old_val']['status']
                    new_status = c['new_val']['status']
                    new_detail = c['new_val']['detail']
                    domain_id = c['new_val']['id']
                    logs.changes.debug('domain_id: {}'.format(domain_id))
                    # if engine is stopped/restarting or not hypervisors online




                    if old_status != new_status:



                        # print('&&&&&&& ID DOMAIN {} - old_status: {} , new_status: {}, detail: {}'.format(domain_id,old_status,new_status, new_detail))
                        # if new_status[-3:] == 'ing':
                        if 1 > 0:
                            date_now = datetime.now()
                            update_domain_history_from_id_domain(domain_id, new_status, new_detail, date_now)
                    else:
                        # print('&&&&&&&ESTADOS IGUALES OJO &&&&&&&\n&&&&&&&& ID DOMAIN {} - old_status: {} , new_status: {}, detail: {}'.
                        #       format(domain_id,old_status,new_status,new_detail))
                        pass

                if (new_domain is True and new_status == "CreatingDiskFromScratch") or \
                        (old_status == 'FailedCreatingDomain' and new_status == "CreatingDiskFromScratch"):
                    ui.creating_disk_from_scratch(domain_id)

                if (new_domain is True and new_status == "Creating") or \
                        (old_status == 'FailedCreatingDomain' and new_status == "Creating"):
                    ui.creating_disks_from_template(domain_id)

                if (new_domain is True and new_status == "CreatingAndStarting"):
                    update_domain_start_after_created(domain_id)
                    ui.creating_disks_from_template(domain_id)


                    # INFO TO DEVELOPER
                    # recoger template de la que hay que derivar
                    # verificar que realmente es una template
                    # hay que recoger ram?? cpu?? o si no hay nada copiamos de la template??

                if (new_domain is True and new_status == "CreatingFromBuilder") or \
                        (old_status == 'FailedCreatingDomain' and new_status == "CreatingFromBuilder"):
                    ui.creating_disk_from_virtbuilder(domain_id)

                if (old_status in ['CreatingDisk','CreatingDiskFromScratch'] and new_status == "CreatingDomain") or \
                        (old_status == 'RunningVirtBuilder' and new_status == "CreatingDomainFromBuilder"):
                    logs.changes.debug('llamo a creating_and_test_xml con domain id {}'.format(domain_id))
                    if new_status == "CreatingDomainFromBuilder":
                        ui.creating_and_test_xml_start(domain_id,
                                                       creating_from_create_dict=True,
                                                       xml_from_virt_install=True,ssl=True)
                    if new_status == "CreatingDomain":
                        ui.creating_and_test_xml_start(domain_id,
                                                       creating_from_create_dict=True,ssl=True)

                if old_status == 'Stopped' and new_status == "CreatingTemplate":
                    ui.create_template_disks_from_domain(domain_id)

                if old_status != 'Started' and new_status == "Deleting":
                    # or \
                    #     old_status == 'Failed' and new_status == "Deleting" or \
                    #     old_status == 'Downloaded' and new_status == "Deleting":
                    ui.deleting_disks_from_domain(domain_id)

                if (old_status == 'Stopped' and new_status == "Updating") or \
                        (old_status == 'Downloaded' and new_status == "Updating"):
                    ui.updating_from_create_dict(domain_id,ssl=True)

                if old_status == 'DeletingDomainDisk' and new_status == "DiskDeleted":
                    logs.changes.debug('disk deleted, mow remove domain form database')
                    remove_domain(domain_id)
                    if get_domain(domain_id) is None:
                        logs.changes.info('domain {} deleted from database'.format(domain_id))
                    else:
                        update_domain_status('Failed', domain_id,
                                             detail='domain {} can not be deleted from database'.format(domain_id))

                if old_status == 'CreatingTemplateDisk' and new_status == "TemplateDiskCreated":
                    # create_template_from_dict(dict_new_template)
                    if get_if_all_disk_template_created(domain_id):
                        ui.create_template_in_db(domain_id)
                    else:
                        # INFO TO DEVELOPER, este else no se si tiene mucho sentido, hay que hacer pruebas con la
                        # creación de una template con dos discos y ver si pasa por aquí
                        # waiting to create other disks
                        update_domain_status(status='CreatingTemplateDisk',
                                             id_domain=domain_id,
                                             hyp_id=False,
                                             detail='Waiting to create more disks for template')

                if (old_status == 'Stopped' and new_status == "Starting") or \
                        (old_status == 'Failed' and new_status == "Starting"):
                    ui.start_domain_from_id(id=domain_id, ssl=True)

                if (old_status == 'Started' and new_status == "Stopping" ) or \
                        (old_status == 'Suspended' and new_status == "Stopping" ):
                    # INFO TO DEVELOPER Esto es lo que debería ser, pero hay líos con el hyp_started
                    # ui.stop_domain_from_id(id=domain_id)
                    hyp_started = get_domain_hyp_started(domain_id)
                    if hyp_started:
                        ui.stop_domain(id_domain=domain_id, hyp_id=hyp_started)
                    else:
                        logs.main.error('domain without hyp_started can not be stopped: {}. '.format(domain_id))

                if (old_status == 'Started' and new_status == "StoppingAndDeleting" ) or \
                        (old_status == 'Suspended' and new_status == "StoppingAndDeleting" ):
                    # INFO TO DEVELOPER Esto es lo que debería ser, pero hay líos con el hyp_started
                    # ui.stop_domain_from_id(id=domain_id)
                    hyp_started = get_domain_hyp_started(domain_id)
                    print(hyp_started)
                    ui.stop_domain(id_domain=domain_id, hyp_id=hyp_started, delete_after_stopped=True)

            logs.main.info('finalished thread domain changes')