Skip to content

Conversation

@platanus-kr
Copy link
Collaborator

Overview

  • Add Router interface to Network tools

Key Changes

Router interface tools

  • Add Interface to Router
  • Get Interfaces in Router
  • Delete Interface from Router

Related Issues

Additional context

스크린샷 2025-10-11 15 49 51 스크린샷 2025-10-11 16 09 14 스크린샷 2025-10-11 16 10 02

conn = get_openstack_conn()
args: dict = {}
if subnet_id is not None:
args["subnet_id"] = subnet_id
Copy link
Collaborator

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 조건문을 태우는게 더 우아한방식일까요?

Copy link
Collaborator Author

@platanus-kr platanus-kr Oct 11, 2025

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)

Copy link
Collaborator

@jja6312 jja6312 Oct 11, 2025

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문을 통해 철옹성 같은?ㅎㅎ 안전한 코드를 짜는게 좋은가 궁금하여 질문드렸습니다

Copy link
Collaborator Author

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
subnet_id = None

반복문 시작 시 subnet_id=None으로 초기화하므로, else 블록의 초기화 로직은 제거해도 될 것 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵! 반영되었습니다 ㅎㅎ

Copy link
Collaborator

@S0okJu S0okJu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^-^... 위에 요청사항 적어뒀습니다.

@platanus-kr platanus-kr requested review from S0okJu and jja6312 October 13, 2025 11:20
Copy link
Collaborator

@S0okJu S0okJu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 LGTM

@platanus-kr platanus-kr merged commit 3b04619 into develop Oct 13, 2025
6 checks passed
@platanus-kr platanus-kr self-assigned this Oct 14, 2025
halucinor pushed a commit that referenced this pull request Oct 23, 2025
* feat(network): add router interface tools (#82)

* improve(network): simplify if condition to adding router interface (#82)

* improve(network): simplify if condition to retrieving router interface (#82)
halucinor pushed a commit that referenced this pull request Oct 24, 2025
* feat(network): add router interface tools (#82)

* improve(network): simplify if condition to adding router interface (#82)

* improve(network): simplify if condition to retrieving router interface (#82)
@halucinor halucinor deleted the feat/router-interface-tools branch October 30, 2025 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants