Exemplo n.º 1
0
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})
Exemplo n.º 2
0
def launch_action_disk(action, hostname, user, port, from_scratch=False):
    disk_path = action['disk_path']
    id_domain = action['domain']
    index_disk = action['index_disk']
    array_out_err = execute_commands(hostname,
                                     ssh_commands=action['ssh_commands'],
                                     user=user,
                                     port=port)

    if action['type'] in ['create_disk', 'create_disk_from_scratch']:
        if len([k['err'] for k in array_out_err if len(k['err']) == 0]):
            ##TODO: TEST WITH MORE THAN ONE DISK, 2 list_backing_chain must be created
            log.debug('all operations creating disk {} for new domain {} runned ok'.format(disk_path, id_domain))
            if from_scratch is False:
                out_cmd_backing_chain = array_out_err[-1]['out']

                list_backing_chain = extract_list_backing_chain(out_cmd_backing_chain)
                if id_domain is not False:
                    update_domain_parents(id_domain)
                    update_disk_backing_chain(id_domain, index_disk, disk_path, list_backing_chain)
                ##INFO TO DEVELOPER
            # ahora ya se puede llamar a starting paused
            if id_domain is not False:
                #update parents if have
                #update_domain_parents(id_domain)
                update_domain_status('CreatingDomain', id_domain, None,
                                     detail='new disk created, now go to creating desktop and testing if desktop start')
        else:

            log.error('operations creating disk {} for new domain {} failed.'.format(disk_path, id_domain))
            log.error('\n'.join(['cmd: {} / out: {} / err: {}'.format(action['ssh_commands'][i],
                                                                      array_out_err[i]['out'],
                                                                      array_out_err[i]['err']) for i in
                                 range(len(action['ssh_commands']))]))
            if id_domain is not False:
                update_domain_status('Failed', id_domain, detail='new disk create operation failed, details in logs')

    elif action['type'] == 'delete_disk':
        if len(array_out_err[0]['err']) > 0:
            log.error(
                'disk from domain {} not found, or permission denied or access to data problems'.format(id_domain))
            log.error('ERROR: {}'.format(array_out_err[0]['err']))
            update_domain_status('DiskDeleted', id_domain, detail='delete disk operation failed, disk not found: {}'.format(
                array_out_err[0]['err']))
        elif len(array_out_err[1]['err']) > 0:
            log.error('disk from domain {} found, but erase command fail'.format(id_domain))
            log.error('ERROR: {}'.format(array_out_err[0]['err']))
            update_domain_status('DiskDeleted', id_domain, detail='delete disk command failed')
        elif len(array_out_err[2]['out']) > 0:
            log.error(
                'disk from domain {} found, erase command not failed with error message, but disk is in directory.'.format(
                    id_domain))
            log.error('ERROR: {}'.format(array_out_err[0]['out']))
            update_domain_status('DiskDeleted', id_domain,
                                 detail='delete disk operation failed, disk in directory can not erase')
        else:
            log.info('disk {} from domain {} erased'.format(disk_path, id_domain))
            update_disk_backing_chain(id_domain, index_disk, 'DISK_ERASED', [])
            update_domain_status('DiskDeleted', id_domain, detail='delete disk operation run ok')
Exemplo n.º 3
0
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})
Exemplo n.º 4
0
def launch_action_create_template_disk(action, hostname, user, port):
    path_template_disk = action['path_template_disk']
    path_domain_disk = action['path_domain_disk']
    id_domain = action['id_domain']
    disk_index = action['disk_index']

    cmds1, cmds2, cmds3 = create_cmds_disk_template_from_domain(
        path_template_disk, path_domain_disk)

    # cmds1: Firsts commands: test if perms, df, files are ok
    cmds_done = execute_commands(hostname,
                                 ssh_commands=cmds1,
                                 dict_mode=True,
                                 user=user,
                                 port=port)
    error_severity, move_tool, cmd_to_move = verify_output_cmds1_template_from_domain(
        cmds_done, path_domain_disk, path_template_disk, id_domain)
    if error_severity == None:

        # move file
        log.debug('commnad to move disk template: {}'.format(cmd_to_move))
        if move_tool == 'mv':
            cmds_done = execute_commands(hostname,
                                         ssh_commands=[cmd_to_move],
                                         dict_mode=False,
                                         user=user,
                                         port=port)

        if move_tool == 'rsync':
            execute_command_with_progress(hostname=hostname,
                                          ssh_command=cmd_to_move,
                                          id_domain=id_domain,
                                          user=user,
                                          port=port)

        # cmds2: Seconds commands: test if perms, df, files are ok
        cmds_done = execute_commands(hostname,
                                     ssh_commands=cmds2,
                                     dict_mode=True,
                                     user=user,
                                     port=port)
        error = verify_output_cmds2(cmds_done, path_domain_disk,
                                    path_template_disk, id_domain)
        if error is None:

            cmds_done = execute_commands(hostname,
                                         ssh_commands=cmds3,
                                         dict_mode=True,
                                         user=user,
                                         port=port)
            error, backing_chain_domain, backing_chain_template = verify_output_cmds3(
                cmds_done, path_domain_disk, path_template_disk, id_domain)
            if error is None:
                # update_domain to status: TemplateDiskCreated
                #####  CREATED OK ######

                update_disk_template_created(id_domain, disk_index)
                update_disk_backing_chain(
                    id_domain,
                    disk_index,
                    path_template_disk,
                    backing_chain_template,
                    new_template=True,
                    list_backing_chain_template=backing_chain_template)

                # disk created, update parents and status
                #update_domain_parents(id_domain)
                update_domain_status(
                    status='TemplateDiskCreated',
                    id_domain=id_domain,
                    hyp_id=False,
                    detail=
                    'new template disk {} for template created from domain {}'.
                    format(path_template_disk, id_domain))

            else:
                update_domain_status(
                    'Crashed',
                    id_domain,
                    detail=
                    'new template disk from domain {} ok, but domain and disk is unknown, details in logs'
                    .format(id_domain))
        else:
            if error == 'Crashed':
                update_domain_status(
                    'Crashed',
                    id_domain,
                    detail=
                    'new template from domain {} failed and disk is unknown, details in logs'
                    .format(id_domain))
            else:
                update_domain_status(
                    'Stopped',
                    id_domain,
                    detail=
                    'new template from domain {} failed, disk domain remain in place, details in logs'
                    .format(id_domain))
    else:
        update_domain_status(
            'Stopped',
            id_domain,
            detail='new template from domain {} failed, details in logs'.
            format(id_domain))
Exemplo n.º 5
0
def launch_action_disk(action, hostname, user, port, from_scratch=False):
    disk_path = action['disk_path']
    id_domain = action['domain']
    index_disk = action['index_disk']
    array_out_err = execute_commands(hostname,
                                     ssh_commands=action['ssh_commands'],
                                     user=user,
                                     port=port)

    if action['type'] in ['create_disk', 'create_disk_from_scratch']:
        if len([k['err'] for k in array_out_err if len(k['err']) == 0]):
            ##TODO: TEST WITH MORE THAN ONE DISK, 2 list_backing_chain must be created
            log.debug(
                'all operations creating disk {} for new domain {} runned ok'.
                format(disk_path, id_domain))
            if from_scratch is False:
                out_cmd_backing_chain = array_out_err[-1]['out']

                list_backing_chain = extract_list_backing_chain(
                    out_cmd_backing_chain)
                if id_domain is not False:
                    update_domain_parents(id_domain)
                    update_disk_backing_chain(id_domain, index_disk, disk_path,
                                              list_backing_chain)
                ##INFO TO DEVELOPER
            # ahora ya se puede llamar a starting paused
            if id_domain is not False:
                #update parents if have
                #update_domain_parents(id_domain)
                update_domain_status(
                    'CreatingDomain',
                    id_domain,
                    None,
                    detail=
                    'new disk created, now go to creating desktop and testing if desktop start'
                )
        else:

            log.error(
                'operations creating disk {} for new domain {} failed.'.format(
                    disk_path, id_domain))
            log.error('\n'.join([
                'cmd: {} / out: {} / err: {}'.format(action['ssh_commands'][i],
                                                     array_out_err[i]['out'],
                                                     array_out_err[i]['err'])
                for i in range(len(action['ssh_commands']))
            ]))
            if id_domain is not False:
                update_domain_status(
                    'Failed',
                    id_domain,
                    detail='new disk create operation failed, details in logs')

    elif action['type'] == 'delete_disk':
        if len(array_out_err[0]['err']) > 0:
            log.error(
                'disk from domain {} not found, or permission denied or access to data problems'
                .format(id_domain))
            log.error('ERROR: {}'.format(array_out_err[0]['err']))
            update_domain_status(
                'Failed',
                id_domain,
                detail='delete disk operation failed, disk not found: {}'.
                format(array_out_err[0]['err']))
        elif len(array_out_err[1]['err']) > 0:
            log.error(
                'disk from domain {} found, but erase command fail'.format(
                    id_domain))
            log.error('ERROR: {}'.format(array_out_err[0]['err']))
            update_domain_status('Failed',
                                 id_domain,
                                 detail='delete disk command failed')
        elif len(array_out_err[2]['out']) > 0:
            log.error(
                'disk from domain {} found, erase command not failed with error message, but disk is in directory.'
                .format(id_domain))
            log.error('ERROR: {}'.format(array_out_err[0]['out']))
            update_domain_status(
                'Failed',
                id_domain,
                detail=
                'delete disk operation failed, disk in directory can not erase'
            )
        else:
            log.info('disk {} from domain {} erased'.format(
                disk_path, id_domain))
            update_disk_backing_chain(id_domain, index_disk, 'DISK_ERASED', [])
            update_domain_status('DiskDeleted',
                                 id_domain,
                                 detail='delete disk operation run ok')
Exemplo n.º 6
0
def  launch_action_create_template_disk(action, hostname, user, port):
    path_template_disk = action['path_template_disk']
    path_domain_disk = action['path_domain_disk']
    id_domain = action['id_domain']
    disk_index = action['disk_index']

    cmds1, cmds2, cmds3 = create_cmds_disk_template_from_domain(path_template_disk, path_domain_disk)

    # cmds1: Firsts commands: test if perms, df, files are ok
    cmds_done = execute_commands(hostname, ssh_commands=cmds1, dict_mode=True, user=user, port=port)
    error_severity, move_tool, cmd_to_move = verify_output_cmds1_template_from_domain(cmds_done,
                                                                                      path_domain_disk,
                                                                                      path_template_disk,
                                                                                      id_domain)
    if error_severity == None:

        # move file
        log.debug('commnad to move disk template: {}'.format(cmd_to_move))
        if move_tool == 'mv':
            cmds_done = execute_commands(hostname, ssh_commands=[cmd_to_move], dict_mode=False, user=user, port=port)

        if move_tool == 'rsync':
            execute_command_with_progress(hostname=hostname,
                                          ssh_command=cmd_to_move,
                                          id_domain=id_domain,
                                          user=user,
                                          port=port)

        # cmds2: Seconds commands: test if perms, df, files are ok
        cmds_done = execute_commands(hostname, ssh_commands=cmds2, dict_mode=True, user=user, port=port)
        error = verify_output_cmds2(cmds_done, path_domain_disk, path_template_disk, id_domain)
        if error is None:

            cmds_done = execute_commands(hostname, ssh_commands=cmds3, dict_mode=True, user=user, port=port)
            error, backing_chain_domain, backing_chain_template = verify_output_cmds3(cmds_done, path_domain_disk,
                                                                                      path_template_disk, id_domain)
            if error is None:
                # update_domain to status: TemplateDiskCreated
                #####  CREATED OK ######

                update_disk_template_created(id_domain, disk_index)
                update_disk_backing_chain(id_domain,
                                          disk_index,
                                          path_template_disk,
                                          backing_chain_template,
                                          new_template=True,
                                          list_backing_chain_template=backing_chain_template)

                # disk created, update parents and status
                #update_domain_parents(id_domain)
                update_domain_status(status='TemplateDiskCreated',
                                     id_domain=id_domain,
                                     hyp_id=False,
                                     detail='new template disk {} for template created from domain {}'.format(
                                         path_template_disk, id_domain))

            else:
                update_domain_status('Crashed', id_domain,
                                     detail='new template disk from domain {} ok, but domain and disk is unknown, details in logs'.format(
                                         id_domain))
        else:
            if error == 'Crashed':
                update_domain_status('Crashed', id_domain,
                                     detail='new template from domain {} failed and disk is unknown, details in logs'.format(
                                         id_domain))
            else:
                update_domain_status('Stopped', id_domain,
                                     detail='new template from domain {} failed, disk domain remain in place, details in logs'.format(
                                         id_domain))
    else:
        update_domain_status('Stopped', id_domain,
                             detail='new template from domain {} failed, details in logs'.format(id_domain))