Add update credentials function in vclib

This commit is contained in:
Abrar Shivani 2018-05-08 14:38:03 -07:00
parent b3837d004a
commit 1fb9ababbd

View File

@ -40,6 +40,7 @@ type VSphereConnection struct {
Port string
Insecure bool
RoundTripperCount uint
credentialsLock sync.Mutex
}
var (
@ -85,6 +86,8 @@ func (connection *VSphereConnection) Connect(ctx context.Context) error {
// otherwise calls SessionManager.Login with user and password.
func (connection *VSphereConnection) login(ctx context.Context, client *vim25.Client) error {
m := session.NewManager(client)
connection.credentialsLock.Lock()
defer connection.credentialsLock.Unlock()
// TODO: Add separate fields for certificate and private-key.
// For now we can leave the config structs and validation as-is and
@ -163,3 +166,10 @@ func (connection *VSphereConnection) NewClient(ctx context.Context) (*vim25.Clie
client.RoundTripper = vim25.Retry(client.RoundTripper, vim25.TemporaryNetworkError(int(connection.RoundTripperCount)))
return client, nil
}
func (connection *VSphereConnection) UpdateCredentials(username string, password string) {
connection.credentialsLock.Lock()
defer connection.credentialsLock.Unlock()
connection.Username = username
connection.Password = password
}