From cc80c2442fa5646d0dcf6712de55f88aa1ecad9b Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 7 Jun 2016 11:28:02 -0700 Subject: [PATCH] Run and plan automatically sets the region --- api/api.go | 5 +++++ command/plan.go | 8 ++++++++ command/run.go | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/api/api.go b/api/api.go index 80c03b256..20ff1735f 100644 --- a/api/api.go +++ b/api/api.go @@ -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 diff --git a/command/plan.go b/command/plan.go index 5de76e0aa..b153d1b4b 100644 --- a/command/plan.go +++ b/command/plan.go @@ -44,6 +44,9 @@ Usage: nomad plan [options] 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 { diff --git a/command/run.go b/command/run.go index d557d212f..032f54e68 100644 --- a/command/run.go +++ b/command/run.go @@ -37,6 +37,9 @@ Usage: nomad run [options] 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 {