EliJuni
Enthusiast
Enthusiast

VI SDK 2.5.0 - Web-based (HTTP) File Access

Jump to solution

The Release Notes for VI SDK 2.5.0 ( http://www.vmware.com/support/developer/vc-sdk/visdk-2.5.0-200711-releasenotes.html ) mention this feature:

ESX Server 3.5 supports web-based, streaming file-access to ESX Server datastore and selected ESX Server configuration files. Datastore access is available through both VirtualCenter Server and ESX Server systems; configuration files are accessible though ESX Server systems only. Sample code for Java client implementation of this new approach is available in the SDK.

The Programming Guide says pretty much the same thing, and I could not find any other mention anywhere else in the docs. I haven't had a chance to try it, but I'm wondering:

  • Will it be avaliable for ESX 3i? (The Release Notes only mention 3.5.)

  • Will it allow me to create directories within a VMFS partition?

  • Will it allow me to delete files which are on the ESX server?

Thanks.

E.

0 Kudos
1 Solution

Accepted Solutions
ssurana
VMware Employee
VMware Employee

Hi Eli,

Q. Will it be available for ESX 3i? (Release Notes only mention 3.5)

A. Yes it available for ESX 3i as well.

Q. Will it allow me to create directories within a VMFS partition

A. With put operation you can create directories under datastore and tmp directory.

Because put operation supports implicit creation of directories.

For Example -: With the following url

https:// /tmp/firstvm/tmp/test.txt

It first creates the following hierarchy under tmp directory.

/tmp

firstvm

tmp

Q. Will it allow me to delete files which are on ESX server?

A. No

~ Sidharth

View solution in original post

0 Kudos
16 Replies
ssurana
VMware Employee
VMware Employee

Hi Eli,

Q. Will it be available for ESX 3i? (Release Notes only mention 3.5)

A. Yes it available for ESX 3i as well.

Q. Will it allow me to create directories within a VMFS partition

A. With put operation you can create directories under datastore and tmp directory.

Because put operation supports implicit creation of directories.

For Example -: With the following url

https:// /tmp/firstvm/tmp/test.txt

It first creates the following hierarchy under tmp directory.

/tmp

firstvm

tmp

Q. Will it allow me to delete files which are on ESX server?

A. No

~ Sidharth

0 Kudos
tos2k
Expert
Expert

Hi!

Deletion of files is not a problem, this works for files and folders via the DeleteDatastoreFile_Task command.

Cant you post a sample how to stream files to a ESX server? Do I have to initiate the HTTP based put manually via the HttpRequest object from .NET or is there anything implemented in the VI SDK?

thx, Tos2k

EliJuni
Enthusiast
Enthusiast

Q. Will it allow me to create directories within a VMFS partition

A. With put operation you can create directories under datastore and tmp directory.

Because put operation supports implicit creation of directories.

For Example -: With the following url

<servername> /tmp/firstvm/tmp/test.txt

It first creates the following hierarchy under tmp directory.

/tmp

firstvm

tmp

Does that mean that in order to create a directory, I have to put a file in it? What if I want to create an empty directory?

And on another front: will it allow me to obtain the list of files within a directory? How about their sizes and timestamps?

0 Kudos
ssurana
VMware Employee
VMware Employee

Hi Eli,

Q. Does that mean in order to create a directory, I have to put a file in it? What if I want to create an empty directory?

A. Yes, becasue HTTP file access is only meant to Get/Put datastores or configuration files.

Q. And on another front: will it allow me to obtain the list of files within a directory? How about their sizes and timestamps?

A. To list the files in directories

******************************************

a) /folder - Directory listing of known datacenters on this server

b) /folder?dcPath=DCPATH - Directory listing of all datastores available at this datacenter

c) /folder?dcPath=DCPATH&dsName=DSNAME - Top level directory listing of the datastore. If the server is an ESX server, dcPath=DCPATH& can be omitted and defaults to dcPath=ha-datacenter.

d) /folder/PATH...?dcPath=DCPATH&dsName=DSNAME - Directory listing of files in a datastore directory. - No virtual disk interpretation (all files shown). If the server is an ESX server, dcPath=DCPATH& can be omitted and defaults to dcPath=ha-datacenter.

e) /host - List all the accessible configuration files.

******************************************

Hope the above information answers your questions.

~ Sidharth

EliJuni
Enthusiast
Enthusiast

Hope the above information answers your questions.

~ Sidharth

Thanks, it does.

0 Kudos
tos2k
Expert
Expert

Hi!

I need to create/upload files to ESX 3i servers via SDK / web service. Can someone send som samples/info on this please?

> >[/]<servername> /tmp/firstvm/tmp/test.txt

> > It first creates the following hierarchy under tmp directory.

This cant be right as the datastore is missing, assuming that spaces in urls are wrong anyway...

Tos2k

0 Kudos
ssurana
VMware Employee
VMware Employee

Hi,

There are few important things to note here:

1. https://

The above url would be used to get/put the files from the particular datastore available . For example the above url will give you access to the path /XP/XP.vmdk

If the server is an ESX server, dcPath=DCPATH& can be omitted and defaults to dcPath=ha-datacenter.

Hope the above information helps to clarify your doubts.

~ Sidharth

0 Kudos
tos2k
Expert
Expert

Hi!

I understand that you dont need a datastore for

<servername>/tmp/A/B/test.txt

Anyway:

  • the space does not really have to be there?

  • at my 3.5 ESXs no directories are created, nor is the (empty file created), not trying 1) nor 2) (using ip address)

Sorry for my unclearness, but I wanted to have (in addition) an example on how to upload an existing file to a 3i server via the webservice/SDK. Is the only way to achieve this as it is described in the java sample:

vi-sdk-2.5.0-64154\SDK\samples\Axis\java\com\vmware\samples\httpfileaccess\ ?

Samples using the SDK and .NET would be appreciated.

Tosk2k

0 Kudos
ariel_erdman
Contributor
Contributor

Hi Sidharth,

I've been trying to follow your instructions, but I have not yet had any success.

1. <servername>/tmp/A/B/test.txt

This gives back HTTP 400: Bad Request. I've checked /tmp and I do not see any created folders/files.

2. <servername>/folder/A/test.txt?dcPath=ha-datacenter&dsName=<datastore_name>

This gives back HTTP 404: Not Found. I can browse to <servername>/folder/A?dcPath=ha-datacenter&dsName=<datastore_name> successfully, but I cannot seem to create the test.txt file.

I've also tried both of these programmatically by sending a file via a HttpWebRequest in C#, but the response is always HTTP 400: Bad Request.

This there anything that you can see that I am doing wrong? Is there something I need to enable on the ESX Server to allow creating/pushing files in this way? Or can you point me to any more C# examples?

Any help would be appreciated,

Thanks,

Ariel

0 Kudos
tos2k
Expert
Expert

Hi!

The description you provided does not seem to work. Cant VMware please publish a (preferrably .NET) sample on how to upload files to a ESX3i with VimApi?

Thx, Tos2k

0 Kudos
tos2k
Expert
Expert

Ssurana, your description seems to be pretty unclear, at least to some of us.

Can you please point us to sample (or post one) how to upload files to ESX 3i servers via the VimSdk?

it should contain:

- source of the file to upload

- target, on where to upload the file on the ESX

Tos2k

p.s. This is due the lack of the service console...

0 Kudos
ssurana
VMware Employee
VMware Employee

Well, as far as samples are concerned there are a couple of examples that gets shipped along with the SDK 2.5. These samples are in Java. You can have a look at the samples "com.vmware.samples.httpfileaccess.ColdMigration" and "com.vmware.samples.httpfileaccess.GetVMFiles".

The ColdMigration demonstrates the put functionality whereas the GetVMFiles demonstrate the get functionality.

You can have a look into the code of these samples as to how the URLs are generated and used.

For quick reference I have also attached the 2 sample files.

The .Net and perl samples would be published later for this functionality.

Hope these samples provide you a better insight to the functionality.

~ Sidharth

0 Kudos
tos2k
Expert
Expert

Okay, thanx for your reply, but lets summarize this:

1) no support for file up-/donwload via VimSdk

2) no upload of files via the browser (even ESX 3i), as described of you before

Tos2k

p.s. It just took a day to find out how to down/upload files via ssl Smiley Wink

0 Kudos
tos2k
Expert
Expert

Something strange: When browsing files via https:///folder works like a charm

0 Kudos
tos2k
Expert
Expert

This seems not to be special for iSCSI. It is a bug in Virtual Center. One of the hosts registered in VC having the datastore mounted had status disconnected in VC. Removing this host solved the problem.

Resume: VirtualCenter uses disconnected hosts for file access -> BUG

Tos2k

0 Kudos
tos2k
Expert
Expert

Okay, I finally decided to publish .NET C# code on how to up- and download files via http (ESX 3.5 / VC 2.5):

HttpWebRequest req = null;

try

{

req = (HttpWebRequest)HttpWebRequest.Create(url);

req.Timeout = 10000;

req.KeepAlive = true;

}

catch{...}

//fetch credential from somewhere

req.Credentials = new NetworkCredential(UserName, Password);

//download file

try

{

using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())

{

StreamReader reader = new StreamReader(res.GetResponseStream());

string line = null;

using (StreamWriter sw = new StreamWriter(<localfile>, true))

{

while (!reader.EndOfStream)

{

line = reader.ReadLine();

sw.WriteLine(line);

}

}

if (reader != null) reader.Close();

}

}

catch{...}

//upload

req = (HttpWebRequest)HttpWebRequest.Create(urlNewFile);

req.PreAuthenticate = true;

req.UserAgent = "Upload Test";

req.Method = "PUT";

req.Credentials = new NetworkCredential(UserName, Password);

//upload changed vmx file

try

{

using (Stream reqStream = req.GetRequestStream())

{

// Open the local file

using (FileStream rdr = new FileStream(<localfile>, FileMode.Open))

{

// Allocate byte buffer to hold file contents

byte[] inData = new byte[http://rdr.Length];

int bytesRead = rdr.Read(inData, 0, inData.Length);

while (bytesRead > 0)

{

reqStream.Write(inData, 0, bytesRead);

bytesRead = rdr.Read(inData, 0, inData.Length);

}

}

}

}

catch { }

Urls are build up as described before of ssurana. Error handling is up to you.

HTH, Tos2k

0 Kudos