-
Notifications
You must be signed in to change notification settings - Fork 13
/
os_repository.go
86 lines (73 loc) · 2.57 KB
/
os_repository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright © 2024 Dell Inc. or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package goscaleio
import (
"fmt"
"net/http"
"time"
types "github.com/dell/goscaleio/types/v1"
)
const osRepoPath = "/api/v1/OSRepository"
// GetAllOSRepositories Gets all OS Repositories
func (s *System) GetAllOSRepositories() ([]types.OSRepository, error) {
defer TimeSpent("GetAllOSRepositories", time.Now())
var osRepositories []types.OSRepository
err := s.client.getJSONWithRetry(
http.MethodGet, osRepoPath, nil, &osRepositories)
if err != nil {
return nil, err
}
return osRepositories, nil
}
// GetOSRepositoryByID Gets OS Repository by ID
func (s *System) GetOSRepositoryByID(id string) (*types.OSRepository, error) {
defer TimeSpent("GetOSRepositoryByID", time.Now())
pathWithID := fmt.Sprintf("%v/%v", osRepoPath, id)
var osRepository types.OSRepository
err := s.client.getJSONWithRetry(
http.MethodGet, pathWithID, nil, &osRepository)
if err != nil {
return nil, err
}
return &osRepository, nil
}
// CreateOSRepository Creates OS Repository
func (s *System) CreateOSRepository(createOSRepository *types.OSRepository) (*types.OSRepository, error) {
defer TimeSpent("CreateOSRepository", time.Now())
var createResponse types.OSRepository
if createOSRepository == nil {
return &createResponse, fmt.Errorf("createOSRepository cannot be nil")
}
bodyData := map[string]interface{}{
"name": createOSRepository.Name,
"repoType": createOSRepository.RepoType,
"sourcePath": createOSRepository.SourcePath,
"imageType": createOSRepository.ImageType,
}
err := s.client.getJSONWithRetry(
http.MethodPost, osRepoPath, bodyData, &createResponse)
if err != nil {
return nil, err
}
return &createResponse, nil
}
// RemoveOSRepository Removes OS Repository
func (s *System) RemoveOSRepository(id string) error {
defer TimeSpent("RemoveOSRepository", time.Now())
pathWithID := fmt.Sprintf("%v/%v", osRepoPath, id)
err := s.client.getJSONWithRetry(
http.MethodDelete, pathWithID, nil, nil)
if err != nil {
return err
}
return nil
}