vsphere/config.go
func (c *Config) Client() (*VSphereClient, error) {
	client := new(VSphereClient)

	u, err := c.vimURL()
	if err != nil {
		return nil, fmt.Errorf("Error generating SOAP endpoint url: %s", err)
	}

	err = c.EnableDebug()
	if err != nil {
		return nil, fmt.Errorf("Error setting up client debug: %s", err)
	}

	// Set up the VIM/govmomi client connection, or load a previous session
	client.vimClient, err = c.SavedVimSessionOrNew(u)
	if err != nil {
		return nil, err
	}

	log.Printf("[DEBUG] VMWare vSphere Client configured for URL: %s", c.VSphereServer)

	if isEligibleTagEndpoint(client.vimClient) {
		// Connect to the CIS REST endpoint for tagging, or load a previous session
		client.tagsClient, err = c.SavedRestSessionOrNew(u)
		if err != nil {
			return nil, err
		}
		log.Println("[DEBUG] CIS REST client configuration successful")
	} else {
		// Just print a log message so that we know that tags are not available on
		// this connection.
		log.Printf("[DEBUG] Connected endpoint does not support tags (%s)", viapi.ParseVersionFromClient(client.vimClient))
	}

	// Done, save sessions if we need to and return
	if err := c.SaveVimClient(client.vimClient); err != nil {
		return nil, fmt.Errorf("error persisting SOAP session to disk: %s", err)
	}
	if err := c.SaveRestClient(client.tagsClient); err != nil {
		return nil, fmt.Errorf("error persisting REST session to disk: %s", err)
	}

	return client, nil
}
func (c *Config) Client() (*VSphereClient, error) {
	client := new(VSphereClient)

	u, err := c.vimURL()
	if err != nil {
		return nil, fmt.Errorf("Error generating SOAP endpoint url: %s", err)
	}

	err = c.EnableDebug()
	if err != nil {
		return nil, fmt.Errorf("Error setting up client debug: %s", err)
	}

	// Set up the VIM/govmomi client connection, or load a previous session
	client.vimClient, err = c.SavedVimSessionOrNew(u)
	if err != nil {
		return nil, err
	}

	log.Printf("[DEBUG] VMWare vSphere Client configured for URL: %s", c.VSphereServer)

	if isEligibleTagEndpoint(client.vimClient) {
		// Connect to the CIS REST endpoint for tagging, or load a previous session
		client.tagsClient, err = c.SavedRestSessionOrNew(u)
		if err != nil {
			return nil, err
		}
		log.Println("[DEBUG] CIS REST client configuration successful")
	} else {
		// Just print a log message so that we know that tags are not available on
		// this connection.
		log.Printf("[DEBUG] Connected endpoint does not support tags (%s)", viapi.ParseVersionFromClient(client.vimClient))
	}

	// Done, save sessions if we need to and return
	if err := c.SaveVimClient(client.vimClient); err != nil {
		return nil, fmt.Errorf("error persisting SOAP session to disk: %s", err)
	}
	if err := c.SaveRestClient(client.tagsClient); err != nil {
		return nil, fmt.Errorf("error persisting REST session to disk: %s", err)
	}

	return client, nil
}
// Client returns a new client for accessing VMWare vSphere.