示例#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);
        }
示例#2
0
        /// <summary>
        /// Gets all port group names that a virtual machine is connected to
        /// </summary>
        /// <param name="vmName">The name of the virtual machine to filter on</param>
        /// <returns></returns>
        public List <String> GetHostStandardPortGroups(VMware.Vim.HostSystem host)
        {
            List <String> HostPortGroups = new List <String>();

            try {
                if (host != null)
                {
                    foreach (ManagedObjectReference mobj in host.Network)
                    {
                        Network network = (Network)vSphereClient.GetView(mobj, null);
                        HostPortGroups.Add(network.Name);
                    }
                }
            }
            catch (VimException e) {
                lock (m_lock) {
                    WriteLogText(logWriter, e.Message.ToString());
                }
            }
            catch (Exception e) {
                lock (m_lock) {
                    WriteLogText(logWriter, e.Message.ToString());
                }
            }
            return(HostPortGroups);
        }
示例#3
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);
        }
示例#4
0
 /// <summary>
 /// Creates a standard port group on a host
 /// </summary>
 /// <param name="host"></param>
 /// <param name="portGroupName"></param>
 /// <param name="vSwitchName"></param>
 public void CreatePortGroup(VMware.Vim.HostSystem host, string portGroupName, string vSwitchName)
 {
     try {
         if (host != null)
         {
             VMware.Vim.HostConfigManager configMgr = host.ConfigManager;
             vimApiAccess.CreatePortGroup(configMgr, portGroupName, vSwitchName);
         }
     } catch (VimException e) {
         lock (m_lock) {
             WriteLogText(logWriter, e.Message.ToString());
         }
     } catch (Exception e) {
         lock (m_lock) {
             WriteLogText(logWriter, e.Message.ToString());
         }
     }
 }