VMWare ESXi의 VM 네트워크 레이블 변경 실패

1. Environment   

VMWare ESXi 6.7

MDRM 4.5.4

2. Symptoms

VMWare ESXi의 VM 네트워크 레이블 변경시 아래와 같은 에러가 발생하며, 실패return:[1], output:[Traceback (most recent call last):File “/tmp/wind/windLocalScript_eaecff7d-afa5-4c8c-a24f-dbbf59bbcbc5”, line 28, in <module>m = re.match(r”(\d+).+\[(.+)\]\s*((.*/).*?)\s”, out)File “/build/mts/release/bora-13004448/bora/build/esx/release/vmvisor/sys-boot/lib64/python3.5/re.py”, line 163, in matchTypeError: cannot use a string pattern on a bytes-like object]

 3. Cause

Character-Set 설정에 따른 구문 오류

4. Solution

컴포넌트 스크립트 구문 수정#!/usr/bin/env pythonimport subprocessimport osimport sysimport redef runCmd(command):    proc = subprocess.Popen([command], stdout=subprocess.PIPE, shell=True)    (out, err) = proc.communicate()    return out.strip() def changeVmx(vmxPath, ethNum, portGroupId):    runCmd(“cp \”%s\” \”%s.backup\”” % (vmxPath, vmxPath))    newlines = []    with open(vmxPath,’r’) as f:        for line in f.readlines():            line = re.sub(r’ethernet%s\.startConnected\s?=\s?.+’ % (ethNum), ‘ethernet%s.startConnected = “TRUE”‘ % (ethNum), line)            line = re.sub(r’ethernet%s\.networkName\s?=\s?.+’ % (ethNum), ‘ethernet%s.networkName = “%s”‘ % (ethNum,portGroupId), line)            newlines.append(line)    with open(vmxPath, ‘w’) as f:        for line in newlines:            f.write(line) if __name__ == “__main__”:    vmname = sys.argv[1]    ethNum = sys.argv[2]    portgroup = sys.argv[3]    out = runCmd(“vim-cmd vmsvc/getallvms | grep \”\s%s\s\”” % (vmname))    m = re.match(r”(\d+).+\[(.+)\]\s*((.*/).*?)\s”, out) <= 변경전 (라인 제거)m = re.match(r”(\d+).+\[(.+)\]\s*((.*/).*?)\s”, out.decode(“utf-8”, “ignore”)) <= 변경후 (라인 추가)    vmid = m.group(1)    datastoreName = m.group(2)    vmxPath = m.group(3)    vmPath = m.group(4)    vmxFullPath = “/vmfs/volumes/%s/%s” % (datastoreName, vmxPath)    vmFullPath = “/vmfs/volumes/%s/%s” % (datastoreName, vmPath)     changeVmx(vmxFullPath, ethNum,portgroup)    out = runCmd(“vim-cmd vmsvc/reload %s” % (vmid))