/// <summary> /// /// </summary> /// <param name="connection"></param> /// <param name="pool">May be null.</param> /// <param name="host">Never null. In the case of a pool, "host" is set to the master.</param> public NewNetworkWizard(Network.IXenConnection connection, Pool pool, Host host) : base(connection) { InitializeComponent(); pageNetworkType = new NetWTypeSelect(); pageName = new NetWName(); pageNetworkDetails = new NetWDetails(); pageBondDetails = new NetWBondDetails(); pageChinDetails = new NetWChinDetails(); System.Diagnostics.Trace.Assert(host != null); Pool = pool; Host = host; if (Pool != null) pageBondDetails.SetPool(Pool); else pageBondDetails.SetHost(Host); pageNetworkDetails.Host = host; pageChinDetails.Host = host; pageChinDetails.Pool = pool; AddPage(pageNetworkType); AddPage(new XenTabPage { Text = "" }); }
public ApplyLicenseAction(Network.IXenConnection connection, Host host, string filepath, bool activateFreeLicense) : base(connection, string.Format(Messages.APPLYLICENSE_TITLE, host.Name), Messages.APPLYLICENSE_PREP) { this.Host = host; this.Filepath = filepath; this.ActivateFreeLicense = activateFreeLicense; }
private Network GetNetwork() { Network network = new Network(); network.name_label = System.Guid.NewGuid().ToString(); network.name_description = "test descript"; return network; }
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; }
public VMCrossPoolMigrateAction(VM vm, Host destinationHost, XenAPI.Network transferNetwork, VmMapping mapping) : base(vm.Connection, GetTitle(vm, destinationHost)) { Session = vm.Connection.Session; Description = Messages.ACTION_PREPARING; VM = vm; Host = destinationHost; Pool = Helpers.GetPool(vm.Connection); this.mapping = mapping; this.transferNetwork = transferNetwork; }
public void SetXenObjects(IXenObject orig, IXenObject clone) { network = clone as XenAPI.Network; if (network == null) return; // use the pif of the master to populate the controls. We use it later in the create_VLAN_from_PIF call in Network Action host = Helpers.GetMaster(network.Connection); Repopulate(); EnableDisable(); }
/// <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(); }
/// <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(); }
public VMCannotSeeNetwork(Check check, VM vm, XenAPI.Network network) : base(check, vm) { Network = network; }
public void TestSetup() { networks = DatabaseManager.ConnectionFor(dbName).Cache.Networks.Length; newNetwork = GetNetwork(); }
public UnplugPlugNetworkAction(XenAPI.Network network, bool suppressHistory) : base(network.Connection, Messages.ACTION_PIF_UNPLUG_PLUG_TITLE, Messages.ACTION_PIF_UNPLUG_PLUG_DESC, suppressHistory) { PIFs = Connection.ResolveAll<PIF>(network.PIFs); PIFs.RemoveAll(delegate(PIF p) { return !p.currently_attached; }); VIFs = Connection.ResolveAll<VIF>(network.VIFs); VIFs.RemoveAll(delegate(VIF v) { if (!v.currently_attached) return true; VM vm = v.Connection.Resolve(v.VM); if (vm == null || vm.power_state != vm_power_state.Running) // we only replug running VMs return true; return false; }); network.Locked = true; foreach (PIF p in PIFs) p.Locked = true; foreach (VIF v in VIFs) v.Locked = true; #region RBAC ApiMethodsToRoleCheck.Add("pif.async_unplug"); ApiMethodsToRoleCheck.Add("pif.async_plug"); ApiMethodsToRoleCheck.Add("vif.async_plug"); ApiMethodsToRoleCheck.Add("vif.async_unplug"); #endregion Pool = Helpers.GetPool(Connection); this.network = network; }
/// <summary> /// /// </summary> /// <param name="bond"></param> public DestroyBondAction(Bond bond) : base(bond.Connection, string.Format(Messages.ACTION_DESTROY_BOND_TITLE, bond.Name), string.Format(Messages.ACTION_DESTROY_BOND_DESCRIPTION, bond.Name)) { #region RBAC Dependencies ApiMethodsToRoleCheck.Add("host.management_reconfigure"); ApiMethodsToRoleCheck.Add("network.destroy"); ApiMethodsToRoleCheck.Add("vif.plug"); ApiMethodsToRoleCheck.Add("vif.unplug"); ApiMethodsToRoleCheck.Add("pif.reconfigure_ip"); ApiMethodsToRoleCheck.Add("pif.plug"); ApiMethodsToRoleCheck.Add("bond.destroy"); ApiMethodsToRoleCheck.AddRange(XenAPI.Role.CommonSessionApiList); ApiMethodsToRoleCheck.AddRange(XenAPI.Role.CommonTaskApiList); #endregion Name = bond.Name; Pool = Helpers.GetPoolOfOne(Connection); foreach (Host host in Connection.Cache.Hosts) { Bond b = NetworkingHelper.FindBond(host, bond); if (b != null) { Bonds.Add(b); b.Locked = true; PIF master = Connection.Resolve(b.master); if (master != null) { Masters.Add(master); master.Locked = true; List<PIF> slaves = Connection.ResolveAll(b.slaves); NetworkingHelper.Sort(slaves); foreach (PIF pif in slaves) { Slaves.Add(pif); pif.Locked = true; } FirstSlaves[master] = Connection.Resolve(b.primary_slave); if (!FirstSlaves.ContainsKey(master) && slaves.Count != 0) FirstSlaves[master] = slaves[0]; } AppliesTo.Add(host.opaque_ref); } } PIF master_master = Connection.Resolve(bond.master); if (master_master != null) { Network = Connection.Resolve(master_master.network); Network.Locked = true; } }
protected override void Run() { // the network lock and the connection.expectDisruption will be cleared in clean() new_bonds = new List<NewBond>(); network = null; Connection.ExpectDisruption = true; int inc = 100 / (Connection.Cache.HostCount * 3 + 1); string network_ref = CreateNetwork(0, inc); try { network = Connection.WaitForCache(new XenRef<XenAPI.Network>(network_ref)); network.Locked = true; XenAPI.Network.remove_from_other_config(Session, network_ref, XenAPI.Network.CREATE_IN_PROGRESS); int lo = inc; foreach (Host host in GetHostsMasterLast()) { List<PIF> pifs = PIFs[host].FindAll(x => x.physical).ToList(); List<XenRef<PIF>> pif_refs = new List<XenRef<PIF>>(); foreach (PIF pif in pifs) { pif_refs.Add(new XenRef<PIF>(pif.opaque_ref)); } log.DebugFormat("Creating bond on {0} with {1} PIFs...", Helpers.GetName(host), pifs.Count); Dictionary<string, string> bondProperties = new Dictionary<string, string>(); if (bondMode == bond_mode.lacp) bondProperties.Add("hashing_algorithm", Bond.HashingAlgoritmToString(hashingAlgoritm)); RelatedTask = tampaOrGreater ? Bond.async_create(Session, network_ref, pif_refs, "", bondMode, bondProperties) : bostonOrGreater ? Bond.async_create(Session, network_ref, pif_refs, "", bondMode) : Bond.async_create(Session, network_ref, pif_refs, ""); PollToCompletion(lo, lo + inc); lo += inc; log.DebugFormat("Creating bond on {0} done: bond is {1}.", Helpers.GetName(host), Result); Bond new_bond = Connection.WaitForCache(new XenRef<Bond>(Result)); if (new_bond == null) throw new Failure(Failure.INTERNAL_ERROR, "Bond didn't appear in our cache!"); PIF new_master = Connection.Resolve(new_bond.master); if (new_master == null) throw new Failure(Failure.INTERNAL_ERROR, "Bond master didn't appear in our cache!"); new_bonds.Add(new NewBond(new_bond, new_master, pifs)); new_bond.Locked = true; new_master.Locked = true; } foreach (NewBond new_bond in new_bonds) { lo += inc; ReconfigureManagementInterfaces(new_bond.slaves, new_bond.master, lo); } foreach (NewBond new_bond in new_bonds) { lo += inc; if (!bostonOrGreater) NetworkingActionHelpers.Plug(this, new_bond.master, lo); } } catch (Exception) { foreach (NewBond new_bond in new_bonds) { RevertManagementInterfaces(new_bond); DestroyBond(new_bond.bond); } DestroyNetwork(network_ref); throw; } Description = string.Format(Messages.ACTION_CREATE_BOND_DONE, name_label); }
private XenAPI.Network PopulateNewNetworkObj() { XenAPI.Network result = new XenAPI.Network(); result.name_label = pageName.NetworkName; result.name_description = pageName.NetworkDescription; result.AutoPlug = (pageNetworkType.SelectedNetworkType == NetworkTypes.CHIN ? pageChinDetails.isAutomaticAddNicToVM : pageNetworkDetails.isAutomaticAddNicToVM); if (pageNetworkType.SelectedNetworkType == NetworkTypes.CHIN) result.MTU = pageChinDetails.MTU; else if (pageNetworkDetails.MTU.HasValue) //Custom MTU may not be allowed if we are making a virtual network or something result.MTU = pageNetworkDetails.MTU.Value; return result; }
public NetworkRow(XenAPI.Network network, IXenObject xmo) { Network = network; Xmo = xmo; Cells.AddRange(ImageCell, NameCell, DescriptionCell, NicCell, VlanCell, AutoCell, LinkStatusCell, MacCell, MtuCell); Network.PropertyChanged += Server_PropertyChanged; Program.Invoke(Program.MainWindow, UpdateDetails); }
protected override void Run() { switch (actionType) { case network_actions.destroy: Description = Messages.NETWORK_ACTION_REMOVING_NETWORK; destroyPIFs(); XenAPI.Network.destroy(Session, networkClone.opaque_ref); networkClone = null; Description = Messages.NETWORK_ACTION_NETWORK_REMOVED; break; case network_actions.update: Description = Messages.NETWORK_ACTION_UPDATING_NETWORK; if (changePIFs) { if (external) { //Before we do a destroy check the vlan tag is not in use on this network foreach (PIF p in Connection.Cache.PIFs) { if (p.VLAN == vlan && p.device == pif.device) throw new Exception(FriendlyErrorNames.PIF_VLAN_EXISTS); } } destroyPIFs(); if (external) CreateVLAN(networkClone.opaque_ref); } Description = Messages.NETWORK_ACTION_NETWORK_UPDATED; break; case network_actions.create: Description = Messages.NETWORK_ACTION_CREATING_NETWORK; XenRef<XenAPI.Network> networkRef = XenAPI.Network.create(Session, networkClone); if (external) CreateVLAN(networkRef.opaque_ref); Description = Messages.NETWORK_ACTION_NETWORK_CREATED; break; } }
private void init() { SetAppliesTo(Connection); if (networkClone.opaque_ref != null) { // we are updating an existing object, and so should lock it networkServerObject = Connection.Resolve<XenAPI.Network>(new XenRef<XenAPI.Network>(networkClone.opaque_ref)); networkServerObject.Locked = true; } if (PIFs == null) return; foreach (PIF pif in PIFs) pif.Locked = true; }
string CreateNetwork(int lo, int hi) { log.DebugFormat("Creating network {0}...", name_label); XenAPI.Network network = new XenAPI.Network(); network.name_label = name_label; network.AutoPlug = autoplug; if (Helpers.CowleyOrGreater(Connection)) network.MTU = mtu; if (network.other_config == null) network.other_config = new Dictionary<string, string>(); network.other_config[XenAPI.Network.CREATE_IN_PROGRESS] = "true"; RelatedTask = XenAPI.Network.async_create(Session, network); PollToCompletion(lo, hi); log.DebugFormat("Created network {0} as {1}.", name_label, Result); return Result; }
/// <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(); }
public NetworkRow(XenAPI.Network network, IXenObject xmo) { Network = network; Xmo = xmo; Cells.AddRange(ImageCell, NameCell, DescriptionCell, NicCell, VlanCell, AutoCell, LinkStatusCell, MacCell); // add MTU to grid view on Network tab for pools and hosts, for Cowley or greater only (CA-45643) if (Helpers.CowleyOrGreater(Xmo.Connection)) Cells.Add(this.MtuCell); Network.PropertyChanged += Server_PropertyChanged; Program.Invoke(Program.MainWindow, UpdateDetails); }