Skip to content

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

Open

Description

@lingsamuel

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
}

Activity

  1. lingsamuel commented on Jan 21, 2021

    @lingsamuel
    Author

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

  2. afbjorklund commented on Feb 9, 2021

    @afbjorklund

    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.

  3. lingsamuel commented on Feb 18, 2021

    @lingsamuel
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions