From bf9c5f763cadd1259fe15b17c92f8f256e788b9d Mon Sep 17 00:00:00 2001 From: pkretzer Date: Tue, 1 Apr 2025 09:49:20 +0200 Subject: [PATCH] add: set custom-trait parameter --- README.md | 3 ++- internal/target/openstack.go | 9 +++++++++ main.go | 11 ++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fc692aa..b013a20 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ There are a few optional flags to define the following: destination machine. Should be disabled with caution as it may result in an unbootable instance. To disable flag must be passed with an =false e.g. `--run-v2v=false` - `--disk-bus-type`: Flag to define volume disk bus type, currently only supports +- `--disk-bus-type`: Flag to define volume disk bus type, currently only supports scsi and virtio. - `--compression-method`: Compression method: skipz, zlib and none. - `--os-type`: Sets the "os_type" volume (image) metadata variable. @@ -189,6 +189,7 @@ There are a few optional flags to define the following: Valid values for the most OpenStack installations are "linux" and "windows" - `--enable-qemu-guest-agent`: Sets the "hw_qemu_guest_agent" volume (image) metadata parameter to "yes". +- `--custom-trait`: Sets a custom trait to required in the volume (image) metadata for nova scheduling) e.g. `--custom-trait trait:CUSTOM_LICENSING`. ## Contributing diff --git a/internal/target/openstack.go b/internal/target/openstack.go index aad451e..0cd51d1 100644 --- a/internal/target/openstack.go +++ b/internal/target/openstack.go @@ -144,6 +144,15 @@ func (t *OpenStack) Connect(ctx context.Context) error { volumeImageMetadata["hw_qemu_guest_agent"] = "yes" } + customTrait, ok := ctx.Value("customTrait").(string); + if ok && customTrait != "" { + log.WithFields(log.Fields{ + "volume_id": volume.ID, + customTrait: "required", + }).Info("Volume set required custom trait metadata parameter") + volumeImageMetadata[customTrait] = "required" + } + if types.GuestOsDescriptorFirmwareType(o.Config.Firmware) == types.GuestOsDescriptorFirmwareTypeEfi { log.WithFields(log.Fields{ "volume_id": volume.ID, diff --git a/main.go b/main.go index e0244ec..2ed8dcc 100644 --- a/main.go +++ b/main.go @@ -72,7 +72,8 @@ var ( busType BusTypeOpts vzUnsafeVolumeByName bool osType string - enableQemuGuestAgent bool + enableQemuGuestAgent bool + customTrait string ) var rootCmd = &cobra.Command{ @@ -197,6 +198,8 @@ var rootCmd = &cobra.Command{ ctx = context.WithValue(ctx, "osType", osType) + ctx = context.WithValue(ctx, "customTrait", customTrait) + ctx = context.WithValue(ctx, "enableQemuGuestAgent", enableQemuGuestAgent) cmd.SetContext(ctx) @@ -350,9 +353,11 @@ func init() { rootCmd.PersistentFlags().BoolVar(&vzUnsafeVolumeByName, "vz-unsafe-volume-by-name", false, "Only use the name to find a volume - workaround for virtuozzu - dangerous option") - rootCmd.PersistentFlags().StringVar(&osType, "os-type", "", "Set os_type in the volume (image) metadata, (if set to \"auto\", it tries to detect the type from VMware GuestId)") + rootCmd.PersistentFlags().StringVar(&osType, "os-type", "", "Set os_type in the volume (image) metadata, (if set to \"auto\", it tries to detect the type from VMware GuestId)") + + rootCmd.PersistentFlags().BoolVar(&enableQemuGuestAgent, "enable-qemu-guest-agent", false, "Sets the hw_qemu_guest_agent metadata parameter to yes") - rootCmd.PersistentFlags().BoolVar(&enableQemuGuestAgent, "enable-qemu-guest-agent", false, "Sets the hw_qemu_guest_agent metadata parameter to yes") + rootCmd.PersistentFlags().StringVar(&customTrait, "custom-trait", "", "Sets a custom trait to required in the volume (image) metadata for nova scheduling)") cutoverCmd.Flags().StringVar(&flavorId, "flavor", "", "OpenStack Flavor ID") cutoverCmd.MarkFlagRequired("flavor")