Skip to content

Commit 4e0d6d5

Browse files
authored
add V1SpectroClustersSpcDownload api (#155)
1 parent c16f6a2 commit 4e0d6d5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

client/cluster_profile.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"os"
8+
"strings"
89

910
clientv1 "github.com/spectrocloud/palette-sdk-go/api/client/v1"
1011
"github.com/spectrocloud/palette-sdk-go/api/models"
@@ -224,6 +225,40 @@ func (h *V1Client) DownloadClusterProfileUIDSpc(profileUID string) (*bytes.Buffe
224225
return &buf, resp.ContentDisposition, nil
225226
}
226227

228+
// DownloadSpcCLI downloads the cluster definition archive file
229+
func (h *V1Client) DownloadSpcCLI(clusterDefinitionName, clusterDefinitionProfilesIDs, cloudType string) (*bytes.Buffer, string, error) {
230+
profileIDs := strings.Split(clusterDefinitionProfilesIDs, ",")
231+
profiles := make([]*models.V1ClusterDefinitionProfileEntity, len(profileIDs))
232+
for i, profileID := range profileIDs {
233+
profileIDTrimmed := strings.TrimSpace(profileID)
234+
profiles[i] = &models.V1ClusterDefinitionProfileEntity{
235+
UID: &profileIDTrimmed,
236+
}
237+
}
238+
239+
body := models.V1ClusterDefinitionEntity{}
240+
body.Metadata = &models.V1ObjectMetaInputEntity{
241+
Name: clusterDefinitionName,
242+
}
243+
body.Spec = &models.V1ClusterDefinitionSpecEntity{
244+
CloudType: &cloudType,
245+
Profiles: profiles,
246+
}
247+
248+
getParam := clientv1.NewV1SpectroClustersSpcDownloadParamsWithContext(h.ctx).WithBody(&body)
249+
250+
var buf bytes.Buffer
251+
writer := io.Writer(&buf)
252+
253+
resp, err := h.Client.V1SpectroClustersSpcDownload(getParam, writer)
254+
if apiutil.Is404(err) {
255+
return &buf, "", nil
256+
} else if err != nil {
257+
return &buf, "", err
258+
}
259+
return &buf, resp.ContentDisposition, nil
260+
}
261+
227262
// GetClusterProfiles retrieves all cluster profiles.
228263
func (h *V1Client) GetClusterProfiles() ([]*models.V1ClusterProfileMetadata, error) {
229264
params := clientv1.NewV1ClusterProfilesMetadataParamsWithContext(h.ctx)

0 commit comments

Comments
 (0)