vmware-archive/rbvmomi

API to create Datastore

sandipsubedi opened this issue · 18 comments

Went through vmware documentation and couldn't find the answer. Is there a way to create datastore via REST API?

From this conversation seems like REST API is not exposed yet:
https://communities.vmware.com/message/2858974#2858974

And looking at rbvmomi for SOAP API, looks like it's not exposed yet either:
https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/Datastore.rb

Am I missing something? Or They are just not available yet?

@sandipsubedi have you checked out the create*Datastore methods in HostDatastoreSystem? E.g.: CreateVmfsDatastore

I just updated my comment. I meant for REST API at first. That seems like it's for SOAP API, but I don't think it's exposed here right?
https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/vim/Datastore.rb

RbVmomi doesn't support talking to the REST API. For that, you'd have to use the Automation SDK. However, creating a datastore is not available from the REST API at this time. To view what's available from the REST API, you can go to https://<your-vcenter>/apiexplorer.

@sandipsubedi Right now, the only way to do this via Ruby is to use RbVmomi and use the methods that @agrare linked to above.

@sandipsubedi The methods to create a datastore aren't defined on the Datastore class which is why you don't see them there.

If you have a host object you can do: host.configManager.datastoreSystem.CreateVmfsDatastore(spec: your_datastore_spec)

☝️ That's correct. Those methods are available on the HostDatastoreSystem object, which you can get to via the way that @agrare described above (Host -> HostConfigManager -> HostDatastoreSystem).

@jrgarcia @agrare Thank you for the info.

We are already using RbVmomi, so we are fine using the SOAP API calls. I will give it a try and see how it goes.

I'm going to go ahead and close this. Feel free to reopen it if you run into any problems.

I was able to make the API call, but getting this error,

RbVmomi::Fault: InvalidArgument: A specified parameter was not correct:

This is what my spec looks like. I have included all the required fields. Couldn't figure out what's going on and the error message doesn't point which parameter is not correct.

{  
diskUuid: '01000d000090003bv000000000000090ef0000c1de121210404040',   
partition: {},  
vmfs: {volumeName: 'ab1ab1_04_3PAR_12fe',  
       majorVersion: 5,  
       extent: {diskName: 'naa.90003bv000000000000090ef0000c1de', partition: 1}}   
}  

Is there a way to get detailed error message? Any idea on what I might be doing wrong?

The LUN is already created and I was able to collect diskUUId and diskName as following:
1. diskUuid:
host.configManager.storageSystem.storageDeviceInfo.scsiLun[5].uuid
2. diskName:
host.configManager.storageSystem.storageDeviceInfo.scsiLun[5].canonicalName

Or maybe there is a log message I can see?

@sandipsubedi If you set the RBVMOMI_DEBUG environment variable or set the :debug option to true when you call RbVmomi::VIM.connect, you'll get debug logging.

I'll also check the code you used and see if I can find the parameter that's not working. I'm not around a computer right now though.

@jrgarcia Thank you for your suggestion. I tried adding the :debug option to true when I call RbVmomi::VIM.connect and I basically get the same error but on XML format:

Response (in 0.051 s)
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault><faultcode>ServerFaultCode</faultcode><faultstring>A specified parameter was not correct: </faultstring><detail><InvalidArgumentFault xmlns="urn:vim25" xsi:type="InvalidArgument"/></detail></soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

I tried binding.pry on the response on rbvmomi and get this(basically the same).

#(Element:0x3fc155534138 {
  name = "Fault",
  namespace = #(Namespace:0x3fc15553c194 { prefix = "soapenv", href = "http://schemas.xmlsoap.org/soap/envelope/" }),
  children = [
    #(Element:0x3fc1550eca30 { name = "faultcode", children = [ #(Text "ServerFaultCode")] }),
    #(Element:0x3fc154c82788 { name = "faultstring", children = [ #(Text "A specified parameter was not correct: ")] }),
    #(Element:0x3fc1550af6f8 {
      name = "detail",
      children = [
        #(Element:0x3fc154c2b0a0 {
          name = "InvalidArgumentFault",
          namespace = #(Namespace:0x3fc154961374 { href = "urn:vim25" }),
          attributes = [
            #(Attr:0x3fc1549611d0 {
              name = "type",
              namespace = #(Namespace:0x3fc155539ae8 { prefix = "xsi", href = "http://www.w3.org/2001/XMLSchema-instance" }),
              value = "InvalidArgument"
              })]
          })]
      })]
  })

desc from here https://github.com/vmware/rbvmomi/blob/master/lib/rbvmomi/connection.rb#L57 looks like this:

{"is-array"=>false, "is-optional"=>false, "is-task"=>false, "version-id-ref"=>nil, "wsdl_type"=>"Datastore"}

I am able to make calls to login to vcenter, get infos about disks, host and so on. And I am able to create datastore from the UI using the same credentials. So I don't think this is any kind of authentication issue.

Hi @jrgarcia , Are you able to reproduce the issue?

Sorry, I haven't responded lately. I'm still looking into this. I've not been able to recreate this and I don't see any issue with the parameters being passed. I'll keep checking though.

@jrgarcia Thank you for the response and your time.
Can you please let us know on which vSphere version you were able to create datastore? We are trying it on Version 6.5.0.20000 Build 8815520.

@akhilkr128 I honestly don't remember. Thanks for mentioning the version you are using. I'll use an environment matching that version to test.