示例#1
0
    def delete_media(self, dict_changes):
        table = dict_changes['table']
        id_down = dict_changes['id']
        d_media = get_media(id_down)
        cmds = create_cmds_delete_disk(d_media['path_downloaded'])

        # change for other pools when pools are implemented in all media
        pool_id = 'default'
        next_hyp = self.manager.pools[pool_id].get_next()
        logs.downloads.debug('hypervisor where delete media {}: {}'.format(
            d_media['path_downloaded'], next_hyp))

        action = dict()
        action['id_media'] = id_down
        action['path'] = d_media['path_downloaded']
        action['type'] = 'delete_media'
        action['ssh_commands'] = cmds

        self.manager.q.workers[next_hyp].put(action)
示例#2
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')
示例#3
0
def populate_dict_hardware_from_create_dict(id_domain):
    domain = get_domain(id_domain)
    create_dict = domain['create_dict']
    new_hardware_dict = {}
    if 'origin' in create_dict.keys():
        template_origin = create_dict['origin']
        template = get_domain(template_origin)
        new_hardware_dict = template['hardware'].copy()

    else:
        # TODO domain from iso or new
        pass

    if 'hardware' in create_dict.keys():
        if 'disks' in create_dict['hardware'].keys():
            new_hardware_dict['disks'] = create_dict['hardware']['disks'].copy(
            )

        for media_type in ['isos', 'floppies']:
            if media_type in create_dict['hardware'].keys():
                new_hardware_dict[media_type] = []
                for d in create_dict['hardware'][media_type]:
                    new_media_dict = {}
                    media = get_media(d['id'])
                    new_media_dict['path'] = media['path_downloaded']
                    new_hardware_dict[media_type].append(new_media_dict)

    new_hardware_dict['name'] = id_domain
    new_hardware_dict['uuid'] = None

    # MEMORY and CPUS
    new_hardware_dict['vcpus'] = create_dict['hardware']['vcpus']
    new_hardware_dict['currentMemory'] = create_dict['hardware'].get(
        'currentMemory',
        int(create_dict['hardware']['memory'] * DEFAULT_BALLOON))
    new_hardware_dict['memory'] = create_dict['hardware']['memory']
    new_hardware_dict['currentMemory_unit'] = 'KiB'
    new_hardware_dict['memory_unit'] = 'KiB'

    # VIDEO
    id_video = create_dict['hardware']['videos'][0]
    new_hardware_dict['video'] = create_dict_video_from_id(id_video)

    # GRAPHICS
    id_graphics = create_dict['hardware']['graphics'][0]

    pool_var = domain['hypervisors_pools']
    id_pool = pool_var if type(pool_var) is str else pool_var[0]
    new_hardware_dict['graphics'] = create_dict_graphics_from_id(
        id_graphics, id_pool)

    # INTERFACES
    list_ids_interfaces = create_dict['hardware']['interfaces']
    new_hardware_dict['interfaces'] = create_list_interfaces_from_list_ids(
        list_ids_interfaces)

    # BOOT MENU
    if 'hardware' in create_dict.keys():
        if 'boot_order' in create_dict['hardware'].keys():
            new_hardware_dict['boot_order'] = create_dict['hardware'][
                'boot_order']
        if 'boot_menu_enable' in create_dict['hardware'].keys():
            new_hardware_dict['boot_menu_enable'] = create_dict['hardware'][
                'boot_menu_enable']
    #import pprint
    #pprint.pprint(new_hardware_dict)
    #print('############### domain {}'.format(id_domain))
    update_table_field('domains',
                       id_domain,
                       'hardware',
                       new_hardware_dict,
                       merge_dict=False)
示例#4
0
def populate_dict_hardware_from_create_dict(id_domain):
    domain = get_domain(id_domain)
    create_dict = domain['create_dict']
    new_hardware_dict = {}
    if 'origin' in create_dict.keys():
        template_origin = create_dict['origin']
        template = get_domain(template_origin)
        new_hardware_dict = template['hardware'].copy()

    else:
        # TODO domain from iso or new
        pass

    if 'hardware' in create_dict.keys():
        if 'disks' in create_dict['hardware'].keys():
            new_hardware_dict['disks'] = create_dict['hardware']['disks'].copy()

        for media_type in ['isos','floppies']:
            if media_type in create_dict['hardware'].keys():
                new_hardware_dict[media_type] = []
                for d in create_dict['hardware'][media_type]:
                    new_media_dict = {}
                    media = get_media(d['id'])
                    new_media_dict['path'] = media['path_downloaded']
                    new_hardware_dict[media_type].append(new_media_dict)


    new_hardware_dict['name'] = id_domain
    new_hardware_dict['uuid'] = None

    # MEMORY and CPUS
    new_hardware_dict['vcpus'] = create_dict['hardware']['vcpus']
    new_hardware_dict['currentMemory'] = create_dict['hardware'].get('currentMemory',int(create_dict['hardware']['memory'] * DEFAULT_BALLOON))
    new_hardware_dict['memory'] = create_dict['hardware']['memory']
    new_hardware_dict['currentMemory_unit'] = 'KiB'
    new_hardware_dict['memory_unit'] = 'KiB'

    # VIDEO
    id_video = create_dict['hardware']['videos'][0]
    new_hardware_dict['video'] = create_dict_video_from_id(id_video)

    # GRAPHICS
    id_graphics = create_dict['hardware']['graphics'][0]

    pool_var = domain['hypervisors_pools']
    id_pool = pool_var if type(pool_var) is str else pool_var[0]
    new_hardware_dict['graphics'] = create_dict_graphics_from_id(id_graphics, id_pool)

    # INTERFACES
    list_ids_interfaces = create_dict['hardware']['interfaces']
    new_hardware_dict['interfaces'] = create_list_interfaces_from_list_ids(list_ids_interfaces)

    # BOOT MENU
    if 'hardware' in create_dict.keys():
        if 'boot_order' in create_dict['hardware'].keys():
            new_hardware_dict['boot_order'] = create_dict['hardware']['boot_order']
        if 'boot_menu_enable' in create_dict['hardware'].keys():
            new_hardware_dict['boot_menu_enable'] = create_dict['hardware']['boot_menu_enable']
    #import pprint
    #pprint.pprint(new_hardware_dict)
    #print('############### domain {}'.format(id_domain))
    update_table_field('domains',
                       id_domain,
                       'hardware',
                       new_hardware_dict,
                       merge_dict=False)