// Constructor used for Move and Delete public FolderAction(IXenObject obj, Folder folder, Kind kind) : base(obj.Connection, GetTitle(obj, folder, kind)) { System.Diagnostics.Trace.Assert(kind == Kind.Move || kind == Kind.Delete); this.obj = obj; this.folder = folder; this.kind = kind; if (obj.GetType() != typeof(Folder)) { ApiMethodsToRoleCheck.Add(obj.GetType().Name.ToLowerInvariant() + ".remove_from_other_config", Folders.FOLDER); ApiMethodsToRoleCheck.Add(obj.GetType().Name.ToLowerInvariant() + ".add_to_other_config", Folders.FOLDER); } ApiMethodsToRoleCheck.Add("pool.remove_from_other_config", Folders.EMPTY_FOLDERS); ApiMethodsToRoleCheck.Add("pool.add_to_other_config", Folders.EMPTY_FOLDERS); AppliesTo.Add(obj.opaque_ref); if (folder != null) { AppliesTo.Add(folder.opaque_ref); } }
/// <summary> /// /// </summary> /// <param name="connection"></param> /// <param name="pool">May be null, in which case we're acting on a single host basis.</param> /// <param name="host">If pool is set, then host should be the pool master.</param> /// <param name="newPIFs">New PIF instances that are to be created on the server.</param> /// <param name="downPIFs"></param> /// <param name="newManagement">May be null, in which case the management network will not be disturbed. /// Note that it is still possible for the management interface to receive a new IP address even if this /// parameter is null, because it may be in newPIFs. You only need to use this parameter if the management /// interface is switching onto a different PIF.</param> /// <param name="downManagement">May be null iff newManagement is null.</param> public ChangeNetworkingAction(IXenConnection connection, Pool pool, Host host, List <PIF> newPIFs, List <PIF> downPIFs, PIF newManagement, PIF downManagement, bool managementIPChanged) : base(connection, Messages.ACTION_CHANGE_NETWORKING_TITLE) { Pool = pool; Host = host; this.newPIFs = newPIFs; this.downPIFs = downPIFs; this.newManagement = newManagement; this.downManagement = downManagement; this.managementIPChanged = managementIPChanged; if (pool != null) { // If we're going to compute address ranges, then we need a sorted list of hosts (to keep the addresses stable). Hosts = Connection.Cache.Hosts; Array.Sort(Hosts); foreach (Host h in Hosts) { AppliesTo.Add(h.opaque_ref); } } #region RBAC Dependencies ApiMethodsToRoleCheck.Add("vm.set_memory_limits"); ApiMethodsToRoleCheck.Add("host.management_reconfigure"); ApiMethodsToRoleCheck.Add("pif.reconfigure_ip"); ApiMethodsToRoleCheck.Add("pif.plug"); ApiMethodsToRoleCheck.AddRange(XenAPI.Role.CommonSessionApiList); ApiMethodsToRoleCheck.AddRange(XenAPI.Role.CommonTaskApiList); #endregion }
public SetCslgCredentialsAction(IEnumerable <IXenConnection> connections, string host, string username, string password) : base(null, Messages.SET_STORAGELINK_CREDS_ACTION_TITLE, Messages.SET_STORAGELINK_CREDS_ACTION_DESCRIPTION) { Util.ThrowIfEnumerableParameterNullOrEmpty(connections, "connections"); _connections = Util.GetList(connections).FindAll(c => c.IsConnected && Helpers.GetPoolOfOne(c) != null && Helpers.MidnightRideOrGreater(c) && !Helpers.FeatureForbidden(c, XenAPI.Host.RestrictStorageChoices)); _host = host; _username = username; _password = password; foreach (IXenConnection c in connections) { XenAPI.Pool pool = Helpers.GetPool(c); if (pool != null) { AppliesTo.Add(pool.opaque_ref); } else { XenAPI.Host master = Helpers.GetMaster(c); if (master != null) { AppliesTo.Add(master.opaque_ref); } } } }
public RenameFolderAction(Folder folder, String name) : base(folder.Connection, string.Format(Messages.RENAMING_FOLDER, Helpers.GetName(folder), name)) { obj = folder; path = Folders.AppendPath(obj.Path, name); AppliesTo.Add(obj.opaque_ref); AppliesTo.Add(path); }
public CreateFolderAction(IXenConnection connection, params string[] paths) : base(connection, GetTitle(paths)) { this.paths = paths; foreach (string path in paths) { AppliesTo.Add(path); } }
// Constructor used for moving multiple objects, across multiple connections public MoveToFolderAction(List <IXenObject> objs, Folder folder) : base(null, string.Format(Messages.MOVE_OBJECTS_TO_FOLDER, folder.Name())) { this.objs.AddRange(objs); this.folder = folder; if (this.folder != null) { AppliesTo.Add(this.folder.opaque_ref); } }
/// <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; } } }
public RemoveStorageLinkSystemAction(StorageLinkSystem system) : base(null, string.Format(Messages.REMOVE_STORAGE_LINK_SYSTEM_ACTION_TITLE, system.Name), string.Format(Messages.REMOVE_STORAGE_LINK_SYSTEM_ACTION_START_DESCRIPTION, system.Name)) { Util.ThrowIfParameterNull(system, "system"); _system = system; AppliesTo.Add(system.StorageLinkServer.opaque_ref); AppliesTo.Add(system.opaque_ref); }
// Constructor used for Rename public FolderAction(Folder obj, String name, Kind kind) : base(obj.Connection, String.Format(Messages.RENAMING_FOLDER, Helpers.GetName(obj), name)) { System.Diagnostics.Trace.Assert(kind == Kind.Rename); this.kind = kind; this.obj = obj; this.path = Folders.AppendPath(obj.Path, name); AppliesTo.Add(obj.opaque_ref); AppliesTo.Add(path); }
private void SetAppliesTo(IXenConnection connection) { foreach (Pool pool in connection.Cache.Pools) { AppliesTo.Add(pool.opaque_ref); } foreach (Host host in connection.Cache.Hosts) { AppliesTo.Add(host.opaque_ref); } }
protected override void Run() { bool succeeded = false; string name = Helpers.GetName(Host); XenAPI.Host master = Helpers.GetMaster(Connection); AppliesTo.Add(master.opaque_ref); Title = string.Format(Messages.ACTION_HOST_START_TITLE, name); Description = Messages.ACTION_HOST_STARTING; try { XenAPI.Host.power_on(Session, Host.opaque_ref); Description = Messages.ACTION_HOST_STARTED; succeeded = true; /* WLB: Below code doesn't work, becasue RelatedTask is not set. * Need to explore other option when enabling set poweron task value for wlb reporting * if (Helpers.IsWLBEnabled(this.Connection) * && Host.other_config.ContainsKey(WlbOptimizePoolAction.OPTIMIZINGPOOL)) * { * // set host poweroff task key values for wlb reporting purpose * Task.add_to_other_config(this.Session, this.RelatedTask.opaque_ref, "wlb_advised", Host.other_config[WlbOptimizePoolAction.OPTIMIZINGPOOL]); * Task.add_to_other_config(this.Session, this.RelatedTask.opaque_ref, "wlb_action", "host_poweron"); * Task.add_to_other_config(this.Session, this.RelatedTask.opaque_ref, "wlb_action_obj_ref", Host.opaque_ref); * Task.add_to_other_config(this.Session, this.RelatedTask.opaque_ref, "wlb_action_obj_type", "host"); * } */ } catch (Exception e) { Failure f = e as Failure; if (f != null) { string msg = f.ErrorDescription.Count > 2 ? Messages.ResourceManager.GetString(f.ErrorDescription[2]) : null; if (msg != null) { throw new Exception(msg); } else { throw new Exception(string.Format(Messages.POWER_ON_REQUEST_FAILED, this.Host)); } } throw; } finally { if (Helpers.WlbConfigured(this.Connection) && Helpers.WlbEnabledAndConfigured(this.Connection)) { UpdateHostLastPowerOnSucceeded(succeeded, Host); } } }
public CreateVMAction(IXenConnection connection, VM template, Host copyBiosStringsFrom, string name, string description, InstallMethod installMethod, string pvArgs, VDI cd, string url, Host homeServer, long vcpus, long memoryDynamicMin, long memoryDynamicMax, long memoryStaticMax, List <DiskDescription> disks, SR fullCopySR, List <VIF> vifs, bool startAfter, Action <VM, bool> warningDialogHAInvalidConfig, Action <VMStartAbstractAction, Failure> startDiagnosisForm) : base(connection, string.Format(Messages.CREATE_VM, name), string.Format(Messages.CREATE_VM_FROM_TEMPLATE, name, Helpers.GetName(template))) { Template = template; CopyBiosStringsFrom = copyBiosStringsFrom; FullCopySR = fullCopySR; NameLabel = name; NameDescription = description; InsMethod = installMethod; PvArgs = pvArgs; Cd = cd; Url = url; HomeServer = homeServer; Vcpus = vcpus; MemoryDynamicMin = memoryDynamicMin; MemoryDynamicMax = memoryDynamicMax; MemoryStaticMax = memoryStaticMax; Disks = disks; Vifs = vifs; StartAfter = startAfter; _warningDialogHAInvalidConfig = warningDialogHAInvalidConfig; _startDiagnosisForm = startDiagnosisForm; Pool pool_of_one = Helpers.GetPoolOfOne(Connection); if (HomeServer != null || pool_of_one != null) // otherwise we have no where to put the action { AppliesTo.Add(HomeServer != null ? HomeServer.opaque_ref : pool_of_one.opaque_ref); } #region RBAC Dependencies if (StartAfter) { ApiMethodsToRoleCheck.Add("vm.start"); } if (HomeServerChanged()) { ApiMethodsToRoleCheck.Add("vm.set_affinity"); } if (Template.memory_dynamic_min != MemoryDynamicMin || Template.memory_dynamic_max != MemoryDynamicMax || Template.memory_static_max != MemoryStaticMax) { ApiMethodsToRoleCheck.Add("vm.set_memory_limits"); } ApiMethodsToRoleCheck.AddRange(StaticRBACDependencies); ApiMethodsToRoleCheck.AddRange(Role.CommonTaskApiList); ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList); #endregion }
public DeleteFolderAction(IXenObject obj) : base(obj.Connection, Messages.DELETING_FOLDER) { objs.Add(obj); if (obj.GetType() != typeof(Folder)) { ApiMethodsToRoleCheck.Add(obj.GetType().Name.ToLowerInvariant() + ".remove_from_other_config", Folders.FOLDER); ApiMethodsToRoleCheck.Add(obj.GetType().Name.ToLowerInvariant() + ".add_to_other_config", Folders.FOLDER); } AppliesTo.Add(obj.opaque_ref); }
// Constructor used for New public FolderAction(IXenConnection connection, Kind kind, params string[] paths) : base(connection, GetTitleForNew(paths)) { System.Diagnostics.Trace.Assert(kind == Kind.New); this.kind = kind; this.paths = paths; ApiMethodsToRoleCheck.Add("pool.remove_from_other_config", Folders.EMPTY_FOLDERS); ApiMethodsToRoleCheck.Add("pool.add_to_other_config", Folders.EMPTY_FOLDERS); foreach (string path in paths) { AppliesTo.Add(path); } }
public MoveToFolderAction(IXenObject obj, Folder folder) : base(obj.Connection, string.Format(Messages.MOVE_OBJECT_TO_FOLDER, Helpers.GetName(obj), folder.Name())) { this.objs.Add(obj); this.folder = folder; if (obj.GetType() != typeof(Folder)) { ApiMethodsToRoleCheck.Add(obj.GetType().Name.ToLowerInvariant() + ".remove_from_other_config", Folders.FOLDER); ApiMethodsToRoleCheck.Add(obj.GetType().Name.ToLowerInvariant() + ".add_to_other_config", Folders.FOLDER); } AppliesTo.Add(obj.opaque_ref); AppliesTo.Add(folder.opaque_ref); }
/// <summary> /// Initializes a new instance of the <see cref="ChangeStorageLinkPasswordAction"/> class. /// /// You need to be a pool-operator or higher to even get access to the password for the storagelink service. /// /// </summary> /// <param name="storageLinkConnection">The storage link connection.</param> /// <param name="username">The username.</param> /// <param name="oldPassword">The old password.</param> /// <param name="newPassword">The new password.</param> public ChangeStorageLinkPasswordAction(IEnumerable <IXenConnection> xenConnections, StorageLinkConnection storageLinkConnection, string username, string oldPassword, string newPassword) : base(null, Messages.CHANGE_SL_SERVER_PASSWORD_ACTION_TITLE, Messages.CHANGE_SL_SERVER_PASSWORD_ACTION_DES_START) { Util.ThrowIfParameterNull(storageLinkConnection, "storageLinkConnection"); Util.ThrowIfStringParameterNullOrEmpty(username, "username"); Util.ThrowIfParameterNull(oldPassword, "oldPassword"); Util.ThrowIfParameterNull(newPassword, "newPassword"); _storageLinkConnection = storageLinkConnection; _username = username; _oldPassword = oldPassword; _newPassword = newPassword; _xenConnections = xenConnections; AppliesTo.Add(storageLinkConnection.Cache.Server.opaque_ref); AppliesTo.AddRange(GetPoolsToCheck().ConvertAll(p => p.opaque_ref)); }
private void SetAppliesToData(Task task) { List <string> applies_to = task.AppliesTo(); if (applies_to != null) { AppliesTo.AddRange(applies_to); } else { // A non-aware client has created this task. We'll create a new action for this, and place it under // the task.resident_on host, or if that doesn't resolve, the pool master. Host host = task.Connection.Resolve(task.resident_on) ?? Helpers.GetMaster(task.Connection); if (host != null) { AppliesTo.Add(host.opaque_ref); } } }
public SetCslgCredentialsToPoolAction(IXenConnection connection, string host, string username, string password) : base(connection, string.Format(Messages.SET_STORAGELINK_CREDS_TO_POOL_ACTION_TITLE, Helpers.GetPoolOfOne(connection)), string.Format(Messages.SET_STORAGELINK_CREDS_TO_POOL_ACTION_DESCRIPTION, Helpers.GetPoolOfOne(connection))) { Util.ThrowIfParameterNull(connection, "connection"); _host = host; _username = username; _password = password; if (Helpers.FeatureForbidden(connection, Host.RestrictStorageChoices)) { throw new ArgumentException("Pool not licensed.", "host"); } if (!Helpers.MidnightRideOrGreater(connection)) { throw new ArgumentException("Pool must by Midnight Ride or later.", "host"); } XenAPI.Pool pool = Helpers.GetPool(Connection); if (pool != null) { AppliesTo.Add(pool.opaque_ref); } else { XenAPI.Host master = Helpers.GetMaster(Connection); if (master != null) { AppliesTo.Add(master.opaque_ref); } } }
/// <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; } }
private void SetXenCenterProperties() { VM.IsBeingCreated = true; XenAdminConfigManager.Provider.HideObject(VM.opaque_ref); AppliesTo.Add(VM.opaque_ref); }
public CreateVMAction(IXenConnection connection, VM template, Host copyBiosStringsFrom, string name, string description, InstallMethod installMethod, string pvArgs, VDI cd, string url, Host homeServer, long vcpusMax, long vcpusAtStartup, long memoryDynamicMin, long memoryDynamicMax, long memoryStaticMax, List <DiskDescription> disks, SR fullCopySR, List <VIF> vifs, bool startAfter, Action <VM, bool> warningDialogHAInvalidConfig, Action <VMStartAbstractAction, Failure> startDiagnosisForm, GPU_group gpuGroup, VGPU_type vgpuType, bool modifyVgpuSettings, long coresPerSocket, string cloudConfigDriveTemplateText) : base(connection, string.Format(Messages.CREATE_VM, name), string.Format(Messages.CREATE_VM_FROM_TEMPLATE, name, Helpers.GetName(template))) { Template = template; CopyBiosStringsFrom = copyBiosStringsFrom; FullCopySR = fullCopySR; NameLabel = name; NameDescription = description; InsMethod = installMethod; PvArgs = pvArgs; Cd = cd; Url = url; HomeServer = homeServer; VcpusMax = vcpusMax; VcpusAtStartup = vcpusAtStartup; MemoryDynamicMin = memoryDynamicMin; MemoryDynamicMax = memoryDynamicMax; MemoryStaticMax = memoryStaticMax; Disks = disks; Vifs = vifs; StartAfter = startAfter; _warningDialogHAInvalidConfig = warningDialogHAInvalidConfig; _startDiagnosisForm = startDiagnosisForm; GpuGroup = gpuGroup; VgpuType = vgpuType; CoresPerSocket = coresPerSocket; this.cloudConfigDriveTemplateText = cloudConfigDriveTemplateText; Pool pool_of_one = Helpers.GetPoolOfOne(Connection); if (HomeServer != null || pool_of_one != null) // otherwise we have no where to put the action { AppliesTo.Add(HomeServer != null ? HomeServer.opaque_ref : pool_of_one.opaque_ref); } assignOrRemoveVgpu = GpuGroup != null && VgpuType != null || modifyVgpuSettings && Helpers.GpuCapability(Connection); #region RBAC Dependencies if (StartAfter) { ApiMethodsToRoleCheck.Add("vm.start"); } if (HomeServerChanged()) { ApiMethodsToRoleCheck.Add("vm.set_affinity"); } if (Template.memory_dynamic_min != MemoryDynamicMin || Template.memory_dynamic_max != MemoryDynamicMax || Template.memory_static_max != MemoryStaticMax) { ApiMethodsToRoleCheck.Add("vm.set_memory_limits"); } if (assignOrRemoveVgpu) { ApiMethodsToRoleCheck.Add("VGPU.destroy"); ApiMethodsToRoleCheck.Add("VGPU.create"); } ApiMethodsToRoleCheck.AddRange(StaticRBACDependencies); ApiMethodsToRoleCheck.AddRange(Role.CommonTaskApiList); ApiMethodsToRoleCheck.AddRange(Role.CommonSessionApiList); #endregion }