示例#1
0
def get_network_storages(data):
    network_storages = []
    dev_symlink_list = get_filelist(ISCSI_DEVICE_DIR)
    dev_symlink_list.sort()
    unmountable_regexp = re.compile("-part[0-9]+$")
    for line in data.split('\n'):
        if not line:
            continue

        (host, port, tpgt, iqn, activity, autostart) = line.split(' ', 6)
        node = {
            'type': "iSCSI",
            'hostname': host,
            'port': port,
            'tpgt': tpgt,
            'iqn': iqn,
            'activity': string.atoi(activity),
            'autostart': string.atoi(autostart),
            'disk_list': [],
        }

        if activity == '1':
            disk_list = []
            symlink_regexp = re.compile(
                "^%s" % (re.escape(ISCSI_DEVICE_NAME_TPL % (host, port, iqn))))
            unmountable_flag = {}
            for sym_link in dev_symlink_list:
                if symlink_regexp.search(sym_link):
                    real_path = symlink2real("%s/%s" %
                                             (ISCSI_DEVICE_DIR, sym_link))
                    is_blockable = True
                    if unmountable_regexp.search(sym_link):
                        is_blockable = False
                        unmountable_flag[unmountable_regexp.sub(
                            "", sym_link)] = True

                    disk_list.append({
                        'symlink_name': sym_link,
                        'realpath_list': real_path,
                        'is_blockable': is_blockable,
                        'is_partitionable': False,
                    })

            for disk in disk_list:
                for key in unmountable_flag.keys():
                    if disk['symlink_name'] == key:
                        disk['is_partitionable'] = True

            node['disk_list'] = disk_list

        network_storages.append(node)
    return network_storages
def get_network_storages(data):
    network_storages = []
    dev_symlink_list = get_filelist(ISCSI_DEVICE_DIR)
    dev_symlink_list.sort()
    unmountable_regexp = re.compile("-part[0-9]+$")
    for line in data.split("\n"):
        if not line:
            continue

        (host, port, tpgt, iqn, activity, autostart) = line.split(" ", 6)
        node = {
            "type": "iSCSI",
            "hostname": host,
            "port": port,
            "tpgt": tpgt,
            "iqn": iqn,
            "activity": string.atoi(activity),
            "autostart": string.atoi(autostart),
            "disk_list": [],
        }

        if activity == "1":
            disk_list = []
            symlink_regexp = re.compile("^%s" % (re.escape(ISCSI_DEVICE_NAME_TPL % (host, port, iqn))))
            unmountable_flag = {}
            for sym_link in dev_symlink_list:
                if symlink_regexp.search(sym_link):
                    real_path = symlink2real("%s/%s" % (ISCSI_DEVICE_DIR, sym_link))
                    is_blockable = True
                    if unmountable_regexp.search(sym_link):
                        is_blockable = False
                        unmountable_flag[unmountable_regexp.sub("", sym_link)] = True

                    disk_list.append(
                        {
                            "symlink_name": sym_link,
                            "realpath_list": real_path,
                            "is_blockable": is_blockable,
                            "is_partitionable": False,
                        }
                    )

            for disk in disk_list:
                for key in unmountable_flag.keys():
                    if disk["symlink_name"] == key:
                        disk["is_partitionable"] = True

            node["disk_list"] = disk_list

        network_storages.append(node)
    return network_storages
示例#3
0
def get_network_storages(data):
    network_storages = []
    dev_symlink_list = get_filelist(ISCSI_DEVICE_DIR)
    dev_symlink_list.sort()
    unmountable_regexp = re.compile("-part[0-9]+$")
    for line in data.split('\n'):
        if not line:
            continue

        (host,port,tpgt,iqn,activity,autostart) = line.split(' ', 6)
        node = {
            'type'      : "iSCSI",
            'hostname'  : host,
            'port'      : port,
            'tpgt'      : tpgt,
            'iqn'       : iqn,
            'activity'  : string.atoi(activity),
            'autostart' : string.atoi(autostart),
            'disk_list' : [],
            }

        if activity == '1':
            disk_list = []
            symlink_regexp = re.compile("^%s" % (re.escape(ISCSI_DEVICE_NAME_TPL % (host, port, iqn))))
            unmountable_flag = {}
            for sym_link in dev_symlink_list:
                if symlink_regexp.search(sym_link):
                    real_path = symlink2real("%s/%s" % (ISCSI_DEVICE_DIR, sym_link))
                    is_blockable = True
                    if unmountable_regexp.search(sym_link):
                        is_blockable = False
                        unmountable_flag[unmountable_regexp.sub("", sym_link)] = True

                    disk_list.append({'symlink_name'     : sym_link,
                                      'realpath_list'    : real_path,
                                      'is_blockable'     : is_blockable,
                                      'is_partitionable' : False,
                                      })

            for disk in disk_list:
                for key in unmountable_flag.keys():
                    if disk['symlink_name'] == key:
                        disk['is_partitionable'] = True

            node['disk_list'] = disk_list

        network_storages.append(node)
    return network_storages
    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
示例#5
0
 def get_symlink2real(self):
     return symlink2real(self.get_target_path())
示例#6
0
 def get_symlink2real(self):
     return symlink2real(self.get_target_path())
示例#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