github.com/1and1/oneandone-cloudserver-sdk-go@v1.4.1/sharedstorages.go (about) 1 package oneandone 2 3 import ( 4 "net/http" 5 ) 6 7 type SharedStorage struct { 8 Identity 9 descField 10 Size int `json:"size"` 11 MinSizeAllowed int `json:"minimum_size_allowed"` 12 SizeUsed string `json:"size_used,omitempty"` 13 State string `json:"state,omitempty"` 14 SiteId string `json:"site_id,omitempty"` 15 CifsPath string `json:"cifs_path,omitempty"` 16 NfsPath string `json:"nfs_path,omitempty"` 17 CreationDate string `json:"creation_date,omitempty"` 18 Servers []SharedStorageServer `json:"servers,omitempty"` 19 Datacenter *Datacenter `json:"datacenter,omitempty"` 20 ApiPtr 21 } 22 23 type SharedStorageServer struct { 24 Id string `json:"id,omitempty"` 25 Name string `json:"name,omitempty"` 26 Rights string `json:"rights,omitempty"` 27 } 28 29 type SharedStorageRequest struct { 30 DatacenterId string `json:"datacenter_id,omitempty"` 31 Name string `json:"name,omitempty"` 32 Description string `json:"description,omitempty"` 33 Size *int `json:"size"` 34 } 35 36 type SharedStorageAccess struct { 37 State string `json:"state,omitempty"` 38 KerberosContentFile string `json:"kerberos_content_file,omitempty"` 39 UserDomain string `json:"user_domain,omitempty"` 40 SiteId string `json:"site_id,omitempty"` 41 NeedsPasswordReset int `json:"needs_password_reset"` 42 } 43 44 // GET /shared_storages 45 func (api *API) ListSharedStorages(args ...interface{}) ([]SharedStorage, error) { 46 url, err := processQueryParams(createUrl(api, sharedStoragePathSegment), args...) 47 if err != nil { 48 return nil, err 49 } 50 result := []SharedStorage{} 51 err = api.Client.Get(url, &result, http.StatusOK) 52 if err != nil { 53 return nil, err 54 } 55 for index, _ := range result { 56 result[index].api = api 57 } 58 return result, nil 59 } 60 61 // POST /shared_storages 62 func (api *API) CreateSharedStorage(request *SharedStorageRequest) (string, *SharedStorage, error) { 63 result := new(SharedStorage) 64 url := createUrl(api, sharedStoragePathSegment) 65 err := api.Client.Post(url, request, &result, http.StatusAccepted) 66 if err != nil { 67 return "", nil, err 68 } 69 result.api = api 70 return result.Id, result, nil 71 } 72 73 // GET /shared_storages/{id} 74 func (api *API) GetSharedStorage(ss_id string) (*SharedStorage, error) { 75 result := new(SharedStorage) 76 url := createUrl(api, sharedStoragePathSegment, ss_id) 77 err := api.Client.Get(url, &result, http.StatusOK) 78 if err != nil { 79 return nil, err 80 } 81 result.api = api 82 return result, nil 83 } 84 85 // DELETE /shared_storages/{id} 86 func (api *API) DeleteSharedStorage(ss_id string) (*SharedStorage, error) { 87 result := new(SharedStorage) 88 url := createUrl(api, sharedStoragePathSegment, ss_id) 89 err := api.Client.Delete(url, nil, &result, http.StatusAccepted) 90 if err != nil { 91 return nil, err 92 } 93 result.api = api 94 return result, nil 95 } 96 97 // PUT /shared_storages/{id} 98 func (api *API) UpdateSharedStorage(ss_id string, request *SharedStorageRequest) (*SharedStorage, error) { 99 result := new(SharedStorage) 100 url := createUrl(api, sharedStoragePathSegment, ss_id) 101 err := api.Client.Put(url, &request, &result, http.StatusAccepted) 102 if err != nil { 103 return nil, err 104 } 105 result.api = api 106 return result, nil 107 } 108 109 // GET /shared_storages/{id}/servers 110 func (api *API) ListSharedStorageServers(st_id string) ([]SharedStorageServer, error) { 111 result := []SharedStorageServer{} 112 url := createUrl(api, sharedStoragePathSegment, st_id, "servers") 113 err := api.Client.Get(url, &result, http.StatusOK) 114 if err != nil { 115 return nil, err 116 } 117 return result, nil 118 } 119 120 // POST /shared_storages/{id}/servers 121 func (api *API) AddSharedStorageServers(st_id string, servers []SharedStorageServer) (*SharedStorage, error) { 122 result := new(SharedStorage) 123 req := struct { 124 Servers []SharedStorageServer `json:"servers"` 125 }{servers} 126 url := createUrl(api, sharedStoragePathSegment, st_id, "servers") 127 err := api.Client.Post(url, &req, &result, http.StatusAccepted) 128 if err != nil { 129 return nil, err 130 } 131 result.api = api 132 return result, nil 133 } 134 135 // GET /shared_storages/{id}/servers/{id} 136 func (api *API) GetSharedStorageServer(st_id string, ser_id string) (*SharedStorageServer, error) { 137 result := new(SharedStorageServer) 138 url := createUrl(api, sharedStoragePathSegment, st_id, "servers", ser_id) 139 err := api.Client.Get(url, &result, http.StatusOK) 140 if err != nil { 141 return nil, err 142 } 143 return result, nil 144 } 145 146 // DELETE /shared_storages/{id}/servers/{id} 147 func (api *API) DeleteSharedStorageServer(st_id string, ser_id string) (*SharedStorage, error) { 148 result := new(SharedStorage) 149 url := createUrl(api, sharedStoragePathSegment, st_id, "servers", ser_id) 150 err := api.Client.Delete(url, nil, &result, http.StatusAccepted) 151 if err != nil { 152 return nil, err 153 } 154 result.api = api 155 return result, nil 156 } 157 158 // GET /shared_storages/access 159 func (api *API) GetSharedStorageCredentials() ([]SharedStorageAccess, error) { 160 result := []SharedStorageAccess{} 161 url := createUrl(api, sharedStoragePathSegment, "access") 162 err := api.Client.Get(url, &result, http.StatusOK) 163 if err != nil { 164 return nil, err 165 } 166 return result, nil 167 } 168 169 // PUT /shared_storages/access 170 func (api *API) UpdateSharedStorageCredentials(new_pass string) ([]SharedStorageAccess, error) { 171 result := []SharedStorageAccess{} 172 req := struct { 173 Password string `json:"password"` 174 }{new_pass} 175 url := createUrl(api, sharedStoragePathSegment, "access") 176 err := api.Client.Put(url, &req, &result, http.StatusAccepted) 177 if err != nil { 178 return nil, err 179 } 180 return result, nil 181 } 182 183 func (ss *SharedStorage) GetState() (string, error) { 184 in, err := ss.api.GetSharedStorage(ss.Id) 185 if in == nil { 186 return "", err 187 } 188 return in.State, err 189 }