-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from UtkarshBhatthere/replication_network
Add Cluster config management to microceph
- Loading branch information
Showing
20 changed files
with
1,044 additions
and
7 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
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,89 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/canonical/microcluster/rest" | ||
"github.com/canonical/microcluster/state" | ||
"github.com/lxc/lxd/lxd/response" | ||
|
||
"github.com/canonical/microceph/microceph/api/types" | ||
"github.com/canonical/microceph/microceph/ceph" | ||
"github.com/canonical/microceph/microceph/client" | ||
) | ||
|
||
// /1.0/configs endpoint. | ||
var configsCmd = rest.Endpoint{ | ||
Path: "configs", | ||
|
||
Get: rest.EndpointAction{Handler: cmdConfigsGet, ProxyTarget: true}, | ||
Put: rest.EndpointAction{Handler: cmdConfigsPut, ProxyTarget: true}, | ||
Delete: rest.EndpointAction{Handler: cmdConfigsDelete, ProxyTarget: true}, | ||
} | ||
|
||
func cmdConfigsGet(s *state.State, r *http.Request) response.Response { | ||
var err error | ||
var req types.Config | ||
var configs types.Configs | ||
|
||
err = json.NewDecoder(r.Body).Decode(&req) | ||
if err != nil { | ||
return response.InternalError(err) | ||
} | ||
|
||
// If a valid key string is passed, fetch that key. | ||
if len(req.Key) > 0 { | ||
configs, err = ceph.GetConfigItem(req) | ||
} else { | ||
// Fetch all configs. | ||
configs, err = ceph.ListConfigs() | ||
} | ||
if err != nil { | ||
return response.SmartError(err) | ||
} | ||
|
||
return response.SyncResponse(true, configs) | ||
} | ||
|
||
func cmdConfigsPut(s *state.State, r *http.Request) response.Response { | ||
var req types.Config | ||
configTable := ceph.GetConstConfigTable() | ||
|
||
err := json.NewDecoder(r.Body).Decode(&req) | ||
if err != nil { | ||
return response.InternalError(err) | ||
} | ||
|
||
// Configure the key/value | ||
err = ceph.SetConfigItem(req) | ||
if err != nil { | ||
return response.SmartError(err) | ||
} | ||
|
||
services := configTable[req.Key].Daemons | ||
client.ConfigChangeRefresh(s, services, req.Wait) | ||
|
||
return response.EmptySyncResponse | ||
} | ||
|
||
func cmdConfigsDelete(s *state.State, r *http.Request) response.Response { | ||
var req types.Config | ||
configTable := ceph.GetConstConfigTable() | ||
|
||
err := json.NewDecoder(r.Body).Decode(&req) | ||
if err != nil { | ||
return response.InternalError(err) | ||
} | ||
|
||
// Clean the key/value | ||
err = ceph.RemoveConfigItem(req) | ||
if err != nil { | ||
return response.SmartError(err) | ||
} | ||
|
||
services := configTable[req.Key].Daemons | ||
client.ConfigChangeRefresh(s, services, req.Wait) | ||
|
||
return response.EmptySyncResponse | ||
} |
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 |
---|---|---|
|
@@ -11,4 +11,6 @@ var Endpoints = []rest.Endpoint{ | |
resourcesCmd, | ||
servicesCmd, | ||
rgwServiceCmd, | ||
configsCmd, | ||
restartServiceCmd, | ||
} |
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
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,12 @@ | ||
// Package types provides shared types and structs. | ||
package types | ||
|
||
// Configs holds the key value pair | ||
type Config struct { | ||
Key string `json:"key" yaml:"key"` | ||
Value string `json:"value" yaml:"value"` | ||
Wait bool `json:"wait" yaml:"wait"` | ||
} | ||
|
||
// Configs is a slice of configs | ||
type Configs []Config |
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
Oops, something went wrong.