-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Add network router interface tools #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| conn = get_openstack_conn() | ||
| args: dict = {} | ||
| if subnet_id is not None: | ||
| args["subnet_id"] = subnet_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
제가 보기엔 다 훌륭하신데 궁금해서 댓글 드립니다.
_proxy.py를 확인해보니 subnet_id와 port_id를 전달하지 않아도 None으로 처리하던데, not None 조건문을 태우는게 더 우아한방식일까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프록시 전달 목적의 argument를 만들기 위해 처리되는 로직입니다.
tools는 string으로 받지만 프록시 인터페이스는 dict로 받고 있으니, 형변환 과정이라고 봐주시면 되겠습니다.
(보충설명)
조금 이야기를 보태자면, 라우터에 인터페이스를 추가하기 위해서는 port나 subnet 중 무조건 둘 중에 하나를 지정해야 합니다.
서브넷을 지정하는 경우 해당 서브넷에서 포트를 생성해서 라우터에 붙이는 방식이고,
포트를 지정하는 경우는 별도 과정 없이 라우터에 붙입니다.
즉, 확인하신 로직은 포트와 서브넷이 바디에 있을때, 어느것을 우선으로 지정해서 보낼건지 결정하는 부분입니다.
def add_interface_to_router(self, router, subnet_id=None, port_id=None):
body = {}
if port_id:
body = {'port_id': port_id}
else:
body = {'subnet_id': subnet_id}
router = self._get_resource(_router.Router, router)
return router.add_interface(self, **body)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서브넷 지정시 포트가 생성되는지 몰랐네요~ 보충설명까지 감사합니다!!
근데 제가 질문이 구체적이지 않아 의도 전달이 불충분하지 않았나 한데요
현재 코드에서
args: dict = {}
if subnet_id is not None:
args["subnet_id"] = subnet_id
if port_id is not None:
args["port_id"] = port_id부분을
args: dict = {}
args["subnet_id"] = subnet_id
args["port_id"] = port_id로 작성한다면 openstacksdk/.../_proxy.py의 add_interface_to_router 함수가 실행될 때 해당 함수가 subnet_id, port_id 매개변수를 기본값 None으로 설정하기때문에 두 코드 다 결론적으로는 같은 동작을 할 것으로 보이는데,
그래도 if문을 통해 철옹성 같은?ㅎㅎ 안전한 코드를 짜는게 좋은가 궁금하여 질문드렸습니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이부분은 수정해서 subnet, port 둘 다 테스트해보니 잘 되네요.
반영하도록 하겠습니다!
| if isinstance(first, dict): | ||
| subnet_id = first.get("subnet_id") | ||
| else: | ||
| subnet_id = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| subnet_id = None |
반복문 시작 시 subnet_id=None으로 초기화하므로, else 블록의 초기화 로직은 제거해도 될 것 같습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵! 반영되었습니다 ㅎㅎ
S0okJu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^-^... 위에 요청사항 적어뒀습니다.
S0okJu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 LGTM
Overview
Key Changes
Related Issues
Additional context