Quantcast
Channel: VMware Communities: Message List - vSphere Management SDK
Viewing all articles
Browse latest Browse all 2052

Re: Deploy OVF C#

$
0
0

First off apologies: this post is >1yr old and responding to old posts is a bit off form.....but I have just spent 3 days fighting with the same problem so thought it worthwhile posting what I had to do.

 

I am using the latest managment SDK for 6.5.0 targetting .NET runtime 4.5.0.

I started with the sample code as given in the OVFManagerImportLocalVApp and found that it did upload the VMDK but that on inspection it contained no partitions &c.

 

So the things I had to change were:

 

 

The final VMDK upload function that appears to work is:

 

void SendVMDKFile(Boolean put, string fileName, string url, long diskCapacity, ManagedObjectReference httpNfcLease)
{
 byte[] buffer = new byte[(64*1024)+1];
 Trace.TraceInformation("Destination host URL: " + url);
 Uri uri = new Uri(url);
 HttpWebRequest request = HttpWebRequest.CreateHttp(uri);
 NetworkCredential nwCred = new NetworkCredential();
 long szVMDK = diskCapacity;

 if (0 == szVMDK)
 {
     System.IO.FileInfo fi = new System.IO.FileInfo(fileName);     szVMDK = fi.Length;
 }

 request.ContentType = "application/x-vnd.vmware-streamVmdk";
 request.ServicePoint.Expect100Continue = true;
 request.KeepAlive = true;
 request.Timeout = WebClientTimeout;
 request.AllowWriteStreamBuffering = false;
 request.ContentLength = szVMDK;

 if (put)
 {
     request.Method = "PUT";
 }
 else
 {     request.Method = "POST";
 }
 System.IO.FileStream fileStream = new FileStream(fileName, FileMode.Open);
 Stream dataStream = request.GetRequestStream();
 int len = 0;
 long totalWritten = 0;
 long threshold = 0;
 if (0 != szVMDK)
 {     threshold = szVMDK / 20;
 }
 while ((len = fileStream.Read(buffer, 0, (64*1024))) > 0)
 {     dataStream.Write(buffer, 0, len);     dataStream.Flush();     totalWritten += len;     if (0 != szVMDK)     {         _server.getConnection().Service.HttpNfcLeaseProgress(httpNfcLease, (int)(((double)(totalWritten / threshold)) * 5));     }     Trace.TraceInformation("SendVMDKFile: Written {0} of {1} ({2:G}). Status {3}", totalWritten, szVMDK, ((double)(totalWritten / threshold)),fileStream.Position);
 }
 dataStream.Flush();
 dataStream.Close();
 fileStream.Close();
}

 

As mentioned, it hits the HttpNcfLeasedProgress a *lot* most of the other samples fire this off to a separate thread and update it significantly fewer times. But I have left it "as is".

 

So hopefully this is useful to someone else


Viewing all articles
Browse latest Browse all 2052

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>