Exemplo n.º 1
0
 public HostNetworkManager(
     VimReferences settings,
     ConcurrentDictionary <string, Vm> vmCache,
     VlanManager vlanManager
     ) : base(settings, vmCache, vlanManager)
 {
 }
Exemplo n.º 2
0
 public NsxNetworkManager(
     VimReferences settings,
     ConcurrentDictionary <string, Vm> vmCache,
     VlanManager vlanManager,
     SddcConfiguration sddcConfig
     ) : base(settings, vmCache, vlanManager)
 {
     _config = sddcConfig;
 }
Exemplo n.º 3
0
 public NetworkManager(
     VimReferences settings,
     ConcurrentDictionary <string, Vm> vmCache,
     VlanManager vlanManager
     )
 {
     _client       = settings;
     _vmCache      = vmCache;
     _vlanManager  = vlanManager;
     _pgAllocation = new Dictionary <string, PortGroupAllocation>();
     _swAllocation = new Dictionary <string, int>();
 }
Exemplo n.º 4
0
        private async Task InitReferences(VimPortTypeClient client)
        {
            var clunkyTree = await LoadReferenceTree(client);

            if (clunkyTree.Length == 0)
            {
                throw new InvalidOperationException();
            }

            string[] path       = _config.PoolPath.ToLower().Split(new char[] { '/', '\\' });
            string   datacenter = (path.Length > 0) ? path[0] : "";
            string   cluster    = (path.Length > 1) ? path[1] : "";
            string   pool       = (path.Length > 2) ? path[2] : "";

            var dcContent = (clunkyTree.FindTypeByName("Datacenter", datacenter) ?? clunkyTree.First("Datacenter"));

            _datacenter = dcContent.obj;
            _vms        = (ManagedObjectReference)dcContent.GetProperty("vmFolder");

            var clusterContent = clunkyTree.FindTypeByName("ComputeResource", cluster) ?? clunkyTree.First("ComputeResource");

            _res = clusterContent.obj;

            var poolContent = clunkyTree.FindTypeByName("ResourcePool", pool)
                              ?? clunkyTree.FindTypeByReference(
                (ManagedObjectReference)clusterContent.GetProperty("resourcePool")
                );

            _pool = poolContent.obj;

            var netSettings = new VimReferences
            {
                vim                = client,
                cluster            = _res,
                props              = _props,
                pool               = _pool,
                vmFolder           = _vms,
                UplinkSwitch       = _config.Uplink,
                ExcludeNetworkMask = _config.ExcludeNetworkMask
            };

            if (_config.IsVCenter)
            {
                ManagedObjectReference[] subpools = poolContent.GetProperty("resourcePool") as ManagedObjectReference[];
                if (subpools != null && subpools.Length > 0)
                {
                    _pool = subpools.First();
                }

                if (_config.Uplink.StartsWith("nsx."))
                {
                    _netman = new NsxNetworkManager(
                        netSettings,
                        _vmCache,
                        _vlanman,
                        _config.Sddc
                        );
                }
                else
                {
                    var dvs = clunkyTree.FindTypeByName("DistributedVirtualSwitch", _config.Uplink.ToLower()) ?? clunkyTree.First("DistributedVirtualSwitch");
                    _dvs     = dvs?.obj;
                    _dvsuuid = dvs?.GetProperty("uuid").ToString();

                    netSettings.dvs     = dvs?.obj;
                    netSettings.DvsUuid = _dvsuuid;

                    _netman = new DistributedNetworkManager(
                        netSettings,
                        _vmCache,
                        _vlanman
                        );
                }
            }
            else
            {
                var hostContent = clunkyTree.FindType("HostSystem").FirstOrDefault();
                if (hostContent != null)
                {
                    var hostConfig = hostContent.GetProperty("configManager") as HostConfigManager;
                    netSettings.net = hostConfig?.networkSystem;
                }

                _netman = new HostNetworkManager(
                    netSettings,
                    _vmCache,
                    _vlanman
                    );
            }

            await _netman.Initialize();
        }