|
5 | 5 | "fmt" |
6 | 6 | "io" |
7 | 7 | "os" |
| 8 | + "strings" |
8 | 9 |
|
9 | 10 | clientv1 "github.com/spectrocloud/palette-sdk-go/api/client/v1" |
10 | 11 | "github.com/spectrocloud/palette-sdk-go/api/models" |
@@ -224,6 +225,40 @@ func (h *V1Client) DownloadClusterProfileUIDSpc(profileUID string) (*bytes.Buffe |
224 | 225 | return &buf, resp.ContentDisposition, nil |
225 | 226 | } |
226 | 227 |
|
| 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 | + |
227 | 262 | // GetClusterProfiles retrieves all cluster profiles. |
228 | 263 | func (h *V1Client) GetClusterProfiles() ([]*models.V1ClusterProfileMetadata, error) { |
229 | 264 | params := clientv1.NewV1ClusterProfilesMetadataParamsWithContext(h.ctx) |
|
0 commit comments