Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 1 | /** |
| 2 | * Control live snapshots |
| 3 | * |
| 4 | * Expected parameters: |
| 5 | * SALT_MASTER_CREDENTIALS Credentials to the Salt API. |
| 6 | * SALT_MASTER_URL Full Salt API address [http://10.10.10.1:8000]. |
| 7 | * CREATE_LIVE_SNAPSHOT Ensures that the live snapshot exists (bool) |
| 8 | * ROLLBACK_LIVE_SNAPSHOT Rollback to a state before live snapshot was taken (bool) |
| 9 | * REMOVE_LIVE_SNAPSHOT Ensures that the live snapshot does not exist (bool) |
| 10 | * MERGE_LIVE_SNAPSHOT Ensures that the live snapshot is merged into it's base image (bool) |
| 11 | * NODE_PROVIDER KVM node that hosts the VM (for ex. kvm02) |
| 12 | * TARGET Unique identification of the VM being snapshoted without domain name (for ex. ctl01) |
| 13 | * SNAPSHOT_NAME Snapshot name |
Martin Polreich | bbb14f9 | 2019-05-02 16:15:33 +0200 | [diff] [blame] | 14 | * LIBVIRT_IMAGES_PATH Path where snapshot image and dumpxml are being put |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 15 | * DISK_NAME Disk name of the snapshot |
| 16 | * |
| 17 | **/ |
| 18 | |
| 19 | def common = new com.mirantis.mk.Common() |
| 20 | def salt = new com.mirantis.mk.Salt() |
| 21 | def virsh = new com.mirantis.mk.Virsh() |
| 22 | def python = new com.mirantis.mk.Python() |
| 23 | |
| 24 | def pepperEnv = "pepperEnv" |
| 25 | timeout(time: 12, unit: 'HOURS') { |
| 26 | node() { |
| 27 | |
| 28 | stage('Setup virtualenv for Pepper') { |
| 29 | python.setupPepperVirtualenv(pepperEnv, SALT_MASTER_URL, SALT_MASTER_CREDENTIALS) |
| 30 | } |
| 31 | |
| 32 | if (CREATE_LIVE_SNAPSHOT.toBoolean() == true) { |
| 33 | stage('Create live snapshot') { |
Martin Polreich | bbb14f9 | 2019-05-02 16:15:33 +0200 | [diff] [blame] | 34 | virsh.liveSnapshotPresent(pepperEnv, NODE_PROVIDER, TARGET, SNAPSHOT_NAME, LIBVIRT_IMAGES_PATH, DISK_NAME) |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
| 38 | if (REMOVE_LIVE_SNAPSHOT.toBoolean() == true) { |
| 39 | stage('Remove live snapshot') { |
Martin Polreich | bbb14f9 | 2019-05-02 16:15:33 +0200 | [diff] [blame] | 40 | virsh.liveSnapshotAbsent(pepperEnv, NODE_PROVIDER, TARGET, SNAPSHOT_NAME, LIBVIRT_IMAGES_PATH) |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 41 | } |
| 42 | } |
| 43 | |
| 44 | if (ROLLBACK_LIVE_SNAPSHOT.toBoolean() == true) { |
| 45 | stage('Rollback live snapshot') { |
| 46 | sleep(30) |
Martin Polreich | bbb14f9 | 2019-05-02 16:15:33 +0200 | [diff] [blame] | 47 | virsh.liveSnapshotRollback(pepperEnv, NODE_PROVIDER, TARGET, SNAPSHOT_NAME, LIBVIRT_IMAGES_PATH) |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | if (MERGE_LIVE_SNAPSHOT.toBoolean() == true) { |
| 52 | stage('Merge live snapshot') { |
| 53 | sleep(30) |
Martin Polreich | bbb14f9 | 2019-05-02 16:15:33 +0200 | [diff] [blame] | 54 | virsh.liveSnapshotMerge(pepperEnv, NODE_PROVIDER, TARGET, SNAPSHOT_NAME, LIBVIRT_IMAGES_PATH, DISK_NAME) |
Jiri Broulik | ed3a9e6 | 2018-02-13 16:08:40 +0100 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |