Developing Products for Citrix Hypervisor

Explore SDKs and Tools

This article was initially published by Cheng Zhang in October, 2016:

A BIT OF WHY

For a XenServer Virtual Machine(VM) administrator, traditional way to set a static IP to a VM maybe not that direct. That is because XenServer do not provide API to set VM IP address from any management tool in history. To change the IP setting for a VM in XenServer, you will need to email the VM user and let them to do the setting manually. Or you may need to install some 3rd party tools to help you to set the IP address to the VM. For create new VM for users by VM clone, set IP maybe means multiple time of reboot.

To provide a better user experience, XenServer is now trying to provides easier way to set static IP address to Guest VM.

SET STATIC IP FOR XENSERVER 7.0 WINDOWS GUEST VM

XenServer 7.0 now have the ability to set Windows guest VM IP address by below interfaces:

•   IPv4

•                     Set VM IPv4 address by command line interface(CLI):

•                     xe vif-configure-ipv4 address=  gateway=  mode=[static/none] uuid=

•                     Set VM IPv4 address by XAPI

•                     VIF.configure_ipv4(vifObject, "static/none", "Some IP address", "some gateway address")

•   IPv6

•                     Set VM IPv6 address by command line interface(CLI):

•                     xe vif-configure-ipv6 address=  gateway=  mode=[static/none] uuid=

•                     Set VM IPv6 address by XAPI

•                     VIF.configure_ipv6(vifObject, "static/none", "Some IP address", "some gateway address")

 

Note:

The mode "none" means remove the current static IP setting and back to DHCP mode. If the static IP is not set by new interface, use the command to set the mode to "none" only do nothing.

DIVE INTO DETAILS

Below diagram show how the configuration goes:

By using the interface:

1. XAPI will first store the IP configuration to XenStore as:

/local/domain//xenserver/device/vif= ""

  static-ip-setting = ""

     mac = "some mac address"

     error-code = "some error code"

     error-msg = "some error message"

     address = "some IP address"

     gateway = "some gateway address"

 

2. XenStore will notify the change to XenServer Guest agent tool of the configuration change.

 

3. XenServer guest agent receives the notification and sets IP address using netsh.

 

4. After setting IP address, XenServer guest agent then writes the operation result to xenstore key as: error-code and error-msg

 

EXAMPLE

 

1. INSTALL XENSERVER PV TOOL TO WINDOWS GUEST VM.

 

2. FROM THE COMMAND LINE INTERFACE (CLI), IDENTIFY THE VIRTUAL NETWORK INTERFACE / VIRTUAL INTERFACE(VIF) YOU WANT TO SET THE IP ADDRESS BY:

 

[root@dt65 ~]# xe vm-vif-list vm=Windows 7 (32-bit) (1) 

uuid ( RO)                         : 7dc56d5b-492c-bcf5-2549-b580dc928274

        vm-name-label ( RO): Windows 7 (32-bit) (1)

                     device ( RO): 1

                        MAC ( RO): 3e:aa:c3:dd:a7:ba

           network-uuid ( RO): 98f9a3b6-ad3f-14b3-da59-e3abc888e58e

network-name-label ( RO): Pool-wide network associated with eth1

 

uuid ( RO)                         : 0f59a97b-afcf-b6db-582d-2411d5bbc449

        vm-name-label ( RO): Windows 7 (32-bit) (1)

                     device ( RO): 0

                        MAC ( RO): 62:a1:03:31:a3:ee

           network-uuid ( RO): 41dac7d6-4a11-c9e6-cc48-ded78ceaf446

network-name-label ( RO): Pool-wide network associated with eth0

 

3. Call new interface to set IP address as:

 

[root@dt65 ~]# xe vif-configure-ipv4 uuid=0f59a97b-afcf-b6db-582d-2411d5bbc449 mode=static address=10.64.5.6/24 gateway=10.64.5.1

 

4. Check result by XenStore error code key "error-code" and "error-msg" as:

 

[root@XenServer ~]# xenstore-ls /local/domain/13/xenserver/device/vif

0 = ""

  static-ip-setting = ""

     mac = "62:a1:03:31:a3:ee"

     error-code = "0"

     error-msg = ""

     address = "10.64.5.6/24"

     gateway = "10.64.5.1"

  1 = ""

     static-ip-setting = ""

     mac = "3e:aa:c3:dd:a7:ba"

     error-code = "0"

     error-msg = ""

Additional Citrix Developer Learning Resources

Create your Citrix Developer account today
An account gives you access to all of the benefits of the Citrix Developer community.

You built a great solution integrating with Citrix APIs, now continue the next step of your journey with Citrix Ready.