コード例 #1
0
ファイル: NIC.cs プロジェクト: phspies/terodoview_ce
        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);
            }
        }
コード例 #2
0
ファイル: NIC.cs プロジェクト: phspies/terodoview_ce
 public void Disconnect()
 {
     using (IVirtualSystemManagementService managmentService = VirtualSystemManagementService.GetVirtualSystemManagmentService(this._Host))
     {
         using (IVirtualSystemSettingData systemSettingData = this._Vm.GetVirtualSystemSettingData())
         {
             using (IEthernetPortAllocationSettingData allocationSettingData = EthernetPortAllocationSettingData.GetRelated(systemSettingData).Where <IEthernetPortAllocationSettingData>((Func <IEthernetPortAllocationSettingData, bool>)(e => e.Parent == ((IWMICommon)this._AdapterSettingData).Object.Path.Path)).FirstOrDefault <IEthernetPortAllocationSettingData>())
             {
                 if (allocationSettingData == null)
                 {
                     NIC.tracer.TraceInformation("Did not find connection to remove.");
                 }
                 else
                 {
                     using (IResourceAllocationSettingData fromObject = ResourceAllocationSettingData.CreateFromObject(((IWMICommon)allocationSettingData).Object))
                     {
                         NIC.tracer.TraceInformation("Found connection to remove.");
                         managmentService.RemoveResourceSettings(new IResourceAllocationSettingData[1]
                         {
                             fromObject
                         });
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: NIC.cs プロジェクト: phspies/terodoview_ce
        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();
                        }
                    }
                }
            }
        }
コード例 #4
0
 protected void AddNicToVm(IVm vm, VirtualNicType nicType, string vswitchName, NicConnectionStatus nicStatus, string nicGuid, int VLan)
 {
     using (IVirtualSystemManagementService managmentService = VirtualSystemManagementService.GetVirtualSystemManagmentService(this._Host))
     {
         using (IVirtualEthernetSwitch virtualEthernetSwitch = VirtualEthernetSwitch.Query(this._Host, "ElementName='{0}'", (object)vswitchName).FirstOrDefault <IVirtualEthernetSwitch>())
         {
             if (virtualEthernetSwitch == null)
             {
                 throw new HyperVException("Virtual Ethernet switch '" + vswitchName + "' not found");
             }
             using (IVirtualSystemSettingData systemSettingData = ((IVmInternals)vm).ComputerSystem.GetVirtualSystemSettingData())
             {
                 ICommonEthernetPortSettingData ethernetPortSettingData;
                 if (nicType != VirtualNicType.Legacy)
                 {
                     if (nicType != VirtualNicType.Synthetic)
                     {
                         throw new HyperVException("I don't know about the nic type " + nicType.ToString());
                     }
                     ethernetPortSettingData = (ICommonEthernetPortSettingData)SyntheticEthernetPortSettingData.GetDefaultSyntheticAdapter(this._Host);
                     ((ISyntheticEthernetPortSettingData)ethernetPortSettingData).VirtualSystemIdentifiers = new string[1]
                     {
                         nicGuid
                     };
                     ethernetPortSettingData.ElementName = "Synthetic Network Adapter";
                 }
                 else
                 {
                     ethernetPortSettingData             = (ICommonEthernetPortSettingData)EmulatedEthernetPortSettingData.GetDefaultLegacyAdapter(this._Host);
                     ethernetPortSettingData.ElementName = "Legacy Network Adapter";
                 }
                 using (ethernetPortSettingData)
                 {
                     ethernetPortSettingData.StaticMacAddress = false;
                     using (IResourceAllocationSettingData allocationSettingData1 = managmentService.AddResourceSettings(systemSettingData, new string[1]
                     {
                         ((IWMICommon)ethernetPortSettingData).Object.GetText(TextFormat.WmiDtd20)
                     }).FirstOrDefault <IResourceAllocationSettingData>())
                     {
                         if (nicStatus != NicConnectionStatus.Connected)
                         {
                             return;
                         }
                         using (IEthernetPortAllocationSettingData allocationSettingData2 = EthernetPortAllocationSettingData.GetDefaultEthernetPortAllocationSettingData(this._Host))
                         {
                             using (IVirtualSwitch virtualSwitchByName = this.GetVirtualSwitchByName(vswitchName))
                             {
                                 Invariant.ArgumentNotNull((object)allocationSettingData2, "Switch port not found");
                                 Invariant.ArgumentNotNull((object)virtualSwitchByName, "Virtual switch '" + vswitchName + "' not found");
                                 allocationSettingData2.Parent       = ((IWMICommon)allocationSettingData1).Object.Path.Path;
                                 allocationSettingData2.HostResource = new string[1]
                                 {
                                     virtualSwitchByName.Object.Path.Path
                                 };
                                 managmentService.AddResourceSettings(systemSettingData, new string[1]
                                 {
                                     ((IWMICommon)allocationSettingData2).Object.GetText(TextFormat.WmiDtd20)
                                 }).FirstOrDefault <IResourceAllocationSettingData>().TryDispose();
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
 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));
 }