dbgeek / terraform-provider-ovm

Terraform provider to manage Oracle OVM resources
MIT License
12 stars 7 forks source link

StorageElementMapping request #7

Open tonyadolph opened 6 years ago

tonyadolph commented 6 years ago

Hi Björn

As discussed, I have attached a python script that mimics most of the apply and destroy functionality of terraform providers. I created it in python as my golang skills at the moment are limited.

I hope that this will help in creating StorageElementMapping functionality.

If you take a look at the function createVmDiskMapping(s,baseUri,racNodeObj,asmDisks): You'll see the difference between the vmd mapping and storageElement mapping is only in the dataobject, either "storageElementId": storageElementId, or "virtualDiskId": virtualDiskId, is populated. The tricky bit is getting the the storageElementId.

For that see getDiskObjByWwid(s,baseUri,diskWwid):

if not asmDisk["obj"] or asmDisk["diskType"] == "PHYSICAL_DISK":
                # get the disk obj
                if asmDisk["diskType"].upper() == "PHYSICAL_DISK":
                    diskWwid = asmDisk["wwid"]
                    if not diskWwid:
                        raise Exception ("{asmDiskName} is set as Physical but the wwid is null".format(asmDiskName=asmDisk["name"]))
                    asmDiskObj=getDiskObjByWwid(s,baseUri,diskWwid)
                elif asmDisk["diskType"].upper() == "VIRTUAL_DISK":
                    raise Exception ("{asmDiskName} is set as Virtual but the id is null - did you skip disk creation?".format(asmDiskName=asmDisk["name"]))
                else:
                    raise Exception ("Unsupported diskType {diskType}".format(diskType=asmDisk["diskType"]))
            else:
                asmDiskObj  = asmDisk["obj"]
                asmDiskName = asmDisk["name"]

and

if asmDisk["diskType"].upper() == "PHYSICAL_DISK":
                storageElementId = asmDiskObj['id']
            else:
                virtualDiskId = asmDiskObj['id']

I hope that my python script clear. createRACnodes.zip

See the config file asmDisks section where the WWID of the external disk aka StorageElement ,"asmDisks":[ { "name": "ASM_DISK1" ,"diskType": "PHYSICAL_DISK" ,"size": 5 ,"shareable": true ,"sparse": "No" ,"description": "ASM RAC Shared Disk TonyA testing" ,"obj": null ,"wwid": "600601600ec03600cb545b949352e811" }, I've added two config files, one for Virtual Disks, one for Physical.

createRAC.zip

Rgds Tony

dbgeek commented 6 years ago

Hi Tonny

I think I will create a resourceOvmSeM (storageElement resource) that have attributes like

My OVM at home have died so will try to do some coding in the black that you can test and my HW setup only support virtdualDisk...

tonyadolph commented 6 years ago

I started but stalled due to lack of golang experience. But I planned the same, but would have a storageElementId too. The object that gets passed to VmDiskMapping in my python version looks like this:

obj = {
            "userData": [],
            "locked": False,
            "description": "mapping for {racNode}".format(racNode=racNodeName),
            "generation": 1,
            "storageElementId": storageElementId,
            "vmId": racNodeObj['id'],
            "diskWriteMode": "READ_WRITE",
            "readOnly": False,
            "emulatedBlockDevice": False,
            "virtualDiskId": virtualDiskId,
            "resourceGroupIds": [],
            "diskTarget": diskTarget,
            "id": None,
            "name": "Mapping for disk Id ({diskId})".format(diskId=diskId)
        }

where storageElementIdand virtualDiskIdare mutually exclusive.

I look forward to seeing your implementation. And I'll be happy to test it.