Esempio n. 1
0
        /// <summary>
        /// Update a network.
        /// </summary>
        /// <param name="network">The modified network that we're going to save to the server.</param>
        /// <param name="changePIFs">True if we're going to create or destroy PIFs (i.e. change a private network to a
        /// VLAN, or vice versa.</param>
        /// <param name="external">Whether the new network is external i.e. a VLAN.</param>
        /// <param name="pif">The PIF representing the physical NIC from which we're basing our new VLAN.
        /// Null iff changePIFs is false or external is false.</param>
        /// <param name="vlan">The new VLAN tag.  Ignored iff changePIFs is false or external is false.</param>
        /// <param name="suppressHistory"></param>
        public NetworkAction(IXenConnection connection, XenAPI.Network network,
                             bool changePIFs, bool external, PIF pif, long vlan, bool suppressHistory)
            : base(connection, string.Format(Messages.NETWORK_ACTION_UPDATING_NETWORK_TITLE,
                                             network.Name(), Helpers.GetName(connection)), suppressHistory)
        {
            actionType        = network_actions.update;
            this.networkClone = network;
            this.changePIFs   = changePIFs;
            this.external     = external;
            this.pif          = pif;
            this.vlan         = vlan;
            PIFs = changePIFs ? Connection.ResolveAll(network.PIFs) : null;

            #region RBAC Dependencies
            ApiMethodsToRoleCheck.Add("network.set_name_label");
            ApiMethodsToRoleCheck.Add("network.set_other_config");
            ApiMethodsToRoleCheck.Add("network.add_to_other_config");
            ApiMethodsToRoleCheck.Add("network.remove_from_other_config");
            ApiMethodsToRoleCheck.Add("network.set_tags");
            ApiMethodsToRoleCheck.Add("network.add_tags");
            ApiMethodsToRoleCheck.Add("network.remove_tags");
            if (changePIFs)
            {
                ApiMethodsToRoleCheck.Add("pif.destroy");
                if (external)
                {
                    ApiMethodsToRoleCheck.Add("pool.create_VLAN_from_PIF");
                }
            }

            #endregion

            init();
        }
Esempio n. 2
0
 public CreateChinAction(IXenConnection connection, XenAPI.Network newNetwork, XenAPI.Network theInterface)
     : base(connection,
            string.Format(Messages.NETWORK_ACTION_CREATING_NETWORK_TITLE, newNetwork.Name(), Helpers.GetName(connection)))
 {
     this.newNetwork   = newNetwork;
     this.theInterface = theInterface;
 }
Esempio n. 3
0
 public CreateSriovAction(IXenConnection connection, XenAPI.Network newNetwork, List <XenAPI.PIF> pifs)
     : base(connection,
            string.Format(Messages.NETWORK_ACTION_CREATING_NETWORK_TITLE, newNetwork.Name(), Helpers.GetName(connection)))
 {
     this.newNetwork   = newNetwork;
     this.selectedPifs = pifs;
 }
Esempio n. 4
0
        protected override void Run()
        {
            PercentComplete             = 0;
            Connection.ExpectDisruption = true;

            int incr = Masters.Count > 0 ? 50 / Masters.Count : 0;

            try
            {
                foreach (PIF master in Masters)
                {
                    NetworkingActionHelpers.MoveManagementInterfaceName(this, master, FirstSlaves[master]);
                    PercentComplete += incr;
                }
            }
            catch (WebException we)
            {
                //ignore keep-alive failure since disruption is expected
                if (we.Status != WebExceptionStatus.KeepAliveFailure)
                {
                    throw;
                }
            }

            PercentComplete = 50;

            Exception e = null;

            int inc = Bonds.Count > 0 ? 40 / Bonds.Count : 0;

            foreach (Bond bond in Bonds)
            {
                Bond bond1 = bond;
                BestEffort(ref e, delegate() { RelatedTask = Bond.async_destroy(Session, bond1.opaque_ref); });
                PollToCompletion(PercentComplete, PercentComplete + inc);
            }

            PercentComplete = 90;

            if (Network != null)
            {
                string oldNetworkName = Network.Name();

                // Destroy the old network
                log.DebugFormat("Destroying network {0} ({1})...", oldNetworkName, Network.uuid);
                BestEffort(ref e, delegate()
                {
                    XenAPI.Network.destroy(Session, Network.opaque_ref);
                    log.DebugFormat("Network {0} ({1}) destroyed.", oldNetworkName, Network.uuid);
                });
            }

            if (e != null)
            {
                throw e;
            }

            Description = string.Format(Messages.ACTION_DESTROY_BOND_DONE, Name);
        }
Esempio n. 5
0
            private VirtualTreeNode AddNetworkNode(XenAPI.Network network)
            {
                bool   hidden  = network.IsHidden();
                bool   slave   = network.IsSlave();
                string rawName = network.Name();
                String name    = slave
                                  ? String.Format(Messages.NIC_SLAVE, rawName)
                                  : hidden
                                        ? String.Format(Messages.X_HIDDEN, rawName)
                                        : rawName;

                return(AddNode(name, Images.GetIconFor(network), slave || hidden, network));
            }
Esempio n. 6
0
        protected override void Run()
        {
            Connection.ExpectDisruption = true;
            List <VIF> unplugged_vifs   = new List <VIF>();
            string     old_network_name = Network == null ? "" : Network.Name();
            Exception  e = null;

            BestEffort(ref e, ReconfigureManagementInterfaces);

            if (e != null)
            {
                throw e;
            }

            PercentComplete = 50;

            int inc = 40 / Bonds.Count;

            int lo = PercentComplete;

            foreach (Bond bond in Bonds)
            {
                Bond bond1 = bond;
                int  lo1   = lo;
                BestEffort(ref e, delegate() { RelatedTask = Bond.async_destroy(Session, bond1.opaque_ref); });
                PollToCompletion(lo1, lo1 + inc);

                lo += inc;
            }

            if (Network != null)
            {
                // Destroy the old network
                log.DebugFormat("Destroying network {0} ({1})...", old_network_name, Network.uuid);
                BestEffort(ref e, delegate()
                {
                    XenAPI.Network.destroy(Session, Network.opaque_ref);
                    log.DebugFormat("Network {0} ({1}) destroyed.", old_network_name, Network.uuid);
                });
            }

            if (e != null)
            {
                throw e;
            }

            Description = string.Format(Messages.ACTION_DESTROY_BOND_DONE, Name);
        }
Esempio n. 7
0
        public string NetworkName()
        {
            if (Connection == null)
            {
                throw new NullReferenceException("NetworkName the VIF does not have connection");
            }
            Network network = Connection.Resolve(this.network);

            if (network != null)
            {
                return(network.Name());
            }
            else
            {
                return("-");
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Create or destroy a private network.
        /// </summary>
        public NetworkAction(IXenConnection connection, XenAPI.Network network, bool create)
            : base(connection,
                   string.Format(create ? Messages.NETWORK_ACTION_CREATING_NETWORK_TITLE : Messages.NETWORK_ACTION_REMOVING_NETWORK_TITLE,
                                 network.Name(), Helpers.GetName(connection)))
        {
            this.networkClone = network;
            this.external     = false;

            if (create)
            {
                #region RBAC Dependencies

                ApiMethodsToRoleCheck.Add("network.create");

                #endregion
                actionType = network_actions.create;
                PIFs       = null;
            }
            else
            {
                PIFs = Connection.ResolveAll(network.PIFs);
                #region RBAC Dependencies
                ApiMethodsToRoleCheck.Add("network.destroy");
                if (PIFs.Find(p => p.IsTunnelAccessPIF()) != null)
                {
                    ApiMethodsToRoleCheck.Add("tunnel.destroy");
                }
                if (PIFs.Find(p => !p.IsTunnelAccessPIF() && p.physical) != null)
                {
                    ApiMethodsToRoleCheck.Add("pif.forget");  // actually, we should have at most one of tunnel.destroy and pif.forget
                }
                if (PIFs.Find(p => !p.IsTunnelAccessPIF() && !p.physical) != null)
                {
                    ApiMethodsToRoleCheck.Add("vlan.destroy");  // same here, shouldn't be both virtual and physcial really
                }
                #endregion
                actionType = network_actions.destroy;
            }

            init();
        }
Esempio n. 9
0
        public void RefreshButtons()
        {
            XenAPI.Network network = (XenAPI.Network)NetworkComboBox.SelectedItem;
            string         purpose = network == null ? null : FindOtherPurpose(network);

            InUseWarning =
                purpose == null || purpose == Purpose ?
                null :
                type == Type.SECONDARY && network == ManagementNetwork?
                string.Format(Messages.NETWORKING_PROPERTIES_IN_USE_WARNING_MANAGEMENT, network.ToString()) :
                    string.Format(Messages.NETWORKING_PROPERTIES_IN_USE_WARNING, network.ToString(), purpose);

            PurposeLabel.Visible         =
                PurposeTextBox.Visible   =
                    DeleteButton.Visible =
                        (type == Type.SECONDARY);

            panelHAEnabledWarning.Visible =
                (type == Type.PRIMARY_WITH_HA);

            SetDNSControlsVisible(type != Type.SECONDARY);

            panelInUseWarning.Visible =
                InUseWarning != null;
            InUseWarningText.Text = InUseWarning;

            IpAddressSettingsLabel.Text = type == Type.SECONDARY
                                              ? Messages.NETWORKING_PROPERTIES_IP_SETTINGS
                                              : Messages.NETWORKING_PROPERTIES_IP_AND_DNS_SETTINGS;
            IPAddressLabel.Text = Pool ? Messages.IP_ADDRESS_RANGE_LABEL : Messages.IP_ADDRESS_LABEL;

            tableLayoutPanelStaticSettings.Enabled = FixedIPRadioButton.Checked;

            RangeEndLabel.Visible = Pool;

            Valid =
                InUseWarning == null &&
                NetworkComboBox.SelectedIndex != -1 &&
                (DHCPIPRadioButton.Checked ||
                 ((StringUtility.IsIPAddress(IPAddressTextBox.Text)) &&
                  StringUtility.IsValidNetmask(SubnetTextBox.Text) && IsOptionalIPAddress(GatewayTextBox.Text))) &&
                (type == Type.SECONDARY || ((IsOptionalIPAddress(PreferredDNSTextBox.Text) &&
                                             IsOptionalIPAddress(AlternateDNS1TextBox.Text) &&
                                             IsOptionalIPAddress(AlternateDNS2TextBox.Text))));

            // Grey out everything if HA is enabled: CA-24714
            if (type == Type.PRIMARY_WITH_HA)
            {
                foreach (Control c in Controls)
                {
                    c.Enabled = false;
                }
                haEnabledWarningIcon.Enabled =
                    haEnabledRubric.Enabled  =
                        true;
            }

            var pif             = Tag as PIF;
            var existingCluster = network != null?network.Connection.Cache.Clusters.FirstOrDefault() : null;

            if (pif != null && existingCluster != null)
            {
                Host host = network.Connection.Resolve(pif.host);

                ClusteringEnabled = network.Connection.Cache.Cluster_hosts.Any(cluster =>
                                                                               cluster.host.opaque_ref == pif.host.opaque_ref && cluster.enabled);

                if (ClusteringEnabled)
                {
                    if (host != null && host.enabled)
                    {
                        DisableControls(string.Format(Messages.CANNOT_CHANGE_IP_CLUSTERING_ENABLED, network.Name()));
                    }
                    else
                    {
                        DeleteButton.Enabled    = false;
                        tableLayoutInfo.Visible = true;
                        labelWarning.Text       = string.Format(Messages.CANNOT_REMOVE_IP_WHEN_CLUSTERING_ON_NETWORK, network.Name());
                    }
                }
            }
        }
Esempio n. 10
0
        protected override void Run()
        {
            SafeToExit = false;
            bool isTemplate;

            try
            {
                string vmRef;

                if (m_filename.EndsWith("ova.xml"))                //importing version 1 from of VM
                {
                    m_filename = m_filename.Replace("ova.xml", "");
                    vmRef      = GetVmRef(applyVersionOneFiles());
                }
                else                //importing current format of VM
                {
                    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);
                if (isTemplate && Helpers.FalconOrGreater(Connection) && VM.get_is_default_template(Session, vmRef))
                {
                    var otherConfig = VM.get_other_config(Session, vmRef);
                    if (!otherConfig.ContainsKey(IMPORT_TASK) || otherConfig[IMPORT_TASK] != RelatedTask.opaque_ref)
                    {
                        throw new Exception(Messages.IMPORT_TEMPLATE_ALREADY_EXISTS);
                    }
                }

                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;

                    // For ElyOrGreater hosts, we can move the VIFs to another network,
                    // but for older hosts 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>();

                    bool canMoveVifs = Helpers.ElyOrGreater(Connection);

                    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);
                        }

                        if (canMoveVifs)
                        {
                            var vifObj = Connection.Resolve(vif);
                            if (vifObj == null)
                            {
                                continue;
                            }
                            // try to find a matching VIF in the m_proxyVIFs list, based on the device field
                            var matchingProxyVif = m_proxyVIFs.FirstOrDefault(proxyVIF => proxyVIF.device == vifObj.device);
                            if (matchingProxyVif != null)
                            {
                                // move the VIF to the desired network
                                VIF.move(Session, vif, matchingProxyVif.network);
                                // remove matchingProxyVif from the list, so we don't create the VIF again later
                                m_proxyVIFs.Remove(matchingProxyVif);
                                continue;
                            }
                        }
                        // destroy the VIF, if we haven't managed to move it
                        VIF.destroy(Session, vif);
                    }

                    // recreate VIFs if needed (m_proxyVIFs can be empty, if we moved all the VIFs in the previous step)
                    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;
        }
Esempio n. 11
0
        /// <summary>
        /// Create an external (VLAN) network.
        /// </summary>
        /// <param name="network">A new Network instance describing the changes to be made on the server side.</param>
        /// <param name="pif">The PIF representing the physical NIC from which we're basing our new VLAN.</param>
        /// <param name="vlan">The new VLAN tag.</param>
        public NetworkAction(IXenConnection connection, XenAPI.Network network, PIF pif, long vlan)
            : base(connection, string.Format(Messages.NETWORK_ACTION_CREATING_NETWORK_TITLE, network.Name(),
                                             Helpers.GetName(connection)))
        {
            actionType        = network_actions.create;
            this.networkClone = network;
            this.pif          = pif;
            this.vlan         = vlan;
            this.external     = true;
            this.PIFs         = null;

            #region RBAC Dependencies
            ApiMethodsToRoleCheck.Add("network.create");
            ApiMethodsToRoleCheck.Add("pool.create_VLAN_from_PIF");
            #endregion

            init();
        }
Esempio n. 12
0
        private void AddStorageMappings(ref List <SummaryDetails> decoratedSummary)
        {
            bool addSummaryKey = true;

            foreach (var pair in mapping.Networks)
            {
                XenAPI.Network net             = connection.Resolve(new XenRef <XenAPI.Network>(pair.Key));
                bool           networkNotFound = net == null;
                string         valueToAdd      = networkNotFound ? Messages.CPM_SUMMARY_NETWORK_NOT_FOUND : net.Name();
                valueToAdd += separatorText + pair.Value.Name();
                decoratedSummary.Add(addSummaryKey
                                         ? new SummaryDetails(Messages.CPM_SUMMARY_KEY_NETWORK, valueToAdd, networkNotFound)
                                         : new SummaryDetails(String.Empty, valueToAdd, networkNotFound));
                addSummaryKey = false;
            }
        }
Esempio n. 13
0
        private void SetMTUControlEnablement()
        {
            if (!network.CanUseJumboFrames())
            {
                labelCannotConfigureMTU.Visible = false;
                labelMTU.Visible = numericUpDownMTU.Visible = false;
                return;
            }

            if (SelectedIsInternal)
            {
                // internal
                // MTU doesn't really do much here
                labelCannotConfigureMTU.Visible = false;
                numericUpDownMTU.Enabled        = false;
                return;
            }

            PIF networksPIF = GetSelectedPIF();  // returns null for new VLAN

            if (networksPIF == null || !networksPIF.IsManagementInterface(XenAdmin.Properties.Settings.Default.ShowHiddenVMs))
            {
                // non management external (could be bond)

                if (runningVMsWithoutTools)
                {
                    // The MTU controls have been designed to be more relaxed than the rest of the page, we will only block if we can't unplug the vifs
                    // due to lack of tools (which then lets us unplug the PIFs)
                    labelCannotConfigureMTU.Text    = Messages.CANNOT_CONFIGURE_JUMBO_VM_NO_TOOLS;
                    labelCannotConfigureMTU.Visible = true;
                    numericUpDownMTU.Enabled        = false;
                }
                else if (networksPIF != null && networksPIF.IsTunnelAccessPIF())
                {
                    // This branch is currently not in use as setting the MTU is disabled on CHINs.
                    // Left in in case future support is added

                    // with no other more danger warnings we should tell the user it's recommended that they set the MTU on the underlying networks to match
                    XenAPI.Network mainNetwork = FindCHINMainNetwork(networksPIF);
                    labelCannotConfigureMTU.Text = string.Format(Messages.SET_MTU_ON_CHINS_UNDER_NETWORK, mainNetwork.Name());
                    // incase some odd value has been set on the CLI
                    numericUpDownMTU.Maximum        = Math.Max(network.MTU, XenAPI.Network.MTU_MAX);
                    numericUpDownMTU.Minimum        = Math.Min(network.MTU, XenAPI.Network.MTU_MIN);
                    numericUpDownMTU.Enabled        = true;
                    labelCannotConfigureMTU.Visible = true;
                }
                else
                {
                    labelCannotConfigureMTU.Visible = false;
                    // in case some odd value has been set on the CLI
                    numericUpDownMTU.Maximum = Math.Max(network.MTU, XenAPI.Network.MTU_MAX);
                    numericUpDownMTU.Minimum = Math.Min(network.MTU, XenAPI.Network.MTU_MIN);
                    numericUpDownMTU.Enabled = true;
                }
            }
            else
            {
                // physical or virtual external management (could be bond)
                numericUpDownMTU.Enabled        = false;
                labelCannotConfigureMTU.Text    = string.Format(Messages.CANNOT_CONFIGURE_JUMBO_DISTURB_MANAGEMENT, networksPIF.ManagementInterfaceNameOrUnknown());
                labelCannotConfigureMTU.Visible = true;
            }
        }