def check_tables_populated(): while True: if table_config_created_and_populated() is True: break else: log.info('waiting config table created') sleep(1)
def analize_backing_chains_outputs(array_out_err=[], path_to_write_json=None, path_to_read_json=None): if path_to_write_json is not None: f = open(path_to_write_json, 'w') json.dump(array_out_err, f) f.close() if path_to_read_json is not None: f = open(path_to_read_json, 'r') array_out_err = json.load(f) log.debug(len(array_out_err)) f.close() domains_ok = 0 domains_err = 0 for d in array_out_err: id = d['title'] if len(d['err']) > 0: domains_err += 1 log.info(d['err']) update_domain_status('Failed', id, detail=d['err']) else: log.debug(id) domains_ok += 1 if type(d['out']) is not str: out = out.decode('utf-8') else: out = d['out'] l = json.loads(out) from pprint import pprint pprint(l) update_disk_backing_chain(id, 0, l[0]['filename'], l) return ({'ok': domains_ok, 'err': domains_err})
def check_tables_populated(): while True: if table_config_created_and_populated() is True: break else: log.info('waiting config table created') sleep(1)
def run(self): self.tid = get_tid() log.info('starting thread: {} (TID {})'.format(self.name, self.tid)) self.hyp_obj, self.ok = try_hyp_connection(self.hyp_id, self.hostname, self.port, self.user) log.debug('Exiting from thread {} try_hyp {}'.format( self.name, self.hostname)) return self.ok
def analize_check_os_output(array_out_err): for d in array_out_err: domains_ok = 0 domains_err = 0 for d in array_out_err: id = d['title'] if len(d['err']) > 0: domains_err += 1 log.info(d['err']) update_domain_os('Unknown', id, detail=d['err']) else: d = xmltodict.parse(d['out']) print('DOMAIN ID: {}, SO product_name: {}'.format(id, d['operatingsystems']['operatingsystem'][ 'product_name']))
def analize_check_os_output(array_out_err): for d in array_out_err: domains_ok = 0 domains_err = 0 for d in array_out_err: id = d['title'] if len(d['err']) > 0: domains_err += 1 log.info(d['err']) update_domain_os('Unknown', id, detail=d['err']) else: d = xmltodict.parse(d['out']) print('DOMAIN ID: {}, SO product_name: {}'.format( id, d['operatingsystems']['operatingsystem']['product_name']))
def analize_backing_chains_outputs(array_out_err=[], path_to_write_json=None, path_to_read_json=None): if path_to_write_json is not None: f = open(path_to_write_json, 'w') json.dump(array_out_err, f) f.close() if path_to_read_json is not None: f = open(path_to_read_json, 'r') array_out_err = json.load(f) log.debug(len(array_out_err)) f.close() domains_ok = 0 domains_err = 0 for d in array_out_err: id = d['title'] if len(d['err']) > 0: domains_err += 1 log.info(d['err']) update_domain_status('Failed', id, detail=d['err']) else: log.debug(id) domains_ok += 1 if type(d['out']) is not str: out = out.decode('utf-8') else: out = d['out'] l = json.loads(out) from pprint import pprint pprint(l) update_disk_backing_chain(id, 0, l[0]['filename'], l) return ({'ok': domains_ok, 'err': domains_err})
def run(self): self.tid = get_tid() log.info('starting thread: {} (TID {})'.format( self.name, self.tid)) self.result = func(arg1)
def run(self): self.tid = get_tid() log.info('starting thread: {} (TID {})'.format(self.name, self.tid)) self.disk_operations_thread()
import rethinkdb as r from engine.services.db import insert_host_viewer, new_rethink_connection, insert_place from engine.services.log import log class dbo (object): def __init__(self): self.conn = new_rethink_connection() db = dbo() if not r.table_list().contains('places').run(db.conn): log.info("Table places not found, creating...") r.table_create('places', primary_key="id").run(db.conn) try: r.table('places').index_create("network").run(db.conn) r.table('places').index_wait("network").run(db.conn) r.table('places').index_create("status").run(db.conn) r.table('places').index_wait("status").run(db.conn) except Exception as e: None if not r.table_list().contains('hosts_viewers').run(db.conn): log.info("Table hosts_viewers not found, creating...") r.table_create('hosts_viewers', primary_key="id").run(db.conn) try: r.table('hosts_viewers').index_create("hostname").run(db.conn) r.table('hosts_viewers').index_wait("hostname").run(db.conn)
def run(self): self.tid = get_tid() log.info('starting thread: {} (TID {})'.format(self.name, self.tid)) self.result = func(arg1)
def long_operations_thread(self): host = self.hostname self.tid = get_tid() log.debug('Thread to launchdisks operations in host {} with TID: {}...'.format(host, self.tid)) while self.stop is not True: try: action = self.queue_actions.get(timeout=TIMEOUT_QUEUES) # for ssh commands id_domain = action['domain'] if action['type'] in ['create_disk_virt_builder']: cmds_done = execute_commands(host=self.hostname, ssh_commands=action['ssh_commands'], dict_mode=True, user=self.user, port=self.port ) if len([d for d in cmds_done if len(d['err']) > 0]) > 1: log.error('some error in virt builder operations') log.error('Virt Builder Failed creating disk file {} in domain {} in hypervisor {}'.format( action['disk_path'], action['domain'], self.hyp_id)) log.debug('print cmds_done:') log.debug(pprint.pprint(cmds_done)) log.debug('print ssh_commands:') log.debug(pprint.pprint(action['ssh_commands'])) update_domain_status('Failed', id_domain, detail='Virt Builder Failed creating disk file') else: log.info('Disk created from virt-builder. Domain: {} , disk: {}'.format(action['domain'], action['disk_path'])) xml_virt_install = cmds_done[-1]['out'] update_table_field('domains', id_domain, 'xml_virt_install', xml_virt_install) update_domain_status('CreatingDomainFromBuilder', id_domain, detail='disk created from virt-builder') elif action['type'] == 'stop_thread': self.stop = True else: log.error('type action {} not supported'.format(action['type'])) except queue.Empty: pass except Exception as e: log.error('Exception when creating disk: {}'.format(e)) log.error('Action: {}'.format(pprint.pformat(action))) log.error('Traceback: {}'.format(traceback.format_exc())) return False if self.stop is True: while self.queue_actions.empty() is not True: action = self.queue_actions.get(timeout=TIMEOUT_QUEUES) if action['type'] == 'create_disk': disk_path = action['disk_path'] id_domain = action['domain'] log.error( 'operations creating disk {} for new domain {} failed. Commands, outs and errors: {}'.format( disk_path, id_domain)) log.error('\n'.join( ['cmd: {}'.format(action['ssh_commands'][i]) for i in range(len(action['ssh_commands']))])) update_domain_status('Failed', id_domain, detail='new disk create operation failed, thread disk operations is stopping, detail of operations cancelled in logs')
import rethinkdb as r from engine.services.db import insert_host_viewer, new_rethink_connection, insert_place from engine.services.log import log class dbo(object): def __init__(self): self.conn = new_rethink_connection() db = dbo() if not r.table_list().contains('places').run(db.conn): log.info("Table places not found, creating...") r.table_create('places', primary_key="id").run(db.conn) try: r.table('places').index_create("network").run(db.conn) r.table('places').index_wait("network").run(db.conn) r.table('places').index_create("status").run(db.conn) r.table('places').index_wait("status").run(db.conn) except Exception as e: None if not r.table_list().contains('hosts_viewers').run(db.conn): log.info("Table hosts_viewers not found, creating...") r.table_create('hosts_viewers', primary_key="id").run(db.conn) try: r.table('hosts_viewers').index_create("hostname").run(db.conn) r.table('hosts_viewers').index_wait("hostname").run(db.conn)
def long_operations_thread(self): host = self.hostname self.tid = get_tid() log.debug( 'Thread to launchdisks operations in host {} with TID: {}...'. format(host, self.tid)) while self.stop is not True: try: action = self.queue_actions.get(timeout=TIMEOUT_QUEUES) # for ssh commands id_domain = action['domain'] if action['type'] in ['create_disk_virt_builder']: cmds_done = execute_commands( host=self.hostname, ssh_commands=action['ssh_commands'], dict_mode=True, user=self.user, port=self.port) if len([d for d in cmds_done if len(d['err']) > 0]) > 1: log.error('some error in virt builder operations') log.error( 'Virt Builder Failed creating disk file {} in domain {} in hypervisor {}' .format(action['disk_path'], action['domain'], self.hyp_id)) log.debug('print cmds_done:') log.debug(pprint.pprint(cmds_done)) log.debug('print ssh_commands:') log.debug(pprint.pprint(action['ssh_commands'])) update_domain_status( 'Failed', id_domain, detail='Virt Builder Failed creating disk file') else: log.info( 'Disk created from virt-builder. Domain: {} , disk: {}' .format(action['domain'], action['disk_path'])) xml_virt_install = cmds_done[-1]['out'] update_table_field('domains', id_domain, 'xml_virt_install', xml_virt_install) update_domain_status( 'CreatingDomainFromBuilder', id_domain, detail='disk created from virt-builder') elif action['type'] == 'stop_thread': self.stop = True else: log.error('type action {} not supported'.format( action['type'])) except queue.Empty: pass except Exception as e: log.error('Exception when creating disk: {}'.format(e)) log.error('Action: {}'.format(pprint.pformat(action))) log.error('Traceback: {}'.format(traceback.format_exc())) return False if self.stop is True: while self.queue_actions.empty() is not True: action = self.queue_actions.get(timeout=TIMEOUT_QUEUES) if action['type'] == 'create_disk': disk_path = action['disk_path'] id_domain = action['domain'] log.error( 'operations creating disk {} for new domain {} failed. Commands, outs and errors: {}' .format(disk_path, id_domain)) log.error('\n'.join([ 'cmd: {}'.format(action['ssh_commands'][i]) for i in range(len(action['ssh_commands'])) ])) update_domain_status( 'Failed', id_domain, detail= 'new disk create operation failed, thread disk operations is stopping, detail of operations cancelled in logs' )