Created
July 28, 2016 18:11
-
-
Save restump/eedb56e4fb1215a14d6da3d2ea0bbed5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment