XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    How to Use xo-cli to Get network=<XCP_Network_UUID> and sr=<XCP_SR_UUID> for vm.importFromEsxi Command?

    Scheduled Pinned Locked Moved REST API
    14 Posts 3 Posters 226 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      jcharles
      last edited by

      Hi, I want to script the migration of vmware to xcp-ng. As the estate of xcp-ng grows it will make looking up the information more and more complicated,

      Thanks

      J 1 Reply Last reply Reply Quote 0
      • J Offline
        john.c @jcharles
        last edited by john.c

        @jcharles said in How to Use xo-cli to Get network=<XCP_Network_UUID> and sr=<XCP_SR_UUID> for vm.importFromEsxi Command?:

        Hi, I want to script the migration of vmware to xcp-ng. As the estate of xcp-ng grows it will make looking up the information more and more complicated,

        Thanks

        Have you checked out V2V (VMware to Vates) present in Xen Orchestra yet? It will perform this migration process for you, catching and dealing with any gotcha's along the way. People have been finding and reporting them for several years now, then Vates updates the feature to fix.

        Also Xen Orchestra integrates currently with NetBox software as a source of truth for the network.

        https://docs.xcp-ng.org/installation/migrate-to-xcp-ng/#xo-v2v

        1 Reply Last reply Reply Quote 0
        • J Offline
          jcharles
          last edited by

          Hi,
          Yes I have used that but it is a GUI and I have thousands of VM guests to migrate from Vmware to xcp-ng. So I would like to write a script to migrate the using the xo-cli vm.importFromEsxi. I am new to xcp-ng as getting this type of information is very easy in vmware with it powershell powercli. I have tied the following code but it gets multiple UUID's.

          Define variables for pool name and VLAN

          $poolName = "Dev-Pool" # Replace with your pool name
          $vlan = 8 # Replace with your VLAN ID

          Load the JSON data

          $jsonData = xo-cli list-objects | ConvertFrom-Json -AsHashTable

          Find the pool UUID based on the pool name

          $poolUUID = ($jsonData | Where-Object { $.type -eq "pool" -and $.name_label -eq $poolName }).uuid

          Find the SR UUID associated with the pool

          $srUUID = ($jsonData | Where-Object { $.type -eq "VDI" -and $.'$pool' -eq $poolUUID }).'$SR'

          Find the Network UUID associated with the VLAN and pool

          $networkUUID = ($jsonData | Where-Object { $.type -eq "PIF" -and $.vlan -eq $vlan -and $_.'$pool' -eq $poolUUID }).'$network'

          Output the results

          Write-Output "SR UUID: $srUUID"
          Write-Output "Network UUID: $networkUUID"

          J 1 Reply Last reply Reply Quote 0
          • J Offline
            john.c @jcharles
            last edited by

            @jcharles said in How to Use xo-cli to Get network=<XCP_Network_UUID> and sr=<XCP_SR_UUID> for vm.importFromEsxi Command?:

            Hi,
            Yes I have used that but it is a GUI and I have thousands of VM guests to migrate from Vmware to xcp-ng. So I would like to write a script to migrate the using the xo-cli vm.importFromEsxi. I am new to xcp-ng as getting this type of information is very easy in vmware with it powershell powercli. I have tied the following code but it gets multiple UUID's.

            Define variables for pool name and VLAN

            $poolName = "Dev-Pool" # Replace with your pool name
            $vlan = 8 # Replace with your VLAN ID

            Load the JSON data

            $jsonData = xo-cli list-objects | ConvertFrom-Json -AsHashTable

            Find the pool UUID based on the pool name

            $poolUUID = ($jsonData | Where-Object { $.type -eq "pool" -and $.name_label -eq $poolName }).uuid

            Find the SR UUID associated with the pool

            $srUUID = ($jsonData | Where-Object { $.type -eq "VDI" -and $.'$pool' -eq $poolUUID }).'$SR'

            Find the Network UUID associated with the VLAN and pool

            $networkUUID = ($jsonData | Where-Object { $.type -eq "PIF" -and $.vlan -eq $vlan -and $_.'$pool' -eq $poolUUID }).'$network'

            Output the results

            Write-Output "SR UUID: $srUUID"
            Write-Output "Network UUID: $networkUUID"

            @Danp Perhaps this is an area where V2V can be improved, if it doesn't have it already. The ability to setup a batch migration of VMs where it can handle hundreds, to thousands at the same time.

            DanpD 1 Reply Last reply Reply Quote 0
            • J Offline
              jcharles
              last edited by

              Hi,
              Importing from hundreds of vmware hosts each using different passwords would be a nightmare to setup in the V2V GUI, unless you access the vmware vcenter to copy the vmdk files from vmware.
              So for my original question is there a way I can write a script using xo-cli to get the network=<XCP_Network_UUID> and sr=<XCP_SR_UUID> information. With this and ability to monitor migration tasks using xo-cli (that will be another forum post) I will be able to script the migration.
              Thanks

              1 Reply Last reply Reply Quote 0
              • DanpD Offline
                Danp Pro Support Team @john.c
                last edited by

                @john.c IDK about hundreds /thousands, but the V2V process will allow you to import multiple VMs simultaneously.

                1 Reply Last reply Reply Quote 0
                • J Offline
                  jcharles
                  last edited by

                  The vm guests are located on hundreds of different esxi hosts in a large number of different data centres. At the moment the V2V only allows a single esxi host login at a time which limits the number of vm guests I can setup and process.

                  I get the feeling the xo-cli will not supply the information I need for my script. Do you have a powershell module for xcp-ng like VMware powercli which gives you the ability to write very complex scripts.

                  Thanks

                  J 1 Reply Last reply Reply Quote 0
                  • J Offline
                    john.c @jcharles
                    last edited by john.c

                    @jcharles said in How to Use xo-cli to Get network=<XCP_Network_UUID> and sr=<XCP_SR_UUID> for vm.importFromEsxi Command?:

                    The vm guests are located on hundreds of different esxi hosts in a large number of different data centres. At the moment the V2V only allows a single esxi host login at a time which limits the number of vm guests I can setup and process.

                    I get the feeling the xo-cli will not supply the information I need for my script. Do you have a powershell module for xcp-ng like VMware powercli which gives you the ability to write very complex scripts.

                    Thanks

                    Do you have VMware vCenter Server (VCSA)?

                    1 Reply Last reply Reply Quote 0
                    • J Offline
                      jcharles
                      last edited by

                      yes we have vmware vcenter but V2V does not interface with that.

                      thanks

                      J 1 Reply Last reply Reply Quote 0
                      • J Offline
                        john.c @jcharles
                        last edited by john.c

                        @jcharles said in How to Use xo-cli to Get network=<XCP_Network_UUID> and sr=<XCP_SR_UUID> for vm.importFromEsxi Command?:

                        yes we have vmware vcenter but V2V does not interface with that.

                        thanks

                        Actually it does with the current stable (or latest) update with the appropriate channel when using XOA. The host IP field can refer to ESXi Host but can also be the IP address of the VMware vCenter Server.

                        Just note that it may only include VMs present in the VMware vCenter Server's inventory. Any not currently registered may not be included.

                        1 Reply Last reply Reply Quote 1
                        • J Offline
                          jcharles
                          last edited by

                          Thanks that worked. I give that a go thanks

                          J 1 Reply Last reply Reply Quote 1
                          • J Offline
                            john.c @jcharles
                            last edited by

                            @jcharles said in How to Use xo-cli to Get network=<XCP_Network_UUID> and sr=<XCP_SR_UUID> for vm.importFromEsxi Command?:

                            Thanks that worked. I give that a go thanks

                            Your welcome.

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post