VMware Cloud Community
jratter
Contributor
Contributor

Visual Studio and VMware.Vim

I have successfully connected Visual Studio to Vmware via the VMware.Vim and having it listing  vms and hosts to a Gridview on a webpage by selecting a vCenters from a listbox with the following code below -

The problem is that if I choose a vCenter that has thousands of vms it takes forever to produce the report - I have the data being sucked into SQL each morning with a powershell script and the reports are produced in this way very quickly. But the problem is the data is not live, and I would like to be able to produce current data, as well as historical data pf the vms and hosts via SQL. If there is any suggestions that would make this thing go faster, I would love to hear it, thank-you in advance. Jason.

int counter = 0;

            int vcenterCount = 0;

            int vmcount;

            DataTable dt = new DataTable();

            dt.Columns.Add("VM Name");

            dt.Columns.Add("vCenter Name");

            foreach (ListItem item in objectList.Items)

            {

                if (item.Selected)

                {

                    listofselections[counter] = (item.Value);

                    string gotit = listofselections[counter];

                    Client.Connect("https://" + listofselections[vcenterCount] + "/sdk"); 

                    Client.Login("username", "password");

                    NameValueCollection filter = new NameValueCollection();

                    VMware.Vim.VimClient client = new VMware.Vim.VimClientImpl();

                    vmlist = Client.FindEntityViews(typeof(VirtualMachine), null, null, null);

                    hostlist = Client.FindEntityViews(typeof(HostSystem), null, null, null);

                    System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => true;

                    string[] stringArray = new string[vmcount];

                    foreach (VirtualMachine vm in vmlist)

                    {

   

                           HostSystem host = (HostSystem)Client.GetView(vm.Runtime.Host, null);

                            dt.Rows.Add(vm.Name, host.Name, listofselections[counter]);

                                 

                        countrows++;

                    }

                    counter++;

                    vcenterCount++;

 

                    rows.Text = countrows.ToString();

                }

                GridView1.DataSource = dt;

                GridView1.DataBind();

}

0 Kudos
1 Reply
kennethgknight
Contributor
Contributor

do you mind helping me get Vmware.vim into Visual Studio?
I am trying to add it as a reference. but I cannot find it anywhere. 

 

0 Kudos