Beispiel #1
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);
            }
        }
Beispiel #2
0
 protected NIC(IComputerSystem host, IComputerSystem vm, ICommonEthernetPortSettingData adapterSettingData, ILogger logger)
 {
     this._Host = host;
     this._Vm   = vm;
     this._AdapterSettingData = adapterSettingData;
     this._Logger             = logger;
 }
Beispiel #3
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();
                        }
                    }
                }
            }
        }
Beispiel #4
0
 public void Dispose()
 {
     this._AdapterSettingData.TryDispose();
     this._AdapterSettingData = (ICommonEthernetPortSettingData)null;
 }