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] add hyper-v vm'ip to name translation #88

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JoJoJoinme
Copy link

Description

[Provide a brief description of the new feature you're adding.]
support hyper-v vm's ipv4 addr to domain name. adn the domain-name format is <-your-vmName->.example.com

Motivation and Context

[Explain why this feature is needed and what problem it solves.]
I meet same problem. 'the ip address of vm inside hyper-v changed everytime when system restart' Inspired by this project. I write a domain-name <---> ip addr translation function

How Has This Been Tested?

[Describe the tests you've run to verify your changes. Provide instructions so we can reproduce.]
Proof of Concept:
there are hyper-v api which you can get vm info(ip addr, vnName, etc..)managed by hyper-v

  1. get all runing vm info Get-VM | Where-Object {$_.State -eq 'Running'} | Select-Object-ExpandProperty Name
  2. get ip addr of running vm Get-VMNetworkAdapter -VMName <-put-your-vmName-> | Select-Object -ExpandProperty IPAddresses This must be run by Administrator

I solve the problem by writing a function to do the same thing

Screenshots (if appropriate):

[Add screenshots to help explain your feature, if applicable.]

No sceenshots but there are logs..

PS D:\Code\go-wsl2-host> .\wsl2host.exe debug
wsl2host.info(1): starting wsl2host service
Get running vm names [Fedora-39-2 win10-home]
vm:Fedora-39-2, ipInfo:ipv4:[172.17.116.89], ipv6:[fe80::215:5dff:fe00:104] vm:win10-home, ipInfo:ipv4:[172.17.112.60], ipv6:[fe80::d7bc:1e4f:3ca0:e1a0]
old hapi entry info:
map[Fedora-39-2.exmaple.com:id:23, ip:172.17.116.89,hostname:Fedora-39-2.exmaple.com, comment:managed by api - hyper-vm win10-home.exmaple.com:id:24, ip:172.17.112.60, hostname:win10-home.exmaple.com, comment:managed by api - hyper-vm]
upsert entry:id:0, ip:172.17.116.89, hostname:Fedora-39-2.exmaple.com, comment:managed by api - hyper-vm
upsert entry:id:0, ip:172.17.112.60, hostname:win10-home.exmaple.com, comment:managed by api - hyper-vm

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

Additional Notes

[Add any additional information that might be helpful for reviewers.]
Additional. I fix a bug of GetHostIP func which get gateway addr of wsl, and write a new func GetHostIPv2 which get result from api directly

Helious Wu and others added 2 commits August 10, 2024 15:23
support hyper-v vm's ipv4 addr to domain name. adn the domain-name format is <-your-vmName->.example.com

[Explain why this feature is needed and what problem it solves.]
I meet same problem. 'the ip address of vm inside hyper-v changed everytime when system restart'
Inspired by this project. I write a domain-name <---> ip addr translation function

And there are hyper-v api which you can get vm info(ip addr, vnName, etc..)managed by hyper-v
1. get all runing vm info
`Get-VM | Where-Object {$_.State -eq 'Running'} | Select-Object-ExpandProperty Name`
2. get ip addr of running vm
` Get-VMNetworkAdapter -VMName <-put-your-vmName-> | Select-Object -ExpandProperty IPAddresses`
This must be run by Administrator

[Describe the tests you've run to verify your changes. Provide instructions so we can reproduce.]
compile it and run.

[Add screenshots to help explain your feature, if applicable.]
No sceenshots but there are logs..
>
PS D:\Code\go-wsl2-host> .\wsl2host.exe debug
wsl2host.info(1): starting wsl2host service
Get running vm names [Fedora-39-2 win10-home]
vm:Fedora-39-2, ipInfo:ipv4:[172.17.116.89], ipv6:[fe80::215:5dff:fe00:104]
vm:win10-home, ipInfo:ipv4:[172.17.112.60], ipv6:[fe80::d7bc:1e4f:3ca0:e1a0]
old hapi entry info:map[Fedora-39-2.exmaple.com:id:23, ip:172.17.116.89, hostname:Fedora-39-2.exmaple.com, comment:managed by api - hyper-vm win10-home.exmaple.com:id:24, ip:172.17.112.60, hostname:win10-home.exmaple.com, comment:managed by api - hyper-vm]
upsert entry:id:0, ip:172.17.116.89, hostname:Fedora-39-2.exmaple.com, comment:managed by api - hyper-vm
upsert entry:id:0, ip:172.17.112.60, hostname:win10-home.exmaple.com, comment:managed by api - hyper-vm

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

- [ ] My code follows the code style of this project.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the **CONTRIBUTING** document.

[Add any additional information that might be helpful for reviewers.]
additional. I fix a bug of `GetHostIP` func which get gateway addr of wsl, and write a new func `GetHostIPv2` which get result from api directly
[ADD] add hyper-v vm'ip to name translation
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.

1 participant