@@ -45,6 +45,7 @@ type CSConfig struct {
4545 SSLNoVerify bool `gcfg:"ssl-no-verify"`
4646 ProjectID string `gcfg:"project-id"`
4747 Zone string `gcfg:"zone"`
48+ Region string `gcfg:"region"`
4849 }
4950}
5051
@@ -53,6 +54,7 @@ type CSCloud struct {
5354 client * cloudstack.CloudStackClient
5455 projectID string // If non-"", all resources will be created within this project
5556 zone string
57+ region string
5658}
5759
5860func init () {
@@ -85,6 +87,7 @@ func newCSCloud(cfg *CSConfig) (*CSCloud, error) {
8587 cs := & CSCloud {
8688 projectID : cfg .Global .ProjectID ,
8789 zone : cfg .Global .Zone ,
90+ region : cfg .Global .Region ,
8891 }
8992
9093 if cfg .Global .APIURL != "" && cfg .Global .APIKey != "" && cfg .Global .SecretKey != "" {
@@ -190,7 +193,8 @@ func (cs *CSCloud) GetZone(ctx context.Context) (cloudprovider.Zone, error) {
190193
191194 klog .V (2 ).Infof ("Current zone is %v" , cs .zone )
192195 zone .FailureDomain = cs .zone
193- zone .Region = cs .zone
196+
197+ zone .Region = cs .getRegionFromZone (cs .zone )
194198
195199 return zone , nil
196200}
@@ -212,7 +216,7 @@ func (cs *CSCloud) GetZoneByProviderID(ctx context.Context, providerID string) (
212216
213217 klog .V (2 ).Infof ("Current zone is %v" , cs .zone )
214218 zone .FailureDomain = instance .Zonename
215- zone .Region = instance .Zonename
219+ zone .Region = cs . getRegionFromZone ( instance .Zonename )
216220
217221 return zone , nil
218222}
@@ -234,7 +238,14 @@ func (cs *CSCloud) GetZoneByNodeName(ctx context.Context, nodeName types.NodeNam
234238
235239 klog .V (2 ).Infof ("Current zone is %v" , cs .zone )
236240 zone .FailureDomain = instance .Zonename
237- zone .Region = instance .Zonename
241+ zone .Region = cs . getRegionFromZone ( instance .Zonename )
238242
239243 return zone , nil
240244}
245+
246+ func (cs * CSCloud ) getRegionFromZone (zone string ) string {
247+ if cs .region != "" {
248+ return cs .region
249+ }
250+ return zone
251+ }
0 commit comments