Skip to content
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

Add netutil pacakge and example initially #1413

Merged
merged 3 commits into from
Jan 10, 2024

Conversation

yunkon-kim
Copy link
Member

Ref. #1412

This PR will add netutil package and example initially.

I'm not sure if I created the files in each appropriate directory.
If there is a suitable location, please feel free to let me know. 😃

@seokho-son
Copy link
Member

Regarding the path,
How about examples/netutil/netutil.go -> src/examples/netutil/netutil.go ? considering all *.go files are in src dir.

@yunkon-kim
Copy link
Member Author

@seokho-son Thanks for your comment.

I'm going to relocate the example directory and file :)

* Relocate `netutil` example
* Add README.md to run the example
@yunkon-kim
Copy link
Member Author

Note - Amend and force-push to resolve Codacy issue

Copy link
Member

@seokho-son seokho-son left a comment

Choose a reason for hiding this comment

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

@yunkon-kim 기여 감사합니다! 매우 유용할 것 같습니다. ㅎㅎ
코드상 몇 가지 질문이 있어서 의견으로 남겨두었습니다.

func main() {
fmt.Println("netuil example")

cidrBlock := "192.168.0.0/16"
Copy link
Member

Choose a reason for hiding this comment

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

개발자가 다양한 구성을 테스트해볼 수 있도록, 현재 고정값으로 지정된 주요 변수들을 arg 로도 입력할 수 있도록 지원 가능하실까요?
그리고 관련 변수들(개발자가 기본값을 코드상에서 수정한다는 가정하에)은 위쪽에 모아두면 좋을 것 같아 보입니다. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@seokho-son 일단은 CIDR block, MinimumSubnetCount, SizeOfHosts 세 가지 정도를 args 값으로 입력할 수 있도록 개선을 진행하겠습니다.

Comment on lines 44 to 48
NetworkAddress string // 192.168.0.0
BroadcastAddress string // 192.168.0.255
Prefix int // 24
Netmask string // 255.255.255.0
HostCapacity int // 254
Copy link
Member

Choose a reason for hiding this comment

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

CIDRBlock 만 주어지면 모두 단순 계산해서 리턴 가능한 값들이지 않을까요?
제거하면, 모델의 구조를 매우 단순하게 제공할 수 있을 것 같다는 생각이 듭니다. ^^
CIDRBlock 변경시, 해당 값들을 업데이트해줘야 하는 이슈도 없어지고 말이죠.

어떻게 생각하시나요~?

Copy link
Member Author

Choose a reason for hiding this comment

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

@seokho-son 네트워크를 구조체화 하는 정도의 차이로 생각됩니다. 다음 예를 포함하여 편의성을 위해 추가된 멤버 데이터 입니다.

myNet := New("192.168.42.0/23")
fmt.Print(Network: %+v\n, myNet) 

제안해 주신 사항을 반영하여 아래와 같이 개선하여 확장성을 지원하는 방향으로 수정하면 어떨까합니다. 괜찮을까요? ^^

type Network struct {
	Name      string    `json:"name"`
	CIDRBlock string    `json:"CIDRBlock"`
	Subnets   []Network `json:"Subnets,omitempty"`
}

type NetworkDetails struct {
	Network
	NetworkAddress   string `json:"NetworkAddress,omitempty"`
	BroadcastAddress string `json:"BroadcastAddress,omitempty"`
	Prefix           int    `json:"Prefix,omitempty"`
	Netmask          string `json:"Netmask,omitempty"`
	HostCapacity     int    `json:"HostCapacity,omitempty"`
}

현 버전의 netutil에서는 최초 Network Configuration에 초점이 맞춰져 있어 한번 생선된 네트워크 객제의 CIDR block의 업데이트하는 경우를 고려하고 있지 않습니다. ^^;;

마지막으로, 네트워크 정보의 업데이트가 필요한 케이스를 공유해주시면 업데이트 관련 기능 추가에 도움이 될 것 같습니다.

Copy link
Member

Choose a reason for hiding this comment

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

음~ 그럼. 일단 좀 사용해보고, 필요에 따라 개선해보면 좋을 것 같습니다. :)
as is 상태로 LGTM 입니다. :)

* Update models
* Add GetPrefix(), GetNetmask()
* Add Cobra  for enhanced CLI argument parsing and help functionality
@yunkon-kim
Copy link
Member Author

@seokho-son 논의사항 반영을 위한 Commit 올렸습니다 :-D

Copy link
Member

@seokho-son seokho-son left a comment

Choose a reason for hiding this comment

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

CLI를 달아주셨네요 ^^;;

Thanks! LGTM.

@seokho-son seokho-son merged commit 7489bff into cloud-barista:main Jan 10, 2024
3 checks passed
@yunkon-kim yunkon-kim deleted the yunkon-kim-240110 branch January 10, 2024 13:23
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.

2 participants