Exemplo n.º 1
0
def create_auth_access_user(auth_access_group_id, user, secret):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path,
            "select * from iscsi_auth_access_users where auth_access_group_id = \'%d\' and user = \'%s\'"
            % (auth_access_group_id, user))
        if err:
            raise Exception(err)
        if d:
            raise Exception(
                "A user set with the same username exists for this authorized access group"
            )

        cl = [(
            "insert into iscsi_auth_access_users(id, auth_access_group_id, user, secret) values (NULL, \'%d\', \'%s\', \'%s\')"
            % (auth_access_group_id, user, secret), )]
        rowid, err = db.execute_iud(db_path, cl, True)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error creating authorized access user : %s' % str(e)
Exemplo n.º 2
0
def create_iscsi_initiator(initiators, auth_network, comment):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path,
            "select * from iscsi_initiators where auth_network = \'%s\' and initiators=\'%s\'"
            % (initiators.lower(), auth_network.lower()))
        if err:
            raise Exception(err)
        if d:
            raise Exception(
                "An initiator with the same parameters (with ID %d) already exists"
                % d["id"])

        cl = [(
            "insert into iscsi_initiators(id, initiators, auth_network, comment) values (NULL, ?, ?, ?)",
            (
                initiators.lower(),
                auth_network.lower(),
                comment,
            ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error creating initiator : %s' % str(e)
Exemplo n.º 3
0
def save_email_settings(d):

    conn = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d1, err = db.get_single_row(db_path, "select * from email_config")
        if err:
            raise Exception(err)
        if d1:
            # Config exists so update
            ret, err = db.execute_iud(db_path, [["update email_config set server=?, port=?, username=?, pswd=?, tls=?, email_alerts=?, email_audit=?, email_quota=?, rcpt_list=? where id = ?", (
                d["server"], d["port"], d["username"], d["pswd"], d["tls"], d["email_alerts"], d["email_audit"], d["email_quota"], d["rcpt_list"], 1,)]])
            if err:
                raise Exception(err)

        else:
            # No config exists so insert
            ret, err = db.execute_iud(db_path, [["insert into email_config (server, port, username, pswd, tls, email_alerts,email_audit,email_quota, rcpt_list, id) values (?,?,?,?,?,?,?,?,?,?)", (
                d["server"], d["port"], d["username"], d["pswd"], d["tls"], d["email_alerts"], d["email_audit"], d["email_quota"], d["rcpt_list"], 1, )]])
            if err:
                raise Exception(err)
    except Exception, e:
        return False, 'Error saving email settings : %s' % str(e)
Exemplo n.º 4
0
def reset_global_target_conf():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cl = [(
            "update iscsi_global_target_conf set discovery_auth_method=?, io_timeout=?, nop_in_interval=?, max_sessions=?, max_connections=?, max_presend_r2t=?, max_outstanding_r2t=?, first_burst_length=?, max_burst_length=?, max_receive_data_segment_length=?, default_time_to_wait=?, default_time_to_retain=? where id='1'",
            (
                None,
                30,
                20,
                16,
                8,
                32,
                16,
                65536,
                262144,
                262144,
                2,
                60,
            ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error resetting ISCSI global configuration : %s' % str(
            e)
def delete_cron(cron_task_id, user='******'):
    """Delete a cron by the cron_task_id."""
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)

        tasks, err = get_tasks_by_cron_task_id(cron_task_id)
        if err:
            raise Exception(err)
        cmd_list = []
        cmd_list.append(
            ['delete from cron_tasks where cron_task_id=%d' % cron_task_id])
        cmd_list.append([
            'update tasks set status="cancelled" where cron_task_id=%s and status is not "completed"'
            % cron_task_id
        ])
        if tasks:
            for task in tasks:
                cmd_list.append([
                    'update subtasks set status="cancelled" where task_id=%d  and status is not "completed"'
                    % task['task_id']
                ])
        # print cmd_list

        ret, err = db.execute_iud(db_path, cmd_list)
        if err:
            raise Exception(err)

        cron = crontab.CronTab(user)
        cron.remove_all(comment=str(cron_task_id))
        cron.write()
    except Exception, e:
        return False, "Error deleting cron entry : %s" % str(e)
def get_remote_replications(remote_replication_id=None):
    replications = []
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        if remote_replication_id is not None:
            cmd = "select * from remote_replications where remote_replication_id='%s'" % remote_replication_id
        else:
            cmd = "select * from remote_replications"
        replications, err = db.get_multiple_rows(db_path, cmd)
        if err:
            raise Exception(err)

        if replications is not None:
            # print 'replications - ', replications
            for replication in replications:
                cron_tasks, err = scheduler_utils.get_cron_tasks(
                    replication['cron_task_id'])
                # print cron_tasks
                if err:
                    raise Exception(err)
                if not cron_tasks:
                    raise Exception('Specified replication schedule not found')
                replication['schedule_description'] = cron_tasks[0]['schedule_description']
                replication['description'] = cron_tasks[0]['description']
    except Exception, e:
        return None, 'Error retrieving remote replications : %s' % e
Exemplo n.º 7
0
def set_log_level(level):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        if level not in [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL]:
            logger.setLevel(logging.INFO)
        else:
            d1, err = db.get_single_row(
                "%s/integral_view_config.db" % db_path, "select * from global_params")
            if err:
                raise Exception(err)
            cmd_list = []
            if d1:
                cmd = [
                    "update global_params set logging_level=? where id = ?", (level, 1,)]
            else:
                cmd = [
                    "insert into global_params (logging_level, id) values(?,?)", (level, 1,)]
            cmd_list.append(cmd)
            ret, err = db.execute_iud(
                "%s/integral_view_config.db" % db_path, cmd_list)
            if err:
                raise Exception(err)
            logger.setLevel(level)
    except Exception, e:
        return False, 'Error setting log level : %s' % str(e)
Exemplo n.º 8
0
def refresh_alerts(request, random=None):
    try:
        from django.utils import timezone
        cmd_list = []
        # this command will insert or update the row value if the row with the
        # user exists.
        cmd = ["INSERT OR REPLACE INTO admin_alerts (user, last_refresh_time) values (?,?);", (
            request.user.username, timezone.now())]
        cmd_list.append(cmd)
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        test, err = db.execute_iud(db_path, cmd_list)
        if err:
            raise Exception(err)
        new_alerts_present, err = alerts.new_alerts()
        if err:
            raise Exception(err)
        if new_alerts_present:
            import json
            alerts_list, err = alerts.get_alerts(last_n=5)
            if err:
                raise Exception(err)
            if not alerts_list:
                raise Exception('Error loading alerts')
            new_alerts = json.dumps([dict(alert=pn) for pn in alerts_list])
            return django.http.HttpResponse(new_alerts, content_type='application/json')
        else:
            clss = "btn btn-default btn-sm"
            message = "View alerts"
            return django.http.HttpResponse("No New Alerts")
    except Exception, e:
        return django.http.HttpResponse("Error loading alerts : %s" % str(e))
Exemplo n.º 9
0
def generate_auth_conf():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        gl, err = load_auth_access_group_list()
        if err:
            raise Exception(err)
        with open("auth.conf", "w") as fh:
            if gl:
                for g in gl:
                    ul, err = load_auth_access_users_info(g["id"])
                    if err:
                        raise Exception(err)
                    if not ul:
                        continue
                    fh.write("\n\n[%s] \n" % g["name"])
                    for u in ul:
                        fh.write("  Auth \"%s\" \"%s\"  \n" %
                                 (u["user"], u["secret"]))
                        '''
            if u["peer_user"]:
              fh.write ("  Auth \"%s\" \"%s\" \\ \n" % (u["user"], u["secret"]))
              fh.write ("        \"%s\" \"%s\"  \n" %(u["peer_user"], u["peer_secret"]))
            else:
              fh.write ("  Auth \"%s\" \"%s\"  \n" % (u["user"], u["secret"]))
            '''
    except Exception, e:
        return False, 'Error generating authentication configuration file : %s' % str(e)
Exemplo n.º 10
0
def save_email_settings(d):

    conn = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d1, err = db.get_single_row(db_path, "select * from email_config")
        if err:
            raise Exception(err)
        if d1:
            # Config exists so update
            ret, err = db.execute_iud(db_path, [["update email_config set server=?, port=?, username=?, pswd=?, tls=?, email_alerts=?, email_audit=?, email_quota=?, rcpt_list=? where id = ?", (
                d["server"], d["port"], d["username"], d["pswd"], d["tls"], d["email_alerts"], d["email_audit"], d["email_quota"], d["rcpt_list"], 1,)]])
            if err:
                raise Exception(err)

        else:
            # No config exists so insert
            ret, err = db.execute_iud(db_path, [["insert into email_config (server, port, username, pswd, tls, email_alerts,email_audit,email_quota, rcpt_list, id) values (?,?,?,?,?,?,?,?,?,?)", (
                d["server"], d["port"], d["username"], d["pswd"], d["tls"], d["email_alerts"], d["email_audit"], d["email_quota"], d["rcpt_list"], 1, )]])
            if err:
                raise Exception(err)
    except Exception, e:
        return False, 'Error saving email settings : %s' % str(e)
Exemplo n.º 11
0
def generate_auth_conf():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        gl, err = load_auth_access_group_list()
        if err:
            raise Exception(err)
        with open("auth.conf", "w") as fh:
            if gl:
                for g in gl:
                    ul, err = load_auth_access_users_info(g["id"])
                    if err:
                        raise Exception(err)
                    if not ul:
                        continue
                    fh.write("\n\n[%s] \n" % g["name"])
                    for u in ul:
                        fh.write("  Auth \"%s\" \"%s\"  \n" %
                                 (u["user"], u["secret"]))
                        '''
            if u["peer_user"]:
              fh.write ("  Auth \"%s\" \"%s\" \\ \n" % (u["user"], u["secret"]))
              fh.write ("        \"%s\" \"%s\"  \n" %(u["peer_user"], u["peer_secret"]))
            else:
              fh.write ("  Auth \"%s\" \"%s\"  \n" % (u["user"], u["secret"]))
            '''
    except Exception, e:
        return False, 'Error generating authentication configuration file : %s' % str(
            e)
Exemplo n.º 12
0
def get_cron_tasks(cron_task_id=None, user='******'):
    """Function to return all the user created cron."""
    cron_list = []
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)

        if cron_task_id is None:
            query = 'select * from cron_tasks'
        else:
            query = 'select * from cron_tasks where cron_task_id=%s' % cron_task_id

        cron_db_entries, err = db.get_multiple_rows(db_path, query)
        if err:
            raise Exception(err)
        # print cron_db_entries

        if cron_db_entries:
            cron = crontab.CronTab(user)
            for cron_db_entry in cron_db_entries:
                cron_dict = {}
                cron_dict['description'] = cron_db_entry['description']
                cron_dict['cron_task_id'] = cron_db_entry['cron_task_id']
                jobs = cron.find_comment(str(cron_db_entry['cron_task_id']))
                if jobs:
                    for job in jobs:
                        cron_dict['schedule_description'] = job.description(
                            use_24hour_time_format=True)
                        cron_dict['job'] = job
                        break
                cron_list.append(cron_dict)
    except Exception, e:
        return None, 'Error listing all cron entries : %s' % str(e)
Exemplo n.º 13
0
def create_task(description,
                subtask_list,
                task_type_id=0,
                cron_task_id=0,
                node=socket.getfqdn(),
                initiate_time=None,
                attempts=3,
                run_as_user_name='root',
                retry_interval=1):
    """Adds a task in to tasks table which performs/runs the subtask_list according to the received arguments."""
    row_id = -1
    try:
        if not description or not subtask_list:
            raise Exception("Insufficient parameters")

        now = int(time.time())
        if not initiate_time:
            initiate_time = now

        log_path, err = config.get_log_folder_path()
        if err:
            raise Exception(err)
        log_dir = '%s/task_logs' % log_path
        if not os.path.isdir(log_dir):
            os.mkdir(log_dir)

        cmd = "insert into tasks (description,task_type_id, node, run_as_user_name, attempts, cron_task_id, retry_interval, create_time, initiate_time) VALUES ('%s','%d','%s','%s','%d','%d','%d', '%d', '%d');" % (
            description, task_type_id, node, run_as_user_name, attempts,
            int(cron_task_id), retry_interval, now, initiate_time)
        # print cmd
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)

        row_id, err = db.execute_iud(db_path, [
            [cmd],
        ], get_rowid=True)
        # print "\n check!"
        if err:
            raise Exception(err)

        if row_id:
            log_file = '%s/%d.log' % (log_dir, row_id)
            for subtask in subtask_list:
                for description, command in subtask.iteritems():
                    command = '%s  &> %s' % (command, log_file)
                    cmd = "insert into subtasks (description,command,task_id) values ('%s','%s','%d');" % (
                        description, command, row_id)
                    status, err = db.execute_iud(db_path, [
                        [cmd],
                    ],
                                                 get_rowid=True)
                    if err:
                        raise Exception(
                            'Error creating scheduled command : %s' % err)
        else:
            raise Exception('Error creating scheduled task')
    except Exception, e:
        return False, ' Error adding task: %s' % e
Exemplo n.º 14
0
def audit(audit_code, audit_str, request, system_initiated=False):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        if system_initiated is False:
            ip, err = networking.get_client_ip(request.META)
            if err:
                raise Exception(err)
        tz = pytz.timezone('UTC')
        django.utils.timezone.activate(tz)
        now_utc = datetime.datetime.now(tz)
        now = int(now_utc.strftime('%s'))
        if system_initiated:
            username = '******'
            source_ip = 'System'
        else:
            username = request.user.username
            source_ip, err = networking.get_client_ip(request.META)
            if err:
                raise Exception(err)
        command_list = []
        cmd = [
            'insert into audit(audit_time, username, source_ip, audit_code, audit_str) values (?,?,?,?,?)', (now, username, source_ip, audit_code, audit_str,)]
        command_list.append(cmd)
        ret, err = db.execute_iud(db_path, command_list)
        if err:
            raise Exception(err)

        d, err = mail.load_email_settings()
        if d:
            if d["email_audit"]:
                local_timezone, err = system_date_time.get_current_timezone()
                if err:
                    raise Exception(err)
                if 'timezone_str' not in local_timezone:
                    timezone_str = 'UTC'
                else:
                    timezone_str = local_timezone['timezone_str']
                tz = pytz.timezone(timezone_str)
                now_local = now_utc.astimezone(tz)
                now_local_str = now_local.strftime("%a, %d %b %Y %H:%M:%S")
                mail_mesg = 'Action: %s\n' % audit_str
                mail_mesg += 'Action initiated from: %s\n' % source_ip
                mail_mesg += 'Action performed by: %s\n' % username
                mail_mesg += 'Action performed at: %s\n' % now_local_str
                # print mail_mesg
                hostname, err = networking.get_hostname()
                if err or not hostname:
                    hostname = 'Undetermined hostname'
                ret, err = mail.send_mail(d["server"], d["port"], d["username"], d["pswd"], d["tls"],
                                          d["rcpt_list"], "Audit message from Integralstor " + hostname, mail_mesg)
                if err:
                    raise Exception(err)
    except Exception, e:
        return False, 'Error performing an audit operation : %s' % str(e)
Exemplo n.º 15
0
def audit(audit_code, audit_str, request, system_initiated=False):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        if system_initiated is False:
            ip, err = networking.get_client_ip(request.META)
            if err:
                raise Exception(err)
        tz = pytz.timezone('UTC')
        django.utils.timezone.activate(tz)
        now_utc = datetime.datetime.now(tz)
        now = int(now_utc.strftime('%s'))
        if system_initiated:
            username = '******'
            source_ip = 'System'
        else:
            username = request.user.username
            source_ip, err = networking.get_client_ip(request.META)
            if err:
                raise Exception(err)
        command_list = []
        cmd = [
            'insert into audit(audit_time, username, source_ip, audit_code, audit_str) values (?,?,?,?,?)', (now, username, source_ip, audit_code, audit_str,)]
        command_list.append(cmd)
        ret, err = db.execute_iud(db_path, command_list)
        if err:
            raise Exception(err)

        d, err = mail.load_email_settings()
        if d:
            if d["email_audit"]:
                local_timezone, err = system_date_time.get_current_timezone()
                if err:
                    raise Exception(err)
                if 'timezone_str' not in local_timezone:
                    timezone_str = 'UTC'
                else:
                    timezone_str = local_timezone['timezone_str']
                tz = pytz.timezone(timezone_str)
                now_local = now_utc.astimezone(tz)
                now_local_str = now_local.strftime("%a, %d %b %Y %H:%M:%S")
                mail_mesg = 'Action: %s\n' % audit_str
                mail_mesg += 'Action initiated from: %s\n' % source_ip
                mail_mesg += 'Action performed by: %s\n' % username
                mail_mesg += 'Action performed at: %s\n' % now_local_str
                # print mail_mesg
                hostname, err = networking.get_hostname()
                if err or not hostname:
                    hostname = 'Undetermined hostname'
                ret, err = mail.send_mail(d["server"], d["port"], d["username"], d["pswd"], d["tls"],
                                          d["rcpt_list"], "Audit message from Integralstor " + hostname, mail_mesg)
                if err:
                    raise Exception(err)
    except Exception, e:
        return False, 'Error performing an audit operation : %s' % str(e)
Exemplo n.º 16
0
def delete_email_settings():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(db_path, [["delete from  email_config "]])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting email settings : %s' % str(e)
Exemplo n.º 17
0
def delete_all_targets():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(db_path, [("delete from iscsi_targets", )])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting all targets : %s' % str(e)
Exemplo n.º 18
0
def delete_all_initiators():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(db_path, [("delete from iscsi_initiators",)])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting all initiators : %s' % str(e)
Exemplo n.º 19
0
def delete_email_settings():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(["delete from  email_config "])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting email settings : %s' % str(e)
def schedule_remote_replication(description, dataset, destination_ip, destination_user_name, destination_pool):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        pos = dataset.find("/")
        if pos == -1:
            raise Exception('Invalid dataset name')
        source_pool = dataset[:pos]
        source_dataset = dataset[(pos + 1):]
        # print 'Source pool is ', source_pool
        # print 'Source dataset is ', source_dataset
        # print 'DestIP is ', destination_ip
        # print 'DestPool is ', destination_pool

        rr, err = get_remote_replications_with(
            dataset, destination_ip, destination_pool)
        # print rr, "\n"
        if err:
            raise Exception(err)
        if not rr:
            raise Exception(
                'Could not locate the specified remote replication task')

        # Check for active replication tasks
        # Modified remote replication is assigned a new cron_task_id.
        # TOFIX: Another replication task might still be 'running' with the old
        # cron_task_id; old cron_task_id may not be in the records, so check
        # for matching descriptions to assert
        existing_tasks, err = scheduler_utils.get_tasks_by_cron_task_id(
            rr[0]['cron_task_id'])
        if err is not None:
            raise Exception(err)
        if existing_tasks:
            for task in existing_tasks:
                if str(task['status']) == "running" and str(task['task_type_id']) == "4":
                    raise Exception(
                        "Will not commence the replication; a background task with the same description is yet to complete its replication!")

        scripts_path, err = config.get_shell_scripts_path()
        if err:
            raise Exception(err)
        path = '%s/replicator.sh' % scripts_path
        cmd = "/bin/bash %s %s %s %s %s %s" % (
            path, source_pool, source_dataset, destination_pool, destination_user_name, destination_ip)
        # print 'Command is ', cmd
        # Retry upto 3 times(default) with a retry interval of 1 hour
        ret, err = scheduler_utils.create_task(description, [
                                            {'Replication': cmd}], task_type_id=4, run_as_user_name='replicator', retry_interval=60, cron_task_id=rr[0]['cron_task_id'])
        # print "return code, err : ", ret, err
        if err:
            raise Exception(err)
    except Exception, e:
        # print e
        return False, 'Error scheduling remote replication : %s' % e
Exemplo n.º 21
0
def reset_global_target_conf():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cl = [("update iscsi_global_target_conf set discovery_auth_method=?, io_timeout=?, nop_in_interval=?, max_sessions=?, max_connections=?, max_presend_r2t=?, max_outstanding_r2t=?, first_burst_length=?, max_burst_length=?, max_receive_data_segment_length=?, default_time_to_wait=?, default_time_to_retain=? where id='1'", (None, 30, 20, 16, 8, 32, 16, 65536, 262144, 262144, 2, 60,))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error resetting ISCSI global configuration : %s' % str(e)
def delete_remote_replication(remote_replication_id):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cmd = "delete from remote_replications where remote_replication_id='%s'" % remote_replication_id
        rowid, err = db.execute_iud(db_path, [[cmd], ], get_rowid=False)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting remote replication task : %s' % e
Exemplo n.º 23
0
def load_auth_access_group_list():

    iscsi_auth_access_group_list = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        iscsi_auth_access_group_list, err = db.get_multiple_rows(
            db_path, "select * from iscsi_auth_access_groups")
    except Exception, e:
        return None, 'Error loading authorized access group list : %s' % str(e)
Exemplo n.º 24
0
def load_auth_access_user_info(user_id):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_auth_access_users where id = \'%d\'" % user_id)
    except Exception, e:
        return None, 'Error loading authorized access user information : %s' % str(e)
Exemplo n.º 25
0
def delete_all_auth_access_users():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(
            db_path, [("delete from iscsi_auth_access_users",)])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting all authorized access users : %s' % str(e)
Exemplo n.º 26
0
def load_auth_access_group_list():

    iscsi_auth_access_group_list = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        iscsi_auth_access_group_list, err = db.get_multiple_rows(
            db_path, "select * from iscsi_auth_access_groups")
    except Exception, e:
        return None, 'Error loading authorized access group list : %s' % str(e)
Exemplo n.º 27
0
def delete_auth_settings():
    """ Delete all authentication settings from the db. """
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(db_path, [["delete from samba_auth "]])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting authentication settings : %s' % str(e)
Exemplo n.º 28
0
def delete_auth_access_user(user_id):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cl = [("delete from iscsi_auth_access_users where id = \'%d\'" % user_id,)]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting authorized access user : %s' % str(e)
def update_remote_replication(remote_replication_id, new_cron_task_id):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cmd = "update remote_replications set cron_task_id='%d' where remote_replication_id='%s'" % (
            new_cron_task_id, remote_replication_id)
        rowid, err = db.execute_iud(db_path, [[cmd], ], get_rowid=True)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error updating  remote replication task : %s' % e
Exemplo n.º 30
0
def save_global_target_conf(cd):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        igt, err = db.get_single_row(
            db_path, "select * from iscsi_global_target_conf where id = \'1\'")
        if err:
            raise Exception(err)
        if not igt:
            cl = [(
                "insert into iscsi_global_target_conf(id, base_name, discovery_auth_method, discovery_auth_group, io_timeout, nop_in_interval, max_sessions, max_connections, max_presend_r2t, max_outstanding_r2t, first_burst_length, max_burst_length, max_receive_data_segment_length, default_time_to_wait, default_time_to_retain) values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                (
                    cd["base_name"],
                    cd["discovery_auth_method"],
                    cd["discovery_auth_group"],
                    cd["io_timeout"],
                    cd["nop_in_interval"],
                    cd["max_sessions"],
                    cd["max_connections"],
                    cd["max_presend_r2t"],
                    cd["max_outstanding_r2t"],
                    cd["first_burst_length"],
                    cd["max_burst_length"],
                    cd["max_receive_data_segment_length"],
                    cd["default_time_to_wait"],
                    cd["default_time_to_retain"],
                ))]
        else:
            cl = [(
                "update iscsi_global_target_conf set base_name=?, discovery_auth_method=?, discovery_auth_group=?, io_timeout=?, nop_in_interval=?, max_sessions=?, max_connections=?, max_presend_r2t=?, max_outstanding_r2t=?, first_burst_length=?, max_burst_length=?, max_receive_data_segment_length=?, default_time_to_wait=?, default_time_to_retain=? where id='1'",
                (
                    cd["base_name"],
                    cd["discovery_auth_method"],
                    cd["discovery_auth_group"],
                    cd["io_timeout"],
                    cd["nop_in_interval"],
                    cd["max_sessions"],
                    cd["max_connections"],
                    cd["max_presend_r2t"],
                    cd["max_outstanding_r2t"],
                    cd["first_burst_length"],
                    cd["max_burst_length"],
                    cd["max_receive_data_segment_length"],
                    cd["default_time_to_wait"],
                    cd["default_time_to_retain"],
                ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error saving ISCSI global target configuration : %s' % str(
            e)
Exemplo n.º 31
0
def load_global_target_conf():
    igt = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        igt, err = db.get_single_row(
            db_path, "select * from iscsi_global_target_conf where id = 2")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading ISCSI global configuration : %s' % str(e)
Exemplo n.º 32
0
def delete_all_auth_access_users():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(db_path,
                                  [("delete from iscsi_auth_access_users", )])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting all authorized access users : %s' % str(
            e)
Exemplo n.º 33
0
def get_shares_list():
    """Load the list of currently created shares from the db. """
    l = []
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        l, err = db.get_multiple_rows(db_path, 'select * from samba_shares')
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading CIFS shares list : %s' % str(e)
Exemplo n.º 34
0
def delete_initiator(id):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(
            db_path, [("delete from iscsi_initiators where id = %d" % id,)])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting initiator : %s' % str(e)
Exemplo n.º 35
0
def load_global_target_conf():
    igt = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        igt, err = db.get_single_row(
            db_path, "select * from iscsi_global_target_conf where id = 2")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading ISCSI global configuration : %s' % str(e)
Exemplo n.º 36
0
def delete_initiator(id):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(
            db_path, [("delete from iscsi_initiators where id = %d" % id, )])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting initiator : %s' % str(e)
Exemplo n.º 37
0
def load_initiators_list():
    iscsi_initiator_list = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        iscsi_initiator_list, err = db.get_multiple_rows(
            db_path, "select * from iscsi_initiators;")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, str(e)
Exemplo n.º 38
0
def load_initiators_list():
    iscsi_initiator_list = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        iscsi_initiator_list, err = db.get_multiple_rows(
            db_path, "select * from iscsi_initiators;")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, str(e)
Exemplo n.º 39
0
def delete_target(id):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        ret, err = db.execute_iud(
            [(db_path, "delete from iscsi_targets where id = \'%d\'" % id,)])
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting target : %s' % str(e)
Exemplo n.º 40
0
def load_targets_list():

    iscsi_target_list = []
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        iscsi_target_list, err = db.get_multiple_rows(
            db_path, "select * from iscsi_targets")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading ISCSI targets list : %s' % str(e)
Exemplo n.º 41
0
def delete_all_audits():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        command_list = []
        cmd = ['delete from audit']
        command_list.append(cmd)
        ret, err = db.execute_iud(db_path, command_list)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting all audits : %s' % str(e)
Exemplo n.º 42
0
def load_targets_list():

    iscsi_target_list = []
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        iscsi_target_list, err = db.get_multiple_rows(
            db_path, "select * from iscsi_targets")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading ISCSI targets list : %s' % str(e)
Exemplo n.º 43
0
def load_auth_access_users_info(auth_access_group_id):

    l = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        l, err = db.get_multiple_rows(
            db_path, "select * from iscsi_auth_access_users where auth_access_group_id = \'%d\'" % auth_access_group_id)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading authorized access users information by group: %s' % str(e)
Exemplo n.º 44
0
def delete_auth_access_user(user_id):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cl = [("delete from iscsi_auth_access_users where id = \'%d\'" %
               user_id, )]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting authorized access user : %s' % str(e)
Exemplo n.º 45
0
def save_initiator(id, cd):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cl = [("update iscsi_initiators set initiators=?, auth_network=?, comment=? where id=?",
               (cd["initiators"].lower(), cd["auth_network"].lower(), cd["comment"], id, ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error saving initiator information : %s' % str(e)
Exemplo n.º 46
0
def load_initiator_info(index):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_initiators where id=\'%d\'" % index)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, ' : %s' % str(e)
Exemplo n.º 47
0
def create_iscsi_target(vol_name, target_alias, lun_size, auth_method, queue_depth, auth_group_id, init_group_id):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cl = [("insert into iscsi_targets(id, vol_name, target_name, target_alias, lun_size, auth_method, queue_depth, auth_group_id, init_group_id) values (NULL, ?, ?, ?, ?, ?, ?, ?, ?)",
               (vol_name, vol_name, target_alias, lun_size, auth_method, queue_depth, auth_group_id, init_group_id, ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error creating ISCSI target : %s' % str(e)
Exemplo n.º 48
0
def load_initiator_info(index):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_initiators where id=\'%d\'" % index)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, ' : %s' % str(e)
Exemplo n.º 49
0
def load_target_info(index):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_targets where id=\'%d\'" % index)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading target information : %s' % str(e)
Exemplo n.º 50
0
def delete_all_audits():
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        command_list = []
        cmd = ['delete from audit']
        command_list.append(cmd)
        ret, err = db.execute_iud(db_path, command_list)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error deleting all audits : %s' % str(e)
Exemplo n.º 51
0
def get_valid_users_list(share_id):
    """Get the list of users from the db who have access to a share. """
    l = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        l, err = db.get_multiple_rows(
            db_path, 'select * from samba_valid_users where share_id = %s' % share_id)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading valid users list : %s' % str(e)
Exemplo n.º 52
0
def load_target_info(index):

    d = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_targets where id=\'%d\'" % index)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading target information : %s' % str(e)
Exemplo n.º 53
0
def get_tasks_by_cron_task_id(cron_task_id):
    tasks = []
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        query = 'select * from tasks where cron_task_id="%d"' % int(
            cron_task_id)
        # print query
        tasks, err = db.get_multiple_rows(db_path, query)
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error retrieving tasks by cron task id: %s' % e
Exemplo n.º 54
0
def create_auth_access_group():

    rowid = None
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cl = [("insert into iscsi_auth_access_groups(id) values (NULL)",)]
        rowid, err = db.execute_iud(db_path, cl, True)
        cl = [("update iscsi_auth_access_groups set name=\'AuthGroup%d\' where rowid = \'%d\'" % (
            rowid, rowid),)]
        ret, err = db.execute_iud(db_path, cl)
    except Exception, e:
        return None, 'Error creating authorized access group : %s' % str(e)
Exemplo n.º 55
0
def load_email_settings():
    conn = None
    d = None
    try:
        # print '1'
        db_path, err = config.get_db_path()
        # print '2'
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from email_config where id = 1")
        if err:
            raise Exception(err)
    except Exception, e:
        return None, 'Error loading email settings : %s' % str(e)
Exemplo n.º 56
0
def save_target(id, cd):

    try:
        if not id or not cd:
            raise Exception('Required parameters missing')
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        cl = [("update iscsi_targets set lun_size=?, target_alias=?, auth_method=?, queue_depth=?, auth_group_id=?, init_group_id = ?  where id=?",
               (cd["lun_size"], cd["target_alias"], cd["auth_method"], cd["queue_depth"], cd["auth_group_id"], cd["init_group_id"], id, ))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error saving target : %s' % str(e)
Exemplo n.º 57
0
def get_entries():
    al = []
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        query = 'select * from audit order by audit_id desc'
        rows, err = db.get_multiple_rows(db_path, query)
        if err:
            raise Exception(err)
        if rows:
            for row in rows:
                audit_entry, err = _parse_audit_entry(row)
                if err:
                    raise Exception(err)
                al.append(audit_entry)
    except Exception, e:
        return None, 'Error loading audit entries : %s' % str(e)
Exemplo n.º 58
0
def save_global_target_conf(cd):
    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        igt, err = db.get_single_row(
            db_path, "select * from iscsi_global_target_conf where id = \'1\'")
        if err:
            raise Exception(err)
        if not igt:
            cl = [("insert into iscsi_global_target_conf(id, base_name, discovery_auth_method, discovery_auth_group, io_timeout, nop_in_interval, max_sessions, max_connections, max_presend_r2t, max_outstanding_r2t, first_burst_length, max_burst_length, max_receive_data_segment_length, default_time_to_wait, default_time_to_retain) values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                   (cd["base_name"], cd["discovery_auth_method"], cd["discovery_auth_group"], cd["io_timeout"], cd["nop_in_interval"], cd["max_sessions"], cd["max_connections"], cd["max_presend_r2t"], cd["max_outstanding_r2t"], cd["first_burst_length"], cd["max_burst_length"], cd["max_receive_data_segment_length"], cd["default_time_to_wait"], cd["default_time_to_retain"],))]
        else:
            cl = [("update iscsi_global_target_conf set base_name=?, discovery_auth_method=?, discovery_auth_group=?, io_timeout=?, nop_in_interval=?, max_sessions=?, max_connections=?, max_presend_r2t=?, max_outstanding_r2t=?, first_burst_length=?, max_burst_length=?, max_receive_data_segment_length=?, default_time_to_wait=?, default_time_to_retain=? where id='1'",
                   (cd["base_name"], cd["discovery_auth_method"], cd["discovery_auth_group"], cd["io_timeout"], cd["nop_in_interval"], cd["max_sessions"], cd["max_connections"], cd["max_presend_r2t"], cd["max_outstanding_r2t"], cd["first_burst_length"], cd["max_burst_length"], cd["max_receive_data_segment_length"], cd["default_time_to_wait"], cd["default_time_to_retain"],))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error saving ISCSI global target configuration : %s' % str(e)
Exemplo n.º 59
0
def add_iscsi_volume(vol_name):

    try:
        if not vol_name:
            raise Exception('No volume name provided')
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        d, err = db.get_single_row(
            db_path, "select * from iscsi_volumes where vol_name=\'%s\'" % vol_name)
        if err:
            raise Exception(err)
        if d:
            return
        cl = [("insert into iscsi_volumes(id, vol_name) values (NULL, ?)", (vol_name,))]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error adding ISCSI volume : %s' % str(e)
Exemplo n.º 60
0
def save_auth_access_user(auth_access_group_id, user_id, user, secret):

    try:
        db_path, err = config.get_db_path()
        if err:
            raise Exception(err)
        '''
    d, err = db.read_single_row(db_path, "select * from iscsi_auth_access_users where auth_access_group_id = \'%d\' and user = \'%s\'"%(auth_access_group_id, user))
    if err:
      raise Exception(err)
    if d:
      raise Exception("A user set with the same username exists for this authorized access group")
    '''
        cl = [("update iscsi_auth_access_users set user=\'%s\', secret=\'%s\' where id = \'%d\'" % (
            user, secret, user_id), )]
        ret, err = db.execute_iud(db_path, cl)
        if err:
            raise Exception(err)
    except Exception, e:
        return False, 'Error saving authorized access user information : %s' % str(e)