Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vmware virtual machine perf statistics
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using VMware.Vim;
- using System.Collections.Specialized;
- namespace VMmanager
- {
- class Program
- {
- public static VimClient client;
- static void Main(string[] args)
- {
- string host = url;
- string user = username;
- string pass = passwrd;
- string resourcePool = poolname;
- client = new VimClient();
- connectToVc(host, user, pass);
- ResourcePool rp = getRP(resourcePool);
- string VMs = VMname;
- getVM(VMs);
- client.Disconnect();
- Console.Read();
- }
- public static void connectToVc(string host, string user, string pass)
- {
- Console.WriteLine("Connecting...");
- DateTime start = DateTime.Now;
- ServiceContent sc = client.Connect(host, CommunicationProtocol.Https, 443);
- UserSession session = client.Login(user, pass);
- DateTime stop = DateTime.Now;
- Console.WriteLine("Time elapsed: " + (stop - start).TotalMilliseconds);
- }
- public static void getVM(string VMId)
- {
- NameValueCollection filter = new NameValueCollection();
- filter.Add("config.name", VMId);
- DateTime start = DateTime.Now;
- VirtualMachine vm = (VirtualMachine)client.FindEntityView(typeof(VirtualMachine), null, filter, null);
- DateTime stop = DateTime.Now;
- Console.WriteLine("Searching for VM, name: " + vm.Name + " id: " + VMId + " took " + (stop - start).TotalMilliseconds + "msn");
- }
- public static ResourcePool getRP(string RPname)
- {
- NameValueCollection RPfilter = new NameValueCollection();
- RPfilter.Add("name", RPname);
- DateTime start = DateTime.Now;
- ResourcePool rp = (ResourcePool)client.FindEntityView(typeof(ResourcePool), null, RPfilter, null);
- DateTime stop = DateTime.Now;
- Console.WriteLine("Searching for Resource Pool, name: " + rp.Name + " took " + (stop - start).TotalMilliseconds + "msn");
- return rp;
- }
- }
- }
Add Comment
Please, Sign In to add comment