Init methods are no-ops when already initialized.

Signed-off-by: Ash Wilson <ash.wilson@rackspace.com>
This commit is contained in:
Ash Wilson
2014-12-11 14:33:29 -05:00
committed by Guillaume Giamarchi
parent 8466d95fa0
commit 7c839273c1
2 changed files with 12 additions and 6 deletions

View File

@@ -294,12 +294,10 @@ func (c *GenericClient) getPorts(d *Driver) ([]string, error) {
}
func (c *GenericClient) InitComputeClient(d *Driver) error {
if c.Provider == nil {
err := c.Authenticate(d)
if err != nil {
return err
}
if c.Compute != nil {
return nil
}
compute, err := openstack.NewComputeV2(c.Provider, gophercloud.EndpointOpts{
Region: d.Region,
Availability: c.getEndpointType(d),
@@ -312,6 +310,10 @@ func (c *GenericClient) InitComputeClient(d *Driver) error {
}
func (c *GenericClient) InitNetworkClient(d *Driver) error {
if c.Network != nil {
return nil
}
network, err := openstack.NewNetworkV2(c.Provider, gophercloud.EndpointOpts{
Region: d.Region,
Availability: c.getEndpointType(d),

View File

@@ -22,9 +22,13 @@ type Client struct {
// Authenticate creates a Rackspace-specific Gophercloud client.
func (c *Client) Authenticate(d *openstack.Driver) error {
if c.Provider != nil {
return nil
}
log.WithFields(log.Fields{
"Username": d.Username,
}).Info("Authenticating...")
}).Info("Authenticating to Rackspace.")
apiKey := c.driver.APIKey
opts := gophercloud.AuthOptions{