Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Not worked at this time
- class Core {
- constructor(server, username, password) {
- console.log("CREATE CORE");
- this.server = server;
- this.username = username;
- this.password = password;
- }
- createPS() {
- console.log("REQ NODEPOWERSHELL");
- let nodePowershell = require('node-powershell');
- this.PS = new nodePowershell({
- executionPolicy: 'RemoteSigned',
- noProfile: true
- });
- console.log("CREATE PS");
- }
- connectVIServer() {
- console.log("CONN VISERVER");
- this.PS.addCommand('Import-Module VMware.PowerCLI')
- this.PS.addCommand('$server = "10.0.15.10"');
- this.PS.addCommand('$user = "administrator@labs.vsphere"');
- this.PS.addCommand('$pass = "vc#13ITkmitl"');
- this.PS.addCommand('Connect-VIServer -Server $server -Username $user -Password $pass -Force:$true')
- .then(function(){
- this.PS.invoke();
- })
- .then(function(output){
- console.log(output);
- })
- /*
- this.PS.invoke()
- .then(output => {
- console.log(output);
- }).catch(err => {
- console.log("CVI" + err);
- });
- */
- }
- disconnectVIServer() {
- console.log("DISCONN VISERVER");
- this.PS.addCommand('Disconnect-VIServer -Server $server -Confirm:$false')
- .then(function(){
- this.PS.invoke();
- this.PS.dispose();
- })
- /*
- this.PS.invoke()
- .then(output => {
- console.log(output);
- this.PS.dispose();
- }).catch(err => {
- console.log("DCVI" + err);
- this.PS.dispose();
- });
- */
- }
- }
- function main() {
- console.log("MAIN FUNC");
- const core = new Core("10.0.15.10", "administrator@labs.vsphere", "vc#13ITkmitl");
- core.createPS();
- core.connectVIServer();
- core.disconnectVIServer();
- console.log("END");
- /*
- core.createPS().then(ps => {
- console.log("THEN");
- core.connectVIServer();
- core.disconnectVIServer();
- }).catch(err => {
- console.log(err);
- });
- */
- /*
- await core.connectVIServer();
- await core.disconnectVIServer();
- */
- }
- main();
- /*
- const core = new Core("10.0.15.10", "administrator@labs.vsphere", "vc#13ITkmitl");
- core.createPS();
- core.connectVIServer();
- core.disconnectVIServer();
- */
Add Comment
Please, Sign In to add comment