Hi,
Does anyone have (example) code available to implement the SetResourceMessage SLNet call, to either create a new resource, or to update an existing one programmatically?
Thanks!
Marieke Goethals [SLC] [DevOps Catalyst] Selected answer as best 12th July 2023
Hi Ruben,
It is highly advised not to use the SRM request messages directly, but rather use the helpers, such as ResourceManagerHelper in SLNet. It does have the API calls to create or update a Resource.
Pseudo code example:
public void Run(Engine engine) { var rmHelper = new ResourceManagerHelper(engine.SendSLNetSingleResponseMessage); var protocolFunctionHelper = new ProtocolFunctionHelper(engine.SendSLNetSingleResponseMessage); var profileHelper = new ProfileHelper(engine.SendSLNetSingleResponseMessage); var mainElement = engine.FindElement("IRD Main Decoder"); var functionElement = engine.FindElement("IRD Satellite Decoder"); FunctionDefinitionID functionID = new FunctionDefinitionID(Guid.Parse("9fca935f-2794-4d9c-aa30-016b73ab4544")); // function definition ID example SystemFunctionDefinition functionDefinition = protocolFunctionHelper.GetFunctionDefinition(functionID, searchSystemFunctionDefinition: false); // function definition example ResourcePool decoderPool = rmHelper.GetResourcePool(Guid.Parse("eb08eb7f-93bc-4b80-943a-f8055c772e10")); //Decoder pool example Parameter capacityParameter = profileHelper.ProfileParameters.Read(ParameterExposers.ID.Equal(Guid.Parse("4fa4d673-c5fd-4477-8551-078d4be09f9f"))).FirstOrDefault(); // Capacity parameter example Parameter capabilityParameter = profileHelper.ProfileParameters.Read(ParameterExposers.ID.Equal(Guid.Parse("30067237-ba12-4ad3-b2c4-2bda53d406c4"))).FirstOrDefault(); // Capability parameter example var tableParameter = 2000; //linked table parameter List<FunctionEntryPoint> entryPoints = protocolFunctionHelper.GetFunctionEntryPoints(functionID.Id, functionElement.DmaId, functionElement.ElementId); FunctionEntryPoint entryData = entryPoints.FirstOrDefault(x => x.ParameterID == tableParameter && x.Data?.Length > 0); EntryPointData nextEntryData = entryData.Data.FirstOrDefault(x => x.Element == null); // next unused table entry var decodeFunctionResource = new Skyline.DataMiner.Net.ResourceManager.Objects.FunctionResource(mainElement.DmaId, mainElement.ElementId) { GUID = Guid.NewGuid(), Name = "IRD Decoder", PoolGUIDs = new List<Guid>() { decoderPool.GUID }, FunctionGUID = functionDefinition.GUID, FunctionName = functionElement.Name, PK = nextEntryData.IndexValue, DmaID = functionElement.DmaId, ElementID = functionElement.ElementId, LinkerTableEntries = new Tuple<int, string>[0], MaxConcurrency = 100, Capacities = new List<Skyline.DataMiner.Net.SRM.Capacities.MultiResourceCapacity>() { new Skyline.DataMiner.Net.SRM.Capacities.MultiResourceCapacity() { CapacityProfileID = capacityParameter.ID, Value = new CapacityParameterValue(maxQuantity: 100) } }, Capabilities = new List<Skyline.DataMiner.Net.SRM.Capabilities.ResourceCapability>() { new Skyline.DataMiner.Net.SRM.Capabilities.ResourceCapability() { CapabilityProfileID = capabilityParameter.ID, IsTimeDynamic = false, Value = new CapabilityParameterValue(minRange: 1, maxRange: 10), } }, Properties = new List<ResourceManagerProperty>() { new ResourceManagerProperty(Name: "Satellite state", Value: "Down"), new ResourceManagerProperty(Name: "Fiber state", Value: "Running"), }, }; rmHelper.AddOrUpdateResources(new Skyline.DataMiner.Net.Messages.Resource[] { decodeFunctionResource }); }
Hope this helps you further
Marieke Goethals [SLC] [DevOps Catalyst] Selected answer as best 12th July 2023