2017-11-07 2 views
0

f5 상자와 통신하고 일부 기본 프로필과 함께 (virtual = VIP = Virtual server)라는 단일 개체를 만들 수 있습니다.구문 오류 : 예기치 않은 EOF (구문 분석 도중) CSV 파일을 사용하는 F5 VIP 작성

근무 코드 :

from f5.bigip import ManagementRoot 
import urllib3 
urllib3.disable_warnings() 
mgmt = ManagementRoot('13.126.189.103','admin','admin') 
ltm = mgmt.tm.ltm 
virtuals = mgmt.tm.ltm.virtuals 
virtual = mgmt.tm.ltm.virtuals.virtual 
virtual1 = mgmt.tm.ltm.virtuals.virtual.create(name='virtual3', description = 'testnew' , destination= '172.31.5.8:80', partition='Common') 

내 요구 사항은, 난, CSV 파일에서 입력을 줄 것이다 (100) VIP의를 할 수있다. 위의 구문은 가져온 CSV 파일에서 하나씩 행을 실행해야합니다. 를 구문 분석하는 동안

from f5.bigip import ManagementRoot 
import urllib3 
import csv 
import sys 
import os 
urllib3.disable_warnings() 
mgmt = ManagementRoot('13.126.189.103','admin','admin') 
ltm = mgmt.tm.ltm 
virtuals = mgmt.tm.ltm.virtuals 
virtual = mgmt.tm.ltm.virtuals.virtual 


def configureVirtuals(bigip, virtualFile): 
    # These are the fields in the file. The purpose of each field is obvious. See. Input from CSV file called 'virtualFile' and each row has config 
details 
    # the BIG-IP iControl REST API for more information. 
    fieldNames = ["name", "description", "ip", "port"] 
    virtualReader = csv.DictReader(virtualFile, fieldnames=fieldNames, 
        delimiter=",") 


# Create a virtual server, one per line. it will take input from CSV file by row one by one 
    try: 
    for row in virtualReader: 
     myvirtual = mgmt.tm.ltm.virtuals.virtual.create(name=row["name"], 
        description=row["description"], 
        destination="%s:%s" % (row["ip"], row["port"]) 

난 내가 F5 엔지니어와 파이썬에 새로운 오전 오류 예기치 않은 EOF를 얻고있다. 대량 변경을위한 응용 프로그램 빌드.

아무도 도와주세요.

답변

0

먼저 닫는 괄호를 잊어 버렸습니다. 두 번째 문제는 except이없는 try 블록입니다. try을 사용하는 경우 예외를 잡아야합니다. 그렇지 않으면 try이 전혀 필요하지 않습니다. 그러니 try

from f5.bigip import ManagementRoot 
import urllib3 
import csv 
import sys 
import os 
urllib3.disable_warnings() 
mgmt = ManagementRoot('13.126.189.103','admin','admin') 
ltm = mgmt.tm.ltm 
virtuals = mgmt.tm.ltm.virtuals 
virtual = mgmt.tm.ltm.virtuals.virtual 


def configureVirtuals(bigip, virtualFile): 
    # These are the fields in the file. The purpose of each field is obvious. See. Input from CSV file called 'virtualFile' and each row has config details 
    # the BIG-IP iControl REST API for more information. 
    fieldNames = ["name", "description", "ip", "port"] 
    virtualReader = csv.DictReader(virtualFile, fieldnames=fieldNames, 
        delimiter=",") 


    # Create a virtual server, one per line. it will take input from CSV file by row one by one 
    for row in virtualReader: 
    myvirtual = mgmt.tm.ltm.virtuals.virtual.create(
     name=row["name"], 
     description=row["description"], 
     destination="%s:%s" % (row["ip"], row["port"])) # pay attention to brackets 

를 사용하거나

from f5.bigip import ManagementRoot 
import urllib3 
import csv 
import sys 
import os 
urllib3.disable_warnings() 
mgmt = ManagementRoot('13.126.189.103','admin','admin') 
ltm = mgmt.tm.ltm 
virtuals = mgmt.tm.ltm.virtuals 
virtual = mgmt.tm.ltm.virtuals.virtual 


def configureVirtuals(bigip, virtualFile): 
    # These are the fields in the file. The purpose of each field is obvious. See. Input from CSV file called 'virtualFile' and each row has config details 
    # the BIG-IP iControl REST API for more information. 
    fieldNames = ["name", "description", "ip", "port"] 
    virtualReader = csv.DictReader(virtualFile, fieldnames=fieldNames, 
        delimiter=",") 


    # Create a virtual server, one per line. it will take input from CSV file by row one by one 

    try: 
    for row in virtualReader: 
     myvirtual = mgmt.tm.ltm.virtuals.virtual.create(
     name=row["name"], 
     description=row["description"], 
     destination="%s:%s" % (row["ip"], row["port"])) # pay attention to brackets 
    except SpecificExceptionType: 
    print('Print some instruction or log an error and continue the flow') 
+0

감사를 예상하는 일을 알고 그것을 처리하는 방법을 경우 예외를 잡을 수없는 Trilliput –

+0

@ 당신은 내가 오류를 인쇄 할 수있는 방법을 알려 주시기 바랍니다 수 마지막 칼럼은 예외 함수를 사용하여, 어떤 에러가 보이면, 다음 로우는 설정을 위해 사용한다. –

관련 문제