Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions playbooks/run_migration_from_conversion_host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
vars:
flavor_name_or_uuid: "{{ data.openstack.flavor_name_or_uuid }}"
vm_name: "{{ data.vm_name }}"
vm_dest_name: "{{ data.vm_dest_name | default('') }}"
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type ModuleArgs struct {
Cloud osm_os.DstCloud `json:"cloud"`
OsMigrateNicsFilePath string `json:"os_migrate_nics_file_path"`
VmName string `json:"vm_name"`
// DestName is an optional override for port naming.
// When provided it is used instead of SafeVmName(VmName).
DestName string `json:"destname"`
UsedMappedNetworks bool `json:"used_mapped_networks"`
SecurityGroups []string `json:"security_groups"`
NetworkName string `json:"network_name"`
Expand Down Expand Up @@ -181,7 +184,11 @@ func main() {
}
}
}
portName := fmt.Sprintf("%s-NIC-%d-VLAN-%s", moduleArgs.VmName, nicIndex, nic.Vlan)
portBaseName := moduleArgs.VmName
if moduleArgs.DestName != "" {
portBaseName = moduleArgs.DestName
}
portName := fmt.Sprintf("%s-NIC-%d-VLAN-%s", portBaseName, nicIndex, nic.Vlan)
port, err := osm_os.CreatePort(provider, portName, network.ID, nic.Mac, nic.Subnet,
moduleArgs.SecurityGroups, nic.FixedIPs)
if err != nil {
Expand Down
17 changes: 15 additions & 2 deletions plugins/modules/src/create_server/create_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"os"
moduleutils "vmware-migration-kit/plugins/module_utils"
"vmware-migration-kit/plugins/module_utils/ansible"
"vmware-migration-kit/plugins/module_utils/logger"
osm_os "vmware-migration-kit/plugins/module_utils/openstack"
Expand Down Expand Up @@ -62,6 +63,10 @@ type ModuleArgs struct {
Cloud osm_os.DstCloud `json:"cloud"`
State string `json:"state"`
Name string `json:"name"`
// DestName is an optional override for the OpenStack instance name.
// When provided it is used as-is, bypassing SafeVmName sanitisation.
// When absent, SafeVmName(Name) is used (default behaviour).
DestName string `json:"destname"`
Nics []interface{} `json:"nics"`
BootVolume string `json:"boot_volume"`
Volumes []string `json:"volumes"`
Expand All @@ -80,6 +85,14 @@ type ModuleResponse struct {
ID string `json:"id"`
}

// resolveInstanceName returns DestName if set, otherwise SafeVmName(Name).
func resolveInstanceName(args ModuleArgs) string {
if args.DestName != "" {
return args.DestName
}
return moduleutils.SafeVmName(args.Name)
Copy link
Copy Markdown
Contributor

@fdiazbra fdiazbra Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the import of the module is missing at the beginning of the file. Something like:
moduleutils "vmware-migration-kit/plugins/module_utils"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right! Yesterday while testing a new build I fixed it locally and forgot to push it. Sorry about that!

}

func success(changed bool, id string) {
res := ModuleResponse{
Changed: changed,
Expand Down Expand Up @@ -153,7 +166,7 @@ func main() {
}

ServerAgrs := osm_os.ServerArgs{
Name: moduleArgs.Name,
Name: resolveInstanceName(moduleArgs),
Flavor: moduleArgs.Flavor,
BootVolume: moduleArgs.BootVolume,
SecurityGroups: moduleArgs.SecurityGroups,
Expand All @@ -172,7 +185,7 @@ func main() {
}

ServerAgrs := osm_os.ServerArgs{
Name: moduleArgs.Name,
Name: resolveInstanceName(moduleArgs),
Flavor: moduleArgs.Flavor,
BootVolume: moduleArgs.BootVolume,
SecurityGroups: moduleArgs.SecurityGroups,
Expand Down
30 changes: 27 additions & 3 deletions plugins/modules/src/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ type MigrationConfig struct {
Server string
Libdir string
VmName string
// DestName is the optional destination name used for Cinder volume naming.
// If empty, SafeVmName(VmName) is used instead (default behaviour).
DestName string
VolumeAz string
VolumeType string
AssumeZero bool
Expand Down Expand Up @@ -104,6 +107,10 @@ type ModuleArgs struct {
Server string
Libdir string
VmName string
// DestName is the optional destination name used for Cinder volume naming.
// When provided, it replaces SafeVmName(VmName) for resource naming while
// VmName continues to be used to locate the VM in vCenter.
DestName string `json:"destname"`
VolumeAz string
VolumeType string
VolumeTypeMapping []VolumeTypeMapping `json:"volume_type_mapping"`
Expand All @@ -127,6 +134,16 @@ type ModuleArgs struct {
ExtraOpts string
}

// resourceName returns the name to use when creating OpenStack resources
// (Cinder volumes). If DestName is set it is used as-is; otherwise the
// VMware VM name is sanitised with SafeVmName.
func (c *MigrationConfig) resourceName(vmName string) string {
if c.DestName != "" {
return c.DestName
}
return moduleutils.SafeVmName(vmName)
}

func (c *MigrationConfig) VMMigration(parentCtx context.Context, runV2V bool) (string, error) {
syncVol := false
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -144,7 +161,7 @@ func (c *MigrationConfig) VMMigration(parentCtx context.Context, runV2V bool) (s
return "", err
}
diskNameStr := strconv.Itoa(int(c.NbdkitConfig.VddkConfig.DiskKey))
volume, err := osm_os.GetVolumeID(c.OSClient, vmName, diskNameStr)
volume, err := osm_os.GetVolumeID(c.OSClient, c.resourceName(vmName), diskNameStr)
if err != nil {
logger.Log.Infof("Failed to get volume: %v", err)
return "", err
Expand Down Expand Up @@ -223,7 +240,7 @@ func (c *MigrationConfig) VMMigration(parentCtx context.Context, runV2V bool) (s
// volumeMetadata["hw_scsi_model"] = "virtio-scsi"
// }
volOpts := osm_os.VolOpts{
Name: vmName + "-" + diskNameStr,
Name: c.resourceName(vmName) + "-" + diskNameStr,
Size: int(diskSize[diskNameStr] / 1024 / 1024),
VolumeType: c.VolumeType,
AvailabilityZone: c.VolumeAz,
Expand Down Expand Up @@ -418,6 +435,7 @@ func main() {
password := ansible.RequireField(moduleArgs.Password, "Password is required")
server := ansible.RequireField(moduleArgs.Server, "Server is required")
vmname := ansible.RequireField(moduleArgs.VmName, "VM name is required")
destname := moduleArgs.DestName
libdir := ansible.DefaultIfEmpty(moduleArgs.Libdir, "/usr/lib/vmware-vix-disklib")
vddkpath := ansible.DefaultIfEmpty(moduleArgs.VddkPath, "/ha-datacenter/vm/")
osmdatadir := ansible.DefaultIfEmpty(moduleArgs.OSMDataDir, "/tmp/")
Expand Down Expand Up @@ -447,8 +465,13 @@ func main() {
response.Msg = "Failed to generate random string"
ansible.FailJson(response)
}
// Use destname for the log file name if provided, otherwise use the sanitised VM name
safeVmName := moduleutils.SafeVmName(vmname)
LogFile := "/tmp/osm-nbdkit-" + safeVmName + "-" + r + ".log"
logBaseName := safeVmName
if destname != "" {
logBaseName = destname
}
LogFile := "/tmp/osm-nbdkit-" + logBaseName + "-" + r + ".log"
logger.InitLogger(LogFile)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down Expand Up @@ -536,6 +559,7 @@ func main() {
HostPool: hostPool,
},
ManageExtVol: externalVolume,
DestName: destname,
OSMDataDir: osmdatadir,
OSClient: provider,
CBTSync: cbtsync,
Expand Down
1 change: 1 addition & 0 deletions roles/convert_metadata/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
content: |
{
"vm_name": "{{ vm_import.vm_name }}",
"vm_dest_name": "{{ vm_import.vm_dest_name | default('') }}",
"openstack": {{ vm_import.openstack | to_json }},
"vmware_guest_info": {{ guest_info | combine(vm_import.vmware_guest_info) | to_json }},
"migration": {{ vm_import.migration | to_json }}
Expand Down
1 change: 1 addition & 0 deletions roles/convert_metadata/templates/import_workloads.json.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"vm_name": "{{ vm_name }}",
"vm_dest_name": "{{ vm_dest_name | default('') }}",
"openstack": {
"flavor_name_or_uuid": "{{ flavor_name_or_uuid }}",
"openstack_private_network": "",
Expand Down
3 changes: 3 additions & 0 deletions roles/import_workloads/tasks/create_network_port.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
cloud: "{{ dst_cloud }}"
os_migrate_nics_file_path: "{{ os_migrate_vmw_data_dir }}/{{ vm_name }}/nics.json"
vm_name: "{{ vm_name }}"
destname: "{{ vm_dest_name | default('') }}"
used_mapped_networks: true
security_groups: ["{{ security_groups | default('default') }}"]
use_fixed_ips: "{{ import_workloads_use_fixed_ips | default(false) | bool }}"
Expand All @@ -27,6 +28,7 @@
cloud: "{{ dst_cloud }}"
os_migrate_nics_file_path: "{{ os_migrate_vmw_data_dir }}/{{ vm_name }}/macs.json"
vm_name: "{{ vm_name }}"
destname: "{{ vm_dest_name | default('') }}"
used_mapped_networks: false
security_groups: ["{{ security_groups | default('default') }}"]
network_name: "{{ openstack_private_network }}"
Expand All @@ -39,3 +41,4 @@
ansible.builtin.set_fact:
nics: "{{ ports_uuid.ports | default([]) }}"
when: os_migrate_create_network_port|default(true)|bool

5 changes: 3 additions & 2 deletions roles/import_workloads/tasks/create_os_instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
- name: Get volume information for virt-v2v
os_migrate.vmware_migration_kit.volume_info:
cloud: "{{ dst_cloud }}"
name: "{{ vm_name }}-sda"
name: "{{ vm_dest_name | default(vm_name) }}-sda"
register: volume_result
when: import_workloads_os_migrate_virt_v2v

- name: Get volume information for Cinder boot
os_migrate.vmware_migration_kit.volume_info:
cloud: "{{ dst_cloud }}"
name: "{{ vm_name }}"
name: "{{ vm_dest_name | default(vm_name) }}"
register: cinder_volume_result
when: import_workloads_boot_from_cinder

Expand Down Expand Up @@ -71,6 +71,7 @@
cloud: "{{ dst_cloud }}"
state: "present"
name: "{{ vm_name }}"
destname: "{{ vm_dest_name | default('') }}"
nics: "{{ nics }}"
volumes: "{{ volumes_list }}"
boot_volume: "{{ boot_volume_uuid }}"
Expand Down
1 change: 1 addition & 0 deletions roles/import_workloads/tasks/nbdkit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
password: "{{ vcenter_password }}"
server: "{{ vcenter_hostname }}"
vmname: "{{ vm_name }}"
destname: "{{ vm_dest_name | default('') }}"
volumeaz: "{{ import_workloads_cinder_az | default(omit) }}"
volumetype: "{{ import_workloads_cinder_volume_type | default(omit) }}"
assumezero: "{{ import_workloads_nbdkit_assume_zero | bool }}"
Expand Down