|
15 | 15 | package datadisk |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + "log" |
| 19 | + |
18 | 20 | "github.com/ibm-hyper-protect/k8s-operator-hpcr/onprem" |
19 | 21 | "github.com/ibm-hyper-protect/k8s-operator-hpcr/server/common" |
| 22 | + C "github.com/ibm-hyper-protect/terraform-provider-hpcr/contract" |
| 23 | + "libvirt.org/go/libvirtxml" |
20 | 24 | ) |
21 | 25 |
|
| 26 | +// createDataDiskReadyAction create the action |
| 27 | +func createDataDiskReadyAction(disk *libvirtxml.StorageVolume) common.Action { |
| 28 | + |
| 29 | + return func() (*common.ResourceStatus, error) { |
| 30 | + // metadata to attach |
| 31 | + metadata := C.RawMap{ |
| 32 | + "Name": disk.Name, |
| 33 | + } |
| 34 | + // marshal the disk info into metadata |
| 35 | + diskStrg, err := onprem.XMLMarshall(disk) |
| 36 | + if err == nil { |
| 37 | + metadata["diskXML"] = diskStrg |
| 38 | + } else { |
| 39 | + log.Printf("Unable to marshal the disk XML, cause: [%v]", err) |
| 40 | + } |
| 41 | + return &common.ResourceStatus{ |
| 42 | + Status: common.Ready, |
| 43 | + Description: diskStrg, |
| 44 | + Error: nil, |
| 45 | + Metadata: metadata, |
| 46 | + }, nil |
| 47 | + } |
| 48 | +} |
| 49 | + |
22 | 50 | // CreateSyncAction synchronizes the state of the resource and determines what to do next |
23 | 51 | func CreateSyncAction(client *onprem.LivirtClient, opt *onprem.DataDiskOptions) common.Action { |
24 | 52 | // checks for the validity of the data disk |
25 | 53 | isDataDiskValid := onprem.IsDataDiskValid(client) |
26 | | - _, ok := isDataDiskValid(opt) |
| 54 | + diskXML, ok := isDataDiskValid(opt) |
27 | 55 | if ok { |
28 | 56 | // ready |
29 | | - return common.CreateReadyAction() |
| 57 | + return createDataDiskReadyAction(diskXML) |
30 | 58 | } |
31 | 59 | // create a disk (will resize if required) |
32 | 60 | diskSync := onprem.CreateDataDiskSync(client) |
33 | | - _, err := diskSync(opt) |
| 61 | + disk, err := diskSync(opt) |
34 | 62 | if err != nil { |
| 63 | + log.Printf("Unable to create data disk [%s], cause: [%v]", opt.Name, err) |
| 64 | + return common.CreateErrorAction(err) |
| 65 | + } |
| 66 | + // try to get the XML description |
| 67 | + getDiskXML := onprem.GetStorageVolXMLDesc(client) |
| 68 | + diskXML, err = getDiskXML(disk) |
| 69 | + if err != nil { |
| 70 | + log.Printf("Unable to get disk XML [%s], cause: [%v]", opt.Name, err) |
35 | 71 | return common.CreateErrorAction(err) |
36 | 72 | } |
37 | 73 | // ready |
38 | | - return common.CreateReadyAction() |
| 74 | + return createDataDiskReadyAction(diskXML) |
39 | 75 | } |
40 | 76 |
|
41 | 77 | func CreateFinalizeAction(client *onprem.LivirtClient, opt *onprem.DataDiskOptions) common.Action { |
|
0 commit comments