Exemplo n.º 1
0
 def get_order(self):
     re_order = re.compile(r'^order\s(.*?)\s(.*?)\s(.*?)$', re.MULTILINE)
     result = s.re_findall(re_order, self.crm_conf_data)
     dict_order = {}
     for order in result:
         dict_order.update({order[0]: [order[1], order[2]]})
     return dict_order
Exemplo n.º 2
0
 def get_colocation(self):
     re_colocation = re.compile(r'^colocation\s(.*?)\sinf:\s(.*?)\s(.*?)$',
                                re.MULTILINE)
     result = s.re_findall(re_colocation, self.crm_conf_data)
     dict_colocation = {}
     for colocation in result:
         dict_colocation.update(
             {colocation[0]: {colocation[1], colocation[2]}})
     return dict_colocation
Exemplo n.º 3
0
 def get_vip(self):
     re_vip = re.compile(
         r'primitive\s(\S+)\sIPaddr2.*\s*params\sip=([0-9.]+)\scidr_netmask=(\d+)'
     )
     result = s.re_findall(re_vip, self.crm_conf_data)
     dict_vip = {}
     for vip in result:
         dict_vip.update({vip[0]: {'ip': vip[1], 'netmask': vip[2]}})
     self.vip = dict_vip
     return dict_vip
Exemplo n.º 4
0
 def get_failed_actions(self, res):
     # 检查crm整体状态,但是目前好像只是用于提取vip的错误信息
     exitreason = None
     cmd_result = execute_crm_cmd('crm st | cat')
     re_error = re.compile(
         f"\*\s({res})\w*\son\s(\S*)\s'(.*)'\s.*exitreason='(.*)',")
     result = s.re_findall(re_error, cmd_result['rst'])
     if result:
         if result[0][3] == '[findif] failed':
             exitreason = 0
         else:
             exitreason = result
     return exitreason
Exemplo n.º 5
0
 def get_target(self):
     re_target = re.compile(
         r'primitive\s(\S+)\siSCSITarget.*\s*params\siqn="?(\S+?)"?\s.*portals="([0-9.]+):(\d+)"'
     )
     result = s.re_findall(re_target, self.crm_conf_data)
     dict_target = {}
     for target in result:
         dict_target.update({
             target[0]: {
                 'target_iqn': target[1],
                 'ip': target[2],
                 'port': target[3]
             }
         })
     self.target = dict_target
     return dict_target
Exemplo n.º 6
0
 def get_portblock(self):
     re_portblock = re.compile(
         r'primitive\s(\S+)\sportblock.*\s*params\sip=([0-9.]+)\sportno=(\d+).*action=(\w+)'
     )
     result = s.re_findall(re_portblock, self.crm_conf_data)
     dict_portblock = {}
     for portblock in result:
         dict_portblock.update({
             portblock[0]: {
                 'ip': portblock[1],
                 'port': portblock[2],
                 'type': portblock[3]
             }
         })
     self.portblock = dict_portblock
     return dict_portblock
Exemplo n.º 7
0
 def get_iscsi_logical_unit(self):
     # ilu : iscsi logical unit
     re_ilu = re.compile(
         r'primitive\s(\S+)\siSCSILogicalUnit.*\s*params\starget_iqn="(\S+)"\s.*?lun=(\d+)\spath="(\S+)"\sallowed_initiators="?(.*?)"?\s\\'
     )
     result = s.re_findall(re_ilu, self.crm_conf_data)
     dict_ilu = {}
     for ilu in result:
         dict_ilu.update({
             ilu[0]: {
                 'target_iqn': ilu[1],
                 'lun': ilu[2],
                 'path': ilu[3],
                 'initiators': ilu[4].split(' ')
             }
         })
     self.ilu = dict_ilu
     return dict_ilu
Exemplo n.º 8
0
def test_re_findall():
    """根据参数正则表达式格式化处理传入字符"""
    re_string = r'iqn\.*[a-zA-Z0-9.:-]+'
    iqn = 'iqn.2020.test:pytest01'
    assert sundry.re_findall(re_string, iqn) == ['iqn.2020.test:pytest01']
Exemplo n.º 9
0
 def refine_vg(self):
     # all_vg = self.data_vg.splitlines()
     # list_vg = []
     re_ = '(\S+)\s+\d+\s+\d+\s+\d+\s+\S+\s+(\S+)\s+(\S+)\s*?'
     return s.re_findall(re_, self.data_vg)
Exemplo n.º 10
0
 def refine_thinlv(self):
     re_ = '(\S+)\s+(\S+)\s+twi\S+\s+(\S*).*\s*?'
     return s.re_findall(re_, self.data_lv)