Exemplo n.º 1
0
        public List <String> GetHostVirtualSwitches(VMware.Vim.HostSystem host)
        {
            List <String> HostVirtualSwitches = new List <String>();

            try {
                if (host != null)
                {
                    ManagedObjectReference mobj          = host.ConfigManager.NetworkSystem;
                    HostNetworkSystem      networkSystem = (HostNetworkSystem)vSphereClient.GetView(mobj, null);
                    foreach (HostVirtualSwitch hvsw in networkSystem.NetworkInfo.Vswitch)
                    {
                        HostVirtualSwitches.Add(hvsw.Name);
                    }
                }
            }
            catch (VimException e) {
                lock (m_lock) {
                    WriteLogText(logWriter, e.Message.ToString());
                }
            }
            catch (Exception e) {
                lock (m_lock) {
                    WriteLogText(logWriter, e.Message.ToString());
                }
            }
            return(HostVirtualSwitches);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get all virtual switches of a host that match a filter
        /// </summary>
        /// <param name="host">HostSystem instance object</param>
        /// <param name="nameFilter">The filter</param>
        /// <returns></returns>
        public List <HostVirtualSwitch> GetHostVirtualSwitches(VMware.Vim.HostSystem host, string nameFilter)
        {
            List <HostVirtualSwitch> HostVirtualSwitches = new List <HostVirtualSwitch>();

            try {
                if (host != null)
                {
                    ManagedObjectReference mobj          = host.ConfigManager.NetworkSystem;
                    HostNetworkSystem      networkSystem = (HostNetworkSystem)vSphereClient.GetView(mobj, null);
                    foreach (HostVirtualSwitch hvsw in networkSystem.NetworkInfo.Vswitch.Where(sw => sw.Portgroup.Where(swp => swp.Contains(nameFilter)).Count() > 0))
                    {
                        HostVirtualSwitches.Add(hvsw);
                    }
                }
            }
            catch (VimException e) {
                lock (m_lock) {
                    WriteLogText(logWriter, e.Message.ToString());
                }
            }
            catch (Exception e) {
                lock (m_lock) {
                    WriteLogText(logWriter, e.Message.ToString());
                }
            }
            return(HostVirtualSwitches);
        }