-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowervs_image_capture.sh
40 lines (28 loc) · 1.19 KB
/
powervs_image_capture.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
### --- Variables --- ###
# IBM Cloud Defines
IBM_CLOUD_API_KEY="ENTER_YOUR_API_KEY"
REGION="ca-tor OR ENTER_YOUR_REGION"
# PowerVS defines
CRN_POWERVS_WRKSPCE="ENTER_YOUR_WORKSPACE_CRN"
LPAR_ID="ENTER_YOUR_LPAR_ID"
# Image Name defines
UNIX_TIME=$(date +%s)
IMAGE_SAVE_NAME="aix_image_$UNIX_TIME"
# COS defines
COS_BUCKET="ENTER_YOUR_COS_BUCKET_NAME"
COS_REGION="ENTER_YOUR_COS_REGION"
COS_ACCESS_KEY="ENTER_YOUR_COS_ACCESS_KEY"
COS_SECRET_KEY="ENTER_YOUR_COS_SECRET_KEY"
### --- Commands --- ###
# Login to IBM Cloud
LOGIN_CMD="ibmcloud login --apikey $IBM_CLOUD_API_KEY -r $REGION"
# Set service target for PowerVS to workspace
SET_TARGET_CMD="ibmcloud pi service-target $CRN_POWERVS_WRKSPCE"
# Capture image of AIX LPAR and save to cloud object storage
CAPTURE_IMAGE_CMD="ibmcloud pi instance-capture $LPAR_ID --destination cloud-storage --name $IMAGE_SAVE_NAME --access-key $COS_ACCESS_KEY --secret-key $COS_SECRET_KEY --region $COS_REGION --image-path $COS_BUCKET"
# Combine commands
COMPLETE_CMD="$LOGIN_CMD && $SET_TARGET_CMD && $CAPTURE_IMAGE_CMD"
### --- Run --- ###
echo "Creating image of LPAR $LPAR_ID and saving to bucket $COS_BUCKET with name $IMAGE_SAVE_NAME"
eval $COMPLETE_CMD