Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- makeAssignments(reqItem, assignments, rule_variables, loggers);
- /** Context contains
- * reqItem - request item (sc_req_item) that the rule is running against
- * assignments - name/value pairs set by previous rule assignments - assigning values to variables of the request item
- * rule_variables - name/value pairs set by previous rule assignments with temporary values that do not persist after the rule finishes making assignments
- * loggers - collection of logging functions, to use:
- * loggers.log(msg, loggers.executor);
- * loggers.logError(msg, loggers.executor);
- * loggers.logWarning(msg, loggers.executor);
- * returns true if assignments made successfully, false otherwise
- */
- function makeAssignments(reqItem, assignments, rule_variables, loggers) {
- /* Hack to select virtual nics, in this case prefixed by "rms" and first not in use.
- The field 'available' is not reliable since it is only updated on the Azure discovery schedule,
- so rely upon cmdb_rel_ci table for the vnic instance
- */
- /* Determine used Network Interface Cards based on fixed prefix. Look at ways to address through relationship
- data from Azure.
- */
- prefix = 'rms';
- usedNics = [ ];
- gr = new GlideRecord('cmdb_rel_ci');
- gr.addQuery('child.sys_class_name', 'cmdb_ci_azure_nic');
- gr.addQuery('parent.sys_class_name', 'cmdb_ci_azure_vm');
- gr.addQuery('child.name', 'STARTSWITH', prefix);
- gr.query();
- while (gr.next()) {
- usedNics.push(gr.child);
- }
- /* Determine unused Network Interface Cards based on fix prefix. */
- selectedNic = null;
- gr = new GlideRecord('cmdb_ci_azure_nic');
- gr.addQuery('name', 'STARTSWITH', prefix);
- gr.addQuery('sys_id', 'NOT IN', usedNics);
- gr.query();
- if (gr.next()) {
- selectedNic = gr;
- }
- if (!selectedNic) {
- loggers.logError("No network interface cards available matching prefix '" + prefix + "'",
- loggers.executor);
- return false;
- }
- assignments.nic = selectedNic.sys_id;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement