Skip to content

Commit

Permalink
Merge pull request #86 from Szubie/host-setup-config-struct
Browse files Browse the repository at this point in the history
Replace map used for host config with a struct
  • Loading branch information
idroz committed Jun 17, 2022
2 parents 5c5f6c4 + abfb746 commit c3e7939
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
11 changes: 6 additions & 5 deletions commands/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func includeInitFlags(cmd *cobra.Command) {
}

func serverInit(cmd *cobra.Command, args []string) {
params := make(map[string]string)
userHome, _ := os.UserHomeDir()

if _, err := os.Stat(path.Join(userHome, ".bravetools")); !os.IsNotExist(err) {
Expand Down Expand Up @@ -70,10 +69,12 @@ func serverInit(cmd *cobra.Command, args []string) {
log.Fatal(err.Error())
}

params["storage"] = storage
params["ram"] = ram
params["network"] = network
params["backend"] = backendType
params := platform.HostConfig{
Storage: storage,
Ram: ram,
Network: network,
Backend: backendType,
}

if hostConfigPath != "" {
// TODO: validate configuration. Now assume that path ends with config.yml
Expand Down
22 changes: 15 additions & 7 deletions platform/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@ func NewBraveHost() *BraveHost {
}
}

type HostConfig struct {
Ram string
Network string
Storage string
Backend string
}

// SetupHostConfiguration creates configuration file and saves it in bravetools directory
func SetupHostConfiguration(params map[string]string, userHome string) {
func SetupHostConfiguration(params HostConfig, userHome string) {
var settings = HostSettings{}
poolSizeInt, _ := strconv.Atoi(params["storage"])
poolSizeInt, _ := strconv.Atoi(params.Storage)
poolSizeInt = poolSizeInt - 2

hostName, err := getCurrentUsername()
Expand All @@ -112,27 +119,28 @@ func SetupHostConfiguration(params map[string]string, userHome string) {
Size: strconv.Itoa(poolSizeInt) + "GB",
},
Network: Network{
Bridge: params["network"],
Bridge: params.Network,
},
Status: "inactive",
}

if params["backend"] == "multipass" {
if params.Backend == "multipass" {

backendSettings := BackendSettings{
Type: "multipass",
Resources: BackendResources{
Name: hostName,
OS: "bionic",
CPU: "2",
RAM: params["ram"],
HD: params["storage"] + "GB",
RAM: params.Ram,
HD: params.Storage + "GB",
IP: "",
},
}
settings.BackendSettings = backendSettings
}

if params["backend"] == "lxd" {
if params.Backend == "lxd" {
backendSettings := BackendSettings{
Type: "lxd",
Resources: BackendResources{
Expand Down

0 comments on commit c3e7939

Please sign in to comment.