def create_dict_graphics_from_id(id, pool_id): dict_graph = get_dict_from_item_in_table('graphics', id) if dict_graph is None: log.error( '{} not defined as id in graphics table, value default is used'. format(id)) dict_graph = get_dict_from_item_in_table('graphics', 'default') # deprectaed #type = dict_graph['type'] d = {} #d['type'] = type pool = get_dict_from_item_in_table('hypervisors_pools', pool_id) if pool['viewer']['defaultMode'] == 'Insecure': d['defaultMode'] = 'Insecure' d['certificate'] = '' d['domain'] = '' if pool['viewer']['defaultMode'] == 'Secure': d['defaultMode'] = 'Secure' d['certificate'] = pool['viewer']['certificate'] d['domain'] = pool['viewer']['defaultMode'] return d
def create_dict_interface_hardware_from_id(id_net): dict_net = get_dict_from_item_in_table('interfaces', id_net) return {'type': dict_net['kind'], 'id': dict_net['ifname'], 'name': dict_net['name'], 'model': dict_net['model'], 'net': dict_net['net']}
def create_dict_video_from_id(id_video): dict_video = get_dict_from_item_in_table('videos', id_video) d = {'heads': dict_video['heads'], 'ram': dict_video['ram'], 'type': dict_video['model'], 'vram': dict_video['vram'] } return d
def create_dict_interface_hardware_from_id(id_net): dict_net = get_dict_from_item_in_table('interfaces', id_net) return {'type': dict_net['kind'], 'id': dict_net['ifname'], 'name': dict_net['name'], 'model': dict_net['model'], 'net': dict_net['net']}
def create_dict_video_from_id(id_video): dict_video = get_dict_from_item_in_table('videos', id_video) d = {'heads': dict_video['heads'], 'ram': dict_video['ram'], 'type': dict_video['model'], 'vram': dict_video['vram'] } return d
def create_dict_graphics_from_id(id, pool_id): dict_graph = get_dict_from_item_in_table('graphics', id) if dict_graph is None: log.error('{} not defined as id in graphics table, value default is used'.format(id)) dict_graph = get_dict_from_item_in_table('graphics', 'default') type = dict_graph['type'] d = {} d['type'] = type pool = get_dict_from_item_in_table('hypervisors_pools', pool_id) if pool['viewer']['defaultMode'] == 'Insecure': d['defaultMode'] = 'Insecure' d['certificate'] = '' d['domain'] = '' if pool['viewer']['defaultMode'] == 'Secure': d['defaultMode'] = 'Secure' d['certificate'] = pool['viewer']['certificate'] d['domain'] = pool['viewer']['defaultMode'] return d
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)
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)
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)