-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: avoid error when cluster already connected
1. check if cluster is connected by ip, if already connected, just use connected cluster, not connect a new one. 2. check cluster uniqueness with label. fix issue-14
- Loading branch information
Showing
2 changed files
with
147 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package helper | ||
|
||
import ( | ||
"github.com/smartxworks/cloudtower-go-sdk/v2/client" | ||
"github.com/smartxworks/cloudtower-go-sdk/v2/client/label" | ||
"github.com/smartxworks/cloudtower-go-sdk/v2/models" | ||
) | ||
|
||
var LabelPrefix = "system.cloudtower/terraform" | ||
|
||
func GetUniquenessLabelKey(t string) string { | ||
return LabelPrefix + "/" + t | ||
} | ||
|
||
func CreateUniquenessLabel(client *client.Cloudtower, t string, id string) (*label.CreateLabelOK, error) { | ||
key := GetUniquenessLabelKey(t) | ||
clp := label.NewCreateLabelParams() | ||
clp.RequestBody = []*models.LabelCreationParams{ | ||
{ | ||
Key: &key, | ||
Value: &id, | ||
}, | ||
} | ||
return client.Label.CreateLabel(clp) | ||
} | ||
|
||
func GetUniquenessLabel(client *client.Cloudtower, t string, id string) (*label.GetLabelsOK, error) { | ||
key := GetUniquenessLabelKey(t) | ||
glp := label.NewGetLabelsParams() | ||
glp.RequestBody = &models.GetLabelsRequestBody{ | ||
Where: &models.LabelWhereInput{ | ||
Key: &key, | ||
Value: &id, | ||
}, | ||
} | ||
return client.Label.GetLabels(glp) | ||
} | ||
|
||
func DeleteUniquenessLabel(client *client.Cloudtower, t string, id string) (*label.DeleteLabelOK, error) { | ||
key := GetUniquenessLabelKey(t) | ||
dlp := label.NewDeleteLabelParams() | ||
dlp.RequestBody = &models.LabelDeletionParams{ | ||
Where: &models.LabelWhereInput{ | ||
Key: &key, | ||
Value: &id, | ||
}, | ||
} | ||
return client.Label.DeleteLabel(dlp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters