-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding volume resource creation to vSphere provider #6273
Conversation
@dkalleg is this fixing an open issue? A bit brain dead this morning ;) I am thinking that this is a new feature? |
New feature |
log.Printf("[DEBUG] resourceVSphereVirtualDiskRead - stat failed on: %v", vDisk.vmdkPath) | ||
d.SetId("") | ||
return err | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think we need this else
Appreciate the work. Looking forward to getting this in. Got a bunch of comments for yah ;) |
bbe6220
to
10c7b39
Compare
@chrislovecnm @kristinn @phinze @tkak Please give this a review at your earliest convenience. |
} | ||
|
||
fileInfo, err := ds.Stat(context.TODO(), rs.Primary.Attributes["vmdk_path"]) | ||
_ = fileInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a go-ism I wasn't sure the best way to work around, I still have much to learn :) As I started explaining myself here I realized my mistake! I'll push up the change!
Basically, I wanted to say _, err := ds.Stat(...
but was getting the error of 'no new vars on left of :=', so I gave it fileInfo
. But with that, fileInfo
has to be used once or the go compiler will get angry, and this is essentially a noop to work around that. All this goes away if i take out the colon :) Doh!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do it as follows:
_, err = ds.Stat(context.TODO(), rs.Primary.Attributes["vmdk_path"])
have already declared err
above AFAICT. You were trying to redeclare the same variable again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, didn't mean to pose that as a question. Thats the answer that came to me after reading kristinn's question :)
Updating the PR shortly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dagnello thanks for the help!
This is a very good PR 👍 Just missing some function signatures, that's all. |
10c7b39
to
b81578a
Compare
} | ||
|
||
fileInfo, err := ds.Stat(context.TODO(), rs.Primary.Attributes["vmdk_path"]) | ||
_ = fileInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you don't need fileInfo, you can replace it with:
_, err = ds.Stat(context.TODO(), vDisk.vmdkPath)
b81578a
to
9eee372
Compare
* `size` - (Required) Size of the disk (in GB). | ||
* `vmdk_path` - (Required) The path, including filename, of the virtual disk to be created. This should end with '.vmdk'. | ||
* `type` - (Optional) 'eagerZeroedThick' (the default), or 'thin' are supported options. | ||
* `datacenter` - (Required) The name of a Datacenter in which to create the disk. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be optional, similar to folder or virtual machine resources
9eee372
to
5a6a2f4
Compare
@kristinn Could you point out which function signature you want to see updated? It isn't obvious for me. Thx. |
"size": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Required: true, | ||
ForceNew: true, //TODO Can this be optional (resize)? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks like these can be false if an upgrade supports the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be changed in a PR that also adds vm Update functionality. For now it needs to stay this way, else TF would go looking for a resourceVSphereVirtualMachineUpdate
that isn't there.
@chrislovecnm @phinze @tkak Any more feedback? |
LGTM! |
The main point I have here is that we are not setting the state of any values on the read. Its a normal practice to use the |
@stack72 Ah yes, let me add that and I'll push an update to this PR hopefully sometime today or tomorrow. Since we aren't getting any specific vmdk info* on the read, I won't be able to fetch every value. But should be able to do a d.Set for size, path, datacenter?, datastore. But not type and adapter type. *I didn't see any way in govmomi apis to drill down and get vmdk-level data on a file, like init_type and adapter_type. If anyone knows how to do this I'd like to be able to add that functionality! Maybe it required changes to govmomi. |
} | ||
|
||
if v, ok := d.GetOk("vmdk_path"); ok { | ||
vDisk.vmdkPath = v.(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stack72 you would expect the set
usage here? More info please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chrislovecnm the setting of the state usually happens I'm the read func so we are sure that we expected to happen has happened.
@stack72 you mind a concrete example? What line in the read func would you like to be modified. I think I understand, but I don't want to assume 😄 |
5a6a2f4
to
fb7e6f0
Compare
@stack72 I believe I've addressed your comment. As of right now, I don't know how to query vSphere vdisks for more info other than simply stat'ing them (even the stat call doesn't seem to be returning the file size properly), so I couldn't add writes for things like size, type, ect. But I've added a todo there to mark further investigation on the govmomi side. Keep those reviews coming :) |
@dkalleg should we open a ticket with govmomi peeps asking the question about vdisk attributes? |
That's probably a good idea. Even if there is some wacky way to accomplish it today, there isn't support in the object/datastore api, which I would think should have it. |
Datastore.Stat returns an interface type ( res, err := Datastore.Stat(ctx, vmdkPath)
if err != nil {...}
info, ok := res.(*types.VmDiskFileInfo)
if !ok { panic("unexpected type") }
// make use of info.{DiskType,CapacityKb,etc} |
@dougm much thanks |
@dougm Thanks for the tip. When I store the result of the assertion / type-cast (I recently learned the proper term for it is a assertion, not a type-cast.. another weird go-ism) and print out its values, they're mostly default / zero'd values.
Focusing on just one attribute, I can confirm the disk is 2GB, but the returned info suggests its 0kb. Any suggestions or ideas on why Stat is giving me this zero'd data? |
@dkalleg this PR will fix that: vmware/govmomi#509 Should get that merged later or tomorrow. |
@dougm Thanks so much for that lightning fast turn around! Does this mean I will continue to expect the remaining fields to not update? ex. ControllerType, Thin, CapacityKb, HardwareVersion, ect
@chrislovecnm @stack72 What this means now, is: |
@dougm Unrelated question.. Can you explain about types.DynamicData? I see the VirtualDevice struct extends DynamicData, which is an empty struct. What is its purpose? Is it a way for govmomi users to add in dynamic data to be associated with a VirtualDevice in vSphere? Or is it a way for vSphere to send non-api defined dynamic data back to the govmomi user? Or something else? Feel free to email me at dkalleg at vt dot edu |
@dkalleg you mind putting in a issue with govmomi? ... Just for tracking. Thanks Chris |
@chrislovecnm @stack72 Any further comments on this PR? |
@dkalleg which version of govmomi do you need for this?? |
This was built on top of the old 0.3.0. I'll need to rebase this. Working on vm resource disk update story today so I might not get to this til next week. |
@dkalleg can you mark this [WIP]. Appreciate the work! We probably going to bump the version again. |
Allows the user to create a vmdk in vSphere to the given path. In the future this could support updates for rename and move.
fb7e6f0
to
867b6a8
Compare
@chrislovecnm @stack72 I've updated to include the new size info via our govmomi upgrade with Doug's updated Stat() info. Please review at your earliest convenience. |
@dkalleg is this good to go? |
@chrislovecnm I believe so |
LGTM now :) Thanks for the extra additions as requested P. |
Thanks @stack72 ! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Allows the user to create a vmdk in vSphere to the given path. Update
not implemented, further research required. In the future this could
support updates for rename and move.