Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Suggestion] Move defaults into provision package #17

Open
adamjohnson01 opened this issue Dec 31, 2019 · 3 comments
Open

[Suggestion] Move defaults into provision package #17

adamjohnson01 opened this issue Dec 31, 2019 · 3 comments

Comments

@adamjohnson01
Copy link
Contributor

adamjohnson01 commented Dec 31, 2019

@alexellis how would you feel about moving the provisioner defaults into the provision package and removing the additional section? The only config currently in there is for projectID, port and zone. If we make port a constant and add it to provision as well then we only have to add projectID and zone to BasicHost which can be populated if set. This would also require some minor changes to a couple of the provisioners.

Something like this in provision.go

func NewBasicHost(provider, name, region, projectID, zone, userData string) (*BasicHost, error) {
	if _, ok := defaults[provider]; !ok {
		return nil, fmt.Errorf("no provisioner for provider: %q", provider)
	}
	host := &BasicHost{
		Name:      name,
		OS:        defaults[provider].os,
		Plan:      defaults[provider].plan,
		UserData:  userData,
		ProjectID: projectID,
		Zone:      zone,
	}
	if region == "" && len(defaults[provider].region) != 0 {
		host.Region = defaults[provider].region
	}  else {
		host.Region = region
	}
	return host, nil
}

type provisionerDefaults struct {
	os     string
	plan   string
	region string
}

const ControlPort = 8080

var defaults = map[string]provisionerDefaults{
	"digitalocean": {
		os:   "ubuntu-16-04-x64",
		plan: "512mb",
	},
	"packet": {
		os:     "ubuntu_16_04",
		plan:   "t1.small.x86",
		region: "ams1",
	},
	"scaleway": {
		os:     "ubuntu-bionic",
		plan:   "DEV1-S",
		region: "fr-par-1",
	},
	"civo": {
		os:   "811a8dfb-8202-49ad-b1ef-1e6320b20497",
		plan: "g2.small",
	},
	"gce": {
		os:   "projects/debian-cloud/global/images/debian-9-stretch-v20191121",
		plan: "f1-micro",
	},
	"ec2": {
		os:     "ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20191114",
		plan:   "t3.nano",
		region: "eu-west-1",
	},
}

I am happy to do the work for this if you think it is a good idea. No worries if not.

@alexellis
Copy link
Member

I'm still trying to grok this, let me take another look in the new year.

@alexellis alexellis changed the title Move defaults into provision package [Suggestion] Move defaults into provision package Jan 2, 2020
@adamjohnson01
Copy link
Contributor Author

@alexellis, I am happy to create a pull request with the proposed change as it might make more sense as a diff.

@adamjohnson01
Copy link
Contributor Author

@alexellis, I have created a PR to demonstrate what I was suggesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants