Exemplo n.º 1
0
    def updating_from_create_dict(self, id_domain):
        try:
            populate_dict_hardware_from_create_dict(id_domain)
        except Exception as e:
            log.error(
                'error when populate dict hardware from create dict in domain {}'
                .format(id_domain))
            log.error('Traceback: \n .{}'.format(traceback.format_exc()))
            log.error('Exception message: {}'.format(e))
            update_domain_status(
                'Failed',
                id_domain,
                detail=
                'Updating aborted, failed when populate hardware dictionary')
            return False

        try:
            xml_raw = update_xml_from_dict_domain(id_domain)
        except Exception as e:
            log.error(
                'error when populate dict hardware from create dict in domain {}'
                .format(id_domain))
            log.error('Traceback: \n .{}'.format(traceback.format_exc()))
            log.error('Exception message: {}'.format(e))
            update_domain_status(
                'Failed',
                id_domain,
                detail=
                'Updating aborted, failed when updating xml from hardware dictionary'
            )
            return False

        update_domain_status(
            'Updating',
            id_domain,
            detail=
            'xml and hardware dict updated, waiting to test if domain start paused in hypervisor'
        )
        pool_id = get_pool_from_domain(id_domain)
        if pool_id is False:
            update_domain_status(
                'Failed',
                id_domain,
                detail='Updating aborted, domain has not pool')
            return False

        kind = get_domain_kind(id_domain)
        if kind == 'desktop':
            self.start_paused_domain_from_xml(xml=xml_raw,
                                              id_domain=id_domain,
                                              pool_id=pool_id)
        else:
            update_domain_status(
                'Stopped',
                id_domain,
                detail='Updating finalished, ready to derivate desktops')

            return True
Exemplo n.º 2
0
    def create_template_in_db(self, id_domain):
        domain_dict = get_domain(id_domain)
        template_dict = domain_dict['create_dict']['template_dict']
        template_dict['status'] = 'CreatingNewTemplateInDB'
        template_id = template_dict['id']
        if insert_domain(template_dict)['inserted'] == 1:
            hw_dict = domain_dict['hardware'].copy()
            for i in range(len(hw_dict['disks'])):
                hw_dict['disks'][i]['file'] = template_dict['create_dict'][
                    'hardware']['disks'][i]['file']
            update_table_field('domains',
                               template_id,
                               'hardware',
                               hw_dict,
                               merge_dict=False)
            xml_parsed = update_xml_from_dict_domain(id_domain=template_id,
                                                     xml=domain_dict['xml'])
            if xml_parsed is False:
                update_domain_status(
                    status='Failed',
                    id_domain=template_id,
                    hyp_id=False,
                    detail='XML Parser Error, xml is not valid')
                return False
            remove_disk_template_created_list_in_domain(id_domain)
            remove_dict_new_template_from_domain(id_domain)
            if 'parents' in domain_dict.keys():
                domain_parents_chain_update = domain_dict['parents'].copy()
            else:
                domain_parents_chain_update = []

            domain_parents_chain_update.append(template_id)
            update_table_field('domains', id_domain, 'parents',
                               domain_parents_chain_update)
            update_origin_and_parents_to_new_template(id_domain, template_id)
            # update_table_field('domains', template_id, 'xml', xml_parsed, merge_dict=False)
            update_domain_status(
                status='Stopped',
                id_domain=template_id,
                hyp_id=False,
                detail=
                'Template created, ready to create domains from this template')
            update_domain_status(
                status='Stopped',
                id_domain=id_domain,
                hyp_id=False,
                detail=
                'Template created from this domain, now domain is ready to start again'
            )

        else:
            log.error(
                'template {} can not be inserted in rethink, domain_id duplicated??'
                .format(template_id))
            return False
Exemplo n.º 3
0
    def updating_from_create_dict(self, id_domain,ssl=True):
        try:
            populate_dict_hardware_from_create_dict(id_domain)
        except Exception as e:
            log.error('error when populate dict hardware from create dict in domain {}'.format(id_domain))
            log.error('Traceback: \n .{}'.format(traceback.format_exc()))
            log.error('Exception message: {}'.format(e))
            update_domain_status('Failed', id_domain,
                                 detail='Updating aborted, failed when populate hardware dictionary')
            return False

        try:
            xml_raw = update_xml_from_dict_domain(id_domain)
            if xml_raw is False:
                update_domain_status(status='Failed',
                                     id_domain=id_domain,
                                     detail='XML Parser Error, xml is not valid')
                return False

        except Exception as e:
            log.error('error when populate dict hardware from create dict in domain {}'.format(id_domain))
            log.error('Traceback: \n .{}'.format(traceback.format_exc()))
            log.error('Exception message: {}'.format(e))
            update_domain_status('Failed', id_domain,
                                 detail='Updating aborted, failed when updating xml from hardware dictionary')
            return False

        update_domain_status('Updating', id_domain,
                             detail='xml and hardware dict updated, waiting to test if domain start paused in hypervisor')
        pool_id = get_pool_from_domain(id_domain)
        if pool_id is False:
            update_domain_status('Failed', id_domain, detail='Updating aborted, domain has not pool')
            return False

        kind = get_domain_kind(id_domain)
        if kind == 'desktop':
            cpu_host_model = self.manager.pools[pool_id].conf.get('cpu_host_model', DEFAULT_HOST_MODE)
            xml_to_test = recreate_xml_to_start(id_domain,ssl,cpu_host_model)
            self.start_paused_domain_from_xml(xml=xml_to_test, id_domain=id_domain, pool_id=pool_id)
        else:
            update_domain_status('Stopped', id_domain,
                                 detail='Updating finalished, ready to derivate desktops')

            return True
Exemplo n.º 4
0
    def create_template_in_db(self, id_domain):
        domain_dict = get_domain(id_domain)
        template_dict = domain_dict['create_dict']['template_dict']
        template_dict['status'] = 'CreatingNewTemplateInDB'
        template_id = template_dict['id']
        if insert_domain(template_dict)['inserted'] == 1:
            hw_dict = domain_dict['hardware'].copy()
            for i in range(len(hw_dict['disks'])):
                hw_dict['disks'][i]['file'] = template_dict['create_dict']['hardware']['disks'][i]['file']
            update_table_field('domains', template_id, 'hardware', hw_dict, merge_dict=False)
            xml_parsed = update_xml_from_dict_domain(id_domain=template_id, xml=domain_dict['xml'])
            if xml_parsed is False:
                update_domain_status(status='Failed',
                                     id_domain=template_id,
                                     hyp_id=False,
                                     detail='XML Parser Error, xml is not valid')
                return False
            remove_disk_template_created_list_in_domain(id_domain)
            remove_dict_new_template_from_domain(id_domain)
            if 'parents' in domain_dict.keys():
                domain_parents_chain_update = domain_dict['parents'].copy()
            else:
                domain_parents_chain_update = []

            domain_parents_chain_update.append(template_id)
            update_table_field('domains', id_domain, 'parents', domain_parents_chain_update)
            update_origin_and_parents_to_new_template(id_domain,template_id)
            # update_table_field('domains', template_id, 'xml', xml_parsed, merge_dict=False)
            update_domain_status(status='Stopped',
                                 id_domain=template_id,
                                 hyp_id=False,
                                 detail='Template created, ready to create domains from this template')
            update_domain_status(status='Stopped',
                                 id_domain=id_domain,
                                 hyp_id=False,
                                 detail='Template created from this domain, now domain is ready to start again')


        else:
            log.error('template {} can not be inserted in rethink, domain_id duplicated??'.format(template_id))
            return False
Exemplo n.º 5
0
    def creating_and_test_xml_start(self,
                                    id_domain,
                                    creating_from_create_dict=False,
                                    xml_from_virt_install=False,
                                    xml_string=None):
        if creating_from_create_dict is True:
            try:
                populate_dict_hardware_from_create_dict(id_domain)
            except Exception as e:
                log.error(
                    'error when populate dict hardware from create dict in domain {}'
                    .format(id_domain))
                log.error('Traceback: \n .{}'.format(traceback.format_exc()))
                log.error('Exception message: {}'.format(e))

        domain = get_domain(id_domain)
        #create_dict_hw = domain['create_dict']['hardware']
        # for media in ['isos','floppies']
        #     if 'isos' in create_dict_hw.keys():
        #         for index_disk in range(len(create_dict_hw['isos'])):
        #             update_hw['hardware']['isos'][index_disk]['file'] = new_file

        if type(xml_string) is str:
            xml_from = xml_string

        elif 'create_from_virt_install_xml' in domain['create_dict']:
            xml_from = get_dict_from_item_in_table(
                'virt_install',
                domain['create_dict']['create_from_virt_install_xml'])['xml']

        elif xml_from_virt_install is False:
            id_template = domain['create_dict']['origin']
            template = get_domain(id_template)
            xml_from = template['xml']

        elif xml_from_virt_install is True:
            xml_from = domain['xml_virt_install']

        else:
            return False

        update_table_field('domains', id_domain, 'xml', xml_from)

        xml_raw = update_xml_from_dict_domain(id_domain)
        update_domain_status(
            'CreatingDomain',
            id_domain,
            detail=
            'xml and hardware dict updated, waiting to test if domain start paused in hypervisor'
        )
        pool_id = get_pool_from_domain(id_domain)

        if 'start_after_created' in domain.keys():
            if domain['start_after_created'] is True:
                update_domain_status(
                    'StartingDomainDisposable',
                    id_domain,
                    detail=
                    'xml and hardware dict updated, starting domain disposable'
                )

                self.start_domain_from_id(id_domain)

        else:
            #change viewer password, remove selinux options and recreate network interfaces
            xml = recreate_xml_to_start(id_domain)
            self.start_paused_domain_from_xml(xml=xml,
                                              id_domain=id_domain,
                                              pool_id=pool_id)
Exemplo n.º 6
0
    def creating_and_test_xml_start(self,
                                    id_domain,
                                    creating_from_create_dict=False,
                                    xml_from_virt_install=False,
                                    xml_string=None):
        if creating_from_create_dict is True:
            try:
                populate_dict_hardware_from_create_dict(id_domain)
            except Exception as e:
                log.error(
                    'error when populate dict hardware from create dict in domain {}'
                    .format(id_domain))
                log.error('Traceback: \n .{}'.format(traceback.format_exc()))
                log.error('Exception message: {}'.format(e))

        domain = get_domain(id_domain)
        #create_dict_hw = domain['create_dict']['hardware']
        # for media in ['isos','floppies']
        #     if 'isos' in create_dict_hw.keys():
        #         for index_disk in range(len(create_dict_hw['isos'])):
        #             update_hw['hardware']['isos'][index_disk]['file'] = new_file

        if type(xml_string) is str:
            xml_from = xml_string

        elif 'create_from_virt_install_xml' in domain['create_dict']:
            xml_from = get_dict_from_item_in_table(
                'virt_install',
                domain['create_dict']['create_from_virt_install_xml'])['xml']

        elif xml_from_virt_install is False:
            id_template = domain['create_dict']['origin']
            template = get_domain(id_template)
            xml_from = template['xml']
            parents_chain = template.get('parents', []) + domain.get(
                'parents', [])
            #when creating template from domain, the domain would be inserted as a parent while template is creating
            # parent_chain never can't have id_domain as parent
            if id_domain in parents_chain:
                for i in range(parents_chain.count('a')):
                    parents_chain.remove(id_domain)

            update_table_field('domains', id_domain, 'parents', parents_chain)

        elif xml_from_virt_install is True:
            xml_from = domain['xml_virt_install']

        else:
            return False

        update_table_field('domains', id_domain, 'xml', xml_from)

        xml_raw = update_xml_from_dict_domain(id_domain)
        if xml_raw is False:
            update_domain_status(status='FailedCreatingDomain',
                                 id_domain=id_domain,
                                 detail='XML Parser Error, xml is not valid')
            return False
        update_domain_status(
            'CreatingDomain',
            id_domain,
            detail=
            'xml and hardware dict updated, waiting to test if domain start paused in hypervisor'
        )
        pool_id = get_pool_from_domain(id_domain)

        if 'start_after_created' in domain.keys():
            if domain['start_after_created'] is True:
                update_domain_status(
                    'StartingDomainDisposable',
                    id_domain,
                    detail=
                    'xml and hardware dict updated, starting domain disposable'
                )

                self.start_domain_from_id(id_domain)

        else:
            #change viewer password, remove selinux options and recreate network interfaces
            try:
                xml = recreate_xml_to_start(id_domain)
            except Exception as e:
                log.error(
                    'recreate_xml_to_start in domain {}'.format(id_domain))
                log.error('Traceback: \n .{}'.format(traceback.format_exc()))
                log.error('Exception message: {}'.format(e))
                xml = False

            if xml is False:
                update_domain_status(
                    'Failed',
                    id_domain,
                    detail="DomainXML can't parse and modify xml to start")
            else:
                self.start_paused_domain_from_xml(xml=xml,
                                                  id_domain=id_domain,
                                                  pool_id=pool_id)
Exemplo n.º 7
0
    def creating_and_test_xml_start(self, id_domain, creating_from_create_dict=False,
                                    xml_from_virt_install=False,
                                    xml_string=None,ssl=True):
        if creating_from_create_dict is True:
            try:
                populate_dict_hardware_from_create_dict(id_domain)
            except Exception as e:
                log.error('error when populate dict hardware from create dict in domain {}'.format(id_domain))
                log.error('Traceback: \n .{}'.format(traceback.format_exc()))
                log.error('Exception message: {}'.format(e))

        domain = get_domain(id_domain)
        #create_dict_hw = domain['create_dict']['hardware']
        # for media in ['isos','floppies']
        #     if 'isos' in create_dict_hw.keys():
        #         for index_disk in range(len(create_dict_hw['isos'])):
        #             update_hw['hardware']['isos'][index_disk]['file'] = new_file

        if type(xml_string) is str:
            xml_from = xml_string

        elif 'create_from_virt_install_xml' in domain['create_dict']:
            xml_from = get_dict_from_item_in_table('virt_install',domain['create_dict']['create_from_virt_install_xml'])['xml']

        elif xml_from_virt_install is False:
            id_template = domain['create_dict']['origin']
            template = get_domain(id_template)
            xml_from = template['xml']
            parents_chain = template.get('parents',[]) + domain.get('parents',[])
            #when creating template from domain, the domain would be inserted as a parent while template is creating
            # parent_chain never can't have id_domain as parent
            if id_domain in parents_chain:
                for i in range(parents_chain.count('a')):
                    parents_chain.remove(id_domain)

            update_table_field('domains', id_domain, 'parents', parents_chain)


        elif xml_from_virt_install is True:
            xml_from = domain['xml_virt_install']

        else:
            return False

        update_table_field('domains', id_domain, 'xml', xml_from)


        xml_raw = update_xml_from_dict_domain(id_domain)
        if xml_raw is False:
            update_domain_status(status='FailedCreatingDomain',
                                 id_domain=id_domain,
                                 detail='XML Parser Error, xml is not valid')
            return False
        update_domain_status('CreatingDomain', id_domain,
                             detail='xml and hardware dict updated, waiting to test if domain start paused in hypervisor')
        pool_id = get_pool_from_domain(id_domain)


        if 'start_after_created' in domain.keys():
            if domain['start_after_created'] is True:
                update_domain_status('StartingDomainDisposable', id_domain,
                                     detail='xml and hardware dict updated, starting domain disposable')

                self.start_domain_from_id(id_domain)

        else:
            #change viewer password, remove selinux options and recreate network interfaces
            try:
                cpu_host_model = self.manager.pools[pool_id].conf.get('cpu_host_model', DEFAULT_HOST_MODE)
                xml = recreate_xml_to_start(id_domain,ssl,cpu_host_model)
            except Exception as e:
                log.error('recreate_xml_to_start in domain {}'.format(id_domain))
                log.error('Traceback: \n .{}'.format(traceback.format_exc()))
                log.error('Exception message: {}'.format(e))
                xml = False

            if xml is False:
                update_domain_status('Failed', id_domain,
                                     detail="DomainXML can't parse and modify xml to start")
            else:
                self.start_paused_domain_from_xml(xml=xml,
                                                  id_domain=id_domain,
                                                  pool_id=pool_id)