rnelson0 / vCenter-roles

Set up roles for common applications to access vCenter
Apache License 2.0
11 stars 3 forks source link

Vester linkage #15

Closed cars closed 8 years ago

cars commented 8 years ago

Trying to leverage this for the Vester project. Vester assumes there's already a vCenter connection. Modify Import-VIRole to try to use that connection rather than re-running connect-viserver which prompts for creds...

rnelson0 commented 8 years ago

@cars I should have tried this before commenting on the previous PR. When I have an existing session, Import-VIRole makes use of it:

H:\> Connect-VIServer vcsa

Name                           Port  User                          
----                           ----  ----                          
vcsa                           443   LAB\rn7284                    

H:\> C:\Users\rnelson0\Documents\vCenter-roles\Import-VIRole.ps1

H:\> Import-VIRole -Name Test -RoleFile C:\Users\rnelson0\Documents\vCenter-roles\Import-VIRole.ps1 -vCenter vcsa
Role already exists.
At C:\Users\rnelson0\Documents\vCenter-roles\Import-VIRole.ps1:106 char:13
+             Throw 'Role already exists.'
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (Role already exists.:String) [], RuntimeException
    + FullyQualifiedErrorId : Role already exists.

In what circumstances are you not seeing it take advantage of the existing connection, or otherwise cause an interruption?

Thanks!

cars commented 8 years ago

I was seeing myself get prompted for credentials when I was using this from a Pester/Vester test.... Let me go look at it again.....

rnelson0 commented 8 years ago

Is there a test that is calling Disconnect-VIServer somewhere in there? By passing the Session value to Connect-VIServer, it should try and use the existing one. The only caveat I see is that you must use the same name you used originally. I.e. Connect-VIserver vcsa.example.com followed by Import-VIRole ... -vCenter vcsa will prompt for credentials as vcsa and vcsa.example.com are treated as different VIServers.

cars commented 8 years ago

Yeah I think that that's what happened. I was switching between vcenters and not being consistent with what hostname I was using.

rnelson0 commented 8 years ago

Cool, glad we could figure it out. Thanks for using this!