Example #1
0
        /// <param name="name_label">The name for the new network.</param>
        /// <param name="PIFs_on_master">The PIFs on the master representing the physical NICs that are to be bonded together.</param>
        /// <param name="autoplug">Whether the new network is marked AutoPlug.</param>
        /// <param name="mtu">The MTU for the Bond, ignored for pre cowley</param>
        /// <param name="bondMode">The bond mode, ignored for pre-Boston</param>
        public CreateBondAction(IXenConnection connection, string name_label, List <PIF> PIFs_on_master, bool autoplug, long mtu, bond_mode bondMode,
                                Bond.hashing_algoritm hashingAlgoritm)
            : base(connection, string.Format(Messages.ACTION_CREATE_BOND_TITLE, name_label),
                   string.Format(Messages.ACTION_CREATE_BOND_DESCRIPTION, name_label))
        {
            this.name_label      = name_label;
            this.autoplug        = autoplug;
            this.mtu             = mtu;
            this.bondMode        = bondMode;
            this.hashingAlgoritm = hashingAlgoritm;

            Pool = Helpers.GetPoolOfOne(Connection);
            if (Pool == null)
            {
                throw new Failure(Failure.INTERNAL_ERROR, "Pool has gone away");
            }

            Master = Connection.Resolve(Pool.master);
            if (Master == null)
            {
                throw new Failure(Failure.INTERNAL_ERROR, "Pool master has gone away");
            }

            bostonOrGreater = Helpers.BostonOrGreater(connection);
            tampaOrGreater  = Helpers.TampaOrGreater(connection);

            foreach (Host host in Connection.Cache.Hosts)
            {
                AppliesTo.Add(host.opaque_ref);
            }

            #region RBAC Dependencies
            ApiMethodsToRoleCheck.Add("host.management_reconfigure");
            ApiMethodsToRoleCheck.Add("network.create");
            ApiMethodsToRoleCheck.Add("network.destroy");
            ApiMethodsToRoleCheck.Add("network.remove_from_other_config");
            ApiMethodsToRoleCheck.Add("pif.reconfigure_ip");
            ApiMethodsToRoleCheck.Add("pif.plug");
            ApiMethodsToRoleCheck.Add("bond.create");
            ApiMethodsToRoleCheck.Add("bond.destroy");
            ApiMethodsToRoleCheck.AddRange(XenAPI.Role.CommonSessionApiList);
            ApiMethodsToRoleCheck.AddRange(XenAPI.Role.CommonTaskApiList);
            #endregion

            PIFs = NetworkingHelper.PIFsOnAllHosts(PIFs_on_master);
            // these locks will be cleared in clean()
            foreach (List <PIF> pifs in PIFs.Values)
            {
                foreach (PIF pif in pifs)
                {
                    pif.Locked = true;
                }
            }
        }
Example #2
0
        /// <param name="name_label">The name for the new network.</param>
        /// <param name="PIFs_on_master">The PIFs on the master representing the physical NICs that are to be bonded together.</param>
        /// <param name="autoplug">Whether the new network is marked AutoPlug.</param>
        /// <param name="mtu">The MTU for the Bond, ignored for pre cowley</param>
        /// <param name="bondMode">The bond mode, ignored for pre-Boston</param>
        public CreateBondAction(IXenConnection connection, string name_label, List<PIF> PIFs_on_master, bool autoplug, long mtu, bond_mode bondMode,
            Bond.hashing_algoritm hashingAlgoritm)
            : base(connection, string.Format(Messages.ACTION_CREATE_BOND_TITLE, name_label),
                   string.Format(Messages.ACTION_CREATE_BOND_DESCRIPTION, name_label))
        {
            this.name_label = name_label;
            this.autoplug = autoplug;
            this.mtu = mtu;
            this.bondMode = bondMode;
            this.hashingAlgoritm = hashingAlgoritm;

            Pool = Helpers.GetPoolOfOne(Connection);
            if (Pool == null)
                throw new Failure(Failure.INTERNAL_ERROR, "Pool has gone away");

            Master = Connection.Resolve(Pool.master);
            if (Master == null)
                throw new Failure(Failure.INTERNAL_ERROR, "Pool master has gone away");

            tampaOrGreater = Helpers.TampaOrGreater(connection);

            foreach (Host host in Connection.Cache.Hosts)
                AppliesTo.Add(host.opaque_ref);

            #region RBAC Dependencies
            ApiMethodsToRoleCheck.Add("host.management_reconfigure");
            ApiMethodsToRoleCheck.Add("network.create");
            ApiMethodsToRoleCheck.Add("network.destroy");
            ApiMethodsToRoleCheck.Add("network.remove_from_other_config");
            ApiMethodsToRoleCheck.Add("pif.reconfigure_ip");
            ApiMethodsToRoleCheck.Add("pif.plug");
            ApiMethodsToRoleCheck.Add("bond.create");
            ApiMethodsToRoleCheck.Add("bond.destroy");
            ApiMethodsToRoleCheck.AddRange(XenAPI.Role.CommonSessionApiList);
            ApiMethodsToRoleCheck.AddRange(XenAPI.Role.CommonTaskApiList);
            #endregion

            PIFs = NetworkingHelper.PIFsOnAllHosts(PIFs_on_master);
            // these locks will be cleared in clean()
            foreach (List<PIF> pifs in PIFs.Values)
            {
                foreach (PIF pif in pifs)
                {
                    pif.Locked = true;
                }
            }
        }