Exemple #1
0
def update_ssh_dir_permissions(user='******'):
    try:
        perm = "chown -R root:root /root/.ssh/"
        (ret, rc), err = command.execute_with_rc(perm, True)
        ssh_perm = "chmod 700 /root/.ssh"
        (ret, rc), err = command.execute_with_rc(ssh_perm, True)
        authorized_key = "chmod 640 /root/.ssh/authorized_keys"
        (ret, rc), err = command.execute_with_rc(authorized_key, True)
        return True, None
    except Exception, e:
        return False, e
Exemple #2
0
def update_ssh_dir_permissions(user='******'):
    try:
        perm = "chown -R root:root /root/.ssh/"
        (ret, rc), err = command.execute_with_rc(perm, True)
        ssh_perm = "chmod 700 /root/.ssh"
        (ret, rc), err = command.execute_with_rc(ssh_perm, True)
        authorized_key = "chmod 640 /root/.ssh/authorized_keys"
        (ret, rc), err = command.execute_with_rc(authorized_key, True)
        return True, None
    except Exception, e:
        return False, e
def get_service_status(service):
    d = {}
    try:
        (ret, rc), err = command.execute_with_rc(
            'service %s status' % service[0])
        if err:
            raise Exception(err)
        d['status_code'] = rc
        if rc == 0:
            d['status_str'] = 'Running'
        elif rc == 3:
            d['status_str'] = 'Stopped'
        elif rc == 1:
            d['status_str'] = 'Error'
        d['output_str'] = ''
        out, err = command.get_output_list(ret)
        if err:
            raise Exception(err)
        if out:
            d['output_str'] += ','.join(out)
        err, e = command.get_error_list(ret)
        if e:
            raise Exception(e)
        if err:
            d['output_str'] += ','.join(err)
    except Exception, e:
        return None, 'Error retrieving service status : %s' % str(e)
Exemple #4
0
def get_service_status(service):
    d = {}
    try:
        (ret,
         rc), err = command.execute_with_rc('service %s status' % service[0])
        if err:
            raise Exception(err)
        d['status_code'] = rc
        if rc == 0:
            d['status_str'] = 'Running'
        elif rc == 3:
            d['status_str'] = 'Stopped'
        elif rc == 1:
            d['status_str'] = 'Error'
        d['output_str'] = ''
        out, err = command.get_output_list(ret)
        if err:
            raise Exception(err)
        if out:
            d['output_str'] += ','.join(out)
        err, e = command.get_error_list(ret)
        if e:
            raise Exception(e)
        if err:
            d['output_str'] += ','.join(err)
    except Exception, e:
        return None, 'Error retrieving service status : %s' % str(e)
def get_sysd_service_status(service):
    d = {}
    d['status'] = {}
    d['status']['rc'] = ''
    d['status']['status_str'] = ''
    d['status']['output_str'] = ''
    d['is_active'] = {}
    d['is_active']['rc'] = ''
    d['is_active']['status_str'] = ''
    d['is_active']['output_str'] = ''
    d['is_failed'] = {}
    d['is_failed']['rc'] = ''
    d['is_failed']['status_str'] = ''
    d['is_failed']['output_str'] = ''
    d['is_enabled'] = {}
    d['is_enabled']['rc'] = ''
    d['is_enabled']['status_str'] = ''
    d['is_enabled']['output_str'] = ''
    try:
        (ret, rc), err = command.execute_with_rc(
            'systemctl status %s' % service[0])
        if err:
            raise Exception(err)
        d['status']['rc'] = rc
        out, err1 = command.get_output_list(ret)
        if err1:
            raise Exception(err1)
        if out:
            d['status']['output_str'] += ','.join(out)
        err2, e = command.get_error_list(ret)
        if e:
            raise Exception(e)
        if err2:
            d['status']['output_str'] += ','.join(err2)

        if not err:
            (ret, rc), err = command.execute_with_rc(
                'systemctl is-failed %s' % service[0])
            if err:
                raise Exception(err)
            d['is_failed']['rc'] = rc
            out, err = command.get_output_list(ret)
            if err:
                raise Exception(err)

            if out:
                d['is_failed']['output_str'] += ','.join(out)

            if rc == 0:
                d['is_failed']['status_str'] = "Failed"
                d['status']['status_str'] = "Failed"
                d['status']['output_str'] += ','.join(out)
            else:
                (ret, rc), err = command.execute_with_rc(
                    'systemctl is-active %s' % service[0])
                if err:
                    raise Exception(err)
                d['is_active']['rc'] = rc

                out, err = command.get_output_list(ret)
                if err:
                    raise Exception(err)
                if out:
                    d['is_active']['output_str'] += ','.join(out)

                if rc == 0:
                    d['is_active']['status_str'] = "Active"
                    d['status']['status_str'] = "Active"
                    d['status']['output_str'] += ','.join(out)
                elif rc == 3:
                    d['is_active']['status_str'] = "Inactive"
                    d['status']['status_str'] = "Inactive"
                    d['status']['output_str'] += ','.join(out)
                else:
                    d['status']['status_str'] = "Unknown State"
        (ret, rc), err = command.execute_with_rc(
            'systemctl is-enabled %s' % service[0])
        if err:
            raise Exception(err)
        d['is_enabled']['rc'] = rc
        out, err = command.get_output_list(ret)
        if err:
            raise Exception(err)

        if out:
            d['is_enabled']['output_str'] += ','.join(out)

        if not rc:
            d['is_enabled']['status_str'] = "Enabled"
        else:
            d['is_enabled']['status_str'] = "Disabled"
    except Exception, e:
        return None, 'Error retrieving service status : %s' % str(e)
Exemple #6
0
def get_sysd_service_status(service):
    d = {}
    d['status'] = {}
    d['status']['rc'] = ''
    d['status']['status_str'] = ''
    d['status']['output_str'] = ''
    d['is_active'] = {}
    d['is_active']['rc'] = ''
    d['is_active']['status_str'] = ''
    d['is_active']['output_str'] = ''
    d['is_failed'] = {}
    d['is_failed']['rc'] = ''
    d['is_failed']['status_str'] = ''
    d['is_failed']['output_str'] = ''
    d['is_enabled'] = {}
    d['is_enabled']['rc'] = ''
    d['is_enabled']['status_str'] = ''
    d['is_enabled']['output_str'] = ''
    try:
        (ret,
         rc), err = command.execute_with_rc('systemctl status %s' % service[0])
        if err:
            raise Exception(err)
        d['status']['rc'] = rc
        out, err1 = command.get_output_list(ret)
        if err1:
            raise Exception(err1)
        if out:
            d['status']['output_str'] += ','.join(out)
        err2, e = command.get_error_list(ret)
        if e:
            raise Exception(e)
        if err2:
            d['status']['output_str'] += ','.join(err2)

        if not err:
            (ret, rc), err = command.execute_with_rc('systemctl is-failed %s' %
                                                     service[0])
            if err:
                raise Exception(err)
            d['is_failed']['rc'] = rc
            out, err = command.get_output_list(ret)
            if err:
                raise Exception(err)

            if out:
                d['is_failed']['output_str'] += ','.join(out)

            if rc == 0:
                d['is_failed']['status_str'] = "Failed"
                d['status']['status_str'] = "Failed"
                d['status']['output_str'] += ','.join(out)
            else:
                (ret, rc), err = command.execute_with_rc(
                    'systemctl is-active %s' % service[0])
                if err:
                    raise Exception(err)
                d['is_active']['rc'] = rc

                out, err = command.get_output_list(ret)
                if err:
                    raise Exception(err)
                if out:
                    d['is_active']['output_str'] += ','.join(out)

                if rc == 0:
                    d['is_active']['status_str'] = "Active"
                    d['status']['status_str'] = "Active"
                    d['status']['output_str'] += ','.join(out)
                elif rc == 3:
                    d['is_active']['status_str'] = "Inactive"
                    d['status']['status_str'] = "Inactive"
                    d['status']['output_str'] += ','.join(out)
                else:
                    d['status']['status_str'] = "Unknown State"
        (ret, rc), err = command.execute_with_rc('systemctl is-enabled %s' %
                                                 service[0])
        if err:
            raise Exception(err)
        d['is_enabled']['rc'] = rc
        out, err = command.get_output_list(ret)
        if err:
            raise Exception(err)

        if out:
            d['is_enabled']['output_str'] += ','.join(out)

        if not rc:
            d['is_enabled']['status_str'] = "Enabled"
        else:
            d['is_enabled']['status_str'] = "Disabled"
    except Exception, e:
        return None, 'Error retrieving service status : %s' % str(e)