コード例 #1
0
ファイル: UpdateVIFCommand.cs プロジェクト: ywwseu/xenadmin
 public UpdateVIFCommand(IMainWindow mainWindow, VM vm, VIF vif, VIF vifDescriptor)
     : base(mainWindow, vm)
 {
     _vm            = vm;
     _vif           = vif;
     _vifDescriptor = vifDescriptor;
 }
コード例 #2
0
 public CreateVIFAction(VM vm, VIF vifDescriptor)
     : base(vm.Connection, String.Format(Messages.ACTION_VIF_CREATING_TITLE, vm.Name()))
 {
     _vifDescriptor = vifDescriptor;
     VM             = vm;
     XmlRpcMethods.ForEach(method => ApiMethodsToRoleCheck.Add(method));
 }
コード例 #3
0
        private void CreateVIF()
        {
            VIF newVIF = new VIF(_proxyVIF);

            RelatedTask = XenAPI.VIF.async_create(Session, newVIF);

            PollToCompletion();
            string newVifRef = Result;

            if (VM.power_state == XenAPI.vm_power_state.Running)
            {
                if (XenAPI.VIF.get_allowed_operations(Session, newVifRef).Contains(XenAPI.vif_operations.plug))
                {
                    // Try hotplug
                    XenAPI.VIF.plug(Session, newVifRef);
                    Result = true.ToString();
                }
                else
                {
                    Result = false.ToString();
                }
            }
            else
            {
                Result = true.ToString();
            }
        }
コード例 #4
0
        public Network getNetworkByVif(VIF vif)
        {
            XenRef <Network> nwRef   = vif.network;
            Network          network = Network.get_record(ConnectManager.session, nwRef);

            return(network);
        }
コード例 #5
0
        private void AddVIFRow(VIF vif)
        {
            var row = new VifRow(vif);

            XenAPI.Network network = m_selectedConnection.Resolve(vif.network);
            bool           isGuestInstallerNetwork = network != null && network.IsGuestInstallerNetwork;

            ToStringWrapper <XenAPI.Network> comboBoxEntry = FindComboBoxEntryForNetwork(network);

            // CA-66962: Don't choose disallowed networks: choose a better one instead.
            // CA-79930/CA-73056: Except for the guest installer network, which we let
            // through for now, but hide it below.
            if (comboBoxEntry == null && !isGuestInstallerNetwork)
            {
                network       = GetDefaultNetwork();
                comboBoxEntry = FindComboBoxEntryForNetwork(network);
                vif.network   = new XenRef <XenAPI.Network>(network.opaque_ref);
            }

            row.CreateCells(m_networkGridView,
                            String.Format(Messages.NETWORKPICKER_INTERFACE, vif.device),
                            vif.MAC,
                            comboBoxEntry);
            row.Cells[0].ReadOnly = true;

            // CA-73056: A row for the guest installer network shouldn't show up. But we still need
            // it present but invisible, otherwise the corresponding VIF doesn't get created at all.
            // CA-218956 - Expose HIMN when showing hidden objects
            if (isGuestInstallerNetwork && !XenAdmin.Properties.Settings.Default.ShowHiddenVMs)
            {
                row.Visible = false;
            }

            m_networkGridView.Rows.Add(row);
        }
コード例 #6
0
 public UpdateVIFCommand(IMainWindow mainWindow, VM vm, VIF vif, Proxy_VIF proxyVIF)
     : base(mainWindow, vm)
 {
     _vm       = vm;
     _vif      = vif;
     _proxyVIF = proxyVIF;
 }
コード例 #7
0
ファイル: VIFDialog.cs プロジェクト: star-dotnet/xenadmin
        public VIF NewVif()
        {
            var vif = new VIF();

            vif.Connection = connection;
            vif.network    = new XenRef <XenAPI.Network>(SelectedNetwork.opaque_ref);
            vif.MAC        = SelectedMac;
            vif.device     = Device.ToString();

            if (checkboxQoS.Checked)
            {
                vif.qos_algorithm_type = VIF.RATE_LIMIT_QOS_VALUE;
            }

            // preserve this param even if we have decided not to turn on qos
            if (!string.IsNullOrWhiteSpace(promptTextBoxQoS.Text))
            {
                vif.qos_algorithm_params = new Dictionary <string, string> {
                    { VIF.KBPS_QOS_PARAMS_KEY, promptTextBoxQoS.Text }
                }
            }
            ;

            return(vif);
        }
コード例 #8
0
ファイル: VIFDialog.cs プロジェクト: star-dotnet/xenadmin
        /// <summary>
        /// Retrieves the new settings as a vif object. You will need to set the VM field to use these settings in a vif action
        /// </summary>
        /// <returns></returns>
        public VIF GetNewSettings()
        {
            var newVif = new VIF();

            if (ExistingVif != null)
            {
                newVif.UpdateFrom(ExistingVif);
            }

            newVif.network = new XenRef <XenAPI.Network>(SelectedNetwork.opaque_ref);
            newVif.MAC     = SelectedMac;
            newVif.device  = Device.ToString();

            if (checkboxQoS.Checked)
            {
                newVif.qos_algorithm_type = VIF.RATE_LIMIT_QOS_VALUE;
            }
            else if (ExistingVif != null && ExistingVif.qos_algorithm_type == VIF.RATE_LIMIT_QOS_VALUE)
            {
                newVif.qos_algorithm_type = "";
            }
            // else ... we leave it alone. Currently we only deal with "ratelimit" and "", don't overwrite the field if it's something else

            // preserve this param even if we turn off qos
            if (!string.IsNullOrEmpty(promptTextBoxQoS.Text))
            {
                newVif.qos_algorithm_params = new Dictionary <string, string> {
                    { VIF.KBPS_QOS_PARAMS_KEY, promptTextBoxQoS.Text }
                }
            }
            ;

            return(newVif);
        }
コード例 #9
0
        private void setNetwork()
        {
            NetworkOper networkOper = new NetworkOper();
            VIF         vif         = new VIF();

            vif.device            = "0";
            vif.MAC               = "";
            vif.MAC_autogenerated = true;
            networkOper.setVIF(vif, pifOper.ManageNetwork);

            string ip      = ipBox1.Value;
            string netmask = ipBox2.Value;
            string gateway = ipBox3.Value;
            Dictionary <string, string> IPMaskGatewayDict = new Dictionary <string, string>();

            IPMaskGatewayDict.Add("ip", ip);
            IPMaskGatewayDict.Add("netmask", netmask);
            IPMaskGatewayDict.Add("gateway", gateway);
            ConnectManager.IPMaskGatewayDict = IPMaskGatewayDict;
            log.InfoFormat("=======已设置网络start======");
            log.InfoFormat("ip: {0}", ip);
            log.InfoFormat("netmask: {0}", netmask);
            log.InfoFormat("gateway: {0}", gateway);
            log.InfoFormat("=======已设置网络end======");
        }
コード例 #10
0
ファイル: UpdateVIFCommand.cs プロジェクト: huizh/xenadmin
 public UpdateVIFCommand(IMainWindow mainWindow, VM vm, VIF vif, Proxy_VIF proxyVIF)
     : base(mainWindow, vm)
 {
     _vm = vm;
     _vif = vif;
     _proxyVIF = proxyVIF;
 }
コード例 #11
0
ファイル: VIFDialog.cs プロジェクト: ywwseu/xenadmin
        public VIFDialog(IXenConnection Connection, VIF ExistingVif, int Device, bool allowSriov = false)
            : base(Connection)
        {
            InitializeComponent();
            CueBannersManager.SetWatermark(promptTextBoxMac, "aa:bb:cc:dd:ee:ff");

            this.ExistingVif = ExistingVif;
            this.Device      = Device;
            if (ExistingVif != null)
            {
                changeToPropertiesTitle();
            }
            this.allowSriov = allowSriov;

            // Check if vSwitch Controller is configured for the pool (CA-46299)
            Pool pool = Helpers.GetPoolOfOne(connection);

            vSwitchController = pool != null && pool.vSwitchController();

            label1.Text = vSwitchController ? Messages.VIF_VSWITCH_CONTROLLER : Messages.VIF_LICENSE_RESTRICTION;
            LoadNetworks();
            LoadDetails();
            updateEnablement();
            SetupEventHandlers();
        }
コード例 #12
0
ファイル: NetworkList.cs プロジェクト: wranders/xenadmin
        private void AddNetworkButton_Click(object sender, EventArgs e)
        {
            if (XenObject is VM)
            {
                VM vm = (VM)_xenObject;

                if (NetworksGridView.Rows.Count >= vm.MaxVIFsAllowed())
                {
                    using (var dlg = new ThreeButtonDialog(
                               new ThreeButtonDialog.Details(
                                   SystemIcons.Error,
                                   FriendlyErrorNames.VIFS_MAX_ALLOWED,
                                   FriendlyErrorNames.VIFS_MAX_ALLOWED_TITLE)))
                    {
                        dlg.ShowDialog(Program.MainWindow);
                    }
                    return;
                }

                Host master = Helpers.GetMaster(vm.Connection);
                if (master == null)
                {
                    // Cache populating?
                    return;
                }

                VIF pVif;
                using (var d = new VIFDialog(vm.Connection, null, VIF.GetDeviceId(vm), vm.HasSriovRecommendation()))
                {
                    if (d.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }

                    pVif = d.GetNewSettings();
                }

                pVif.VM = new XenRef <VM>(vm.opaque_ref);
                var action = new CreateVIFAction(vm, pVif);
                action.Completed += createVIFAction_Completed;
                action.RunAsync();
            }
            else if (XenObject is Host)
            {
                Host host = (Host)_xenObject;
                Program.MainWindow.ShowPerConnectionWizard(_xenObject.Connection,
                                                           new NewNetworkWizard(_xenObject.Connection, null, host));
            }
            else if (XenObject is Pool)
            {
                Pool pool = (Pool)_xenObject;
                Host host = pool.Connection.Resolve(pool.master);
                if (host != null)
                {
                    Program.MainWindow.ShowPerConnectionWizard(_xenObject.Connection,
                                                               new NewNetworkWizard(_xenObject.Connection, pool, host));
                }
            }
        }
コード例 #13
0
        private void m_buttonAddNetwork_Click(object sender, EventArgs e)
        {
            if (m_networkGridView.Rows.Count >= m_vm.MaxVIFsAllowed)
            {
                new ThreeButtonDialog(new ThreeButtonDialog.Details(
                                          SystemIcons.Error,
                                          FriendlyErrorNames.VIFS_MAX_ALLOWED, FriendlyErrorNames.VIFS_MAX_ALLOWED_TITLE)).ShowDialog(Program.MainWindow);
                return;
            }

            VIF vif = new VIF {
                Connection = m_selectedConnection
            };

            int i = 0;

            while (true)
            {
                bool exists = false;
                foreach (DataGridViewRow row in m_networkGridView.Rows)
                {
                    VifRow vifRow = row as VifRow;
                    if (vifRow == null)
                    {
                        continue;
                    }

                    VIF v = vifRow.Vif;
                    if (v == null)
                    {
                        continue;
                    }

                    if (int.Parse(v.device) == i)
                    {
                        exists = true;
                    }
                }

                if (exists)
                {
                    i++;
                }
                else
                {
                    break;
                }
            }

            vif.device = i.ToString();
            vif.MAC    = Messages.MAC_AUTOGENERATE;

            if (GetDefaultNetwork() != null)
            {
                vif.network = new XenRef <XenAPI.Network>(GetDefaultNetwork().opaque_ref);
            }

            AddVIFRow(vif);
        }
コード例 #14
0
ファイル: UpdateVIFAction.cs プロジェクト: huizh/xenadmin
 /// <summary>
 /// Update the VIF
 /// </summary>
 /// <param name="vm"></param>
 /// <param name="vif"></param>
 /// <param name="proxyVIF"></param>
 public UpdateVIFAction(VM vm, VIF vif, Proxy_VIF proxyVIF)
     : base(vm.Connection, String.Format(Messages.ACTION_VIF_UPDATING_TITLE, vif.NetworkName(), vm.Name))
 {
     this.vif = vif;
     VM = vm;
     this.proxyVIF = proxyVIF;
     Initialise();
     xmlRpcMethods.ForEach(method => ApiMethodsToRoleCheck.Add(method));
 }
コード例 #15
0
ファイル: UpdateVIFAction.cs プロジェクト: hl10502/XenCenter
 /// <summary>
 /// Update the VIF
 /// </summary>
 /// <param name="vm"></param>
 /// <param name="vif"></param>
 /// <param name="proxyVIF"></param>
 public UpdateVIFAction(VM vm, VIF vif, Proxy_VIF proxyVIF)
     : base(vm.Connection, String.Format(Messages.ACTION_VIF_UPDATING_TITLE, vif.NetworkName(), vm.Name))
 {
     this.vif      = vif;
     VM            = vm;
     this.proxyVIF = proxyVIF;
     Initialise();
     xmlRpcMethods.ForEach(method => ApiMethodsToRoleCheck.Add(method));
 }
コード例 #16
0
 /// <summary>
 /// Update the VIF
 /// </summary>
 /// <param name="vm"></param>
 /// <param name="vif"></param>
 /// <param name="vifDescriptor"></param>
 public UpdateVIFAction(VM vm, VIF vif, VIF vifDescriptor)
     : base(vm.Connection, String.Format(Messages.ACTION_VIF_UPDATING_TITLE, vif.NetworkName(), vm.Name()))
 {
     this.vif           = vif;
     VM                 = vm;
     this.vifDescriptor = vifDescriptor;
     Initialise();
     apiMethods.ForEach(method => ApiMethodsToRoleCheck.Add(method));
 }
コード例 #17
0
        public NetworkListViewItem(IXenConnection connection, XenAPI.Network network, int index)
        {
            Vif = new VIF();
            Vif.Connection = connection;

            Vif.device = index.ToString();
            Vif.network = new XenRef<XenAPI.Network>(network.opaque_ref);

            CreateCells();
        }
コード例 #18
0
ファイル: UpdateVIFAction.cs プロジェクト: ywscr/xenadmin
        public UpdateVIFAction(VM vm, VIF vif, VIF vifDescriptor)
            : base(vm.Connection, string.Format(Messages.ACTION_VIF_UPDATING_TITLE, vif.NetworkName(), vm.Name()))
        {
            this.vif           = vif;
            VM                 = vm;
            this.vifDescriptor = vifDescriptor;

            ApiMethodsToRoleCheck.AddRange(DeleteVIFAction.XmlRpcMethods);
            ApiMethodsToRoleCheck.AddRange(CreateVIFAction.XmlRpcMethods);
        }
コード例 #19
0
        public PvsProxyCreateAction(VM vm, PVS_site site, VIF vif)
            : base(vm.Connection, string.Format(Messages.ACTION_ENABLE_PVS_READ_CACHING_FOR, vm, site))
        {
            this.site = site;
            this.vif  = vif;
            this.VM   = vm;

            this.Description = Messages.WAITING;
            SetRBACPermissions();
        }
コード例 #20
0
        public CreateVIFAction(VM vm, VIF vifDescriptor, bool suppressHistory = false)
            : base(vm.Connection, string.Format(Messages.ACTION_VIF_CREATING_TITLE, vm.Name()), suppressHistory)
        {
            _vifDescriptor = vifDescriptor;
            VM             = vm;

            foreach (var method in XmlRpcMethods)
            {
                ApiMethodsToRoleCheck.Add(method);
            }
        }
コード例 #21
0
        private void m_networkGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            VifRow row = m_networkGridView.Rows[e.RowIndex] as VifRow;

            if (row == null)
            {
                return;
            }

            VIF vif = row.Vif;

            if (vif == null)
            {
                return;
            }

            if (e.ColumnIndex == MACAddressNetworkColumn.Index)
            {
                row.HasValidMac = true;
                string mac = (string)row.Cells[e.ColumnIndex].Value;

                if (mac == null || mac.Trim().Length == 0)
                {
                    // We take it that zero-length mac means the user wants to auto-generate
                    row.Cells[e.ColumnIndex].Value = Messages.MAC_AUTOGENERATE;
                }
                else if (mac.Trim() == Messages.MAC_AUTOGENERATE)
                {
                    row.Cells[e.ColumnIndex].Value = Messages.MAC_AUTOGENERATE;
                    vif.MAC = Messages.MAC_AUTOGENERATE;
                }
                else if (Helpers.IsValidMAC(mac))
                {
                    vif.MAC = mac;
                }
                else
                {
                    row.HasValidMac = false;
                }

                UpdateControlsEnabledState(AllMacAddressesValid());
            }
            else if (e.ColumnIndex == NetworkNetworkColumn.Index)
            {
                object         enteredValue = row.Cells[e.ColumnIndex].Value;
                var            entry        = enteredValue as ToStringWrapper <XenAPI.Network>;
                XenAPI.Network network      = (entry == null) ? (XenAPI.Network)enteredValue : entry.item;

                if (network != null)
                {
                    vif.network = new XenRef <XenAPI.Network>(network.opaque_ref);
                }
            }
        }
コード例 #22
0
ファイル: VIFOper.cs プロジェクト: radtek/WinCenterClient
        public List <VIF> getVIFList()
        {
            List <VIF>           vifList = new List <VIF>();
            List <XenRef <VIF> > vifRefs = VIF.get_all(ConnectManager.session);

            foreach (XenRef <VIF> vifRef in vifRefs)
            {
                VIF vif = VIF.get_record(ConnectManager.session, vifRef);
                vifList.Add(vif);
            }
            return(vifList);
        }
コード例 #23
0
        public NetworkListViewItem(IXenConnection connection, VIF vif, int index, bool keepMac)
        {
            Vif = new VIF();
            Vif.Connection = connection;

            Vif.device = vif.device;
            Vif.MAC = keepMac ? vif.MAC : "";
            Vif.network = vif.network;
            Vif.qos_algorithm_type = vif.qos_algorithm_type;
            Vif.qos_algorithm_params = vif.qos_algorithm_params;

            CreateCells();
        }
コード例 #24
0
        private void AddNetworkButton_Click(object sender, EventArgs e)
        {
            if (XenObject is VM)
            {
                VM vm = (VM)_xenObject;

                if (NetworksGridView.Rows.Count >= vm.MaxVIFsAllowed)
                {
                    new ThreeButtonDialog(
                        new ThreeButtonDialog.Details(
                            SystemIcons.Error,
                            FriendlyErrorNames.VIFS_MAX_ALLOWED,
                            FriendlyErrorNames.VIFS_MAX_ALLOWED_TITLE)).ShowDialog(Program.MainWindow);
                    return;
                }

                Host master = Helpers.GetMaster(vm.Connection);
                if (master == null)
                {
                    // Cache populating?
                    return;
                }
                VIFDialog d = new VIFDialog(vm.Connection, null, VIF.GetDeviceId(vm));
                if (d.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                Proxy_VIF pVif = d.GetNewSettings();
                pVif.VM = vm.opaque_ref;
                CreateVIFCommand action = new CreateVIFCommand(Program.MainWindow, vm, pVif);
                action.Execute();
            }
            else if (XenObject is Host)
            {
                Host host = (Host)_xenObject;
                Program.MainWindow.ShowPerConnectionWizard(_xenObject.Connection,
                                                           new NewNetworkWizard(_xenObject.Connection, null, host));
            }
            else if (XenObject is Pool)
            {
                Pool pool = (Pool)_xenObject;
                Host host = pool.Connection.Resolve(pool.master);
                if (host != null)
                {
                    Program.MainWindow.ShowPerConnectionWizard(_xenObject.Connection,
                                                               new NewNetworkWizard(_xenObject.Connection, pool, host));
                }
            }
        }
コード例 #25
0
ファイル: VIFDialog.cs プロジェクト: star-dotnet/xenadmin
        public VIFDialog(IXenConnection connection, VIF existingVif, int device, bool allowSriov = false)
            : base(connection)
        {
            InitializeComponent();
            CueBannersManager.SetWatermark(promptTextBoxMac, "aa:bb:cc:dd:ee:ff");

            ExistingVif     = existingVif;
            Device          = device;
            this.allowSriov = allowSriov;

            if (ExistingVif != null)
            {
                Text          = Messages.VIRTUAL_INTERFACE_PROPERTIES;
                buttonOk.Text = Messages.OK;
            }
        }
コード例 #26
0
ファイル: CreateVMAction.cs プロジェクト: ywwseu/xenadmin
        private void AddNetworks()
        {
            // first of all we need to clear any vifs that we have cloned from the template
            double     progress = 90;
            VIF        vif;
            List <VIF> existingTemplateVifs = Connection.ResolveAll(VM.VIFs);
            double     step = 5.0 / (double)existingTemplateVifs.Count;

            for (int i = 0; i < existingTemplateVifs.Count; i++)
            {
                vif         = existingTemplateVifs[i];
                RelatedTask = XenAPI.VIF.async_destroy(Session, vif.opaque_ref);

                PollToCompletion(progress, progress + step);
                progress += step;
            }

            // then we add the ones the user has specified
            step = 5.0 / (double)Vifs.Count;
            for (int i = 0; i < Vifs.Count; i++)
            {
                vif = Vifs[i];
                List <string> devices = AllowedVIFs;
                VIF           new_vif = new VIF();

                if (devices.Count < 1)
                {
                    // If we have assigned more VIFs than we have space for then don't try to create them
                    log.Warn("Tried to create more VIFs than the server allows. Ignoring remaining vifs");
                    return;
                }
                new_vif.device               = devices.Contains(vif.device) ? vif.device : devices[0];
                new_vif.MAC                  = vif.MAC;
                new_vif.network              = vif.network;
                new_vif.VM                   = new XenRef <VM>(VM.opaque_ref);
                new_vif.qos_algorithm_type   = vif.qos_algorithm_type;
                new_vif.qos_algorithm_params = vif.qos_algorithm_params;
                RelatedTask                  = XenAPI.VIF.async_create(Session, new_vif);

                PollToCompletion(progress, progress + step);
                progress += step;

                Connection.WaitForCache(new XenRef <VIF>(Result));
            }
        }
コード例 #27
0
        private void Plug(VIF v)
        {
            if (v.currently_attached)
            {
                // We will try and plug the VIF even if it seems to be already plugged (CA-75969)
                log.DebugFormat("Plugging VIF '{0}': this VIF is currently attached. Will try to plug anyway", v.uuid);
            }

            VM vm = v.Connection.Resolve(v.VM);

            if (vm == null || vm.power_state != vm_power_state.Running)
            {
                log.DebugFormat("Ignoring VIF '{0}' for plug as its VM is not running", v.uuid);
                return;
            }

            VIF.plug(Session, v.opaque_ref);
        }
コード例 #28
0
ファイル: VIFDialog.cs プロジェクト: yimng/xenconsole
        public VIF NewVif()
        {
            VIF vif = new VIF();

            vif.Connection = connection;
            vif.network    = new XenRef <XenAPI.Network>(SelectedNetwork.opaque_ref);
            vif.MAC        = SelectedMac;
            vif.device     = Device.ToString();

            if (checkboxQoS.Checked)
            {
                vif.RateLimited = true;
            }

            // preserve this param even if we have decided not to turn on qos
            if (!string.IsNullOrEmpty(promptTextBoxQoS.Text))
            {
                Dictionary <String, String> qos_algorithm_params = new Dictionary <String, String>();
                qos_algorithm_params.Add(VIF.KBPS_QOS_PARAMS_KEY, promptTextBoxQoS.Text);
                vif.qos_algorithm_params = qos_algorithm_params;
            }
            return(vif);
        }
コード例 #29
0
ファイル: CreateVIFAction.cs プロジェクト: huizh/xenadmin
        private void CreateVIF()
        {
            VIF newVIF = new VIF(_proxyVIF);
            RelatedTask = XenAPI.VIF.async_create(Session, newVIF);

            PollToCompletion();
            string newVifRef = Result;

            if (VM.power_state == XenAPI.vm_power_state.Running)
            {
                if (XenAPI.VIF.get_allowed_operations(Session, newVifRef).Contains(XenAPI.vif_operations.plug))
                {
                    // Try hotplug
                    XenAPI.VIF.plug(Session, newVifRef);
                    Result = true.ToString();
                }
                else
                {
                    Result = false.ToString();
                }
            }
            else
                Result = true.ToString();
        }
コード例 #30
0
 public VifRow(VIF vif)
 {
     Vif = vif;
 }
コード例 #31
0
ファイル: Import.cs プロジェクト: ushamandya/xenadmin
        private void AddResourceSettingData(Session xenSession, XenRef<VM> vmRef, RASD_Type rasd, string pathToOvf, string filename, string compression, string version, string passcode)
        {
            switch (rasd.ResourceType.Value)
            {
                case 3: // Processor: Already set in DefineSystem
                case 4: // Memory: Already set in DefineSystem
                case 5: // Internal Disk Controller of one type or another.
                case 6:
                case 7:
                case 8:
                case 9:
                    {
                        // For Xen really nothing to do here, does not support the different
                        // controller types, therefore we must ensure
                        // via positional on controllers.
                        // IDE - #1
                        // SCSI - #2
                        // IDE 0 Disk  0 Goes to Xen: userdevice=0
                        // IDE 0 Disk  1 Goes to Xen: userdevice=1
                        // IDE 1 Disk  0 Goes to Xen: userdevice=2
                        // IDE 1 CDDVD 1 Goes to Xen: userdevice=3
                        // SCSI 0 Disk 0 Goes to Xen: userdevice=4
                        // SCSI 0 Disk 1 Goes to Xen: userdevice=5
                        // and so forth.
                        break;
                    }
                case 10: // Network
                    {
                        XenRef<Network> net = null;
                        XenRef<Network> netDefault = null;
                        string netuuid = null;

                        #region SELECT NETWORK
                        Dictionary<XenRef<Network>, Network> networks = Network.get_all_records(xenSession);
                        if (rasd.Connection != null && rasd.Connection.Length > 0)
                        {
                            if (!string.IsNullOrEmpty(rasd.Connection[0].Value))
                            {
                                // Ignore the NetworkSection/Network
                                // During Network Selection the UUID for Network was set in Connection Field
                                // Makes data self contained here.

                                if (rasd.Connection[0].Value.Contains(Properties.Settings.Default.xenNetworkKey) ||
                                    rasd.Connection[0].Value.Contains(Properties.Settings.Default.xenNetworkUuidKey))
                                {
                                    string[] s = rasd.Connection[0].Value.Split(new char[] { ',' });
                                    for (int i = 0; i < s.Length; i++)
                                    {
                                        if (s[i].StartsWith(Properties.Settings.Default.xenNetworkKey) ||
                                            s[i].StartsWith(Properties.Settings.Default.xenNetworkUuidKey))
                                        {
                                            string[] s1 = s[i].Split(new char[] { '=' } );
                                            netuuid = s1[1];
                                        }
                                    }
                                }
                                foreach (XenRef<Network> netRef in networks.Keys)
                                {
                                    // if its a UUID and we find it... use it..
                                    if (net == null && netuuid != null &&
                                        netuuid.Equals(networks[netRef].uuid))
                                    {
                                        net = netRef;
                                    }
                                    // Ok second is to match it as a NAME_LABEL
                                    else if (net == null && netuuid != null &&
                                        networks[netRef].name_label.ToLower().Contains(netuuid))
                                    {
                                        net = netRef;
                                    }
                                    // hhmm neither... is it a BRIDGE name?
                                    else if (net == null && netuuid != null &&
                                        networks[netRef].bridge.ToLower().Contains(netuuid))
                                    {
                                        net = netRef;
                                    }
                                    // ok find the default.
                                    if (networks[netRef].bridge.ToLower().Contains(Properties.Settings.Default.xenDefaultNetwork))
                                    {
                                        netDefault = netRef;
                                    }
                                }
                                if (net == null)
                                {
                                    net = netDefault;
                                }
                            }
                        }
                        #endregion

                        #region ATTACH NETWORK TO VM
                        Hashtable vifHash = new Hashtable();
                        // This is MAC address if available use it.
                        // needs to be in form:  00:00:00:00:00:00
                        if (Tools.ValidateProperty("Address", rasd))
                        {
                            StringBuilder networkAddress = new StringBuilder();
                            if (!rasd.Address.Value.Contains(":"))
                            {
                                for (int i = 0; i < rasd.Address.Value.Length; i++)
                                {
                                    if ((i > 0) && (i % 2) == 0)
                                    {
                                        networkAddress.Append(":");
                                    }
                                    networkAddress.Append(rasd.Address.Value[i]);
                                }
                            }
                            if (networkAddress.Length == 0)
                            {
                                networkAddress.Append(rasd.Address.Value);
                            }
                            vifHash.Add("MAC", networkAddress.ToString());
                        }
                        vifHash.Add("uuid", Guid.NewGuid().ToString());
                        vifHash.Add("allowed_operations", new string[] { "attach" });
                        vifHash.Add("device", Convert.ToString(vifDeviceIndex++));
                        vifHash.Add("network", net.opaque_ref);
                        vifHash.Add("VM", vmRef.opaque_ref);
                        vifHash.Add("MTU", "1500");
                        vifHash.Add("locking_mode", "network_default");
                        VIF vif = new VIF(vifHash);
                        try
                        {
                            VIF.create(xenSession, vif);
                        }
                        catch (Exception ex)
                        {
                            log.ErrorFormat("{0} {1}", Messages.ERROR_CREATE_VIF_FAILED, ex.Message);
                            throw new Exception(Messages.ERROR_CREATE_VIF_FAILED, ex);
                        }
                        #endregion
                        log.Debug("OVF.Import.AddResourceSettingData: Network Added");

                        break;
                    }
                case 15: // CD Drive
                case 16: // DVD Drive
                    {
                        // We always attach as "EMPTY".
                        // Currenlty Xen Server can only have ONE CD, so we must
                        // Skip the others.
                        // If it's not necessary.. skip it.

                        #region Attach DVD to VM
                        bool SkipCD = false;
                        List<XenRef<VBD>> vbds = VM.get_VBDs(xenSession, vmRef);
                        foreach (XenRef<VBD> vbd in vbds)
                        {
                            vbd_type vbdType = VBD.get_type(xenSession, vbd);
                            if (vbdType == vbd_type.CD)
                            {
                                SkipCD = true;
                                break;
                            }
                        }

                        if (!SkipCD)
                        {
                            List<XenRef<VDI>> vdiRef = new List<XenRef<VDI>>();
                            if (filename != null)
                            {
                                #region IS THE ISO SR IN THE OVF?
                                string isoUuid = null;
                                if (rasd.Connection != null && rasd.Connection.Length > 0)
                                {
                                    if (rasd.Connection[0].Value.ToLower().Contains("sr="))
                                    {
                                        string[] vpairs = rasd.Connection[0].Value.Split(new char[] { ',' });
                                        foreach (string vset in vpairs)
                                        {
                                            if (vset.ToLower().StartsWith("sr="))
                                            {
                                                isoUuid = vset.Substring(vset.LastIndexOf('=') + 1);
                                                try
                                                {
                                                    #region TRY IT AS UUID
                                                    try
                                                    {
                                                        XenRef<SR> srref = SR.get_by_uuid(xenSession, isoUuid);
                                                        if (srref == null)
                                                        {
                                                            isoUuid = null;
                                                        }
                                                        else
                                                        {
                                                            break;
                                                        }
                                                    }
                                                    catch
                                                    {
                                                        traceLog.Debug("Import.AddResourceSettingData: iso sr uuid not found, trying name_label");
                                                    }
                                                    #endregion

                                                    #region TRY IT AS NAME_LABEL
                                                    try
                                                    {
                                                        List<XenRef<SR>> srrefList = SR.get_by_name_label(xenSession, isoUuid);
                                                        if (srrefList != null && srrefList.Count > 0)
                                                        {
                                                            isoUuid = SR.get_uuid(xenSession, srrefList[0]);
                                                            break;
                                                        }
                                                    }
                                                    catch
                                                    {
                                                        traceLog.Debug("Import.AddResourceSettingData: iso sr uuid not found, looking for vdi...");
                                                    }
                                                    #endregion
                                                }
                                                catch (Exception ex)
                                                {
                                                    log.WarnFormat("Import.AddResourceSettingData: could not find SR: {0}", ex.Message);
                                                    isoUuid = null;
                                                }
                                                break;
                                            }
                                        }
                                    }
                                }
                                #endregion

                                // VDI trumps SR
                                List<XenRef<VDI>> isoVDIlist = VDI.get_by_name_label(xenSession, filename);
                                if (isoVDIlist.Count > 0)
                                {
                                    vdiRef.Add(isoVDIlist[0]);
                                }
                                else
                                {
                                    #region LAST CHANCE USE XENTOOLS ISO SR
                                    if (isoUuid == null)
                                    {
                                        Dictionary<XenRef<SR>, SR> srDictionary = SR.get_all_records(xenSession);
                                        foreach (XenRef<SR> key in srDictionary.Keys)
                                        {
                                            if (srDictionary[key].content_type.ToLower() == "iso" && srDictionary[key].type.ToLower() == "iso")
                                            {
                                                if (srDictionary[key].name_label.ToLower().Equals(Properties.Settings.Default.xenTools.ToLower()))
                                                {
                                                    isoUuid = srDictionary[key].uuid;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    #endregion

                                    #region DO IMPORT ISO FILE
                                    if (isoUuid != null && !MetaDataOnly)
                                    {
                                        _currentfilename = filename;
                                        try
                                        {
                                            vdiRef = ImportFileProc(new TaskInfo(xenSession, this, filename, pathToOvf, filename, isoUuid, version, passcode, compression, "", null));
                                        }
                                        catch (Exception ex)
                                        {
                                            if (ex is OperationCanceledException)
                                                throw;
                                            var msg = string.Format(Messages.ERROR_ADDRESOURCESETTINGDATA_FAILED, Messages.ISO);
                                            log.ErrorFormat("{0}, {1}", msg, ex.Message);
                                            throw new Exception(msg, ex);
                                        }
                                        finally
                                        {
                                            if (vdiRef == null || vdiRef.Count <= 0)
                                            {
                                                log.Error(string.Format(Messages.ERROR_IMPORT_DISK_FAILED, filename, isoUuid));
                                                RemoveSystem(xenSession, vmRef);
                                            }
                                        }
                                    }
                                    #endregion
                                }
                            }
                            else
                            {
                                vdiRef.Add(XenRef<VDI>.Create(string.Empty));
                            }

                            #region CREATE VBD CONNECTION
                            string booleans = "empty,bootable,unpluggable,attachable,storage-lock";
                            string skipvalues = "sr,vdi";

                            foreach (XenRef<VDI> currentVDI in vdiRef)
                            {
                                Hashtable vbdHash = new Hashtable();

                                if (rasd.Connection != null && rasd.Connection.Length > 0)
                                {
                                    string[] valuepairs = rasd.Connection[0].Value.Split(new char[] { ',' });

                                    foreach (string valuepair in valuepairs)
                                    {
                                        string[] namevalue = valuepair.Split(new char[] { '=' });
                                        if (!skipvalues.ToLower().Contains(namevalue[0].ToLower()))
                                        {
                                            string name = namevalue[0];
                                            if (name.ToLower().Equals("device"))
                                            {
                                                name = "userdevice";
                                            }
                                            if (booleans.Contains(name))
                                            {
                                                vbdHash.Add(name, Convert.ToBoolean(namevalue[1]));
                                            }
                                            else
                                            {
                                                vbdHash.Add(name, namevalue[1]);
                                            }
                                        }
                                    }
                                }
                                if (!vbdHash.ContainsKey("vm-name-label")) vbdHash.Add("vm-name-label", VM.get_name_label(xenSession, vmRef));
                                if (!vbdHash.ContainsKey("VM")) vbdHash.Add("VM", vmRef.opaque_ref);
                                if (currentVDI != null && !string.IsNullOrEmpty(currentVDI.opaque_ref))
                                {
                                    // Override values.
                                    if (!vbdHash.ContainsKey("VDI")) vbdHash.Add("VDI", currentVDI.opaque_ref);
                                    else vbdHash["VDI"] = currentVDI.opaque_ref;
                                    if (!vbdHash.ContainsKey("empty")) vbdHash.Add("empty", false);
                                    else vbdHash["empty"] = false;
                                    if (!vbdHash.ContainsKey("bootable")) vbdHash.Add("bootable", true);
                                    else vbdHash["bootable"] = true;
                                    if (!vbdHash.ContainsKey("unpluggable")) vbdHash.Add("unpluggable", true);
                                    else vbdHash["unpluggable"] = true;
                                }
                                else
                                {
                                    // Override.
                                    if (!vbdHash.ContainsKey("empty")) vbdHash.Add("empty", true);
                                    else vbdHash["empty"] = true;
                                }
                                if (!vbdHash.ContainsKey("mode")) vbdHash.Add("mode", "RO");
                                if (!vbdHash.ContainsKey("userdevice")) vbdHash.Add("userdevice", "3");
                                if (!vbdHash.ContainsKey("type")) vbdHash.Add("type", "CD");
                                if (!vbdHash.ContainsKey("attachable")) vbdHash.Add("attachable", true);
                                if (!vbdHash.ContainsKey("storage-lock")) vbdHash.Add("storage-lock", false);
                                if (!vbdHash.ContainsKey("status-code")) vbdHash.Add("status-code", "0");

                                vbdHash["userdevice"] = VerifyUserDevice(xenSession, vmRef, (string)vbdHash["userdevice"]);

                                Hashtable hOtherConfig = new Hashtable();
                                hOtherConfig.Add("owner", "true");
                                vbdHash.Add("other_config", hOtherConfig);

                                if (!((string)vbdHash["userdevice"]).EndsWith("+"))
                                {
                                    VBD vbd = new VBD(vbdHash);
                                    try
                                    {
                                        VBD.create(xenSession, vbd);
                                    }
                                    catch (Exception ex)
                                    {
                                        log.ErrorFormat("Import.AddResourceSettingData: {0}", ex.Message);
                                    }
                                }
                                else
                                {
                                    log.WarnFormat("Import:  ================== ATTENTION NEEDED =======================");
                                    log.WarnFormat("Import:  Could not determine appropriate number of device placement.");
                                    log.WarnFormat("Import:  Please Start, Logon, Shut down, System ({0})", (string)vbdHash["vm_name_label"]);
                                    log.WarnFormat("Import:  Then attach disks with labels ending with \"+\" to the device number defined before the +.");
                                    log.Warn("Import:  ===========================================================");
                                    OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.Progress, "Import", Messages.WARNING_ADMIN_REQUIRED));
                                }
                            }
                            #endregion

                        }
                        #endregion
                        OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.ImportProgress, "CD/DVD Drive",
                            string.Format(Messages.DEVICE_ATTACHED, Messages.CD_DVD_DEVICE)));
                        log.Debug("Import.AddResourceSettingData: CD/DVD ROM Added");

                        break;
                    }
                case 17: // Disk Drive
                case 19: // Storage Extent
                case 21: // Microsoft: Harddisk/Floppy/ISO
                    {
                        #region ADD DISK
                        if (filename == null) // NO disk is available, why import RASD?
                        {
                            log.WarnFormat("No file available to import, skipping: RASD{0}: {1}", rasd.ResourceType.Value, rasd.InstanceID.Value);
                            break;
                        }
                        string sruuid = null;
                        string vdiuuid = null;
                        string userdeviceid = null;
                        string namelabel = VM.get_name_label(xenSession, vmRef);
                        bool isbootable = false;
                        string mode = "RW";

                        bool importThisRasd = true;
                        if (Tools.ValidateProperty("Caption", rasd)) // rasd.Caption != null && rasd.Caption.Value != null && rasd.Caption.Value.Length > 0)
                        {
                            if (
                                rasd.Caption.Value.ToUpper().Contains("COM") ||
                                rasd.Caption.Value.ToUpper().Contains("FLOPPY") ||
                                rasd.Caption.Value.ToUpper().Contains("ISO")
                                )
                            {
                                importThisRasd = false;
                            }
                        }

                        if (importThisRasd)
                        {
                            #region IMPORT DISKS
                            if (!MetaDataOnly)
                            {
                                _currentfilename = filename;

                                List<XenRef<VDI>> vdiRef = null;

                                #region PARSE CONNECTION
                                if (Tools.ValidateProperty("Connection", rasd))
                                {
                                    string[] s = rasd.Connection[0].Value.Split(new char[] { '=', ',' });
                                    for (int i = 0; i < s.Length; i++)
                                    {
                                        string checkme = s[i].ToLower().Trim();
                                        switch (checkme)
                                        {
                                            case "device":
                                                {
                                                    userdeviceid = s[++i];
                                                    break;
                                                }
                                            case "bootable":
                                                {
                                                    isbootable = Convert.ToBoolean(s[++i]);
                                                    break;
                                                }
                                            case "mode":
                                                {
                                                    if (s[++i].Equals("r"))
                                                    {
                                                        mode = "RO";
                                                    }
                                                    break;
                                                }
                                            case "vdi":
                                                {
                                                    vdiuuid = s[++i];
                                                    break;
                                                }
                                            case "sr":
                                                {
                                                    sruuid = s[++i];
                                                    break;
                                                }
                                        }
                                    }
                                }
                                #endregion

                                #region VERIFY SR UUID
                                if (!string.IsNullOrEmpty(sruuid))
                                {
                                    XenRef<SR> srref = null;
                                    try
                                    {
                                        srref = SR.get_by_uuid(xenSession, sruuid);
                                    }
                                    catch
                                    {
                                        traceLog.Debug("Import.AddResourceSettingData: SR missing... still looking..");
                                    }
                                    if (srref == null)
                                    {
                                        List<XenRef<SR>> srlist = null;
                                        try
                                        {
                                            srlist = SR.get_by_name_label(xenSession, sruuid);
                                        }
                                        catch
                                        {
                                            traceLog.Debug("Import.AddResourceSettingData: SR missing... still looking..");
                                        }
                                        if (srlist != null && srlist.Count > 0)
                                        {
                                            sruuid = SR.get_uuid(xenSession, srlist[0]);
                                        }
                                    }
                                }
                                else
                                {
                                    sruuid = null;
                                }
                                #endregion

                                #region LAST CHANGE TO FIND SR
                                if (sruuid == null)
                                {
                                    if (DefaultSRUUID == null)
                                    {
                                        log.Error(Messages.ERROR_COULD_NOT_FIND_SR);
                                        throw new InvalidDataException(Messages.ERROR_COULD_NOT_FIND_SR);
                                    }

                                    Dictionary<XenRef<SR>, SR> srDict = SR.get_all_records(xenSession);
                                    if (vdiuuid != null)
                                    {
                                        //Try and get the SR that belongs to the VDI attached
                                        XenRef<VDI> tempVDI = VDI.get_by_uuid(xenSession, vdiuuid);
                                        if (tempVDI == null)
                                        {
                                            log.Error(Messages.ERROR_COULD_NOT_FIND_SR);
                                            throw new InvalidDataException(Messages.ERROR_COULD_NOT_FIND_SR);
                                        }

                                        XenRef<SR> tempSR = VDI.get_SR(xenSession, tempVDI.opaque_ref);
                                        sruuid = srDict[tempSR].uuid;
                                    }
                                    else
                                        sruuid = srDict[DefaultSRUUID].uuid;
                                }
                                #endregion

                                try
                                {
                                    string disklabel = string.Format("{0}_{1}",namelabel, userdeviceid);

                                    if ((rasd.ElementName != null) && (!string.IsNullOrEmpty(rasd.ElementName.Value)))
                                        disklabel = rasd.ElementName.Value;

                                    string description = "";

                                    if ((rasd.Description != null) && (!string.IsNullOrEmpty(rasd.Description.Value)))
                                        description = rasd.Description.Value;

                                    vdiRef = ImportFileProc(new TaskInfo(xenSession, this, disklabel, pathToOvf, filename, sruuid, version, passcode, compression, description, vdiuuid));
                                }
                                catch (Exception ex)
                                {
                                    if (ex is OperationCanceledException)
                                        throw;
                                    var msg = string.Format(Messages.ERROR_ADDRESOURCESETTINGDATA_FAILED, Messages.DISK_DEVICE);
                                    log.ErrorFormat("{0} {1}", msg, ex.Message);
                                    throw new InvalidDataException(msg, ex);
                                }
                                finally
                                {
                                    if (vdiRef == null)
                                    {
                                        var msg = string.Format(Messages.ERROR_IMPORT_DISK_FAILED, filename, sruuid);
                                        log.Error(msg);
                                        RemoveSystem(xenSession, vmRef);
                                    }
                                }

                                log.DebugFormat("Import.AddResourceSettingData coung {0} VDIs", vdiRef.Count);

                                foreach (XenRef<VDI> currentVDI in vdiRef)
                                {
                                    Hashtable vbdHash = new Hashtable();
                                    if (userdeviceid != null)
                                    {
                                        vbdHash.Add("userdevice", VerifyUserDevice(xenSession, vmRef, userdeviceid));
                                    }
                                    else
                                    {
                                        vbdHash.Add("userdevice", VerifyUserDevice(xenSession, vmRef, "99"));
                                    }
                                    vbdHash.Add("bootable", isbootable);
                                    vbdHash.Add("VDI", currentVDI.opaque_ref);
                                    vbdHash.Add("mode", mode);
                                    vbdHash.Add("uuid", Guid.NewGuid().ToString());
                                    vbdHash.Add("vm_name_label", namelabel);
                                    vbdHash.Add("VM", vmRef.opaque_ref);
                                    vbdHash.Add("empty", false);
                                    vbdHash.Add("type", "Disk");
                                    vbdHash.Add("currently_attached", false);
                                    vbdHash.Add("attachable", true);
                                    vbdHash.Add("storage_lock", false);
                                    vbdHash.Add("status_code", "0");

                                    #region SET OTHER_CONFIG STUFF HERE !
                                    //
                                    // below other_config keys XS to delete the disk along with the VM.
                                    //
                                    Hashtable hOtherConfig = new Hashtable();
                                    hOtherConfig.Add("owner", "true");
                                    vbdHash.Add("other_config", hOtherConfig);
                                    #endregion

                                    if (!((string)vbdHash["userdevice"]).EndsWith("+"))
                                    {
                                        VBD vbd = new VBD(vbdHash);

                                        try
                                        {
                                            VBD.create(xenSession, vbd);
                                        }
                                        catch (Exception ex)
                                        {
                                            log.ErrorFormat("{0} {1}", Messages.ERROR_CREATE_VBD_FAILED, ex.Message);
                                            throw new Exception(Messages.ERROR_CREATE_VBD_FAILED, ex);
                                        }
                                    }
                                    else
                                    {
                                        log.WarnFormat("Import:  ================== ATTENTION NEEDED =======================");
                                        log.WarnFormat("Import:  Could not determine appropriate number for device placement.");
                                        log.WarnFormat("Import:  Please Start, Logon, Shut down, System ({0})", (string)vbdHash["vm_name_label"]);
                                        log.WarnFormat("Import:  Then manually attach disks with labels with {0}_# that are not attached to {0}", (string)vbdHash["vm_name_label"]);
                                        log.WarnFormat("Import:  ===========================================================");
                                        OnUpdate(new XenOvfTranportEventArgs(XenOvfTranportEventType.Progress, "Import", Messages.WARNING_ADMIN_REQUIRED));
                                    }
                                }
                            }
                            else
                            {
                                log.InfoFormat("Import: FILE SKIPPED (METADATA ONLY SELECTED)  {0}", _currentfilename);
                            }
                            #endregion

                        }
                        log.Debug("Import.AddResourceSettingData: Hard Disk Image Added");
                        break;
                        #endregion
                    }
            }
        }
コード例 #32
0
 public CrossPoolMigrationNetworkResource(VIF vif)
 {
     this.vif = vif;
 }
コード例 #33
0
        private void m_buttonAddNetwork_Click(object sender, EventArgs e)
        {
            if (m_networkGridView.Rows.Count >= m_vm.MaxVIFsAllowed)
            {
                using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(
                                      	SystemIcons.Error,
                                        FriendlyErrorNames.VIFS_MAX_ALLOWED, FriendlyErrorNames.VIFS_MAX_ALLOWED_TITLE)))
                {
                    dlg.ShowDialog(Program.MainWindow);
                }
                return;
            }

            VIF vif = new VIF {Connection = m_selectedConnection};

            int i = 0;
            while (true)
            {
                bool exists = false;
                foreach (DataGridViewRow row in m_networkGridView.Rows)
                {
                    VifRow vifRow = row as VifRow;
                    if (vifRow == null)
                        continue;

                    VIF v = vifRow.Vif;
                    if (v == null)
                        continue;

                    if (int.Parse(v.device) == i)
                        exists = true;
                }

                if (exists)
                    i++;
                else
                    break;
            }

            vif.device = i.ToString();
            vif.MAC = Messages.MAC_AUTOGENERATE;

            if (GetDefaultNetwork() != null)
                vif.network = new XenRef<XenAPI.Network>(GetDefaultNetwork().opaque_ref);

            AddVIFRow(vif);
        }
コード例 #34
0
ファイル: NetworkList.cs プロジェクト: agimofcarmen/xenadmin
            public VifRow(VIF vif)
            {
                Vif = vif;

                Cells.AddRange(ImageCell,
                               DeviceCell,
                               MacCell,
                               LimitCell,
                               NetworkCell,
                               IpCell,
                               AttachedCell);

                Vif.PropertyChanged += Server_PropertyChanged;

                UpdateDetails();
            }
コード例 #35
0
ファイル: ImportVmAction.cs プロジェクト: slamj1/xenadmin
        protected override void Run()
        {
            SafeToExit = false;
        	bool isTemplate;

        	try
            {
                string vmRef = GetVmRef(applyFile());

            	if (Cancelling)
                    throw new CancelledException();

                // Now lets try and set the affinity and start the VM

                if (string.IsNullOrEmpty(vmRef))
                    return;

                while (!Cancelling && (VM = Connection.Resolve(new XenRef<VM>(vmRef))) == null)
                    Thread.Sleep(100);

                if (Cancelling)
                    throw new CancelledException();

                isTemplate = VM.get_is_a_template(Session, vmRef);
                Description = isTemplate ? Messages.IMPORT_TEMPLATE_UPDATING_TEMPLATE : Messages.IMPORTVM_UPDATING_VM;
                VM.set_name_label(Session, vmRef, DefaultVMName(VM.get_name_label(Session, vmRef)));

				if (!isTemplate && m_affinity != null)
					VM.set_affinity(Session, vmRef, m_affinity.opaque_ref);

                // Wait here for the wizard to finish
                Description = isTemplate ? Messages.IMPORT_TEMPLATE_WAITING_FOR_WIZARD : Messages.IMPORTVM_WAITING_FOR_WIZARD;
				lock (monitor)
				{
					while (!(m_wizardDone || Cancelling))
						Monitor.Wait(monitor);
				}

                if (Cancelling)
                    throw new CancelledException();

                if (m_proxyVIFs != null)
                {
                    Description = isTemplate ? Messages.IMPORT_TEMPLATE_UPDATING_NETWORKS : Messages.IMPORTVM_UPDATING_NETWORKS;

                    // We need to destroy all vifs and recreate them.

                    List<XenRef<VIF>> vifs = VM.get_VIFs(Session, vmRef);
                    List<XenAPI.Network> networks = new List<XenAPI.Network>();

                    foreach (XenRef<VIF> vif in vifs)
                    {
                        // Save the network as we may have to delete it later
                        XenAPI.Network network = Connection.Resolve(VIF.get_network(Session, vif));
                        if (network != null)
                            networks.Add(network);

                        VIF.destroy(Session, vif);
                    }

                    foreach (Proxy_VIF proxyVIF in m_proxyVIFs)
                    {
                        VIF vif = new VIF(proxyVIF) {VM = new XenRef<VM>(vmRef)};
                        VIF.create(Session, vif);
                    }

                    // now delete any Networks associated with this task if they have no VIFs

                    foreach (XenAPI.Network network in networks)
                    {
                        if (!network.other_config.ContainsKey(IMPORT_TASK))
                            continue;

                        if (network.other_config[IMPORT_TASK] != RelatedTask.opaque_ref)
                            continue;

                        try
                        {
                            if (XenAPI.Network.get_VIFs(Session, network.opaque_ref).Count > 0)
                                continue;

                            if (XenAPI.Network.get_PIFs(Session, network.opaque_ref).Count > 0)
                                continue;

                            XenAPI.Network.destroy(Session, network.opaque_ref);
                        }
                        catch (Exception e)
                        {
                            log.ErrorFormat("Exception while deleting network {0}. Squashing.", network.Name);
                            log.Error(e, e);
                        }
                    }
                }

                if (!VM.get_is_a_template(Session, vmRef))
                {
                    if (m_startAutomatically)
                    {
                        Description = Messages.IMPORTVM_STARTING;
                        VM.start(Session, vmRef, false, false);
                    }
                }
            }
            catch (CancelledException)
            {
                Description = Messages.CANCELLED_BY_USER;
                throw;
            }

            Description = isTemplate ? Messages.IMPORT_TEMPLATE_IMPORTCOMPLETE : Messages.IMPORTVM_IMPORTCOMPLETE;
        }
コード例 #36
0
        static string createVIF(Session session, string netRef, string vmRef, string device)
        {
            VIF vif = new VIF()
            {
                VM = new XenRef<VM>(vmRef),
                network = new XenRef<Network>(netRef),
                device = device
            };
            XenRef<VIF> vifRef = VIF.create(session, vif);

            return vifRef.opaque_ref;
        }
コード例 #37
0
        private void AddVIFRow(VIF vif)
        {
            var row = new VifRow(vif);
            XenAPI.Network network = m_selectedConnection.Resolve(vif.network);
            bool isGuestInstallerNetwork = network != null && network.IsGuestInstallerNetwork;

            ToStringWrapper<XenAPI.Network> comboBoxEntry = FindComboBoxEntryForNetwork(network);
            // CA-66962: Don't choose disallowed networks: choose a better one instead.
            // CA-79930/CA-73056: Except for the guest installer network, which we let
            // through for now, but hide it below.
            if (comboBoxEntry == null && !isGuestInstallerNetwork)
            {
                network = GetDefaultNetwork();
                comboBoxEntry = FindComboBoxEntryForNetwork(network);
                vif.network = new XenRef<XenAPI.Network>(network.opaque_ref);
            }

            row.CreateCells(m_networkGridView,
                            String.Format(Messages.NETWORKPICKER_INTERFACE, vif.device),
                            vif.MAC,
                            comboBoxEntry);
            row.Cells[0].ReadOnly = true;

            // CA-73056: A row for the guest installer network shouldn't show up. But we still need
            // it present but invisible, otherwise the corresponding VIF doesn't get created at all.
            // CA-218956 - Expose HIMN when showing hidden objects
            if (isGuestInstallerNetwork && !XenAdmin.Properties.Settings.Default.ShowHiddenVMs)
                row.Visible = false;

            m_networkGridView.Rows.Add(row);
        }
コード例 #38
0
        private void Unplug(VIF v)
        {
            if (!v.currently_attached)
            {
                // We will try and unplug the VIF even if it seems to be already unplugged (CA-75969)
                log.DebugFormat("Unplugging VIF '{0}': this VIF is not currently attached. Will try to unplug anyway", v.uuid);
            }

            VM vm = v.Connection.Resolve(v.VM);
            if (vm == null || vm.power_state != vm_power_state.Running)
            {
                log.DebugFormat("Ignoring VIF '{0}' for unplug as its VM is not running", v.uuid);
                return;
            }

            VIF.unplug(Session, v.opaque_ref);
        }
コード例 #39
0
        private void AddNetworks()
        {
            // first of all we need to clear any vifs that we have cloned from the template
            double progress = 90;
            VIF vif;
            List<VIF> existingTemplateVifs = Connection.ResolveAll(VM.VIFs);
            double step = 5.0 / (double)existingTemplateVifs.Count;
            for (int i = 0; i < existingTemplateVifs.Count; i++)
            {
                vif = existingTemplateVifs[i];
                RelatedTask = XenAPI.VIF.async_destroy(Session, vif.opaque_ref);

                PollToCompletion(progress, progress + step);
                progress += step;
            }

            // then we add the ones the user has specified
            step = 5.0 / (double)Vifs.Count;
            for (int i = 0; i < Vifs.Count; i++)
            {
                vif = Vifs[i];
                List<string> devices = AllowedVIFs;
                VIF new_vif = new VIF();

                if (devices.Count < 1)
                {
                    // If we have assigned more VIFs than we have space for then don't try to create them
                    log.Warn("Tried to create more VIFs than the server allows. Ignoring remaining vifs");
                    return;
                }
                new_vif.device = devices.Contains(vif.device) ? vif.device : devices[0];
                new_vif.MAC = vif.MAC;
                new_vif.network = vif.network;
                new_vif.VM = new XenRef<VM>(VM.opaque_ref);
                new_vif.qos_algorithm_type = vif.qos_algorithm_type;
                new_vif.qos_algorithm_params = vif.qos_algorithm_params;
                RelatedTask = XenAPI.VIF.async_create(Session, new_vif);

                PollToCompletion(progress, progress + step);
                progress += step;

                Connection.WaitForCache(new XenRef<VIF>(Result));
            }
        }