Guest User

Untitled

a guest
Aug 1st, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. Vmware virtual machine perf statistics
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using VMware.Vim;
  7. using System.Collections.Specialized;
  8.  
  9. namespace VMmanager
  10. {
  11. class Program
  12. {
  13. public static VimClient client;
  14. static void Main(string[] args)
  15. {
  16. string host = url;
  17. string user = username;
  18. string pass = passwrd;
  19. string resourcePool = poolname;
  20. client = new VimClient();
  21. connectToVc(host, user, pass);
  22. ResourcePool rp = getRP(resourcePool);
  23. string VMs = VMname;
  24. getVM(VMs);
  25. client.Disconnect();
  26. Console.Read();
  27. }
  28.  
  29. public static void connectToVc(string host, string user, string pass)
  30. {
  31.  
  32. Console.WriteLine("Connecting...");
  33.  
  34. DateTime start = DateTime.Now;
  35.  
  36. ServiceContent sc = client.Connect(host, CommunicationProtocol.Https, 443);
  37.  
  38. UserSession session = client.Login(user, pass);
  39.  
  40. DateTime stop = DateTime.Now;
  41.  
  42. Console.WriteLine("Time elapsed: " + (stop - start).TotalMilliseconds);
  43.  
  44. }
  45.  
  46.  
  47.  
  48. public static void getVM(string VMId)
  49. {
  50. NameValueCollection filter = new NameValueCollection();
  51. filter.Add("config.name", VMId);
  52. DateTime start = DateTime.Now;
  53. VirtualMachine vm = (VirtualMachine)client.FindEntityView(typeof(VirtualMachine), null, filter, null);
  54. DateTime stop = DateTime.Now;
  55. Console.WriteLine("Searching for VM, name: " + vm.Name + " id: " + VMId + " took " + (stop - start).TotalMilliseconds + "msn");
  56. }
  57.  
  58.  
  59.  
  60. public static ResourcePool getRP(string RPname)
  61. {
  62. NameValueCollection RPfilter = new NameValueCollection();
  63. RPfilter.Add("name", RPname);
  64. DateTime start = DateTime.Now;
  65. ResourcePool rp = (ResourcePool)client.FindEntityView(typeof(ResourcePool), null, RPfilter, null);
  66. DateTime stop = DateTime.Now;
  67. Console.WriteLine("Searching for Resource Pool, name: " + rp.Name + " took " + (stop - start).TotalMilliseconds + "msn");
  68. return rp;
  69. }
  70. }
  71. }
Add Comment
Please, Sign In to add comment