v0.0.17 | 보안그룹 관리 API 추가 (CRUD + 규칙 CRUD)
All checks were successful
Build And Test / build-and-push (push) Successful in 53s
All checks were successful
Build And Test / build-and-push (push) Successful in 53s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -254,6 +254,103 @@ class ApiVpc(BaseAPI):
|
||||
url = f"{self.vpc_url}/v2.0/security-groups/{security_group_id}"
|
||||
return self._get(url)
|
||||
|
||||
def create_security_group(self, name: str, description: str = "") -> dict:
|
||||
"""
|
||||
보안 그룹 생성
|
||||
|
||||
Args:
|
||||
name: 보안 그룹 이름
|
||||
description: 설명
|
||||
|
||||
Returns:
|
||||
dict: 생성된 보안 그룹 정보
|
||||
"""
|
||||
url = f"{self.vpc_url}/v2.0/security-groups"
|
||||
payload = {"security_group": {"name": name, "description": description}}
|
||||
logger.info(f"보안 그룹 생성 요청: {name}")
|
||||
return self._post(url, payload)
|
||||
|
||||
def update_security_group(self, security_group_id: str, name: str = None, description: str = None) -> dict:
|
||||
"""보안 그룹 수정"""
|
||||
url = f"{self.vpc_url}/v2.0/security-groups/{security_group_id}"
|
||||
payload = {"security_group": {}}
|
||||
if name is not None:
|
||||
payload["security_group"]["name"] = name
|
||||
if description is not None:
|
||||
payload["security_group"]["description"] = description
|
||||
logger.info(f"보안 그룹 수정 요청: {security_group_id}")
|
||||
return self._put(url, payload)
|
||||
|
||||
def delete_security_group(self, security_group_id: str) -> dict:
|
||||
"""보안 그룹 삭제"""
|
||||
url = f"{self.vpc_url}/v2.0/security-groups/{security_group_id}"
|
||||
logger.info(f"보안 그룹 삭제 요청: {security_group_id}")
|
||||
return self._delete(url)
|
||||
|
||||
# ==================== Security Group Rule ====================
|
||||
|
||||
def get_security_group_rule_list(self, security_group_id: str = None) -> dict:
|
||||
"""보안 그룹 규칙 목록 조회"""
|
||||
url = f"{self.vpc_url}/v2.0/security-group-rules"
|
||||
params = {}
|
||||
if security_group_id:
|
||||
params["security_group_id"] = security_group_id
|
||||
return self._get(url, params=params if params else None)
|
||||
|
||||
def create_security_group_rule(
|
||||
self,
|
||||
security_group_id: str,
|
||||
direction: str,
|
||||
ethertype: str = "IPv4",
|
||||
protocol: str = None,
|
||||
port_range_min: int = None,
|
||||
port_range_max: int = None,
|
||||
remote_ip_prefix: str = None,
|
||||
remote_group_id: str = None,
|
||||
description: str = "",
|
||||
) -> dict:
|
||||
"""
|
||||
보안 그룹 규칙 생성
|
||||
|
||||
Args:
|
||||
security_group_id: 보안 그룹 ID
|
||||
direction: 방향 (ingress/egress)
|
||||
ethertype: IPv4/IPv6
|
||||
protocol: 프로토콜 (tcp/udp/icmp 등)
|
||||
port_range_min: 최소 포트
|
||||
port_range_max: 최대 포트
|
||||
remote_ip_prefix: 원격 IP 대역 (CIDR)
|
||||
remote_group_id: 원격 보안 그룹 ID
|
||||
description: 설명
|
||||
"""
|
||||
url = f"{self.vpc_url}/v2.0/security-group-rules"
|
||||
rule = {
|
||||
"security_group_id": security_group_id,
|
||||
"direction": direction,
|
||||
"ethertype": ethertype,
|
||||
}
|
||||
if protocol:
|
||||
rule["protocol"] = protocol
|
||||
if port_range_min is not None:
|
||||
rule["port_range_min"] = port_range_min
|
||||
if port_range_max is not None:
|
||||
rule["port_range_max"] = port_range_max
|
||||
if remote_ip_prefix:
|
||||
rule["remote_ip_prefix"] = remote_ip_prefix
|
||||
if remote_group_id:
|
||||
rule["remote_group_id"] = remote_group_id
|
||||
if description:
|
||||
rule["description"] = description
|
||||
payload = {"security_group_rule": rule}
|
||||
logger.info(f"보안 그룹 규칙 생성 요청: sg={security_group_id}, dir={direction}, proto={protocol}")
|
||||
return self._post(url, payload)
|
||||
|
||||
def delete_security_group_rule(self, rule_id: str) -> dict:
|
||||
"""보안 그룹 규칙 삭제"""
|
||||
url = f"{self.vpc_url}/v2.0/security-group-rules/{rule_id}"
|
||||
logger.info(f"보안 그룹 규칙 삭제 요청: {rule_id}")
|
||||
return self._delete(url)
|
||||
|
||||
# ==================== Port (NIC) ====================
|
||||
|
||||
def get_port_list(self) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user