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
def start_domain_from_id(self, id, ssl=True): # INFO TO DEVELOPER, QUE DE UN ERROR SI EL ID NO EXISTE id_domain = id pool_id = get_pool_from_domain(id_domain) cpu_host_model = self.manager.pools[pool_id].conf.get('cpu_host_model',DEFAULT_HOST_MODE) # TODO: Read the cpu_host_model value from hypervisor_pool database try: 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 not parse and modify xml to start") return False else: hyp = self.start_domain_from_xml(xml, id_domain, pool_id=pool_id) return hyp
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)