Run and plan automatically sets the region

This commit is contained in:
Alex Dadgar 2016-06-07 11:28:02 -07:00
parent 86e368cdb8
commit a0557e766e
3 changed files with 21 additions and 0 deletions

View File

@ -126,6 +126,11 @@ func NewClient(config *Config) (*Client, error) {
return client, nil
}
// SetRegion sets the region to forward API requests to.
func (c *Client) SetRegion(region string) {
c.config.Region = region
}
// request is used to help build up a request
type request struct {
config *Config

View File

@ -44,6 +44,9 @@ Usage: nomad plan [options] <file>
A structured diff between the local and remote job is displayed to
give insight into what the scheduler will attempt to do and why.
If the job has specified the region, the -region flag and NOMAD_REGION
environment variable are overridden to the job's region.
General Options:
` + generalOptionsUsage() + `
@ -116,6 +119,11 @@ func (c *PlanCommand) Run(args []string) int {
return 1
}
// Force the region to be that of the job.
if r := job.Region; r != "" {
client.SetRegion(r)
}
// Submit the job
resp, _, err := client.Jobs().Plan(apiJob, diff, nil)
if err != nil {

View File

@ -37,6 +37,9 @@ Usage: nomad run [options] <file>
exit code will be 2. Any other errors, including client connection
issues or internal errors, are indicated by exit code 1.
If the job has specified the region, the -region flag and NOMAD_REGION
environment variable are overridden to the job's region.
General Options:
` + generalOptionsUsage() + `
@ -134,6 +137,11 @@ func (c *RunCommand) Run(args []string) int {
return 1
}
// Force the region to be that of the job.
if r := job.Region; r != "" {
client.SetRegion(r)
}
// Submit the job
evalID, _, err := client.Jobs().Register(apiJob, nil)
if err != nil {