Oneswap convert ESXI undefined method `to_hash' for nil:NilClass

HI @ nhansen

I’m attempting to run oneswap for the first time and I’m stuck getting started.
I’ve attended and watched a couple webinars on oneswap and followed the wiki, but I can’t get past this error. I’m guessing I’m missing a required arg - thus the NULL value, but I can’t figure out which one … if that is the reason.

Any hint as to what this is failing on?
BTW this was a git clone from today. I ran “./install.sh -c”

I’ve tried running as root and oneadmin, same results

git clone https://github.com/OpenNebula/one-swap.git


oneadmin@onedeploy-3:~$ 
oneadmin@onedeploy-3:~$ oneswap convert 'clone-smoke2-tools-host-convert'  --verbose 
Deleting password files.
Delete not enabled, leaving disks in /tmp/clone-smoke2-tools-host-convert/conversions
Delete not enabled, leaving /tmp/clone-smoke2-tools-host-convert alone.
undefined method `to_hash' for nil:NilClass
oneadmin@onedeploy-3:~$

oneadmin@onedeploy-3:~$ ls -lrht  /tmp/clone-smoke2-tools-h*
total 8.0K
drwxrwxr-x 2 oneadmin oneadmin 4.0K Feb 25 23:35 transfers
drwxrwxr-x 2 oneadmin oneadmin 4.0K Feb 25 23:35 conversions
oneadmin@onedeploy-3:~$ ls -lrht  /tmp/clone-smoke2-tools-h*/*
/tmp/clone-smoke2-tools-host-convert/transfers:
total 0

/tmp/clone-smoke2-tools-host-convert/conversions:
total 0
oneadmin@onedeploy-3:~$ ls -lrht /var/log/one/oneswa* 
-rw-rw-r-- 1 oneadmin oneadmin 0 Feb 25 23:34 /var/log/one/oneswap.stdout
-rw-rw-r-- 1 oneadmin oneadmin 0 Feb 25 23:34 /var/log/one/oneswap.stderr
oneadmin@onedeploy-3:~$ 

I

I’m trying to use ssh to ESXI host as my convert option. Its all in the same lab, so I figured that would be the fastest method for me.

I’m running this on a functional OneDeploy 6.10.0 setup. Front-end and onecli working fine. Its on a new install of Ubuntu24.04 as well. I check and the requied oneswap packages are there.

oneswap can communicate with my vcenter fine and list the VM I’m looking for.

oneadmin@onedeploy-3:~$ oneswap list vms | grep clone-smoke2-tools-h
vm-27436 clone-smoke2-tools-h poweredOff HostSystem 2   8192    4226f1aa-34d5-6072-cf37-041304e5e013
oneadmin@onedeploy-3:~$ 

From this same host I can manually ssh into the ESXI listed with user/pass provided just fine. I also set the VCENTER_NETWORK_MATCH attritubes on my two vnets.

I had seen in another post to turn on DEBUG mode at oneswap_helper.rb. It seems I’m failing before that as those files are created, but zero length.

I have the following in /var/lib/one/oneswap.yaml I also tried with value on command line, but had the same result.

(change value for this post from my real host/password)


oneadmin@onedeploy-3:~$ cat oneswap.yaml pwd
# OpenNebula Transfer Options, required for remote OpenNebula server
:http_transfer: false      # Enable HTTP transfer
#:http_host: '192.168.0.10' # Hostname of this server
#:http_port: 29869          # HTTP Port to transfer over

# vCenter Authentication
:vcenter: 'laasdev-vcenter'              # vCenter hostname or IP
:vuser: 'myuser@vsphere.local' # vCenter username
:vpass: 'mypass'                 # vCenter password
:port: 443                            # vCenter port

# ESXi Authentication
:esxi_ip: 'lassdev-m4-40g-h5'  # ESXi hostname or IP
:esxi_user: 'root'        # ESXi username
:esxi_pass: 'mypass@123' # ESXi password

# Transfer Options
#:custom_convert: # Uses OpenNebula's custom conversion process, useful for distributions which are not supported or fail to convert
#:fallback:       # Fallback to OpenNebula's custom conversion process
#:hybrid:         # Transfer using rbvmomi2's download, then convert with virt-v2v locally
#:img_wait:       # Amount of time to wait in seconds for image to be created in OpenNebula, default: 120

# NIC Options
:network: 25      # ID of the OpenNebula network
:skip_ip: true # Do not create IP in OpenNebula network
:skip_mac: true # Do not create MAC in OpenNebula network

# Datastore Options
:datastore: 1    # ID of the OpenNebula Image datastore

# virt-v2v Options
#:work_dir: '/tmp'                        # Directory where disk conversion takes place, will make subdir for each VM
:format: 'qcow2'                         # Disk format [ qcow2 | raw ]
#:vddk_path:                              # Path to VDDK library
#:qemu_ga_win:                            # Path to QEMU Guest Agent ISO for Windows
#:qemu_ga_linux:                          # Install QEMU Guest Agent for Linux
#:virtio_path:                            # Path to VirtIO drivers for Windows
#:virt_tools: /usr/local/share/virt-tools # Path to the directory containing rhsrvany.exe
#:v2v_path: 'virt-v2v'                    # Path to virt-v2v

# Extra Options
#:delete: false                     # Delete the VM Disks after transfer
#:context: '/var/lib/one/context/'  # Path to OpenNebula context packages

# OpenNebula Placement Options
:one_cluster: 0           # ID of the OpenNebula Cluster
:one_host: 0              # ID of the OpenNebula Host
:one_datastore: 0         # ID of the OpenNebula System Datastore
#:one_datastore_cluster: # ID of the OpenNebula Cluster for automatic Datastore assignment

# Extra VM Options:
#:dev_prefix:                 # Device prefix for the VM disks ex: sd, hd, vd
#:cpu_model:                  # CPU model
#:graphics_type:              # Graphics type: vnc, sdl, spice
#:graphics_listen:            # Graphics listen IP
#:graphics_port:              # Graphics port
#:graphics_keymap:            # Graphics keymap
#:graphics_password:          # Graphics password
#:graphics_command:           # Graphics command
#:disable_contextualization:  # Remove default contextualization options in OpenNebula, Default: Network and SSH enabled
#:persistent_img:             # Persistent Image, default: false
#:memory_max:                 # Memory max in MB
#:vcpu_max:                   # vCPU max allowed in integer format. CPU Hot Add required in VMWare.
#:cpu:                        # Physical CPU allowed in integer format. Default: match CPU cores from vCenter
#:vcpu:                       # vCPU allowed in integer format. Default: match CPU cores from vCenter


Thank you for your time and help,

–Ken

Ok, I found it. I started reviewing the code to find matching to_hash. It is failing here: (added a few prints to ensure I was in the location I thought)

root@onedeploy-3:/var/lib/one# rm /var/log/one/oneswap.std* ; oneswap convert 'clone-smoke2-tools-host-convert2'  --verbose
Ken before distributed_networks.find
Ken commneted out cleanup_all
undefined method `to_hash' for nil:NilClass
root@onedeploy-3:/var/lib/one# 

/usr/lib/one/ruby/cli/one_helper/oneswap_helper.rb
@ distributed_networks.find { |dn| dn.to_hash

        nic_backing = vc_nics.map do |n|
            if n[:backing].is_a? RbVmomi::VIM::VirtualEthernetCardDistributedVirtualPortBackingInfo
                puts "Ken before distributed_networks.find"
                ds_network = distributed_networks.find { |dn| dn.to_hash['key'] == n[:backing][:port][:portgroupKey] }
                [n[:key], ds_network.to_hash['name']]
                puts "Ken after distributed_networks.find ds_network =##{ds_network}"
            else

We might be a bit odd in our use-case. This was not a running VM. We have many VM-templates that we clone new VMs from. I did convert this to a VM for oneswap, but didn’t add NICs to DVSwitch. We have X VNICs predefined and our automation on vmware would add to DVS at launch time. Oneswap is failing on this. I added DVS assignments to the nic at vcenter and now its proceeding.

Here is screen shot of what the VM looked like before

I’m all set on this pariticular error.

Thanks!

–Ken

Thanks for the good information and great debugging work. I’ll see if there’s a good workaround so I can test this sometime but as you say it’s a bit of a weird case. It was able to detect distributed port groups and the backing was of the type we expect it to be, but then the networks to not have any keys.

Glad to hear things have been fixed for you. We will either update the code or the documentation. Thanks!

1 Like