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

Is there any reason retrieve IP every time in Hyper-V? #31

Open
lingsamuel opened this issue Jan 21, 2021 · 3 comments · May be fixed by #32
Open

Is there any reason retrieve IP every time in Hyper-V? #31

lingsamuel opened this issue Jan 21, 2021 · 3 comments · May be fixed by #32

Comments

@lingsamuel
Copy link

Inside Start, we already set IPAddress

func (d *Driver) Start() error {
if err := cmd("Hyper-V\\Start-VM", d.MachineName); err != nil {
return err
}
ip, err := d.waitForIP()
if err != nil {
return err
}
d.IPAddress = ip

But inside GetIP, we retrieve IP instead of use cached value.

func (d *Driver) GetIP() (string, error) {
s, err := d.GetState()
if err != nil {
return "", err
}
if s != state.Running {
return "", drivers.ErrHostIsNotRunning
}
stdout, err := cmdOut("((", "Hyper-V\\Get-VM", d.MachineName, ").networkadapters[0]).ipaddresses[0]")
if err != nil {
return "", err
}
resp := parseLines(stdout)
if len(resp) < 1 {
return "", fmt.Errorf("IP not found")
}
return resp[0], nil
}

@lingsamuel
Copy link
Author

By this simple patch, we could reduce a huge latency (each cmdOut takes about 1s).

@afbjorklund
Copy link

I think it got changed along the way: fa8fa69

Before, it would allow running with DHCP (just like in the VirtualBox driver)

Can you open a PR in docker/machine as well, just for showing good will ?

Given implementation, your optimization sounds doable.

@lingsamuel
Copy link
Author

Opened docker#4870

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 a pull request may close this issue.

2 participants