Skip to content

Conversation

@platanus-kr
Copy link
Collaborator

@platanus-kr platanus-kr commented Oct 14, 2025

Overview

  • Add Security Group features to Network tools

Key Changes

  • Add Security group
  • Update Security group
  • Delete Security group
  • Get Security group
  • Get Security group list

Related Issues

Additional context

스크린샷 2025-10-14 11 57 45
스크린샷 2025-10-14 11 57 52

@platanus-kr platanus-kr self-assigned this Oct 14, 2025
@platanus-kr platanus-kr added the feature Request for new feature or functionality enhancement label Oct 14, 2025
@platanus-kr platanus-kr changed the title feat(network): Add security group tools (#85) feat: Add security group tools Oct 14, 2025
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.

현재 코드에는 security group의 속성만 관리하고, security group rule를 관리(추가 및 해제) 기능이 생략된 것 같습니다.
이 부분에 대해 추가 계획이 있으신가요?

if isinstance(r, dict):
rid = r.get("id")
else:
rid = getattr(r, "id", None)
Copy link
Collaborator

@S0okJu S0okJu Oct 14, 2025

Choose a reason for hiding this comment

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

getattr 으로 속성을 확인하신 이유가 궁금합니다.

Copy link
Collaborator Author

@platanus-kr platanus-kr Oct 14, 2025

Choose a reason for hiding this comment

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

security group에 rule이 없을때 None을 반환하는 로직입니다~

아래 승주님 의견받아 rule 객체로 변환하면서 해당 로직은 사라졌습니다!

Comment on lines 1273 to 1289
def _convert_to_security_group_model(self, openstack_sg) -> SecurityGroup:
"""
Convert an OpenStack Security Group object to a SecurityGroup pydantic model.
:param openstack_sg: OpenStack security group object
:return: Pydantic SecurityGroup model
"""
rule_ids: list[str] | None = None
rules = getattr(openstack_sg, "security_group_rules", None)
if rules is not None:
extracted: list[str] = []
for r in rules:
rid = None
if isinstance(r, dict):
rid = r.get("id")
else:
rid = getattr(r, "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.

private 함수 없이 Pydantic 객체로 변환하는게 불가능한가요?, 복잡한 변환이 아니여서 함수없이도 충분히 가능해보입니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

문자열 리스트가 아닌 보안그룹 규칙 객체로 반환하도록 개선하겠습니다!

@platanus-kr
Copy link
Collaborator Author

platanus-kr commented Oct 14, 2025

@S0okJu

현재 코드에는 security group의 속성만 관리하고, security group rule를 관리(추가 및 해제) 기능이 생략된 것 같습니다.
이 부분에 대해 추가 계획이 있으신가요?

넵. 이 다음에 rules 랑 port-securitygroup 바인딩 관련 이어서 진행하려고 합니다
#87

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

Copy link
Collaborator

@jja6312 jja6312 left a comment

Choose a reason for hiding this comment

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

저는 한 가지 의견을 제외하고는 이견이 없습니다!👍

def get_security_groups(
self,
project_id: str | None = None,
name: str | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

이미 훌륭한 코드에 한 가지 제 생각을 덧붙여보자면, id필드가 있으면 더 좋지 않을까 생각이 듭니다.
id가 필요없을까? 생각에서 뻗어나갔는데요,
security group은 name을 중복값으로 생성할 수 있을텐데,
만약 조금 복잡하게 질문해서

  • 전제: 중복된 security name이 많음
  • 프롬프트: "instance중에 tag가 prod인 인스턴스들을 조회하고, 그 인스턴스들이 어떤 security group을 쓰는지 조회해줘"
    라고 했을 때,
    기존 프로젝트의 compute에서는 return은 id와 name 모두를 반환하므로 get_security_group_detail 함수에 id를 통해 정확히 조회해준다면 아름답겠지만, 자칫 get_security_groups의 name으로 조회하게된다면, 결과를 보장하기 힘들 것 같습니다.
    그런데 id필드가 있으면 적어도 이 케이스에 대해서는 안전할 것 같습니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그러네요 ID 필드 추가하도록 하겠습니다!

Copy link
Collaborator

@halucinor halucinor 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 5d7a207 into develop Oct 19, 2025
6 checks passed
halucinor pushed a commit that referenced this pull request Oct 23, 2025
* feat(network): Add security group tools (#85)

* improve(network): change to convert security group rules into objects during security group conversion (#85)

* improve(network): remove unnecessary None checks for network, subnet, port, floating ip, router, security group (#85)

* fix(network): add id field to get security group (#85)

* fix(network): remove unnecessary None checks (#85)

* fix(network): integrate test (#85)
halucinor pushed a commit that referenced this pull request Oct 24, 2025
* feat(network): Add security group tools (#85)

* improve(network): change to convert security group rules into objects during security group conversion (#85)

* improve(network): remove unnecessary None checks for network, subnet, port, floating ip, router, security group (#85)

* fix(network): add id field to get security group (#85)

* fix(network): remove unnecessary None checks (#85)

* fix(network): integrate test (#85)
@halucinor halucinor deleted the feat/security-group-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

feature Request for new feature or functionality enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants