ananace / fog-hyperv

Hyper-V provider for fog
MIT License
8 stars 1 forks source link

IP address change of provisioned VM #22

Closed Surja1997 closed 3 years ago

Surja1997 commented 3 years ago

Is there a way to change ip_address of the created HyperV VM , such that we can RDP into it. Right now, the only way is to use 'connect' option and then go in there and change TCP/IPv4 using GUI only.

PS- I see a field "ip_addresses" in network adapters, but unable to change it, there is no method as such.

Urgently need it for doing RDP.

In short- how to assign ip address to the generated HyperV Virtual machine using fog-hyperV?

ananace commented 3 years ago

Hello,

Hyper-V doesn't actually handle IP addresses, it only supports reading the value that the operating system has assigned to the virtual adapter. There's no way for the hypervisor to set this value, only the OS.
You can read and change the MAC address, as that's the hardware address, but the IP is handled on the operating system level and there's no method for Hyper-V to interfere there.

Surja1997 commented 3 years ago

Hello ,

First of all, you've done an excellent job developing this library. But what I want to do is - " After I create a VM, and attach all DVDs, HDDs, RAM etc, and it starts (compute.start_vm), how to use RDP (remote desktop protocol) to connect to the VM ? Right now we just click "connect" on the hyperV interface, but I want to use the VM I created using RDP so that an entire new window opens.

PS- for RDP, one needs IP address of the machine (the hyperV VM created), Username and password (of the installed OS in the created VM)


All we have achieved till now is creating and starting the VM with an OS (ex - MS server 2016) , but how to connect to it ??

If you could please help me with this it would be really helpful.

Thank you

On Sun, Jan 10, 2021, 7:46 PM ananace notifications@github.com wrote:

Hello,

Hyper-V doesn't actually handle IP addresses, it only supports reading the value that the operating system has assigned to the virtual adapter. There's no way for the hypervisor to set this value, only the OS. You can read and change the MAC address, as that's the hardware address, but the IP is handled on the operating system level and there's no method for Hyper-V to interfere there.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ananace/fog-hyperv/issues/22#issuecomment-757483229, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM56VLT2RNTPQHIW3HA7MMDSZGZCHANCNFSM4VSYUSEQ .

ananace commented 3 years ago

To connect to Hyper-V VMs before they have a running OS, you will RDP to the VM host and use the correct parameter for Hyper-V to pass the RDP connection on into the VM console.
https://superuser.com/questions/685968/directly-accessing-hyper-v-console-via-rdp - the answer contains information both for connecting with vmconnect and RDP on Windows, as well as FreeRDP otherwise.

If you - on the other hand - actually need to connect directly to the VM itself, then you will need to let it boot, have it install and run an operating system, let it get an IP address from your DHCP server, and then connect to that IP address.

Surja1997 commented 3 years ago

Thanks a ton, will check out the link you provided. Actually I don't want to connect to the hyperV VM without installing OS.

I am totally fine using any OS installation, preferably ms server.

But the scenario is,

I want a user input of a static IP address he wants via frontend, and somehow assign that IP address to my commissioned hyper VM, so that he can then connect to it. It's like how we provision VMs on Azure or VMware... We can set a static IP and then connect to it right ...

On Sun, Jan 10, 2021, 8:20 PM ananace notifications@github.com wrote:

To connect to Hyper-V VMs before they have a running OS, you will RDP to the VM host and use the correct parameter for Hyper-V to pass the RDP connection on into the VM console.

https://superuser.com/questions/685968/directly-accessing-hyper-v-console-via-rdp

  • the answer contains information both for connecting with vmconnect and RDP on Windows, as well as FreeRDP otherwise.

If you - on the other hand - actually need to connect directly to the VM itself, then you will need to let it boot, have it install and run an operating system, let it get an IP address from your DHCP server, and then connect to that IP address.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ananace/fog-hyperv/issues/22#issuecomment-757489026, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM56VLXEWNLCEY2EQ7F6G4TSZG5EVANCNFSM4VSYUSEQ .

ananace commented 3 years ago

What you will want to do for your use-case would be to set the VM's MAC address in your DHCP server to give it a fixed IP address.
Hyper-V is a regular hypervisor, one that only deals with the virtualization of hardware. The IP address that a running machine acquires isn't able to be decided by the network hardware, it's done on the OS level - either with a client that talks DHCP to get a lease on an address, or by statically configuring an IP address on the interface. Either way, Hyper-V is only able to affect the virtualized hardware itself, and the network adapter hardware itself doesn't have any say in this particular regard.

If other providers - cloud or not - allow for configuring the IP on a virtual machine inside of them, it's most likely done by them running a DHCP server internally which the VM will end up receiving the IP from. Or they're relying on the installation of VM tools, which would let the virtual machine communicate directly with the hypervisor to read a requested IP config and apply it on the OS level.

For my foreman_hyperv plugin, your scenario is done by; the user entering an IP in the Foreman interface when creating a host, a VM is then created in Hyper-V, launched for a second, before then being killed again so that Hyper-V has to generate a MAC address for it, then reconfigured to have that MAC address assigned statically to the adapter. After that, the DHCP server has an entry orchestrated to fix the chosen address to the generated MAC address, which the VM will then pick up when it next boots and runs a DHCP request.

Surja1997 commented 3 years ago

Thank you ananace for the insightful information. :) Will definitely look into it.

On Sun, Jan 10, 2021 at 11:42 PM ananace notifications@github.com wrote:

What you will want to do for your use-case would be to set the VM's MAC address in your DHCP server to give it a fixed IP address. Hyper-V is a regular hypervisor, one that only deals with the virtualization of hardware. The IP address that a running machine acquires isn't able to be decided by the network hardware, it's done on the OS level

  • either with a client that talks DHCP to get a lease on an address, or by statically configuring an IP address on the interface. Either way, Hyper-V is only able to affect the virtualized hardware itself, and the network adapter hardware itself doesn't have any say in this particular regard.

If other providers - cloud or not - allow for configuring the IP on a virtual machine inside of them, it's most likely done by them running a DHCP server internally which the VM will end up receiving the IP from. Or they're relying on the installation of VM tools, which would let the virtual machine communicate directly with the hypervisor to read a requested IP config and apply it on the OS level.

For my foreman_hyperv https://github.com/ananace/foreman_hyperv plugin, your scenario is done by; the user entering an IP in the Foreman interface when creating a host, a VM is then created in Hyper-V, launched for a second, before then being killed again so that Hyper-V has to generate a MAC address for it, then reconfigured to have that MAC address assigned statically to the adapter. After that, the DHCP server has an entry orchestrated to fix the chosen address to the generated MAC address, which the VM will then pick up when it next boots and runs a DHCP request.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ananace/fog-hyperv/issues/22#issuecomment-757518917, or unsubscribe https://github.com/notifications/unsubscribe-auth/AM56VLVKMGGI5UNWNXPPCHLSZHUZLANCNFSM4VSYUSEQ .