Пример #1
0
 public static IEnumerable <INIC> GetRelated(IComputerSystem host, IComputerSystem vm, IVirtualSystemSettingData vssd, ILogger logger)
 {
     foreach (ICommonEthernetPortSettingData adapterSettingData in CommonEthernetPortSettingData.GetRelated(vssd))
     {
         yield return((INIC) new NIC(host, vm, adapterSettingData, logger));
     }
 }
Пример #2
0
        public void SetMacAddressType(MacAddressType macAddressType)
        {
            bool flag = false;

            switch (macAddressType)
            {
            case MacAddressType.Static:
                if (this._AdapterSettingData.Address != "000000000000")
                {
                    flag = true;
                    this._AdapterSettingData.StaticMacAddress = true;
                    break;
                }
                break;

            case MacAddressType.Dynamic:
                flag = true;
                this._AdapterSettingData.StaticMacAddress = false;
                this._AdapterSettingData.Address          = "000000000000";
                break;
            }
            if (!flag)
            {
                return;
            }
            using (IVirtualSystemManagementService managmentService = VirtualSystemManagementService.GetVirtualSystemManagmentService(this._Host))
            {
                IResourceAllocationSettingData rasd = managmentService.ModifyResourceSettings(new string[1]
                {
                    ((IWMICommon)this._AdapterSettingData).Object.GetText(TextFormat.WmiDtd20)
                }).FirstOrDefault <IResourceAllocationSettingData>();
                this._AdapterSettingData.TryDispose();
                this._AdapterSettingData = CommonEthernetPortSettingData.CreateFromResourceAllocationSettingData(rasd);
            }
        }
 public static ICommonEthernetPortSettingData CreateFromResourceAllocationSettingData(IResourceAllocationSettingData rasd)
 {
     if ((int)rasd.ResourceType != 10)
     {
         throw new HyperVException("Not an ethernet port setting data");
     }
     return(CommonEthernetPortSettingData.CreateFromObject(((IWMICommon)rasd).Object));
 }
Пример #4
0
        public static INIC Create(IComputerSystem host, IComputerSystem vm, VirtualNicType nicType, string nicGuid, ILogger logger)
        {
            ICommonEthernetPortSettingData ethernetPortSettingData;

            switch (nicType)
            {
            case VirtualNicType.Default:
            case VirtualNicType.Legacy:
                ethernetPortSettingData             = (ICommonEthernetPortSettingData)EmulatedEthernetPortSettingData.GetDefaultLegacyAdapter(host);
                ethernetPortSettingData.ElementName = "Legacy Network Adapter";
                break;

            case VirtualNicType.Synthetic:
                ethernetPortSettingData = (ICommonEthernetPortSettingData)SyntheticEthernetPortSettingData.GetDefaultSyntheticAdapter(host);
                ((ISyntheticEthernetPortSettingData)ethernetPortSettingData).VirtualSystemIdentifiers = new string[1]
                {
                    nicGuid
                };
                ethernetPortSettingData.ElementName = "Synthetic Network Adapter";
                break;

            default:
                throw new HyperVException("I don't know about the nic type " + (object)nicType);
            }
            ethernetPortSettingData.StaticMacAddress = false;
            using (IVirtualSystemManagementService managmentService = VirtualSystemManagementService.GetVirtualSystemManagmentService(host))
            {
                using (IVirtualSystemSettingData systemSettingData = vm.GetVirtualSystemSettingData())
                {
                    IResourceAllocationSettingData adapter = managmentService.AddResourceSettings(systemSettingData, new string[1]
                    {
                        ((IWMICommon)ethernetPortSettingData).Object.GetText(TextFormat.WmiDtd20)
                    }).FirstOrDefault <IResourceAllocationSettingData>();
                    try
                    {
                        ICommonEthernetPortSettingData adapterSettingData = CommonEthernetPortSettingData.GetRelated(systemSettingData).Where <ICommonEthernetPortSettingData>((Func <ICommonEthernetPortSettingData, bool>)(cepsd => adapter.InstanceID == cepsd.InstanceID)).FirstOrDefault <ICommonEthernetPortSettingData>();
                        if (adapterSettingData == null)
                        {
                            throw new HyperVException("Couldn't find the network adapter we just created");
                        }
                        return((INIC) new NIC(host, vm, adapterSettingData, logger));
                    }
                    finally
                    {
                        if (adapter != null)
                        {
                            adapter.Dispose();
                        }
                    }
                }
            }
        }
Пример #5
0
        public static IEnumerable <INIC> GetRelated(IComputerSystem host, IComputerSystem vm, ILogger logger)
        {
            IVirtualSystemSettingData vssd = vm.GetVirtualSystemSettingData();

            try
            {
                foreach (ICommonEthernetPortSettingData adapterSettingData in CommonEthernetPortSettingData.GetRelated(vssd))
                {
                    yield return((INIC) new NIC(host, vm, adapterSettingData, logger));
                }
            }
            finally
            {
                if (vssd != null)
                {
                    vssd.Dispose();
                }
            }
            vssd = (IVirtualSystemSettingData)null;
        }