Skip to content

Commit

Permalink
Merge pull request rancher#196 from rawmind0/rancherVersion
Browse files Browse the repository at this point in the history
Added GetRancherVersion function to provider config
  • Loading branch information
rawmind0 authored Dec 4, 2019
2 parents 4b844fe + fbb68e0 commit cfc6d45
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
## 1.7.1 (Unreleased)

FEATURES:



ENHANCEMENTS:

* Added GetRancherVersion function to provider config

BUG FIXES:



## 1.7.0 (November 20, 2019)

FEATURES:
Expand Down
27 changes: 27 additions & 0 deletions rancher2/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,31 @@ type Config struct {
Bootstrap bool `json:"bootstrap"`
ClusterID string `json:"clusterId"`
ProjectID string `json:"projectId"`
Version string
Sync sync.Mutex
Client Client
}

// GetRancherVersion get Rancher server version
func (c *Config) GetRancherVersion() (string, error) {
if len(c.Version) > 0 {
return c.Version, nil
}

client, err := c.ManagementClient()
if err != nil {
return "", fmt.Errorf("[ERROR] Getting Rancher version: %s", err)
}

version, err := client.Setting.ByID("server-version")
if err != nil {
return "", fmt.Errorf("[ERROR] Getting Rancher version: %s", err)
}
c.Version = version.Value

return c.Version, nil
}

// UpdateToken update tokenkey and restart client connections
func (c *Config) UpdateToken(token string) error {
if len(token) == 0 {
Expand Down Expand Up @@ -85,6 +106,12 @@ func (c *Config) ManagementClient() (*managementClient.Client, error) {
}
c.Client.Management = mClient

version, err := mClient.Setting.ByID("server-version")
if err != nil {
return nil, err
}
c.Version = version.Value

return c.Client.Management, nil
}

Expand Down

0 comments on commit cfc6d45

Please sign in to comment.