Guest User

Untitled

a guest
Nov 29th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. //Not worked at this time
  2.  
  3. class Core {
  4.  
  5. constructor(server, username, password) {
  6. console.log("CREATE CORE");
  7. this.server = server;
  8. this.username = username;
  9. this.password = password;
  10. }
  11.  
  12. createPS() {
  13. console.log("REQ NODEPOWERSHELL");
  14. let nodePowershell = require('node-powershell');
  15. this.PS = new nodePowershell({
  16. executionPolicy: 'RemoteSigned',
  17. noProfile: true
  18. });
  19. console.log("CREATE PS");
  20. }
  21.  
  22. connectVIServer() {
  23. console.log("CONN VISERVER");
  24. this.PS.addCommand('Import-Module VMware.PowerCLI')
  25. this.PS.addCommand('$server = "10.0.15.10"');
  26. this.PS.addCommand('$user = "administrator@labs.vsphere"');
  27. this.PS.addCommand('$pass = "vc#13ITkmitl"');
  28. this.PS.addCommand('Connect-VIServer -Server $server -Username $user -Password $pass -Force:$true')
  29. .then(function(){
  30. this.PS.invoke();
  31. })
  32. .then(function(output){
  33. console.log(output);
  34. })
  35. /*
  36. this.PS.invoke()
  37. .then(output => {
  38. console.log(output);
  39. }).catch(err => {
  40. console.log("CVI" + err);
  41. });
  42. */
  43. }
  44.  
  45. disconnectVIServer() {
  46. console.log("DISCONN VISERVER");
  47. this.PS.addCommand('Disconnect-VIServer -Server $server -Confirm:$false')
  48. .then(function(){
  49. this.PS.invoke();
  50. this.PS.dispose();
  51. })
  52. /*
  53. this.PS.invoke()
  54. .then(output => {
  55. console.log(output);
  56. this.PS.dispose();
  57. }).catch(err => {
  58. console.log("DCVI" + err);
  59. this.PS.dispose();
  60. });
  61. */
  62. }
  63. }
  64.  
  65. function main() {
  66. console.log("MAIN FUNC");
  67. const core = new Core("10.0.15.10", "administrator@labs.vsphere", "vc#13ITkmitl");
  68. core.createPS();
  69. core.connectVIServer();
  70. core.disconnectVIServer();
  71. console.log("END");
  72.  
  73.  
  74. /*
  75. core.createPS().then(ps => {
  76. console.log("THEN");
  77. core.connectVIServer();
  78. core.disconnectVIServer();
  79. }).catch(err => {
  80. console.log(err);
  81. });
  82. */
  83.  
  84. /*
  85. await core.connectVIServer();
  86. await core.disconnectVIServer();
  87. */
  88. }
  89.  
  90. main();
  91.  
  92.  
  93. /*
  94. const core = new Core("10.0.15.10", "administrator@labs.vsphere", "vc#13ITkmitl");
  95. core.createPS();
  96. core.connectVIServer();
  97. core.disconnectVIServer();
  98. */
Add Comment
Please, Sign In to add comment