Skip to content

Clone a Virtual Machine#5216

Closed
atrocitytheme wants to merge 139 commits intoapache:mainfrom
atrocitytheme:full-clone
Closed

Clone a Virtual Machine#5216
atrocitytheme wants to merge 139 commits intoapache:mainfrom
atrocitytheme:full-clone

Conversation

@atrocitytheme
Copy link
Contributor

@atrocitytheme atrocitytheme commented Jul 16, 2021

Description/Report

This PR adds a Clone VM feature at the API level (as part of GSoC project #4818), which enables the creation of a fully-cloned virtual machine with ROOT / DATA disks, and the same system configuration as the original VM. (Currently Supported for KVM hypervisor only)

Steps involved:

  1. Creation of temporary snapshots (during the clone VM operation) for both ROOT
  2. Creation of template from the ROOT disk snapshot
  3. Create a new VM from the template created in step 2
  4. Automatic assignment of new network resources for the new Cloned VM
  5. Creation of temporary snapshots for data disk
  6. Create data disk Volume from the snapshots created in step 5
  7. Newly created DATA disk created in step 6 is attached to the new VM
  8. Cleanup of temporary resources (snapshots) and error handling of the clone VM process

Note: The template created in step 2 cannot be cleaned up as the newly created clone VM uses this template

Feature included:

  • A new CloneVmCmd API interface to use this feature
  • A clone button in the compute instance page supporting the related functionalities

Documentation

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

Clone Scene

How Has This Been Tested?

This has been manually tested with a mbx KVM setup on a local machine and mbx kvm setup on GCP

  • This feature has been tested on a local Linux system with KVM support (5.3.0-64-generic Ubuntu) and Google Cloud instance (4.9.0-15-amd64 Debian)
  • Try with cloudmonkey if the management server is running with default configurations.
cloneVirtualMachine virtualmachineid=<target_vm_id>

will start the cloning process, it'll create a new cloned VM and start it (with all copied data available), network Ip will be assigned to DB instantly and the actual VM will get this IP after a while

  • When secondary system VM agents are not available, the cloning process will fail and clean the previously cloned resources
  • It'll copy all the data disk content from the target VM no matter whether the data disks are mounted in the VM system or the VM is running
  • Temporary resources created (snapshots) during the process will not remain whether the clone succeeds or not
  • New smoke test has been added in test_vm_life_cycle.py with class TestCloneVM, which tests the clone of a VM with data disk attached.
  • New unit test has been added as validateCloneCondition in the UserVmManagerImpl class
  • Manual test of Clone: in the VM page, there's a clone VM button, click it and it'll clone a new VM if with the correct hypervisor setup.

GCP environment setup

cat /sys/module/kvm_intel/parameters/nested
// if return N
sudo modprobe -r kvm_intel
sudo modprobe kvm_intel nested=1 

@sureshanaparti
Copy link
Contributor

@blueorangutan package

@blueorangutan
Copy link

@sureshanaparti a Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@acs-robot
Copy link

Found UI changes, kicking a new UI QA build
@blueorangutan ui

@blueorangutan
Copy link

@acs-robot a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result: ✖️ el7 ✖️ el8 ✖️ debian ✖️ suse15. SL-JID 3847

@blueorangutan
Copy link

UI build: ✔️
Live QA URL: http://qa.cloudstack.cloud:8080/client/pr/5216 (SL-JID-2022)

@github-actions
Copy link

github-actions bot commented Aug 2, 2022

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@DaanHoogland
Copy link
Contributor

@atrocitytheme can you resolve the conflict?


import java.util.Optional;

@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a virtual VM",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a virtual VM",
@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a virtual machine",

or

Suggested change
@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a virtual VM",
@APICommand(name = "cloneVirtualMachine", responseObject = UserVmResponse.class, description = "clone a VM",

VMTemplateVO finalTmpProduct = null;
SnapshotVO snapshot = null;
try {
TemplateInfo cloneTempalateInfp = _tmplFactory.getTemplate(templateId, DataStoreRole.Image);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TemplateInfo cloneTempalateInfp = _tmplFactory.getTemplate(templateId, DataStoreRole.Image);
TemplateInfo cloneTemplateInfo = _tmplFactory.getTemplate(templateId, DataStoreRole.Image);

store = snapStore; // pick snapshot image store to create template
}
}
future = _tmpltSvr.createTemplateFromSnapshotAsync(snapInfo, cloneTempalateInfp, store);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
future = _tmpltSvr.createTemplateFromSnapshotAsync(snapInfo, cloneTempalateInfp, store);
future = _tmpltSvr.createTemplateFromSnapshotAsync(snapInfo, cloneTemplateInfo, store);

Comment on lines +1819 to +1825
} catch (InterruptedException e) {
s_logger.debug("Failed to create template for id: " + templateId, e);
throw new CloudRuntimeException("Failed to create template" , e);
} catch (ExecutionException e) {
s_logger.debug("Failed to create template for id: " + templateId, e);
throw new CloudRuntimeException("Failed to create template ", e);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} catch (InterruptedException e) {
s_logger.debug("Failed to create template for id: " + templateId, e);
throw new CloudRuntimeException("Failed to create template" , e);
} catch (ExecutionException e) {
s_logger.debug("Failed to create template for id: " + templateId, e);
throw new CloudRuntimeException("Failed to create template ", e);
}
} catch (InterruptedException | ExecutionException e) {
s_logger.debug("Failed to create template for id: " + templateId, e);
throw new CloudRuntimeException("Failed to create template" , e);
}

@DaanHoogland
Copy link
Contributor

@atrocitytheme are you taking care of this? can you resolve the conflicts?

@DaanHoogland
Copy link
Contributor

@atrocitytheme are you still having this in your scope? shall I move it to 4.19?

@DaanHoogland DaanHoogland changed the title Support for new Feature: Clone a Virtual Machine (#4818) Clone a Virtual Machine Jan 12, 2023
@DaanHoogland DaanHoogland reopened this Jan 12, 2023
@DaanHoogland DaanHoogland modified the milestones: 4.18.0.0, 4.19.0.0 Jan 16, 2023
@github-actions
Copy link

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@shwstppr
Copy link
Contributor

shwstppr commented May 9, 2023

Discussed it with GSoC mentors at the time. Considering the outstanding changes and manual testing, closing this for now. We will revisit this at a later stage. cc @rohityadavcloud @borisstoyanov @DaanHoogland
Feel free to add anything @atrocitytheme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.