// 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); } }
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); }
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); }
protected SaveChangesAction(IXenObject obj, bool suppressHistory) : base(obj.Connection, Messages.ACTION_SAVE_CHANGES_TITLE, Messages.ACTION_SAVE_CHANGES_IN_PROGRESS, suppressHistory) { // This is lovely. We need to lock the server object (not the copy we have taken) before calling save changes. // We don't know the type so we use the MethodInfo object and MakeGenericMethod to do a resolve against the type // we have extracted from GetType(). The Resolve() call itself needs a XenRef which we make by calling the XenRef constructor that takes the // opaque ref as an argument and using the MakeGenericType call to give it the same type as the object... // ... _then_ we lock it. SetObject(obj); _xenObject = obj; if (obj.opaque_ref != null) // creating a new object comes through here, but with obj.opaque_ref == null { System.Reflection.MethodInfo mi = typeof(IXenConnection).GetMethod("Resolve", BindingFlags.Public | BindingFlags.Instance); Type type = obj.GetType(); object[] xenRefParam = new object[] { typeof(XenRef <>).MakeGenericType(type).GetConstructor(new Type[] { typeof(string) }).Invoke(new Object[] { obj.opaque_ref }) }; _serverXenObject = (IXenObject)mi.MakeGenericMethod(type).Invoke(obj.Connection, xenRefParam); if (_serverXenObject != null) { // CA-35210: Removed this exception pending locking overhaul post MR in CA-38966 //if (_serverXenObject.Locked) // lockViolation = true; _serverXenObject.Locked = true; } } }
public SaveCustomFieldsAction(IXenObject xenObject, List<CustomField> customFields, bool suppressHistory) : base(xenObject.Connection, Messages.ACTION_SAVE_CUSTOM_FIELDS, string.Format(Messages.ACTION_SAVING_CUSTOM_FIELDS_FOR, xenObject), suppressHistory) { this.xenObject = xenObject; this.customFields = customFields; string type = xenObject.GetType().Name.ToLowerInvariant(); }
public SaveCustomFieldsAction(IXenObject xenObject, List <CustomField> customFields, bool suppressHistory) : base(xenObject.Connection, Messages.ACTION_SAVE_CUSTOM_FIELDS, string.Format(Messages.ACTION_SAVING_CUSTOM_FIELDS_FOR, xenObject), suppressHistory) { this.xenObject = xenObject; this.customFields = customFields; string type = xenObject.GetType().Name.ToLowerInvariant(); }
/// <summary> /// Iterate through all implemented IEquatable<T> interfaces and call Equals on each, if any of them /// return false, then this method returns false, otherwise it returns true. /// /// Both o and oo should be of the same type. /// </summary> private bool IEquatableEquals(IXenObject o, IXenObject oo) { Assert.AreEqual(o.GetType(), oo.GetType()); foreach (Type iface in o.GetType().GetInterfaces()) { if (iface.Name.StartsWith("IEquatable")) { MethodInfo mi = iface.GetMethod("Equals"); if (!(bool)mi.Invoke(o, new object[] { oo })) { return(false); } } } return(true); }
public PerfmonDefinitionAction(IXenObject xo, List<PerfmonDefinition> perfmonDefinitions) : base(xo.Connection, Messages.ACTION_SAVE_ALERTS, string.Format(Messages.ACTION_SAVING_ALERTS_FOR, xo)) { this.xo = xo; this.perfmonDefinitions = perfmonDefinitions; string type = xo.GetType().Name.ToLowerInvariant(); ApiMethodsToRoleCheck.Add(type + ".remove_from_other_config", PerfmonDefinition.PERFMON_KEY_NAME); if (perfmonDefinitions != null && perfmonDefinitions.Count != 0) ApiMethodsToRoleCheck.Add(type + ".add_to_other_config", PerfmonDefinition.PERFMON_KEY_NAME); }
public static DelegatedAsyncAction RemoveTagAction(IXenObject o, string tag) { return(new DelegatedAsyncAction(o.Connection, String.Format(Messages.DELETE_TAG, tag), String.Format(Messages.DELETING_TAG, tag), String.Format(Messages.DELETED_TAG, tag), delegate(Session session) { Tags.RemoveTag(session, o, tag); }, o.GetType().Name.ToLowerInvariant() + ".remove_tags" )); }
public void SetObject(IXenObject XenObject) { // Annoyingly all of our classes start with an uppercase character, whereas the servers only uppercase abbreviations List <string> abbreviations = new List <string>(new string[] { "SR", "VDI", "VBD", "VM", "PIF", "VIF", "PBD" }); SelectedObjectType = XenObject.GetType().Name; if (abbreviations.Find(delegate(string s) { return(SelectedObjectType.StartsWith(s)); }) == null) { string firstLetter = SelectedObjectType.Substring(0, 1); SelectedObjectType = firstLetter.ToLowerInvariant() + SelectedObjectType.Substring(1, SelectedObjectType.Length - 1); } SelectedObjectRef = XenObject.opaque_ref; }
public static DelegatedAsyncAction AddTagAction(IXenObject o, string tag) { return new DelegatedAsyncAction(o.Connection, String.Format(Messages.ADD_TAG, tag), String.Format(Messages.ADDING_TAG, tag), String.Format(Messages.ADDED_TAG, tag), delegate(Session session) { Tags.AddTag(session, o, tag); }, o.GetType().Name.ToLowerInvariant() + ".add_tags" ); }
public PerfmonDefinitionAction(IXenObject xo, List <PerfmonDefinition> perfmonDefinitions, bool suppressHistory) : base(xo.Connection, Messages.ACTION_SAVE_ALERTS, string.Format(Messages.ACTION_SAVING_ALERTS_FOR, xo), suppressHistory) { this.xo = xo; this.perfmonDefinitions = perfmonDefinitions; string type = xo.GetType().Name.ToLowerInvariant(); ApiMethodsToRoleCheck.Add(type + ".remove_from_other_config", PerfmonDefinition.PERFMON_KEY_NAME); if (perfmonDefinitions != null && perfmonDefinitions.Count != 0) { ApiMethodsToRoleCheck.Add(type + ".add_to_other_config", PerfmonDefinition.PERFMON_KEY_NAME); } }
/// <summary> /// Sets the random stuff to the string, int, long, double fields of the specified object. /// </summary> private void SetRandomStuffToFields(IXenObject xenObject) { foreach (FieldInfo fi in xenObject.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (!fi.IsInitOnly && !fi.IsLiteral) //check field isn't const or readonly { if (fi.FieldType == typeof(string)) { fi.SetValue(xenObject, Guid.NewGuid().ToString()); } else if (fi.FieldType == typeof(int) || fi.FieldType == typeof(long) || fi.FieldType == typeof(double)) { fi.SetValue(xenObject, _random.Next()); } } } }
public BrowseStorageDialog(IXenObject xenObject) : base(xenObject.Connection) { this.timer = new System.Timers.Timer(); this._selectedTab = -1; this.InitializeComponent(); this.xenObject = xenObject; this.xenObjectBefore = xenObject.Clone(); this.xenObjectCopy = xenObject.Clone(); base.Name = string.Format("Browse {0}", xenObject.GetType().Name); this.Text = string.Format(Messages.BROWSE_STORAGE_DIALOG_TITLE, Helpers.GetName(xenObject)); this.okButton.Text = Messages.OK; if (!Application.RenderWithVisualStyles) { base.ContentPanel.BackColor = SystemColors.Control; } this.Build(); }
// Returns a set of params which relate to the object you have selected in the treeview private List <string> RetrieveParams(IXenObject obj) { IXenConnection connection = obj.Connection; Host master = connection != null?Helpers.GetMaster(connection) : null; // get master asserts connection is not null string masterAddress = EmptyParameter; if (master != null) { masterAddress = Helpers.GetUrl(master.Connection); WriteTrustedCertificates(master.Connection); } string sessionRef = connection.Session != null ? connection.Session.opaque_ref : EmptyParameter; string objCls = obj != null?obj.GetType().Name : EmptyParameter; string objUuid = obj != null && connection.Session != null?Helpers.GetUuid(obj) : EmptyParameter; return(new List <string>(new string[] { masterAddress, sessionRef, objCls, objUuid })); }
private static string TypeOf(IXenObject o) { if (o is Folder) { return("10"); } if (o is Pool) { return("20"); } if (o is Host) { return("30"); } VM vm = o as VM; if (vm != null && vm.is_a_real_vm) { return("40"); } return(o.GetType().ToString()); }
public GeneralEditPageAction(IXenObject xenObjectOrig, IXenObject xenObjectCopy, string newFolder, List <string> newTags, bool suppressHistory) : base(xenObjectCopy.Connection, Messages.ACTION_SAVE_FOLDER_TAGS, string.Format(Messages.ACTION_SAVING_FOLDER_TAGS_FOR, xenObjectCopy), suppressHistory) { this.xenObjectOrig = xenObjectOrig; this.xenObjectCopy = xenObjectCopy; this.newFolder = newFolder; this.oldTags = new List <string>(Tags.GetTags(xenObjectCopy)); this.newTags = newTags; oldTags.Sort(); newTags.Sort(); string type = xenObjectCopy.GetType().Name.ToLowerInvariant(); if (newFolder != xenObjectCopy.Path) { ApiMethodsToRoleCheck.Add(type + ".remove_from_other_config", Folders.FOLDER); if (!String.IsNullOrEmpty(newFolder)) { ApiMethodsToRoleCheck.Add(type + ".add_to_other_config", Folders.FOLDER); } // TODO: Full RBAC for folders } foreach (string tag in oldTags) { if (newTags.BinarySearch(tag) < 0) { ApiMethodsToRoleCheck.Add(type + ".remove_tags"); break; } } foreach (string tag in newTags) { if (oldTags.BinarySearch(tag) < 0) { ApiMethodsToRoleCheck.Add(type + ".add_tags"); break; } } }
public PropertiesDialog(IXenObject xenObject) : base(xenObject.Connection) { // xenObject must not be null. If this occurs, we shouldn't have offered Properties in the UI. Debug.Assert(xenObject != null, "XenObject is null"); InitializeComponent(); this.xenObject = xenObject; xenObjectBefore = xenObject.Clone(); xenObjectCopy = xenObject.Clone(); Name = String.Format("Edit{0}GeneralSettingsDialog", xenObject.GetType().Name); Text = String.Format(Messages.PROPERTIES_DIALOG_TITLE, Helpers.GetName(xenObject)); if (!Application.RenderWithVisualStyles) { ContentPanel.BackColor = SystemColors.Control; } Build(); }
public GeneralEditPageAction(IXenObject xenObjectOrig, IXenObject xenObjectCopy, string newFolder, List<string> newTags, bool suppressHistory) : base(xenObjectCopy.Connection, Messages.ACTION_SAVE_FOLDER_TAGS, string.Format(Messages.ACTION_SAVING_FOLDER_TAGS_FOR, xenObjectCopy), suppressHistory) { this.xenObjectOrig = xenObjectOrig; this.xenObjectCopy = xenObjectCopy; this.newFolder = newFolder; this.oldTags = new List<string>(Tags.GetTags(xenObjectCopy)); this.newTags = newTags; oldTags.Sort(); newTags.Sort(); string type = xenObjectCopy.GetType().Name.ToLowerInvariant(); if (newFolder != xenObjectCopy.Path) { ApiMethodsToRoleCheck.Add(type + ".remove_from_other_config", Folders.FOLDER); if (!String.IsNullOrEmpty(newFolder)) ApiMethodsToRoleCheck.Add(type + ".add_to_other_config", Folders.FOLDER); // TODO: Full RBAC for folders } foreach (string tag in oldTags) { if (newTags.BinarySearch(tag) < 0) { ApiMethodsToRoleCheck.Add(type + ".remove_tags"); break; } } foreach (string tag in newTags) { if (oldTags.BinarySearch(tag) < 0) { ApiMethodsToRoleCheck.Add(type + ".add_tags"); break; } } }
public PropertiesDialog(IXenObject xenObject) : base(xenObject.Connection) { // xenObject must not be null. If this occurs, we shouldn't have offered Properties in the UI. Debug.Assert(xenObject != null, "XenObject is null"); InitializeComponent(); this.xenObject = xenObject; xenObjectBefore = xenObject.Clone(); xenObjectCopy = xenObject.Clone(); Name = String.Format("Edit{0}GeneralSettingsDialog", xenObject.GetType().Name); Text = String.Format(Messages.PROPERTIES_DIALOG_TITLE, Helpers.GetName(xenObject)); if (!Application.RenderWithVisualStyles) ContentPanel.BackColor = SystemColors.Control; Build(); }
protected SaveChangesAction(IXenObject obj, bool suppressHistory) : base(obj.Connection, Messages.ACTION_SAVE_CHANGES_TITLE, Messages.ACTION_SAVE_CHANGES_IN_PROGRESS, suppressHistory) { // This is lovely. We need to lock the server object (not the copy we have taken) before calling save changes. // We don't know the type so we use the MethodInfo object and MakeGenericMethod to do a resolve against the type // we have extracted from GetType(). The Resolve() call itself needs a XenRef which we make by calling the XenRef constructor that takes the // opaque ref as an argument and using the MakeGenericType call to give it the same type as the object... // ... _then_ we lock it. SetObject(obj); _xenObject = obj; if (obj.opaque_ref != null) // creating a new object comes through here, but with obj.opaque_ref == null { System.Reflection.MethodInfo mi = typeof(IXenConnection).GetMethod("Resolve", BindingFlags.Public | BindingFlags.Instance); Type type = obj.GetType(); object[] xenRefParam = new object[] { typeof(XenRef<>).MakeGenericType(type).GetConstructor(new Type[] {typeof(string)}).Invoke(new Object[] {obj.opaque_ref}) }; _serverXenObject = (IXenObject)mi.MakeGenericMethod(type).Invoke(obj.Connection, xenRefParam); if (_serverXenObject != null) { // CA-35210: Removed this exception pending locking overhaul post MR in CA-38966 //if (_serverXenObject.Locked) // lockViolation = true; _serverXenObject.Locked = true; } } }
public static DelegatedAsyncAction RemoveTagAction(IXenObject o, string tag) { return new DelegatedAsyncAction(o.Connection, String.Format(Messages.DELETE_TAG, tag), String.Format(Messages.DELETING_TAG, tag), String.Format(Messages.DELETED_TAG, tag), delegate(Session session) { Tags.RemoveTag(session, o, tag); }, o.GetType().Name.ToLowerInvariant() + ".remove_tags" ); }
/// <summary> /// Iterate through all implemented IEquatable<T> interfaces and call Equals on each, if any of them /// return false, then this method returns false, otherwise it returns true. /// /// Both o and oo should be of the same type. /// </summary> private bool IEquatableEquals(IXenObject o, IXenObject oo) { Assert.AreEqual(o.GetType(), oo.GetType()); foreach (Type iface in o.GetType().GetInterfaces()) { if (iface.Name.StartsWith("IEquatable")) { MethodInfo mi = iface.GetMethod("Equals"); if (!(bool)mi.Invoke(o, new object[] { oo })) { return false; } } } return true; }
public void SetObject(IXenObject XenObject) { // Annoyingly all of our classes start with an uppercase character, whereas the servers only uppercase abbreviations List<string> abbreviations = new List<string>(new string[]{"SR", "VDI", "VBD", "VM", "PIF", "VIF", "PBD"}); SelectedObjectType = XenObject.GetType().Name; if (abbreviations.Find(delegate(string s) { return SelectedObjectType.StartsWith(s); }) == null) { string firstLetter = SelectedObjectType.Substring(0, 1); SelectedObjectType = firstLetter.ToLowerInvariant() + SelectedObjectType.Substring(1, SelectedObjectType.Length - 1); } SelectedObjectRef = XenObject.opaque_ref; }
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); }
// Returns a set of params which relate to the object you have selected in the treeview private List<string> RetrieveParams(IXenObject obj) { IXenConnection connection = obj.Connection; Host master = connection != null ? Helpers.GetMaster(connection) : null; // get master asserts connection is not null string masterAddress = EmptyParameter; if (master != null) { masterAddress = Helpers.GetUrl(master.Connection); WriteTrustedCertificates(master.Connection); } string sessionRef = connection.Session != null ? connection.Session.uuid : EmptyParameter; string objCls = obj != null ? obj.GetType().Name : EmptyParameter; string objUuid = obj != null && connection.Session != null ? Helpers.GetUuid(obj) : EmptyParameter; return new List<string>(new string[] { masterAddress, sessionRef, objCls, objUuid }); }
private static string TypeOf(IXenObject o) { if (o is Folder) return "10"; if (o is Pool) return "20"; if (o is Host) return "30"; VM vm = o as VM; if (vm != null && vm.is_a_real_vm) return "40"; return o.GetType().ToString(); }
// 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); }