virt-launcher, migration: Extract migration params preparation
@@ -508,32 +508,11 @@ func (l *LibvirtDomainManager) asyncMigrate(vmi *v1.VirtualMachineInstance, opti
l.setMigrationResult(vmi, true, fmt.Sprintf("%v", err), "")
}
- bandwidth, err := converter.QuantityToMebiByte(options.Bandwidth)
- if err != nil {
- log.Log.Object(vmi).Reason(err).Error("Live migration failed. Invalid bandwidth supplied.")
- return
- }
-
- migrURI := fmt.Sprintf("tcp://%s", ip.NormalizeIPAddress(loopbackAddress))
-
- xmlstr, err := domXMLWithoutKubevirtMetadata(dom, vmi)
+ params, err := prepareMigrationParams(options, vmi, loopbackAddress, dom)
if err != nil {
- log.Log.Object(vmi).Reason(err).Error("Live migration failed. Could not compute target XML.")
+ log.Log.Object(vmi).Reason(err).Error("Live migration failed.")
return
}
-
- params := &libvirt.DomainMigrateParameters{
- Bandwidth: bandwidth, // MiB/s
- URI: migrURI,
- URISet: true,
- DestXML: xmlstr,
- DestXMLSet: true,
- }
- copyDisks := getDiskTargetsForMigration(dom, vmi)
- if len(copyDisks) != 0 {
- params.MigrateDisks = copyDisks
- params.MigrateDisksSet = true
- }
// start live migration tracking
migrationErrorChan := make(chan error, 1)
defer close(migrationErrorChan)
@@ -556,6 +535,34 @@ func (l *LibvirtDomainManager) asyncMigrate(vmi *v1.VirtualMachineInstance, opti
}(l, vmi)
}
+func prepareMigrationParams(options *cmdclient.MigrationOptions, vmi *v1.VirtualMachineInstance, loopbackAddress string, dom cli.VirDomain) (*libvirt.DomainMigrateParameters, error) {
+ bandwidth, err := converter.QuantityToMebiByte(options.Bandwidth)
+ if err != nil {
+ return nil, fmt.Errorf("invalid bandwidth supplied, err: %v", err)
+ }
+
+ migrURI := fmt.Sprintf("tcp://%s", ip.NormalizeIPAddress(loopbackAddress))
+
+ xmlstr, err := domXMLWithoutKubevirtMetadata(dom, vmi)
+ if err != nil {
+ return nil, fmt.Errorf("could not compute target XML, err: %v", err)
+ }
+
+ params := &libvirt.DomainMigrateParameters{
+ Bandwidth: bandwidth, // MiB/s
+ URI: migrURI,
+ URISet: true,
+ DestXML: xmlstr,
+ DestXMLSet: true,
+ }
+ copyDisks := getDiskTargetsForMigration(dom, vmi)
+ if len(copyDisks) != 0 {
+ params.MigrateDisks = copyDisks
+ params.MigrateDisksSet = true
+ }
+ return params, nil
+}
+
// startMigrationProxyServer starts a local migration proxy.
// Right now Libvirt won't let us perform a migration using a unix socket, so
// we have to create a local host tcp server (on port 22222) that forwards the traffic
