VMware {code} Community
comiscience
Contributor
Contributor

How to create/add a new datastore with C#?

Hi everybody

How to create/add a new datastore with C#?

Thanks Smiley Happy

Reply
0 Kudos
4 Replies
togtog
Hot Shot
Hot Shot

Hi comiscience!

Take a look at Creating and Managing Datastores this should be a good starting point.

Thomas G.
comiscience
Contributor
Contributor

Thanks Togtog

Here is my successeful code

                    Object cmobj
                       = cb.getServiceUtil().GetDynamicProperty(hostmor, "configManager");
                    HostConfigManager configMgr = (HostConfigManager)cmobj;
                    ManagedObjectReference storageSystem = configMgr.datastoreSystem;
                    HostNasVolumeSpec hnvSpec = new HostNasVolumeSpec();
                    hnvSpec.accessMode = "readWrite";
                    hnvSpec.localPath = cb.get_option("datastorename"); // Like  vol_test_NFS
                    hnvSpec.remoteHost = cb.get_option("stocakgeip");  // 192.168.100.100
                    hnvSpec.remotePath = "/vol/" + cb.get_option("datastorename");  // /vol/vol_test_NFS
                    ManagedObjectReference dsMoref = cb.getConnection()._service.CreateNasDatastore(storageSystem, hnvSpec);
                    if (dsMoref != null)
                        return true;
                    else
                        return false;
Reply
0 Kudos
togtog
Hot Shot
Hot Shot

Hi comiscience!

Congratulations on your achievement 🙂

Please do not forget to close answered questions and to award points for helpful replies 😉

Thomas G.
Reply
0 Kudos
comiscience
Contributor
Contributor

But; how to do that...

Reply
0 Kudos