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(); } } } } }
public VmCreationInfo(string name, string guestId, int numCPU, int numCoresPerProcessor, long memoryMB, ScsiControllerType scsiControllerType, VirtualNicType nicType, string[] nicMapping, VmDiskInfo[] disks, IVimDatastore location) { this.Name = name; this.GuestId = guestId; this.NumCPU = numCPU; this.NumCoresPerProcessor = numCoresPerProcessor; this.MemoryMB = memoryMB; this.ScsiControllerType = scsiControllerType; this.NicType = nicType; this.NICMapping = nicMapping; this.Disks = disks; this.Location = location; }
public ServerNicInfo(ServerNicInfo nic) { this.IPAddresses = (string[])nic.IPAddresses.Clone(); this.IPMasks = (string[])nic.IPMasks.Clone(); this.IPGateways = nic.IPGateways != null ? (string[])nic.IPGateways.Clone() : (string[])null; this.DNSAddrs = nic.DNSAddrs != null ? (string[])nic.DNSAddrs.Clone() : (string[])null; this.BusNumber = nic.BusNumber; this.DeviceNumber = nic.DeviceNumber; this.FriendlyName = nic.FriendlyName; this.Index = nic.Index; this.NicGuid = nic.NicGuid; this.NicType = nic.NicType; this.PNPInstanceId = nic.PNPInstanceId; this.TcpIpServiceUuid = nic.TcpIpServiceUuid; this.VirtualNetwork = nic.VirtualNetwork; }
private VmCreationInfo _BuildCreationInfo() { this._Logger.Verbose("Setting up VMDK file information"); this._AssignControllersToVolumes(); VmDiskInfo[] disks = this._BuildDiskList(this._Context.JobInfoWrapper.VolumePersistedState); if (disks.Length == 0) { throw new OculiServiceServiceException(0, "There are no disks to create"); } this._Logger.Verbose("Setting up NIC information"); this._AssignDeviceAndBusNumbers(this._Context.JobInfoWrapper.Nics); OculiServiceInternalVirtualNetworkInterfaceInfo[] replicaNics = this._Context.JobInfoWrapper.Nics; string[] nicMapping = this._VirtualNetworkList(replicaNics); this._Logger.Verbose("Added information for " + replicaNics.Length.ToString() + " nics."); VirtualNicType nicType = this._VirtualNicType(); this._CheckStopping(); IVimDatastore replicaDatastore = this._GetDatastore(); return(new VmCreationInfo(this._Context.JobInfoWrapper.VmName, this._Context.JobInfoWrapper.GuestOS, this._Context.JobInfoWrapper.NumberOfCPUs, this._Context.JobInfoWrapper.NumberOfCoresPerProcessor, this._Context.JobInfoWrapper.RamSizeMB, this._ScsiControllerType(), nicType, nicMapping, disks, replicaDatastore)); }
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(); } } } } } } } }