Skip to content
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

API to create Datastore #166

Closed
sandipsubedi opened this issue May 13, 2019 · 18 comments

Comments

@sandipsubedi
Copy link

commented May 13, 2019

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?

@agrare

This comment has been minimized.

Copy link
Contributor

commented May 13, 2019

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

@sandipsubedi sandipsubedi changed the title API to create Datastore REST API to create Datastore May 13, 2019

@sandipsubedi

This comment has been minimized.

Copy link
Author

commented May 13, 2019

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

@jrgarcia

This comment has been minimized.

Copy link
Member

commented May 13, 2019

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 sandipsubedi changed the title REST API to create Datastore API to create Datastore May 13, 2019

@jrgarcia

This comment has been minimized.

Copy link
Member

commented May 13, 2019

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

@agrare

This comment has been minimized.

Copy link
Contributor

commented May 13, 2019

@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)

@jrgarcia

This comment has been minimized.

Copy link
Member

commented May 13, 2019

☝️ 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).

@sandipsubedi

This comment has been minimized.

Copy link
Author

commented May 13, 2019

@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.

@jrgarcia

This comment has been minimized.

Copy link
Member

commented May 13, 2019

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

@jrgarcia jrgarcia closed this May 13, 2019

@sandipsubedi

This comment has been minimized.

Copy link
Author

commented May 16, 2019

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

@sandipsubedi

This comment has been minimized.

Copy link
Author

commented May 16, 2019

Or maybe there is a log message I can see?

@jrgarcia

This comment has been minimized.

Copy link
Member

commented May 17, 2019

@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.

@jrgarcia

This comment has been minimized.

Copy link
Member

commented May 17, 2019

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.

@sandipsubedi

This comment has been minimized.

Copy link
Author

commented May 17, 2019

@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"}
@sandipsubedi

This comment has been minimized.

Copy link
Author

commented May 17, 2019

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.

@akhilkr128

This comment has been minimized.

Copy link

commented Jun 8, 2019

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

@jrgarcia

This comment has been minimized.

Copy link
Member

commented Jun 10, 2019

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.

@akhilkr128

This comment has been minimized.

Copy link

commented Jun 10, 2019

@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.

@jrgarcia

This comment has been minimized.

Copy link
Member

commented Jun 10, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.