def get_iscsi_cmd(obj, host_id):
    cmd_name = u'Get iSCSI List'
    jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
    jobgroup.jobs.append(Job('%s command' % cmd_name, 0, "%s/%s" \
                             % (karesansui.config['application.bin.dir'], ISCSI_COMMAND_GET)))
    jobgroup.type = JOBGROUP_TYPE['PARALLEL']

    host = findbyhost1(obj.orm, host_id)
    _machine2jobgroup = m2j_new(machine=host,
                                jobgroup_id=-1,
                                uniq_key=karesansui.sheconf['env.uniqkey'],
                                created_user=obj.me,
                                modified_user=obj.me,
                                )
    if corp(obj.orm, obj.pysilhouette.orm,_machine2jobgroup, jobgroup) is False:
        return False

    ret = jobgroup.jobs[0].action_stdout
    network_storages = get_network_storages(ret)
    return network_storages
Example #2
0
def get_iscsi_cmd(obj, host_id):
    cmd_name = u'Get iSCSI List'
    jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
    jobgroup.jobs.append(Job('%s command' % cmd_name, 0, "%s/%s" \
                             % (karesansui.config['application.bin.dir'], ISCSI_COMMAND_GET)))
    jobgroup.type = JOBGROUP_TYPE['PARALLEL']

    host = findbyhost1(obj.orm, host_id)
    _machine2jobgroup = m2j_new(
        machine=host,
        jobgroup_id=-1,
        uniq_key=karesansui.sheconf['env.uniqkey'],
        created_user=obj.me,
        modified_user=obj.me,
    )
    if corp(obj.orm, obj.pysilhouette.orm, _machine2jobgroup,
            jobgroup) is False:
        return False

    ret = jobgroup.jobs[0].action_stdout
    network_storages = get_network_storages(ret)
    return network_storages
Example #3
0
def read_conf(modules, webobj=None, machine=None, extra_args={}):
    """<comment-ja>
    設定ファイルパーサー(モジュール)により設定ファイルの内容を
    辞書配列操作クラスに渡し、そのオブジェクトを返す
    @param modules: モジュールのリスト配列
    @param webobj: 
    @param machine: 
    @type modules: list
    @rtype: object dict_op
    @return: 辞書配列操作オブジェクト
    </comment-ja>
    <comment-en>
    TODO: English Comment
    </comment-en>
    """

    if type(modules) == str:
        modules = [modules]

    options = {"module" : ":".join(modules)}

    try:
        options['include'] = extra_args['include']
    except:
        pass

    #cmd_name = u"Get Settings - %s" % ":".join(modules)
    cmd_name = u"Get Settings"

    if type(webobj) == types.InstanceType:
        from karesansui.db.model._2pysilhouette import Job, JobGroup, \
                                                       JOBGROUP_TYPE
        from karesansui.db.access._2pysilhouette import jg_findby1, jg_save,corp
        from karesansui.db.access._2pysilhouette import save_job_collaboration
        from karesansui.db.access.machine2jobgroup import new as m2j_new
        from pysilhouette.command import dict2command

        _cmd = dict2command(
            "%s/%s" % (karesansui.config['application.bin.dir'],
                       CONFIGURE_COMMAND_READ), options)

        jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
        jobgroup.jobs.append(Job('%s command' % cmd_name, 0, _cmd))
        jobgroup.type = JOBGROUP_TYPE['PARALLEL']

        _machine2jobgroup = m2j_new(machine=machine,
                                jobgroup_id=-1,
                                uniq_key=karesansui.sheconf['env.uniqkey'],
                                created_user=webobj.me,
                                modified_user=webobj.me,
                                )

        if corp(webobj.orm, webobj.pysilhouette.orm,_machine2jobgroup, jobgroup) is False:
            webobj.logger.debug("%s command failed. Return to timeout" % (cmd_name))
            return False

        cmd_res = jobgroup.jobs[0].action_stdout

    else:
        from karesansui.lib.utils import execute_command

        opts_str = ""
        for x in options.keys():
            if options[x] is None:
                opts_str += "--%s " % x 
            else:
                opts_str += "--%s=%s " % (x, options[x])

        _cmd = "%s/bin/%s %s" % (KARESANSUI_PREFIX, CONFIGURE_COMMAND_READ, opts_str.strip(),)

        command_args = _cmd.strip().split(" ")
        (rc,res) = execute_command(command_args)
        if rc != 0:
            return False

        cmd_res = "\n".join(res)

    dop = DictOp()
    try:
        exec(cmd_res)
    except Exception:
        return False

    for module in modules:
        try:
            exec("dop.addconf('%s',Config_Dict_%s)" % (module,module,))
        except:
            pass

    return dop
Example #4
0
def iptables_lint(filepath, webobj=None, machine=None, delete=False):
    from karesansui.lib.const import IPTABLES_COMMAND_CONTROL

    options = {"config": filepath, "lint": None}

    cmd_name = u"Check iptables settings - %s" % filepath

    if type(webobj) == types.InstanceType:
        from karesansui.db.model._2pysilhouette import Job, JobGroup, \
                                                       JOBGROUP_TYPE
        from karesansui.db.access._2pysilhouette import jg_findby1, jg_save, corp
        from karesansui.db.access._2pysilhouette import save_job_collaboration
        from karesansui.db.access.machine2jobgroup import new as m2j_new
        from pysilhouette.command import dict2command

        _cmd = dict2command(
            "%s/%s" % (karesansui.config['application.bin.dir'],
                       IPTABLES_COMMAND_CONTROL), options)

        jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
        jobgroup.jobs.append(Job('%s command' % cmd_name, 0, _cmd))
        jobgroup.type = JOBGROUP_TYPE['PARALLEL']

        _machine2jobgroup = m2j_new(
            machine=machine,
            jobgroup_id=-1,
            uniq_key=karesansui.sheconf['env.uniqkey'],
            created_user=webobj.me,
            modified_user=webobj.me,
        )

        if corp(webobj.orm, webobj.pysilhouette.orm, _machine2jobgroup,
                jobgroup) is False:
            webobj.logger.debug("%s command failed. Return to timeout" %
                                (cmd_name))
            if delete is True and os.path.exists(filepath):
                os.unlink(filepath)
            return False

        cmd_res = jobgroup.jobs[0].action_stdout

    else:
        from karesansui.lib.const import KARESANSUI_PREFIX
        from karesansui.lib.utils import execute_command

        opts_str = ""
        for x in options.keys():
            if options[x] is None:
                opts_str += "--%s " % x
            else:
                opts_str += "--%s=%s " % (x, options[x])

        _cmd = "%s/bin/%s %s" % (
            KARESANSUI_PREFIX,
            IPTABLES_COMMAND_CONTROL,
            opts_str.strip(),
        )

        command_args = _cmd.strip().split(" ")
        (rc, res) = execute_command(command_args)
        if rc != 0:
            if delete is True and os.path.exists(filepath):
                os.unlink(filepath)
            return False

        cmd_res = "\n".join(res)

    if delete is True and os.path.exists(filepath):
        os.unlink(filepath)

    return cmd_res
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        if self.is_mode_input() is True:
            self.view.host_id = host_id

        iqn = self.input.iqn
        options = {'iqn' : iqn}

        _cmd = dict2command(
            "%s/%s" % (karesansui.config['application.bin.dir'], ISCSI_COMMAND_GET), options)

        cmd_name = u'Get iSCSI Detail'
        jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
        jobgroup.jobs.append(Job('%s command' % cmd_name, 0, _cmd))
        jobgroup.type = JOBGROUP_TYPE['PARALLEL']

        host = findbyhost1(self.orm, host_id)
        _machine2jobgroup = m2j_new(machine=host,
                                    jobgroup_id=-1,
                                    uniq_key=karesansui.sheconf['env.uniqkey'],
                                    created_user=self.me,
                                    modified_user=self.me,
                                    )

        if corp(self.orm, self.pysilhouette.orm,_machine2jobgroup, jobgroup) is False:
            self.logger.debug("%s command failed. Return to timeout" % (cmd_name))
            return web.internalerror('Internal Server Error. (Timeout)')

        cmd_res = jobgroup.jobs[0].action_stdout

        if not cmd_res:
            self.view.info = {
                'type'      : "iSCSI",
                'hostname'  : "",
                'port'      : "",
                'tpgt'      : "",
                'iqn'       : "",
                'activity'  : "",
                'autostart' : "",
                'auth'      : "",
                'user'      : "",
                'disk_list' : [],
                }

            return True

        (host,port,tpgt,iqn,activity,autostart,auth,user) = cmd_res.strip("\n").split(' ', 8)
        info = {
            'type'      : "iSCSI",
            'hostname'  : host,
            'port'      : port,
            'tpgt'      : tpgt,
            'iqn'       : iqn,
            'activity'  : string.atoi(activity),
            'autostart' : string.atoi(autostart),
            'auth'      : auth,
            'user'      : user,
            'disk_list' : [],
            }

        dev_symlink_list = get_filelist(ISCSI_DEVICE_DIR)
        if activity == '1':
            disk_list = []
            symlink_regexp = re.compile("^%s" % (re.escape(ISCSI_DEVICE_NAME_TPL % (host, port, iqn))))
            for sym_link in dev_symlink_list:
                if symlink_regexp.match(sym_link):
                    real_path = symlink2real("%s/%s" % (ISCSI_DEVICE_DIR, sym_link))
                    disk_list.append({'symlink_name' : sym_link,
                                      'realpath_list' : real_path,
                                      })
            info['disk_list'] = disk_list

        self.view.info = info
        return True
Example #6
0
def iptables_lint(filepath, webobj=None, machine=None, delete=False):
    from karesansui.lib.const import IPTABLES_COMMAND_CONTROL

    options = {"config" : filepath, "lint" : None}

    cmd_name = u"Check iptables settings - %s" % filepath

    if type(webobj) == types.InstanceType:
        from karesansui.db.model._2pysilhouette import Job, JobGroup, \
                                                       JOBGROUP_TYPE
        from karesansui.db.access._2pysilhouette import jg_findby1, jg_save,corp
        from karesansui.db.access._2pysilhouette import save_job_collaboration
        from karesansui.db.access.machine2jobgroup import new as m2j_new
        from pysilhouette.command import dict2command

        _cmd = dict2command(
            "%s/%s" % (karesansui.config['application.bin.dir'],
                       IPTABLES_COMMAND_CONTROL), options)

        jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
        jobgroup.jobs.append(Job('%s command' % cmd_name, 0, _cmd))
        jobgroup.type = JOBGROUP_TYPE['PARALLEL']

        _machine2jobgroup = m2j_new(machine=machine,
                                jobgroup_id=-1,
                                uniq_key=karesansui.sheconf['env.uniqkey'],
                                created_user=webobj.me,
                                modified_user=webobj.me,
                                )

        if corp(webobj.orm, webobj.pysilhouette.orm,_machine2jobgroup, jobgroup) is False:
            webobj.logger.debug("%s command failed. Return to timeout" % (cmd_name))
            if delete is True and os.path.exists(filepath):
                os.unlink(filepath)
            return False

        cmd_res = jobgroup.jobs[0].action_stdout

    else:
        from karesansui.lib.const import KARESANSUI_PREFIX
        from karesansui.lib.utils import execute_command

        opts_str = ""
        for x in options.keys():
            if options[x] is None:
                opts_str += "--%s " % x 
            else:
                opts_str += "--%s=%s " % (x, options[x])

        _cmd = "%s/bin/%s %s" % (KARESANSUI_PREFIX, IPTABLES_COMMAND_CONTROL, opts_str.strip(),)

        command_args = _cmd.strip().split(" ")
        (rc,res) = execute_command(command_args)
        if rc != 0:
            if delete is True and os.path.exists(filepath):
                os.unlink(filepath)
            return False

        cmd_res = "\n".join(res)


    if delete is True and os.path.exists(filepath):
        os.unlink(filepath)

    return cmd_res
Example #7
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        if self.is_mode_input() is True:
            self.view.host_id = host_id

        iqn = self.input.iqn
        options = {'iqn': iqn}

        _cmd = dict2command(
            "%s/%s" %
            (karesansui.config['application.bin.dir'], ISCSI_COMMAND_GET),
            options)

        cmd_name = u'Get iSCSI Detail'
        jobgroup = JobGroup(cmd_name, karesansui.sheconf['env.uniqkey'])
        jobgroup.jobs.append(Job('%s command' % cmd_name, 0, _cmd))
        jobgroup.type = JOBGROUP_TYPE['PARALLEL']

        host = findbyhost1(self.orm, host_id)
        _machine2jobgroup = m2j_new(
            machine=host,
            jobgroup_id=-1,
            uniq_key=karesansui.sheconf['env.uniqkey'],
            created_user=self.me,
            modified_user=self.me,
        )

        if corp(self.orm, self.pysilhouette.orm, _machine2jobgroup,
                jobgroup) is False:
            self.logger.debug("%s command failed. Return to timeout" %
                              (cmd_name))
            return web.internalerror('Internal Server Error. (Timeout)')

        cmd_res = jobgroup.jobs[0].action_stdout

        if not cmd_res:
            self.view.info = {
                'type': "iSCSI",
                'hostname': "",
                'port': "",
                'tpgt': "",
                'iqn': "",
                'activity': "",
                'autostart': "",
                'auth': "",
                'user': "",
                'disk_list': [],
            }

            return True

        (host, port, tpgt, iqn, activity, autostart, auth,
         user) = cmd_res.strip("\n").split(' ', 8)
        info = {
            'type': "iSCSI",
            'hostname': host,
            'port': port,
            'tpgt': tpgt,
            'iqn': iqn,
            'activity': string.atoi(activity),
            'autostart': string.atoi(autostart),
            'auth': auth,
            'user': user,
            'disk_list': [],
        }

        dev_symlink_list = get_filelist(ISCSI_DEVICE_DIR)
        if activity == '1':
            disk_list = []
            symlink_regexp = re.compile(
                "^%s" % (re.escape(ISCSI_DEVICE_NAME_TPL % (host, port, iqn))))
            for sym_link in dev_symlink_list:
                if symlink_regexp.match(sym_link):
                    real_path = symlink2real("%s/%s" %
                                             (ISCSI_DEVICE_DIR, sym_link))
                    disk_list.append({
                        'symlink_name': sym_link,
                        'realpath_list': real_path,
                    })
            info['disk_list'] = disk_list

        self.view.info = info
        return True