Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. makeAssignments(reqItem, assignments, rule_variables, loggers);
  2.  
  3. /** Context contains
  4. * reqItem - request item (sc_req_item) that the rule is running against
  5. * assignments - name/value pairs set by previous rule assignments - assigning values to variables of the request item
  6. * rule_variables - name/value pairs set by previous rule assignments with temporary values that do not persist after the rule finishes making assignments
  7. * loggers - collection of logging functions, to use:
  8. * loggers.log(msg, loggers.executor);
  9. * loggers.logError(msg, loggers.executor);
  10. * loggers.logWarning(msg, loggers.executor);
  11. * returns true if assignments made successfully, false otherwise
  12. */
  13. function makeAssignments(reqItem, assignments, rule_variables, loggers) {
  14.  
  15. /* Hack to select virtual nics, in this case prefixed by "rms" and first not in use.
  16.  
  17. The field 'available' is not reliable since it is only updated on the Azure discovery schedule,
  18. so rely upon cmdb_rel_ci table for the vnic instance
  19. */
  20.  
  21.  
  22. /* Determine used Network Interface Cards based on fixed prefix. Look at ways to address through relationship
  23. data from Azure.
  24. */
  25. prefix = 'rms';
  26.  
  27. usedNics = [ ];
  28. gr = new GlideRecord('cmdb_rel_ci');
  29. gr.addQuery('child.sys_class_name', 'cmdb_ci_azure_nic');
  30. gr.addQuery('parent.sys_class_name', 'cmdb_ci_azure_vm');
  31. gr.addQuery('child.name', 'STARTSWITH', prefix);
  32. gr.query();
  33.  
  34. while (gr.next()) {
  35. usedNics.push(gr.child);
  36. }
  37.  
  38. /* Determine unused Network Interface Cards based on fix prefix. */
  39. selectedNic = null;
  40. gr = new GlideRecord('cmdb_ci_azure_nic');
  41. gr.addQuery('name', 'STARTSWITH', prefix);
  42. gr.addQuery('sys_id', 'NOT IN', usedNics);
  43. gr.query();
  44. if (gr.next()) {
  45. selectedNic = gr;
  46. }
  47.  
  48. if (!selectedNic) {
  49. loggers.logError("No network interface cards available matching prefix '" + prefix + "'",
  50. loggers.executor);
  51. return false;
  52. }
  53.  
  54. assignments.nic = selectedNic.sys_id;
  55. return true;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement