-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed usages from powershell commands #1
Changes from 13 commits
4074ad4
a8414d0
1dbe0cf
5a77b14
f2bee8a
931a5ec
6282456
e89d83b
a497291
5b76be3
fe3c394
1b02c5f
077e0cc
014da6c
f18e3f5
79fa39b
4fa547c
9cc57e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,6 @@ var HypervBox = { | |
return 'powershell.exe'; | ||
}, | ||
// TODO: ..We'll probably need a differnt command here in the future. That's why code dupe. | ||
commandElevated: function () { | ||
return 'powershell.exe'; | ||
}, | ||
installed: function () { | ||
return util.execFile([this.command(), '@(Get-Command get-vm).ModuleName']).then(stdout => { | ||
console.log('stdout: ', stdout); | ||
|
@@ -31,19 +28,19 @@ var HypervBox = { | |
*/ | ||
|
||
hasAdminRights: function() { | ||
return util.execFile([this.command(), 'Get-VMHostSupportedVersion']).then(stdout => { | ||
return util.execFile([this.command(), 'Get-VMHost']).then(stdout => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I run the command
So for me there is no text "invalidoperation" ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, so maybe FullyQualifiedErrorId would be better to check for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pmario changed this in my latest commit. |
||
console.log('stdout: ', stdout); | ||
// To execute the above command you'll need Admin or Hyper-V-Admin rights. | ||
if ( stdout.toUpperCase().indexOf('TRUE') !== -1) { | ||
if (stdout.toLowerCase().indexOf('invalidoperation') === -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you have a problem with this admin test command? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That function is not available for all installations. It is present on 50% of the machines I've tested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah. ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't pinpointed which package/program added the powershell commands :( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just found
As you suggested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the above lines of code. |
||
return Promise.resolve(true); | ||
} | ||
return Promise.resolve(false); | ||
}).catch(() => { | ||
return Promise.resolve(false); | ||
}); | ||
}, | ||
switchName: function (name) { | ||
// return util.execFile([this.command(), '$(Get-VMSwitch | where {$_.SwitchType -eq "external"}).name']).then(out => { | ||
return util.execFile([this.command(), '$(Get-VMSwitch).name']).then(out => { | ||
return util.execFile([this.command(), '$(Get-VMSwitch | where {$_.SwitchType -eq "external"}).name']).then(out => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't use the test for an external switch, since it's possible to use internal switches, too! An internal swtich can get internet access with a shared network connection. see: docker#1541 (comment) So we basically need to use the first one, we find. .... even if it is the wrong one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pmario this was removed in the latest version of code, after extensive testing on several machines. |
||
// We use the same mechanism as docker-machine. Use the first switch we find. | ||
return (out.replace('\r','').split('\n')[0]); | ||
}).catch(() => { | ||
|
@@ -54,9 +51,8 @@ var HypervBox = { | |
// there seems to be a problem with elevated execution. see: https://github.com/nodejs/node-v0.x-archive/issues/6797 | ||
// The only easy possibility seems to be to communicat with a file. | ||
|
||
return util.execFile([this.command(), 'Get-VMHostSupportedVersion']).then(stdout => { | ||
|
||
let match = stdout.match(/^(.*) True/im); | ||
return util.execFile([this.command(), 'Get-VM | Where {$_.Name -eq "default" -and $_.Version} | select Version']).then(stdout => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will change this to be name instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This might be done as a future pull request as default if hard coded all over the place now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pmario changed this in my latest commit. Now using machine.name() |
||
let match = stdout.match(/\d+(?:\.\d+)+/g); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did test the stuff. Seems to work with hyper-v, but there is a problem here. needs to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
if (match != null) { | ||
// matched text: match[0] | ||
// match start: match.index | ||
|
@@ -76,8 +72,9 @@ var HypervBox = { | |
// Needed for consistency check | ||
vmExists: function (name) { | ||
return util.execFile([this.command(), "Get-VM | Where {$_.Name -eq '" + name + "'}"]).then(out => { | ||
console.log(out) | ||
return (out.indexOf(name) !== -1); | ||
console.log(out); | ||
var machineExists = out.indexOf(name) !== -1; | ||
return machineExists; | ||
}).catch(() => { | ||
return false; | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import util from './Util'; | ||
|
||
var PowershellUtil = | ||
{ | ||
runCommandWithArgs : function (args) { | ||
console.log("cmd: ", args); | ||
return util.execFile([this.commandElevated(), 'start-process', 'powershell', '-verb', 'runas', '-wait', '-argumentList', args]).then(stdout => { | ||
return Promise.resolve(null); | ||
}).catch((error) => { | ||
throw new Error(error.message); | ||
}); | ||
}, | ||
commandElevated: function commandElevated() { | ||
return 'powershell.exe'; | ||
}, | ||
}; | ||
|
||
module.exports = PowershellUtil; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo there is no need for the extra check of
virtualboxinstalled
. create is only called, if we are already sure, that we can call it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
virtualboxinstalled
is only needed as at that step you might not have it installed and we need to through an Exception and stop the whole process.